[clang] [lld] [llvm] [CodeGen][MC] Pass a LibraryOptionsContext to the MC option readers. NFC (PR #239919)
Fangrui Song via cfe-commits
cfe-commits at lists.llvm.org
Fri Nov 6 23:52:53 PST 2026
https://github.com/MaskRay created https://github.com/llvm/llvm-project/pull/239919
Rename `InitMCTargetOptionsFromFlags` to `getMCTargetOptions` and
`InitTargetOptionsFromCodeGenFlags` to `getTargetOptions`. Most of these
options take values, so "Flags" is a misnomer.
These functions and `getABIName` now take the `LibraryOptionsContext` to read
from. A per-context option declared in TableGen has no global value.
LLM-aided
---
<sub>Stack created with <a href="https://github.com/github/gh-stack">GitHub Stacks CLI</a> • <a href="https://gh.io/stacks-feedback">Give Feedback 💬</a></sub>
>From 41be203f259b71a16d86596d512a7f94fc62a73d Mon Sep 17 00:00:00 2001
From: Fangrui Song <i at maskray.me>
Date: Fri, 6 Nov 2026 11:16:36 -0800
Subject: [PATCH] [CodeGen][MC] Pass a LibraryOptionsContext to the MC option
readers. NFC
Rename `InitMCTargetOptionsFromFlags` to `getMCTargetOptions` and
`InitTargetOptionsFromCodeGenFlags` to `getTargetOptions`. Most of these
options take values, so "Flags" is a misnomer.
These functions and `getABIName` now take the `LibraryOptionsContext` to read
from. A per-context option declared in TableGen has no global value.
LLM-aided
---
.../clang-fuzzer/handle-llvm/handle_llvm.cpp | 4 ++--
.../ClangLinkerWrapper.cpp | 22 +++++++++++--------
.../ClangNVLinkWrapper.cpp | 2 +-
lld/COFF/LTO.cpp | 2 +-
lld/Common/TargetOptionsCommandFlags.cpp | 5 +++--
lld/ELF/LTO.cpp | 2 +-
lld/MachO/LTO.cpp | 2 +-
.../lld/Common/TargetOptionsCommandFlags.h | 3 ++-
lld/wasm/LTO.cpp | 2 +-
llvm/include/llvm-c/lto.h | 2 +-
llvm/include/llvm/CodeGen/CommandFlags.h | 5 +++--
.../llvm/MC/MCTargetOptionsCommandFlags.h | 8 +++++--
llvm/lib/CodeGen/CommandFlags.cpp | 11 +++++-----
llvm/lib/MC/MCTargetOptionsCommandFlags.cpp | 12 +++++++---
llvm/lib/Target/SPIRV/SPIRVAPI.cpp | 2 +-
llvm/tools/gold/gold-plugin.cpp | 2 +-
llvm/tools/llc/lib/llcdriver.cpp | 2 +-
llvm/tools/lli/lli.cpp | 2 +-
llvm/tools/llvm-lto/llvm-lto.cpp | 8 +++----
llvm/tools/llvm-lto2/llvm-lto2.cpp | 2 +-
llvm/tools/llvm-mc/llvm-mc.cpp | 2 +-
llvm/tools/llvm-mca/llvm-mca.cpp | 2 +-
llvm/tools/lto/lto.cpp | 19 ++++++++--------
llvm/tools/opt/optdriver.cpp | 7 +++---
offload/plugins-nextgen/common/src/JIT.cpp | 3 ++-
25 files changed, 77 insertions(+), 56 deletions(-)
diff --git a/clang/tools/clang-fuzzer/handle-llvm/handle_llvm.cpp b/clang/tools/clang-fuzzer/handle-llvm/handle_llvm.cpp
index a35f11ab4619e7..10b973fa8308f1 100644
--- a/clang/tools/clang-fuzzer/handle-llvm/handle_llvm.cpp
+++ b/clang/tools/clang-fuzzer/handle-llvm/handle_llvm.cpp
@@ -122,7 +122,7 @@ static std::string OptLLVM(const std::string &IR, CodeGenOptLevel OLvl) {
Triple ModuleTriple(M->getTargetTriple());
const TargetOptions Options =
- codegen::InitTargetOptionsFromCodeGenFlags(ModuleTriple);
+ codegen::getTargetOptions(Context.getLibraryOptions(), ModuleTriple);
std::string E;
const Target *TheTarget =
TargetRegistry::lookupTarget(codegen::getMArch(), ModuleTriple, E);
@@ -179,7 +179,7 @@ static void CreateAndRunJITFunc(const std::string &IR, CodeGenOptLevel OLvl) {
builder.setMCJITMemoryManager(std::make_unique<SectionMemoryManager>());
builder.setOptLevel(OLvl);
builder.setTargetOptions(
- codegen::InitTargetOptionsFromCodeGenFlags(ModuleTriple));
+ codegen::getTargetOptions(Context.getLibraryOptions(), ModuleTriple));
std::unique_ptr<ExecutionEngine> EE(builder.create());
if (!EE)
diff --git a/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp b/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
index 9f3976949d3f6b..1024d5e6e1a6c8 100644
--- a/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
+++ b/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
@@ -681,15 +681,16 @@ Expected<StringRef> writeOffloadFile(const OffloadFile &File) {
// Compile the module to an object file using the appropriate target machine for
// the host triple.
-Expected<StringRef> compileModule(Module &M, OffloadKind Kind) {
+Expected<StringRef>
+compileModule(const cl::LibraryOptionsContext &LibraryOptions, Module &M,
+ OffloadKind Kind) {
llvm::TimeTraceScope TimeScope("Compile module");
std::string Msg;
const Target *T = TargetRegistry::lookupTarget(M.getTargetTriple(), Msg);
if (!T)
return createStringError(Msg);
- auto Options =
- codegen::InitTargetOptionsFromCodeGenFlags(M.getTargetTriple());
+ auto Options = codegen::getTargetOptions(LibraryOptions, M.getTargetTriple());
StringRef CPU = "";
StringRef Features = "";
std::unique_ptr<TargetMachine> TM(
@@ -781,7 +782,8 @@ wrapDeviceImagesVerbose(ArrayRef<std::unique_ptr<MemoryBuffer>> Buffers,
/// Creates the object file containing the device image and runtime
/// registration code from the device images stored in \p Images.
Expected<StringRef>
-wrapDeviceImages(ArrayRef<std::unique_ptr<MemoryBuffer>> Buffers,
+wrapDeviceImages(const cl::LibraryOptionsContext &LibraryOptions,
+ ArrayRef<std::unique_ptr<MemoryBuffer>> Buffers,
const ArgList &Args, OffloadKind Kind) {
llvm::TimeTraceScope TimeScope("Wrap bundled images");
@@ -847,7 +849,7 @@ wrapDeviceImages(ArrayRef<std::unique_ptr<MemoryBuffer>> Buffers,
WriteBitcodeToFile(M, OS);
}
- auto FileOrErr = compileModule(M, Kind);
+ auto FileOrErr = compileModule(LibraryOptions, M, Kind);
if (!FileOrErr)
return FileOrErr.takeError();
return *FileOrErr;
@@ -1094,7 +1096,8 @@ Error handleOverrideImages(
/// be registered by the runtime. If NeedsWrapping is false, writes bundled
/// output directly without wrapping or host linking.
Expected<SmallVector<StringRef>>
-linkAndWrapDeviceFiles(ArrayRef<SmallVector<OffloadFile>> LinkerInputFiles,
+linkAndWrapDeviceFiles(const cl::LibraryOptionsContext &LibraryOptions,
+ ArrayRef<SmallVector<OffloadFile>> LinkerInputFiles,
const InputArgList &Args, char **Argv, int Argc,
bool NeedsWrapping) {
llvm::TimeTraceScope TimeScope("Handle all device input");
@@ -1226,7 +1229,8 @@ linkAndWrapDeviceFiles(ArrayRef<SmallVector<OffloadFile>> LinkerInputFiles,
continue;
}
- auto OutputOrErr = wrapDeviceImages(*BundledImagesOrErr, Args, WrapperKind);
+ auto OutputOrErr = wrapDeviceImages(LibraryOptions, *BundledImagesOrErr,
+ Args, WrapperKind);
if (!OutputOrErr)
return OutputOrErr.takeError();
WrappedOutput.push_back(*OutputOrErr);
@@ -1610,8 +1614,8 @@ int main(int Argc, char **Argv) {
// Link and process the device images. The function may emit a direct fat
// binary if --emit-fatbin-only is specified.
- auto FilesOrErr = linkAndWrapDeviceFiles(*DeviceInputFiles, Args, Argv,
- Argc, !EmitFatbinOnly);
+ auto FilesOrErr = linkAndWrapDeviceFiles(LibraryOptions, *DeviceInputFiles,
+ Args, Argv, Argc, !EmitFatbinOnly);
if (!FilesOrErr)
reportError(FilesOrErr.takeError());
diff --git a/clang/tools/clang-nvlink-wrapper/ClangNVLinkWrapper.cpp b/clang/tools/clang-nvlink-wrapper/ClangNVLinkWrapper.cpp
index 7bd9b007c74087..9b134b004953ca 100644
--- a/clang/tools/clang-nvlink-wrapper/ClangNVLinkWrapper.cpp
+++ b/clang/tools/clang-nvlink-wrapper/ClangNVLinkWrapper.cpp
@@ -387,7 +387,7 @@ createLTO(const cl::LibraryOptionsContext &LibraryOptions,
lto::createInProcessThinBackend(heavyweight_hardware_concurrency(Jobs));
Conf.CPU = Args.getLastArgValue(OPT_arch);
- Conf.Options = codegen::InitTargetOptionsFromCodeGenFlags(Triple);
+ Conf.Options = codegen::getTargetOptions(LibraryOptions, Triple);
Conf.RemarksFilename =
Args.getLastArgValue(OPT_opt_remarks_filename, RemarksFilename);
diff --git a/lld/COFF/LTO.cpp b/lld/COFF/LTO.cpp
index ed22a2f8206395..5e3d8d4b396f93 100644
--- a/lld/COFF/LTO.cpp
+++ b/lld/COFF/LTO.cpp
@@ -57,7 +57,7 @@ std::string BitcodeCompiler::getThinLTOOutputFile(StringRef path) {
lto::Config BitcodeCompiler::createConfig() {
lto::Config c;
c.LibraryOptions = &ctx.config.libraryOptions;
- c.Options = initTargetOptionsFromCodeGenFlags();
+ c.Options = getTargetOptions(ctx.config.libraryOptions);
c.Options.EmitAddrsig = true;
for (StringRef C : ctx.config.mllvmOpts)
c.MllvmArgs.emplace_back(C.str());
diff --git a/lld/Common/TargetOptionsCommandFlags.cpp b/lld/Common/TargetOptionsCommandFlags.cpp
index 0860e8ff8ef8e1..180e8c98e1037b 100644
--- a/lld/Common/TargetOptionsCommandFlags.cpp
+++ b/lld/Common/TargetOptionsCommandFlags.cpp
@@ -12,8 +12,9 @@
#include "llvm/TargetParser/Triple.h"
#include <optional>
-llvm::TargetOptions lld::initTargetOptionsFromCodeGenFlags() {
- return llvm::codegen::InitTargetOptionsFromCodeGenFlags(llvm::Triple());
+llvm::TargetOptions
+lld::getTargetOptions(const llvm::cl::LibraryOptionsContext &libraryOptions) {
+ return llvm::codegen::getTargetOptions(libraryOptions, llvm::Triple());
}
std::optional<llvm::Reloc::Model> lld::getRelocModelFromCMModel() {
diff --git a/lld/ELF/LTO.cpp b/lld/ELF/LTO.cpp
index 7666e2bbb84094..a3e6fbfb814f11 100644
--- a/lld/ELF/LTO.cpp
+++ b/lld/ELF/LTO.cpp
@@ -58,7 +58,7 @@ static lto::Config createConfig(Ctx &ctx) {
c.LibraryOptions = &ctx.arg.libraryOptions;
// LLD supports the new relocations and address-significance tables.
- c.Options = initTargetOptionsFromCodeGenFlags();
+ c.Options = getTargetOptions(ctx.arg.libraryOptions);
c.Options.EmitAddrsig = true;
for (StringRef C : ctx.arg.mllvmOpts)
c.MllvmArgs.emplace_back(C.str());
diff --git a/lld/MachO/LTO.cpp b/lld/MachO/LTO.cpp
index d54a74e108e05f..ccdd1a39ffb534 100644
--- a/lld/MachO/LTO.cpp
+++ b/lld/MachO/LTO.cpp
@@ -39,7 +39,7 @@ static std::string getThinLTOOutputFile(StringRef modulePath) {
static lto::Config createConfig() {
lto::Config c;
c.LibraryOptions = &config->libraryOptions;
- c.Options = initTargetOptionsFromCodeGenFlags();
+ c.Options = getTargetOptions(config->libraryOptions);
c.Options.EmitAddrsig = config->icfLevel == ICFLevel::safe ||
config->icfLevel == ICFLevel::safe_thunks;
for (StringRef C : config->mllvmOpts)
diff --git a/lld/include/lld/Common/TargetOptionsCommandFlags.h b/lld/include/lld/Common/TargetOptionsCommandFlags.h
index 9bc22d441e1836..92334bb3ba4ff3 100644
--- a/lld/include/lld/Common/TargetOptionsCommandFlags.h
+++ b/lld/include/lld/Common/TargetOptionsCommandFlags.h
@@ -18,7 +18,8 @@
#include <optional>
namespace lld {
-llvm::TargetOptions initTargetOptionsFromCodeGenFlags();
+llvm::TargetOptions
+getTargetOptions(const llvm::cl::LibraryOptionsContext &libraryOptions);
std::optional<llvm::Reloc::Model> getRelocModelFromCMModel();
std::optional<llvm::CodeModel::Model> getCodeModelFromCMModel();
std::string getCPUStr();
diff --git a/lld/wasm/LTO.cpp b/lld/wasm/LTO.cpp
index 774908babc84de..1a88c175ac939d 100644
--- a/lld/wasm/LTO.cpp
+++ b/lld/wasm/LTO.cpp
@@ -43,7 +43,7 @@ static std::string getThinLTOOutputFile(StringRef modulePath) {
static lto::Config createConfig() {
lto::Config c;
c.LibraryOptions = &ctx.arg.libraryOptions;
- c.Options = initTargetOptionsFromCodeGenFlags();
+ c.Options = getTargetOptions(ctx.arg.libraryOptions);
// Always emit a section per function/data with LTO.
c.Options.FunctionSections = true;
diff --git a/llvm/include/llvm-c/lto.h b/llvm/include/llvm-c/lto.h
index 09bdba5d299a0c..a776f715fb5b47 100644
--- a/llvm/include/llvm-c/lto.h
+++ b/llvm/include/llvm-c/lto.h
@@ -539,7 +539,7 @@ LLVM_C_ABI extern unsigned int lto_api_version(void);
/**
* Parses options immediately, making them available as early as possible. For
- * example during executing codegen::InitTargetOptionsFromCodeGenFlags. Since
+ * example during executing codegen::getTargetOptions. Since
* parsing shud only happen once, only one of lto_codegen_debug_options or
* lto_set_debug_options should be called.
*
diff --git a/llvm/include/llvm/CodeGen/CommandFlags.h b/llvm/include/llvm/CodeGen/CommandFlags.h
index cbaffbba98eaef..2c343fe95226d0 100644
--- a/llvm/include/llvm/CodeGen/CommandFlags.h
+++ b/llvm/include/llvm/CodeGen/CommandFlags.h
@@ -161,13 +161,14 @@ LLVM_ABI llvm::BasicBlockSection
getBBSectionsMode(llvm::TargetOptions &Options);
/// Common utility function tightly tied to the options listed here. Initializes
-/// a TargetOptions object with CodeGen flags and returns it.
+/// a TargetOptions object with CodeGen options and returns it.
/// \p TheTriple is used to determine the default value for options if
/// options are not explicitly specified. If those triple dependant options
/// value do not have effect for your component, a default Triple() could be
/// passed in.
LLVM_ABI TargetOptions
-InitTargetOptionsFromCodeGenFlags(const llvm::Triple &TheTriple);
+getTargetOptions(const cl::LibraryOptionsContext &LibraryOptions,
+ const llvm::Triple &TheTriple);
LLVM_ABI std::string getCPUStr();
diff --git a/llvm/include/llvm/MC/MCTargetOptionsCommandFlags.h b/llvm/include/llvm/MC/MCTargetOptionsCommandFlags.h
index 136eb2567678dc..34fe189255ff54 100644
--- a/llvm/include/llvm/MC/MCTargetOptionsCommandFlags.h
+++ b/llvm/include/llvm/MC/MCTargetOptionsCommandFlags.h
@@ -25,6 +25,10 @@ enum class RelocSectionSymType;
enum class EmitDwarfUnwindType;
class StringRef;
+namespace cl {
+class LibraryOptionsContext;
+}
+
namespace mc {
LLVM_ABI bool getRelaxAll();
@@ -70,7 +74,7 @@ LLVM_ABI RelocSectionSymType getRelocSectionSym();
LLVM_ABI bool getLargeEHEncoding();
-LLVM_ABI StringRef getABIName();
+LLVM_ABI StringRef getABIName(const cl::LibraryOptionsContext &C);
LLVM_ABI StringRef getAsSecureLogFile();
@@ -80,7 +84,7 @@ struct RegisterMCTargetOptionsFlags {
LLVM_ABI RegisterMCTargetOptionsFlags();
};
-LLVM_ABI MCTargetOptions InitMCTargetOptionsFromFlags();
+LLVM_ABI MCTargetOptions getMCTargetOptions(const cl::LibraryOptionsContext &C);
} // namespace mc
diff --git a/llvm/lib/CodeGen/CommandFlags.cpp b/llvm/lib/CodeGen/CommandFlags.cpp
index a780abce7e5bb5..cb352f15d9ef9a 100644
--- a/llvm/lib/CodeGen/CommandFlags.cpp
+++ b/llvm/lib/CodeGen/CommandFlags.cpp
@@ -516,9 +516,10 @@ codegen::getBBSectionsMode(llvm::TargetOptions &Options) {
}
// Common utility function tightly tied to the options listed here. Initializes
-// a TargetOptions object with CodeGen flags and returns it.
+// a TargetOptions object with CodeGen options and returns it.
TargetOptions
-codegen::InitTargetOptionsFromCodeGenFlags(const Triple &TheTriple) {
+codegen::getTargetOptions(const cl::LibraryOptionsContext &LibraryOptions,
+ const Triple &TheTriple) {
TargetOptions Options;
Options.NoZerosInBSS = getDontPlaceZerosInBSS();
Options.GuaranteedTailCallOpt = getEnableGuaranteedTailCallOpt();
@@ -553,7 +554,7 @@ codegen::InitTargetOptionsFromCodeGenFlags(const Triple &TheTriple) {
Options.JMCInstrument = getJMCInstrument();
Options.XCOFFReadOnlyPointers = getXCOFFReadOnlyPointers();
- Options.MCOptions = mc::InitMCTargetOptionsFromFlags();
+ Options.MCOptions = mc::getMCTargetOptions(LibraryOptions);
Options.DebuggerTuning = getDebuggerTuningOpt();
Options.SwiftAsyncFramePointer = getSwiftAsyncFramePointer();
@@ -741,7 +742,7 @@ void codegen::setFunctionAttributes(Module &M, StringRef CPU,
//
// FIXME: verifyOptionsConsistency validates consistency for target-abi. We
// should consistently handle all ABI module flags either here or there.
- StringRef ABIName = mc::getABIName();
+ StringRef ABIName = mc::getABIName(M.getContext().getLibraryOptions());
if (!ABIName.empty() && !M.getModuleFlag("target-abi")) {
M.addModuleFlag(Module::Error, "target-abi",
MDString::get(M.getContext(), ABIName));
@@ -761,7 +762,7 @@ Expected<std::unique_ptr<TargetMachine>> codegen::createTargetMachineForTriple(
TargetRegistry::lookupTarget(codegen::getMArch(), TheTriple, Error);
if (!TheTarget)
return createStringError(inconvertibleErrorCode(), Error);
- TargetOptions Options = codegen::InitTargetOptionsFromCodeGenFlags(TheTriple);
+ TargetOptions Options = codegen::getTargetOptions(LibraryOptions, TheTriple);
Options.MCOptions.LibraryOptions = &LibraryOptions;
auto *Target = TheTarget->createTargetMachine(
TheTriple, codegen::getCPUStr(), codegen::getFeaturesStr(), Options,
diff --git a/llvm/lib/MC/MCTargetOptionsCommandFlags.cpp b/llvm/lib/MC/MCTargetOptionsCommandFlags.cpp
index 65c550a998bfe3..90b3ef196f04f4 100644
--- a/llvm/lib/MC/MCTargetOptionsCommandFlags.cpp
+++ b/llvm/lib/MC/MCTargetOptionsCommandFlags.cpp
@@ -62,9 +62,14 @@ MCOPT(bool, X86Sse2Avx)
MCOPT(bool, DisableIntegratedAS)
MCOPT(RelocSectionSymType, RelocSectionSym)
MCOPT(bool, LargeEHEncoding)
-MCSTROPT(ABIName)
MCSTROPT(AsSecureLogFile)
+static cl::opt<std::string> *ABINameView;
+StringRef llvm::mc::getABIName(const cl::LibraryOptionsContext &) {
+ assert(ABINameView && "RegisterMCTargetOptionsFlags not created.");
+ return *ABINameView;
+}
+
llvm::mc::RegisterMCTargetOptionsFlags::RegisterMCTargetOptionsFlags() {
#define MCBINDOPT(NAME) \
do { \
@@ -212,7 +217,8 @@ llvm::mc::RegisterMCTargetOptionsFlags::RegisterMCTargetOptionsFlags() {
#undef MCBINDOPT
}
-MCTargetOptions llvm::mc::InitMCTargetOptionsFromFlags() {
+MCTargetOptions
+llvm::mc::getMCTargetOptions(const cl::LibraryOptionsContext &C) {
MCTargetOptions Options;
Options.MCRelaxAll = getRelaxAll();
Options.MCIncrementalLinkerCompatible = getIncrementalLinkerCompatible();
@@ -220,7 +226,7 @@ MCTargetOptions llvm::mc::InitMCTargetOptionsFromFlags() {
Options.Dwarf64 = getDwarf64();
Options.DwarfVersion = getDwarfVersion();
Options.ShowMCInst = getShowMCInst();
- Options.ABIName = getABIName();
+ Options.ABIName = getABIName(C);
Options.MCFatalWarnings = getFatalWarnings();
Options.MCNoWarn = getNoWarn();
Options.MCNoDeprecatedWarn = getNoDeprecatedWarn();
diff --git a/llvm/lib/Target/SPIRV/SPIRVAPI.cpp b/llvm/lib/Target/SPIRV/SPIRVAPI.cpp
index 810a91ffb42803..a42e24c981cdb6 100644
--- a/llvm/lib/Target/SPIRV/SPIRVAPI.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVAPI.cpp
@@ -75,7 +75,7 @@ SPIRVTranslate(Module *M, std::string &SpirvObj, std::string &ErrMsg,
if (!TheTarget)
return false;
- // A call to codegen::InitTargetOptionsFromCodeGenFlags(TargetTriple) hits an
+ // A call to codegen::getTargetOptions(TargetTriple) hits an
// assertion in one of the codegen flag getters in
// llvm/lib/CodeGen/CommandFlags.cpp:
// `...View && "RegisterCodeGenFlags not created."' failed.
diff --git a/llvm/tools/gold/gold-plugin.cpp b/llvm/tools/gold/gold-plugin.cpp
index 844314f9d2a765..3ceeadd0704152 100644
--- a/llvm/tools/gold/gold-plugin.cpp
+++ b/llvm/tools/gold/gold-plugin.cpp
@@ -881,7 +881,7 @@ createLTO(const cl::LibraryOptionsContext &LibraryOptions,
Conf.LibraryOptions = &LibraryOptions;
Conf.CPU = options::mcpu;
- Conf.Options = codegen::InitTargetOptionsFromCodeGenFlags(Triple());
+ Conf.Options = codegen::getTargetOptions(LibraryOptions, Triple());
// Disable the new X86 relax relocations since gold might not support them.
// FIXME: Check the gold version or add a new option to enable them.
diff --git a/llvm/tools/llc/lib/llcdriver.cpp b/llvm/tools/llc/lib/llcdriver.cpp
index bbb2ab875330ed..8cd358340dc0f2 100644
--- a/llvm/tools/llc/lib/llcdriver.cpp
+++ b/llvm/tools/llc/lib/llcdriver.cpp
@@ -535,7 +535,7 @@ static int compileModule(char **argv, SmallVectorImpl<PassPlugin> &PluginList,
}
TargetOptions Options;
auto InitializeOptions = [&](const Triple &TheTriple) {
- Options = codegen::InitTargetOptionsFromCodeGenFlags(TheTriple);
+ Options = codegen::getTargetOptions(Context.getLibraryOptions(), TheTriple);
Options.MCOptions.LibraryOptions = &Context.getLibraryOptions();
if (Options.XCOFFReadOnlyPointers) {
diff --git a/llvm/tools/lli/lli.cpp b/llvm/tools/lli/lli.cpp
index cd35cd10ae1fc4..f5b00bf76030d7 100644
--- a/llvm/tools/lli/lli.cpp
+++ b/llvm/tools/lli/lli.cpp
@@ -524,7 +524,7 @@ int main(int argc, char **argv, char * const *envp) {
builder.setOptLevel(getOptLevel());
TargetOptions Options =
- codegen::InitTargetOptionsFromCodeGenFlags(Triple(TargetTriple));
+ codegen::getTargetOptions(LibraryOptions, Triple(TargetTriple));
if (FloatABI::ABIType ABI = codegen::getFloatABIForCalls();
ABI != FloatABI::Default && !Mod->getModuleFlag("float-abi")) {
diff --git a/llvm/tools/llvm-lto/llvm-lto.cpp b/llvm/tools/llvm-lto/llvm-lto.cpp
index fa36650c97951c..2ae1f0b4acb82c 100644
--- a/llvm/tools/llvm-lto/llvm-lto.cpp
+++ b/llvm/tools/llvm-lto/llvm-lto.cpp
@@ -516,11 +516,11 @@ static void listDependentLibraries() {
}
}
-static void printMachOCPUOnly() {
+static void printMachOCPUOnly(const cl::LibraryOptionsContext &LibraryOptions) {
LLVMContext Context;
Context.setDiagnosticHandler(std::make_unique<LLVMLTODiagnosticHandler>(),
true);
- TargetOptions Options = codegen::InitTargetOptionsFromCodeGenFlags(Triple());
+ TargetOptions Options = codegen::getTargetOptions(LibraryOptions, Triple());
for (auto &Filename : InputFilenames) {
ErrorOr<std::unique_ptr<LTOModule>> ModuleOrErr =
LTOModule::createFromFile(Context, Filename, Options);
@@ -1017,7 +1017,7 @@ int main(int argc, char **argv) {
error("optimization level must be between 0 and 3");
// set up the TargetOptions for the machine
- TargetOptions Options = codegen::InitTargetOptionsFromCodeGenFlags(Triple());
+ TargetOptions Options = codegen::getTargetOptions(LibraryOptions, Triple());
if (ListSymbolsOnly || QueryHasCtorDtor) {
testLTOModule(Options);
@@ -1050,7 +1050,7 @@ int main(int argc, char **argv) {
}
if (PrintMachOCPUOnly) {
- printMachOCPUOnly();
+ printMachOCPUOnly(LibraryOptions);
return 0;
}
diff --git a/llvm/tools/llvm-lto2/llvm-lto2.cpp b/llvm/tools/llvm-lto2/llvm-lto2.cpp
index b1491b0e381eea..506262b7c0d53d 100644
--- a/llvm/tools/llvm-lto2/llvm-lto2.cpp
+++ b/llvm/tools/llvm-lto2/llvm-lto2.cpp
@@ -350,7 +350,7 @@ static int run(int argc, char **argv) {
Conf.TimeTraceGranularity = TimeTraceGranularity;
}
Conf.CPU = codegen::getMCPU();
- Conf.Options = codegen::InitTargetOptionsFromCodeGenFlags(Triple());
+ Conf.Options = codegen::getTargetOptions(LibraryOptions, Triple());
Conf.MAttrs = codegen::getMAttrs();
if (auto RM = codegen::getExplicitRelocModel())
Conf.RelocModel = *RM;
diff --git a/llvm/tools/llvm-mc/llvm-mc.cpp b/llvm/tools/llvm-mc/llvm-mc.cpp
index a6f28978099057..b0324ab381c553 100644
--- a/llvm/tools/llvm-mc/llvm-mc.cpp
+++ b/llvm/tools/llvm-mc/llvm-mc.cpp
@@ -419,7 +419,7 @@ int main(int argc, char **argv) {
timeTraceProfilerCleanup();
});
- MCTargetOptions MCOptions = mc::InitMCTargetOptionsFromFlags();
+ MCTargetOptions MCOptions = mc::getMCTargetOptions(LibraryOptions);
MCOptions.LibraryOptions = &LibraryOptions;
MCOptions.CompressDebugSections = CompressDebugSections.getValue();
MCOptions.ShowMCInst = ShowInst;
diff --git a/llvm/tools/llvm-mca/llvm-mca.cpp b/llvm/tools/llvm-mca/llvm-mca.cpp
index f36ee308450aab..1b350902d1ebfa 100644
--- a/llvm/tools/llvm-mca/llvm-mca.cpp
+++ b/llvm/tools/llvm-mca/llvm-mca.cpp
@@ -457,7 +457,7 @@ int main(int argc, char **argv) {
std::unique_ptr<MCRegisterInfo> MRI(TheTarget->createMCRegInfo(TheTriple));
assert(MRI && "Unable to create target register info!");
- MCTargetOptions MCOptions = mc::InitMCTargetOptionsFromFlags();
+ MCTargetOptions MCOptions = mc::getMCTargetOptions(LibraryOptions);
MCOptions.LibraryOptions = &LibraryOptions;
std::unique_ptr<MCAsmInfo> MAI(
TheTarget->createMCAsmInfo(*MRI, TheTriple, MCOptions));
diff --git a/llvm/tools/lto/lto.cpp b/llvm/tools/lto/lto.cpp
index 1b73a2413692c6..74c90d62541b6c 100644
--- a/llvm/tools/lto/lto.cpp
+++ b/llvm/tools/lto/lto.cpp
@@ -239,7 +239,7 @@ lto_module_is_object_file_in_memory_for_target(const void* mem,
lto_module_t lto_module_create(const char* path) {
lto_initialize();
llvm::TargetOptions Options =
- codegen::InitTargetOptionsFromCodeGenFlags(Triple());
+ codegen::getTargetOptions(LTOContext->getLibraryOptions(), Triple());
ErrorOr<std::unique_ptr<LTOModule>> M =
LTOModule::createFromFile(*LTOContext, StringRef(path), Options);
if (!M)
@@ -250,7 +250,7 @@ lto_module_t lto_module_create(const char* path) {
lto_module_t lto_module_create_from_fd(int fd, const char *path, size_t size) {
lto_initialize();
llvm::TargetOptions Options =
- codegen::InitTargetOptionsFromCodeGenFlags(Triple());
+ codegen::getTargetOptions(LTOContext->getLibraryOptions(), Triple());
ErrorOr<std::unique_ptr<LTOModule>> M = LTOModule::createFromOpenFile(
*LTOContext, fd, StringRef(path), size, Options);
if (!M)
@@ -264,7 +264,7 @@ lto_module_t lto_module_create_from_fd_at_offset(int fd, const char *path,
off_t offset) {
lto_initialize();
llvm::TargetOptions Options =
- codegen::InitTargetOptionsFromCodeGenFlags(Triple());
+ codegen::getTargetOptions(LTOContext->getLibraryOptions(), Triple());
ErrorOr<std::unique_ptr<LTOModule>> M = LTOModule::createFromOpenFileSlice(
*LTOContext, fd, StringRef(path), map_size, offset, Options);
if (!M)
@@ -275,7 +275,7 @@ lto_module_t lto_module_create_from_fd_at_offset(int fd, const char *path,
lto_module_t lto_module_create_from_memory(const void* mem, size_t length) {
lto_initialize();
llvm::TargetOptions Options =
- codegen::InitTargetOptionsFromCodeGenFlags(Triple());
+ codegen::getTargetOptions(LTOContext->getLibraryOptions(), Triple());
ErrorOr<std::unique_ptr<LTOModule>> M =
LTOModule::createFromBuffer(*LTOContext, mem, length, Options);
if (!M)
@@ -288,7 +288,7 @@ lto_module_t lto_module_create_from_memory_with_path(const void* mem,
const char *path) {
lto_initialize();
llvm::TargetOptions Options =
- codegen::InitTargetOptionsFromCodeGenFlags(Triple());
+ codegen::getTargetOptions(LTOContext->getLibraryOptions(), Triple());
ErrorOr<std::unique_ptr<LTOModule>> M = LTOModule::createFromBuffer(
*LTOContext, mem, length, Options, StringRef(path));
if (!M)
@@ -300,7 +300,7 @@ lto_module_t lto_module_create_in_local_context(const void *mem, size_t length,
const char *path) {
lto_initialize();
llvm::TargetOptions Options =
- codegen::InitTargetOptionsFromCodeGenFlags(Triple());
+ codegen::getTargetOptions(LTOContext->getLibraryOptions(), Triple());
// Create a local context. Ownership will be transferred to LTOModule.
std::unique_ptr<LLVMContext> Context = std::make_unique<LLVMContext>();
@@ -320,7 +320,7 @@ lto_module_t lto_module_create_in_codegen_context(const void *mem,
lto_code_gen_t cg) {
lto_initialize();
llvm::TargetOptions Options =
- codegen::InitTargetOptionsFromCodeGenFlags(Triple());
+ codegen::getTargetOptions(LTOContext->getLibraryOptions(), Triple());
ErrorOr<std::unique_ptr<LTOModule>> M = LTOModule::createFromBuffer(
unwrap(cg)->getContext(), mem, length, Options, StringRef(path));
if (!M)
@@ -394,7 +394,8 @@ void lto_codegen_set_diagnostic_handler(lto_code_gen_t cg,
static lto_code_gen_t createCodeGen(bool InLocalContext) {
lto_initialize();
- TargetOptions Options = codegen::InitTargetOptionsFromCodeGenFlags(Triple());
+ TargetOptions Options =
+ codegen::getTargetOptions(LTOContext->getLibraryOptions(), Triple());
LibLTOCodeGenerator *CodeGen =
InLocalContext ? new LibLTOCodeGenerator(std::make_unique<LLVMContext>())
@@ -570,7 +571,7 @@ thinlto_code_gen_t thinlto_create_codegen(void) {
new ThinLTOCodeGenerator(LTOContext->getLibraryOptions());
CodeGen->setMllvmArgs(ThinLTOMllvmArgs);
CodeGen->setTargetOptions(
- codegen::InitTargetOptionsFromCodeGenFlags(Triple()));
+ codegen::getTargetOptions(LTOContext->getLibraryOptions(), Triple()));
CodeGen->setFreestanding(EnableFreestanding);
if (OptLevel.getNumOccurrences()) {
diff --git a/llvm/tools/opt/optdriver.cpp b/llvm/tools/opt/optdriver.cpp
index e59d6bb3854b3d..aa46d98e2ef724 100644
--- a/llvm/tools/opt/optdriver.cpp
+++ b/llvm/tools/opt/optdriver.cpp
@@ -521,7 +521,7 @@ optMain(int argc, char **argv,
// Pass "help" as CPU for -mtune=help
std::string SkipModuleCPU = (TuneCPUStr == "help" ? "help" : CPUStr);
TargetOptions Options =
- codegen::InitTargetOptionsFromCodeGenFlags(TheTriple);
+ codegen::getTargetOptions(Context.getLibraryOptions(), TheTriple);
// Create the target machine just to print the help info. Use unique_ptr
// to avoid a memory leak.
std::unique_ptr<TargetMachine> TM(TheTarget->createTargetMachine(
@@ -559,7 +559,8 @@ optMain(int argc, char **argv,
codegen::MaybeEnableStatistics();
- StringRef ABIName = mc::getABIName(); // FIXME: Handle module flag.
+ StringRef ABIName =
+ mc::getABIName(Context.getLibraryOptions()); // FIXME: Handle module flag.
// Load the input module...
auto SetDataLayout = [&](StringRef IRTriple,
@@ -714,7 +715,7 @@ optMain(int argc, char **argv,
const TargetOptions *Options = TM ? &TM->Options : &CodeGenFlagsOptions;
if (!TM) {
CodeGenFlagsOptions =
- codegen::InitTargetOptionsFromCodeGenFlags(ModuleTriple);
+ codegen::getTargetOptions(Context.getLibraryOptions(), ModuleTriple);
}
// Override function attributes based on CPUStr, TuneCPUStr, FeaturesStr, and
diff --git a/offload/plugins-nextgen/common/src/JIT.cpp b/offload/plugins-nextgen/common/src/JIT.cpp
index afa31a0ae3f722..5a4d79bae0f958 100644
--- a/offload/plugins-nextgen/common/src/JIT.cpp
+++ b/offload/plugins-nextgen/common/src/JIT.cpp
@@ -104,7 +104,8 @@ createTargetMachine(Module &M, std::string CPU, unsigned OptLevel) {
std::optional<CodeModel::Model> CodeModel = M.getCodeModel();
- TargetOptions Options = codegen::InitTargetOptionsFromCodeGenFlags(TT);
+ TargetOptions Options =
+ codegen::getTargetOptions(M.getContext().getLibraryOptions(), TT);
std::unique_ptr<TargetMachine> TM(
T->createTargetMachine(M.getTargetTriple(), CPU, Features.getString(),
More information about the cfe-commits
mailing list