mirror of
https://github.com/intel/llvm.git
synced 2026-01-19 09:31:59 +08:00
Remove ExplicitEmulatedTLS and simplify -femulated-tls handling
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.
This commit is contained in:
@@ -1590,7 +1590,7 @@ def femit_all_decls : Flag<["-"], "femit-all-decls">, Group<f_Group>, Flags<[CC1
|
||||
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",
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -111,6 +111,7 @@ std::string getBBSections();
|
||||
unsigned getTLSSize();
|
||||
|
||||
bool getEmulatedTLS();
|
||||
std::optional<bool> getExplicitEmulatedTLS();
|
||||
|
||||
bool getUniqueSectionNames();
|
||||
|
||||
|
||||
@@ -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<JITTargetMachineBuilder> detectHost();
|
||||
|
||||
/// Create a TargetMachine.
|
||||
@@ -125,9 +123,9 @@ public:
|
||||
/// 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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -18,7 +18,6 @@ namespace orc {
|
||||
JITTargetMachineBuilder::JITTargetMachineBuilder(Triple TT)
|
||||
: TT(std::move(TT)) {
|
||||
Options.EmulatedTLS = true;
|
||||
Options.ExplicitEmulatedTLS = true;
|
||||
Options.UseInitArray = true;
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user