diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index eed0d517a1ad7..2abec84271356 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -1590,7 +1590,7 @@ def femit_all_decls : Flag<["-"], "femit-all-decls">, Group, Flags<[CC1 defm emulated_tls : BoolFOption<"emulated-tls", CodeGenOpts<"EmulatedTLS">, DefaultFalse, PosFlag, - NegFlag, BothFlags<[CC1Option]>>; + NegFlag>; def fencoding_EQ : Joined<["-"], "fencoding=">, Group; def ferror_limit_EQ : Joined<["-"], "ferror-limit=">, Group, Flags<[CoreOption]>; defm exceptions : BoolFOption<"exceptions", diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp index e6e058bfc5b86..ea38cc402575a 100644 --- a/clang/lib/CodeGen/BackendUtil.cpp +++ b/clang/lib/CodeGen/BackendUtil.cpp @@ -422,7 +422,6 @@ static bool initTargetOptions(DiagnosticsEngine &Diags, CodeGenOpts.UniqueBasicBlockSectionNames; Options.TLSSize = CodeGenOpts.TLSSize; Options.EmulatedTLS = CodeGenOpts.EmulatedTLS; - Options.ExplicitEmulatedTLS = true; Options.DebuggerTuning = CodeGenOpts.getDebuggerTuning(); Options.EmitStackSizeSection = CodeGenOpts.StackSizeSection; Options.StackUsageOutput = CodeGenOpts.StackUsageOutput; diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp index 56250fccfa855..edea4acfc3abd 100644 --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -6125,10 +6125,12 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, Args.AddLastArg(CmdArgs, options::OPT_femit_all_decls); Args.AddLastArg(CmdArgs, options::OPT_fheinous_gnu_extensions); Args.AddLastArg(CmdArgs, options::OPT_fdigraphs, options::OPT_fno_digraphs); - Args.AddLastArg(CmdArgs, options::OPT_femulated_tls, - options::OPT_fno_emulated_tls); Args.AddLastArg(CmdArgs, options::OPT_fzero_call_used_regs_EQ); + if (Args.hasFlag(options::OPT_femulated_tls, options::OPT_fno_emulated_tls, + Triple.hasDefaultEmulatedTLS())) + CmdArgs.push_back("-femulated-tls"); + if (Arg *A = Args.getLastArg(options::OPT_fzero_call_used_regs_EQ)) { // FIXME: There's no reason for this to be restricted to X86. The backend // code needs to be changed to include the appropriate function calls diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp b/clang/lib/Driver/ToolChains/CommonArgs.cpp index 2f3450432ba25..315cf6325d396 100644 --- a/clang/lib/Driver/ToolChains/CommonArgs.cpp +++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp @@ -764,11 +764,10 @@ void tools::addLTOOptions(const ToolChain &ToolChain, const ArgList &Args, D.Diag(clang::diag::warn_drv_fjmc_for_elf_only); } - if (Arg *A = Args.getLastArg(options::OPT_femulated_tls, - options::OPT_fno_emulated_tls)) { - bool Enable = A->getOption().getID() == options::OPT_femulated_tls; - CmdArgs.push_back(Args.MakeArgString( - Twine(PluginOptPrefix) + "-emulated-tls=" + (Enable ? "1" : "0"))); + if (Args.hasFlag(options::OPT_femulated_tls, options::OPT_fno_emulated_tls, + ToolChain.getTriple().hasDefaultEmulatedTLS())) { + CmdArgs.push_back( + Args.MakeArgString(Twine(PluginOptPrefix) + "-emulated-tls")); } if (Args.hasFlag(options::OPT_fstack_size_section, diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp index 1ecf116848195..cb29049d5a3dd 100644 --- a/clang/lib/Frontend/CompilerInvocation.cpp +++ b/clang/lib/Frontend/CompilerInvocation.cpp @@ -1536,8 +1536,8 @@ void CompilerInvocation::GenerateCodeGenArgs( F.Filename, SA); } - GenerateArg( - Args, Opts.EmulatedTLS ? OPT_femulated_tls : OPT_fno_emulated_tls, SA); + if (Opts.EmulatedTLS) + GenerateArg(Args, OPT_femulated_tls, SA); if (Opts.FPDenormalMode != llvm::DenormalMode::getIEEE()) GenerateArg(Args, OPT_fdenormal_fp_math_EQ, Opts.FPDenormalMode.str(), SA); @@ -1890,11 +1890,6 @@ bool CompilerInvocation::ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args, Opts.LinkBitcodeFiles.push_back(F); } - if (!Args.getLastArg(OPT_femulated_tls) && - !Args.getLastArg(OPT_fno_emulated_tls)) { - Opts.EmulatedTLS = T.hasDefaultEmulatedTLS(); - } - if (Arg *A = Args.getLastArg(OPT_ftlsmodel_EQ)) { if (T.isOSAIX()) { StringRef Name = A->getValue(); diff --git a/clang/test/Driver/emulated-tls.cpp b/clang/test/Driver/emulated-tls.cpp index edc68e0f29f59..2044bc89a3663 100644 --- a/clang/test/Driver/emulated-tls.cpp +++ b/clang/test/Driver/emulated-tls.cpp @@ -1,15 +1,15 @@ // Android, Cygwin and OpenBSD use emutls by default. -// Clang should pass -femulated-tls or -fno-emulated-tls to cc1 if they are used, -// and cc1 should set up EmulatedTLS and ExplicitEmulatedTLS to LLVM CodeGen. +// Clang should pass -femulated-tls to cc1 if they are used, +// and cc1 should set up EmulatedTLS to LLVM CodeGen. // -// RUN: %clang -### -target arm-linux-androideabi %s 2>&1 \ -// RUN: | FileCheck -check-prefix=DEFAULT %s -// RUN: %clang -### -target arm-linux-gnu %s 2>&1 \ -// RUN: | FileCheck -check-prefix=DEFAULT %s -// RUN: %clang -### -target i686-pc-cygwin %s 2>&1 \ -// RUN: | FileCheck -check-prefix=DEFAULT %s -// RUN: %clang -### -target i686-pc-openbsd %s 2>&1 \ -// RUN: | FileCheck -check-prefix=DEFAULT %s +// RUN: %clang -### --target=arm-linux-androideabi %s 2>&1 \ +// RUN: | FileCheck -check-prefix=EMU %s +// RUN: %clang -### --target=arm-linux-gnu %s 2>&1 \ +// RUN: | FileCheck -check-prefix=NOEMU %s +// RUN: %clang -### --target=i686-pc-cygwin %s 2>&1 \ +// RUN: | FileCheck -check-prefix=EMU %s +// RUN: %clang -### --target=i686-pc-openbsd %s 2>&1 \ +// RUN: | FileCheck -check-prefix=EMU %s // RUN: %clang -### -target arm-linux-androideabi -fno-emulated-tls -femulated-tls %s 2>&1 \ // RUN: | FileCheck -check-prefix=EMU %s @@ -42,18 +42,14 @@ // Default without -f[no-]emulated-tls, will be decided by the target triple. // DEFAULT-NOT: "-cc1" {{.*}}"-femulated-tls" -// DEFAULT-NOT: "-cc1" {{.*}}"-fno-emulated-tls" -// Explicit and last -f[no-]emulated-tls flag will be passed to cc1. -// EMU: "-cc1" {{.*}}"-femulated-tls" -// EMU-NOT: "-cc1" {{.*}}"-fno-emulated-tls" +// EMU: "-cc1" +// EMU-SAME: "-femulated-tls" -// NOEMU: "-cc1" {{.*}}"-fno-emulated-tls" -// NOEMU-NOT: "-cc1" {{.*}}"-femulated-tls" +// NOEMU: "-cc1" +// NOEMU-NOT: "-femulated-tls" // LTO related checks -// LTO_NOEMUTLS: plugin-opt=-emulated-tls=0 -// LTO_NOEMUTLS-NOT: plugin-opt=-emulated-tls=1 +// LTO_NOEMUTLS-NOT: "-plugin-opt=-emulated-tls" -// LTO_EMUTLS: plugin-opt=-emulated-tls=1 -// LTO_EMUTLS-NOT: plugin-opt=-emulated-tls=0 +// LTO_EMUTLS: "-plugin-opt=-emulated-tls" diff --git a/llvm/include/llvm/CodeGen/CommandFlags.h b/llvm/include/llvm/CodeGen/CommandFlags.h index 19b466629dbfc..ff7f1ba673b2e 100644 --- a/llvm/include/llvm/CodeGen/CommandFlags.h +++ b/llvm/include/llvm/CodeGen/CommandFlags.h @@ -111,6 +111,7 @@ std::string getBBSections(); unsigned getTLSSize(); bool getEmulatedTLS(); +std::optional getExplicitEmulatedTLS(); bool getUniqueSectionNames(); diff --git a/llvm/include/llvm/ExecutionEngine/Orc/JITTargetMachineBuilder.h b/llvm/include/llvm/ExecutionEngine/Orc/JITTargetMachineBuilder.h index 39e34e5162ee2..85751142dfb30 100644 --- a/llvm/include/llvm/ExecutionEngine/Orc/JITTargetMachineBuilder.h +++ b/llvm/include/llvm/ExecutionEngine/Orc/JITTargetMachineBuilder.h @@ -38,18 +38,16 @@ class JITTargetMachineBuilder { public: /// Create a JITTargetMachineBuilder based on the given triple. /// - /// Note: TargetOptions is default-constructed, then EmulatedTLS and - /// ExplicitEmulatedTLS are set to true. If EmulatedTLS is not - /// required, these values should be reset before calling - /// createTargetMachine. + /// Note: TargetOptions is default-constructed, then EmulatedTLS is set to + /// true. If EmulatedTLS is not required, these values should be reset before + /// calling createTargetMachine. JITTargetMachineBuilder(Triple TT); /// Create a JITTargetMachineBuilder for the host system. /// - /// Note: TargetOptions is default-constructed, then EmulatedTLS and - /// ExplicitEmulatedTLS are set to true. If EmulatedTLS is not - /// required, these values should be reset before calling - /// createTargetMachine. + /// Note: TargetOptions is default-constructed, then EmulatedTLS is set to + /// true. If EmulatedTLS is not required, these values should be reset before + /// calling createTargetMachine. static Expected detectHost(); /// Create a TargetMachine. @@ -125,9 +123,9 @@ class JITTargetMachineBuilder { /// Set TargetOptions. /// /// Note: This operation will overwrite any previously configured options, - /// including EmulatedTLS, ExplicitEmulatedTLS, and UseInitArray which - /// the JITTargetMachineBuilder sets by default. Clients are responsible - /// for re-enabling these overwritten options. + /// including EmulatedTLS and UseInitArray which the JITTargetMachineBuilder + /// sets by default. Clients are responsible for re-enabling these overwritten + /// options. JITTargetMachineBuilder &setOptions(TargetOptions Options) { this->Options = std::move(Options); return *this; diff --git a/llvm/include/llvm/Target/TargetOptions.h b/llvm/include/llvm/Target/TargetOptions.h index 76e4248088afd..5a04a7d5178cb 100644 --- a/llvm/include/llvm/Target/TargetOptions.h +++ b/llvm/include/llvm/Target/TargetOptions.h @@ -135,14 +135,14 @@ namespace llvm { IgnoreXCOFFVisibility(false), XCOFFTracebackTable(true), UniqueSectionNames(true), UniqueBasicBlockSectionNames(false), TrapUnreachable(false), NoTrapAfterNoreturn(false), TLSSize(0), - EmulatedTLS(false), ExplicitEmulatedTLS(false), EnableIPRA(false), - EmitStackSizeSection(false), EnableMachineOutliner(false), - EnableMachineFunctionSplitter(false), SupportsDefaultOutlining(false), - EmitAddrsig(false), EmitCallSiteInfo(false), - SupportsDebugEntryValues(false), EnableDebugEntryValues(false), - ValueTrackingVariableLocations(false), ForceDwarfFrameSection(false), - XRayOmitFunctionIndex(false), DebugStrictDwarf(false), - Hotpatch(false), PPCGenScalarMASSEntries(false), JMCInstrument(false), + EmulatedTLS(false), EnableIPRA(false), EmitStackSizeSection(false), + EnableMachineOutliner(false), EnableMachineFunctionSplitter(false), + SupportsDefaultOutlining(false), EmitAddrsig(false), + EmitCallSiteInfo(false), SupportsDebugEntryValues(false), + EnableDebugEntryValues(false), ValueTrackingVariableLocations(false), + ForceDwarfFrameSection(false), XRayOmitFunctionIndex(false), + DebugStrictDwarf(false), Hotpatch(false), + PPCGenScalarMASSEntries(false), JMCInstrument(false), EnableCFIFixup(false), MisExpect(false), XCOFFReadOnlyPointers(false), FPDenormalMode(DenormalMode::IEEE, DenormalMode::IEEE) {} @@ -285,9 +285,6 @@ namespace llvm { /// function in the runtime library.. unsigned EmulatedTLS : 1; - /// Whether -emulated-tls or -no-emulated-tls is set. - unsigned ExplicitEmulatedTLS : 1; - /// This flag enables InterProcedural Register Allocation (IPRA). unsigned EnableIPRA : 1; diff --git a/llvm/lib/CodeGen/CommandFlags.cpp b/llvm/lib/CodeGen/CommandFlags.cpp index c58547d917b05..6dafe23955c62 100644 --- a/llvm/lib/CodeGen/CommandFlags.cpp +++ b/llvm/lib/CodeGen/CommandFlags.cpp @@ -88,7 +88,7 @@ CGOPT(bool, IgnoreXCOFFVisibility) CGOPT(bool, XCOFFTracebackTable) CGOPT(std::string, BBSections) CGOPT(unsigned, TLSSize) -CGOPT(bool, EmulatedTLS) +CGOPT_EXP(bool, EmulatedTLS) CGOPT(bool, UniqueSectionNames) CGOPT(bool, UniqueBasicBlockSectionNames) CGOPT(EABI, EABIVersion) @@ -549,8 +549,8 @@ codegen::InitTargetOptionsFromCodeGenFlags(const Triple &TheTriple) { Options.UniqueSectionNames = getUniqueSectionNames(); Options.UniqueBasicBlockSectionNames = getUniqueBasicBlockSectionNames(); Options.TLSSize = getTLSSize(); - Options.EmulatedTLS = getEmulatedTLS(); - Options.ExplicitEmulatedTLS = EmulatedTLSView->getNumOccurrences() > 0; + Options.EmulatedTLS = + getExplicitEmulatedTLS().value_or(TheTriple.hasDefaultEmulatedTLS()); Options.ExceptionModel = getExceptionModel(); Options.EmitStackSizeSection = getEnableStackSizeSection(); Options.EnableMachineFunctionSplitter = getEnableMachineFunctionSplitter(); diff --git a/llvm/lib/ExecutionEngine/Orc/JITTargetMachineBuilder.cpp b/llvm/lib/ExecutionEngine/Orc/JITTargetMachineBuilder.cpp index 27299aa5f8936..d0fc364280f0d 100644 --- a/llvm/lib/ExecutionEngine/Orc/JITTargetMachineBuilder.cpp +++ b/llvm/lib/ExecutionEngine/Orc/JITTargetMachineBuilder.cpp @@ -18,7 +18,6 @@ namespace orc { JITTargetMachineBuilder::JITTargetMachineBuilder(Triple TT) : TT(std::move(TT)) { Options.EmulatedTLS = true; - Options.ExplicitEmulatedTLS = true; Options.UseInitArray = true; } diff --git a/llvm/lib/ExecutionEngine/TargetSelect.cpp b/llvm/lib/ExecutionEngine/TargetSelect.cpp index 5ba02d6c53778..b739837aa5926 100644 --- a/llvm/lib/ExecutionEngine/TargetSelect.cpp +++ b/llvm/lib/ExecutionEngine/TargetSelect.cpp @@ -89,7 +89,6 @@ TargetMachine *EngineBuilder::selectTarget(const Triple &TargetTriple, Options, RelocModel, CMModel, OptLevel, /*JIT*/ true); Target->Options.EmulatedTLS = EmulatedTLS; - Target->Options.ExplicitEmulatedTLS = true; assert(Target && "Could not allocate target machine!"); return Target; diff --git a/llvm/lib/Target/TargetMachine.cpp b/llvm/lib/Target/TargetMachine.cpp index 8d1ad617889c9..2fbd1401da8ce 100644 --- a/llvm/lib/Target/TargetMachine.cpp +++ b/llvm/lib/Target/TargetMachine.cpp @@ -143,13 +143,7 @@ bool TargetMachine::shouldAssumeDSOLocal(const Module &M, return false; } -bool TargetMachine::useEmulatedTLS() const { - // Returns Options.EmulatedTLS if the -emulated-tls or -no-emulated-tls - // was specified explicitly; otherwise uses target triple to decide default. - if (Options.ExplicitEmulatedTLS) - return Options.EmulatedTLS; - return getTargetTriple().hasDefaultEmulatedTLS(); -} +bool TargetMachine::useEmulatedTLS() const { return Options.EmulatedTLS; } TLSModel::Model TargetMachine::getTLSModel(const GlobalValue *GV) const { bool IsPIE = GV->getParent()->getPIELevel() != PIELevel::Default;