Currently clangDriver passes -femulated-tls and -fno-emulated-tls to cc1.
cc1 forwards the option to LLVMCodeGen and ExplicitEmulatedTLS is used
to decide the value. Simplify this by moving the Clang decision to
clangDriver and moving the LLVM decision to InitTargetOptionsFromCodeGenFlags.
defm emulated_tls : BoolFOption<"emulated-tls",
CodeGenOpts<"EmulatedTLS">, DefaultFalse,
PosFlag<SetTrue, [CC1Option], "Use emutls functions to access thread_local variables">,
- NegFlag<SetFalse>, BothFlags<[CC1Option]>>;
+ NegFlag<SetFalse>>;
def fencoding_EQ : Joined<["-"], "fencoding=">, Group<f_Group>;
def ferror_limit_EQ : Joined<["-"], "ferror-limit=">, Group<f_Group>, Flags<[CoreOption]>;
defm exceptions : BoolFOption<"exceptions",
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;
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
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,
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);
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();
// 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
// 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"
unsigned getTLSSize();
bool getEmulatedTLS();
+std::optional<bool> getExplicitEmulatedTLS();
bool getUniqueSectionNames();
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<JITTargetMachineBuilder> detectHost();
/// Create a TargetMachine.
/// 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;
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) {}
/// 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;
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)
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();
JITTargetMachineBuilder::JITTargetMachineBuilder(Triple TT)
: TT(std::move(TT)) {
Options.EmulatedTLS = true;
- Options.ExplicitEmulatedTLS = true;
Options.UseInitArray = true;
}
Options, RelocModel, CMModel, OptLevel,
/*JIT*/ true);
Target->Options.EmulatedTLS = EmulatedTLS;
- Target->Options.ExplicitEmulatedTLS = true;
assert(Target && "Could not allocate target machine!");
return Target;
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;