[clang] [flang] [llvm] [mlir] [TargetRegistry] Accept Triple in createTargetMachine() (NFC) (PR #130940)
via cfe-commits
cfe-commits at lists.llvm.org
Wed Mar 12 03:46:18 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-backend-webassembly
@llvm/pr-subscribers-backend-amdgpu
Author: Nikita Popov (nikic)
<details>
<summary>Changes</summary>
This avoids doing a Triple -> std::string -> Triple round trip in lots of places, now that the Module stores a Triple.
---
Patch is 51.13 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/130940.diff
62 Files Affected:
- (modified) bolt/lib/Passes/AsmDump.cpp (+1-1)
- (modified) clang/lib/CodeGen/BackendUtil.cpp (+1-1)
- (modified) clang/lib/Interpreter/DeviceOffload.cpp (+1-1)
- (modified) clang/lib/Interpreter/Wasm.cpp (+2-3)
- (modified) clang/tools/clang-fuzzer/handle-llvm/handle_llvm.cpp (+2-2)
- (modified) clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp (+1-1)
- (modified) clang/tools/driver/cc1_main.cpp (+10-6)
- (modified) flang/tools/bbc/bbc.cpp (+1-1)
- (modified) flang/tools/flang-driver/fc1_main.cpp (+2-2)
- (modified) llvm/examples/Kaleidoscope/Chapter8/toy.cpp (+1-1)
- (modified) llvm/include/llvm/MC/TargetRegistry.h (+3-3)
- (modified) llvm/lib/CodeGen/CommandFlags.cpp (+1-1)
- (modified) llvm/lib/DWARFLinker/Classic/DWARFStreamer.cpp (+1-1)
- (modified) llvm/lib/DWARFLinker/Parallel/DWARFEmitterImpl.cpp (+1-1)
- (modified) llvm/lib/ExecutionEngine/Orc/JITTargetMachineBuilder.cpp (+2-3)
- (modified) llvm/lib/ExecutionEngine/TargetSelect.cpp (+3-4)
- (modified) llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp (+1-1)
- (modified) llvm/lib/LTO/LTOBackend.cpp (+1-1)
- (modified) llvm/lib/LTO/LTOCodeGenerator.cpp (+2-2)
- (modified) llvm/lib/LTO/LTOModule.cpp (+2-2)
- (modified) llvm/lib/LTO/ThinLTOCodeGenerator.cpp (+1-1)
- (modified) llvm/lib/Target/SPIRV/SPIRVAPI.cpp (+1-1)
- (modified) llvm/lib/Target/TargetMachineC.cpp (+4-4)
- (modified) llvm/tools/llc/llc.cpp (+2-2)
- (modified) llvm/tools/llvm-exegesis/lib/LlvmState.cpp (+2-2)
- (modified) llvm/tools/llvm-split/llvm-split.cpp (+1-1)
- (modified) llvm/unittests/CodeGen/AArch64SelectionDAGTest.cpp (+1-1)
- (modified) llvm/unittests/CodeGen/AMDGPUMetadataTest.cpp (+3-2)
- (modified) llvm/unittests/CodeGen/DroppedVariableStatsMIRTest.cpp (+2-1)
- (modified) llvm/unittests/CodeGen/GlobalISel/GISelMITest.cpp (+4-4)
- (modified) llvm/unittests/CodeGen/InstrRefLDVTest.cpp (+3-3)
- (modified) llvm/unittests/CodeGen/MachineDomTreeUpdaterTest.cpp (+3-3)
- (modified) llvm/unittests/CodeGen/PassManagerTest.cpp (+3-5)
- (modified) llvm/unittests/CodeGen/SelectionDAGAddressAnalysisTest.cpp (+1-1)
- (modified) llvm/unittests/CodeGen/SelectionDAGPatternMatchTest.cpp (+1-1)
- (modified) llvm/unittests/CodeGen/TargetOptionsTest.cpp (+2-2)
- (modified) llvm/unittests/CodeGen/TestAsmPrinter.cpp (+2-2)
- (modified) llvm/unittests/DebugInfo/DWARF/DwarfGenerator.cpp (+1-1)
- (modified) llvm/unittests/MC/AMDGPU/DwarfRegMappings.cpp (+4-3)
- (modified) llvm/unittests/MI/LiveIntervalTest.cpp (+1-1)
- (modified) llvm/unittests/MIR/MachineMetadata.cpp (+2-1)
- (modified) llvm/unittests/MIR/MachineStableHashTest.cpp (+2-1)
- (modified) llvm/unittests/Target/AArch64/AArch64RegisterInfoTest.cpp (+1-1)
- (modified) llvm/unittests/Target/AArch64/AArch64SVESchedPseudoTest.cpp (+1-1)
- (modified) llvm/unittests/Target/AArch64/AddressingModes.cpp (+1-1)
- (modified) llvm/unittests/Target/AArch64/Immediates.cpp (+1-1)
- (modified) llvm/unittests/Target/AArch64/InstSizes.cpp (+1-1)
- (modified) llvm/unittests/Target/AArch64/MatrixRegisterAliasing.cpp (+1-1)
- (modified) llvm/unittests/Target/AMDGPU/AMDGPUUnitTests.cpp (+3-2)
- (modified) llvm/unittests/Target/AMDGPU/PALMetadata.cpp (+3-3)
- (modified) llvm/unittests/Target/ARM/InstSizes.cpp (+1-1)
- (modified) llvm/unittests/Target/ARM/MachineInstrTest.cpp (+6-6)
- (modified) llvm/unittests/Target/LoongArch/InstSizes.cpp (+1-1)
- (modified) llvm/unittests/Target/PowerPC/AIXRelocModelTest.cpp (+1-1)
- (modified) llvm/unittests/Target/RISCV/RISCVInstrInfoTest.cpp (+1-1)
- (modified) llvm/unittests/Target/VE/MachineInstrTest.cpp (+1-1)
- (modified) llvm/unittests/Target/WebAssembly/WebAssemblyExceptionInfoTest.cpp (+1-1)
- (modified) llvm/unittests/Target/X86/MachineSizeOptsTest.cpp (+1-1)
- (modified) llvm/unittests/Target/X86/TernlogTest.cpp (+1-1)
- (modified) llvm/unittests/tools/llvm-exegesis/Common/AssemblerUtils.h (+8-9)
- (modified) mlir/lib/Target/LLVM/ModuleToObject.cpp (+2-2)
- (modified) offload/plugins-nextgen/common/src/JIT.cpp (+1-1)
``````````diff
diff --git a/bolt/lib/Passes/AsmDump.cpp b/bolt/lib/Passes/AsmDump.cpp
index 97f985d56ce64..08191669e72f3 100644
--- a/bolt/lib/Passes/AsmDump.cpp
+++ b/bolt/lib/Passes/AsmDump.cpp
@@ -143,7 +143,7 @@ void dumpFunction(const BinaryFunction &BF) {
std::move(MCEInstance.MCE), std::move(MAB)));
AsmStreamer->initSections(true, *BC.STI);
std::unique_ptr<TargetMachine> TM(BC.TheTarget->createTargetMachine(
- BC.TripleName, "", "", TargetOptions(), std::nullopt));
+ *BC.TheTriple, "", "", TargetOptions(), std::nullopt));
std::unique_ptr<AsmPrinter> MAP(
BC.TheTarget->createAsmPrinter(*TM, std::move(AsmStreamer)));
diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp
index 62a0e3c69bad1..7557cb8408921 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -595,7 +595,7 @@ static void setCommandLineOpts(const CodeGenOptions &CodeGenOpts) {
void EmitAssemblyHelper::CreateTargetMachine(bool MustCreateTM) {
// Create the TargetMachine for generating code.
std::string Error;
- std::string Triple = TheModule->getTargetTriple().str();
+ const llvm::Triple &Triple = TheModule->getTargetTriple();
const llvm::Target *TheTarget = TargetRegistry::lookupTarget(Triple, Error);
if (!TheTarget) {
if (MustCreateTM)
diff --git a/clang/lib/Interpreter/DeviceOffload.cpp b/clang/lib/Interpreter/DeviceOffload.cpp
index 5e35fa035b2b8..1999d63d1aa04 100644
--- a/clang/lib/Interpreter/DeviceOffload.cpp
+++ b/clang/lib/Interpreter/DeviceOffload.cpp
@@ -83,7 +83,7 @@ llvm::Expected<llvm::StringRef> IncrementalCUDADeviceParser::GeneratePTX() {
std::error_code());
llvm::TargetOptions TO = llvm::TargetOptions();
llvm::TargetMachine *TargetMachine = Target->createTargetMachine(
- PTU.TheModule->getTargetTriple().str(), TargetOpts.CPU, "", TO,
+ PTU.TheModule->getTargetTriple(), TargetOpts.CPU, "", TO,
llvm::Reloc::Model::PIC_);
PTU.TheModule->setDataLayout(TargetMachine->createDataLayout());
diff --git a/clang/lib/Interpreter/Wasm.cpp b/clang/lib/Interpreter/Wasm.cpp
index 6f584fab52ba9..f7cb7598c77f8 100644
--- a/clang/lib/Interpreter/Wasm.cpp
+++ b/clang/lib/Interpreter/Wasm.cpp
@@ -73,9 +73,8 @@ llvm::Error WasmIncrementalExecutor::addModule(PartialTranslationUnit &PTU) {
}
llvm::TargetOptions TO = llvm::TargetOptions();
- llvm::TargetMachine *TargetMachine =
- Target->createTargetMachine(PTU.TheModule->getTargetTriple().str(), "",
- "", TO, llvm::Reloc::Model::PIC_);
+ llvm::TargetMachine *TargetMachine = Target->createTargetMachine(
+ PTU.TheModule->getTargetTriple(), "", "", TO, llvm::Reloc::Model::PIC_);
PTU.TheModule->setDataLayout(TargetMachine->createDataLayout());
std::string ObjectFileName = PTU.TheModule->getName().str() + ".o";
std::string BinaryFileName = PTU.TheModule->getName().str() + ".wasm";
diff --git a/clang/tools/clang-fuzzer/handle-llvm/handle_llvm.cpp b/clang/tools/clang-fuzzer/handle-llvm/handle_llvm.cpp
index 4618c0bcc6be8..798b34b3ef0af 100644
--- a/clang/tools/clang-fuzzer/handle-llvm/handle_llvm.cpp
+++ b/clang/tools/clang-fuzzer/handle-llvm/handle_llvm.cpp
@@ -127,8 +127,8 @@ static std::string OptLLVM(const std::string &IR, CodeGenOptLevel OLvl) {
ErrorAndExit(E);
std::unique_ptr<TargetMachine> TM(TheTarget->createTargetMachine(
- M->getTargetTriple().str(), codegen::getCPUStr(),
- codegen::getFeaturesStr(), Options, codegen::getExplicitRelocModel(),
+ M->getTargetTriple(), codegen::getCPUStr(), codegen::getFeaturesStr(),
+ Options, codegen::getExplicitRelocModel(),
codegen::getExplicitCodeModel(), OLvl));
if (!TM)
ErrorAndExit("Could not create target machine");
diff --git a/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp b/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
index dcfed14746200..8d63d2c414cef 100644
--- a/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
+++ b/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
@@ -637,7 +637,7 @@ Expected<StringRef> compileModule(Module &M, OffloadKind Kind) {
StringRef CPU = "";
StringRef Features = "";
std::unique_ptr<TargetMachine> TM(
- T->createTargetMachine(M.getTargetTriple().str(), CPU, Features, Options,
+ T->createTargetMachine(M.getTargetTriple(), CPU, Features, Options,
Reloc::PIC_, M.getCodeModel()));
if (M.getDataLayout().isDefault())
diff --git a/clang/tools/driver/cc1_main.cpp b/clang/tools/driver/cc1_main.cpp
index 26b5e78cfb4b5..341520c6a6f73 100644
--- a/clang/tools/driver/cc1_main.cpp
+++ b/clang/tools/driver/cc1_main.cpp
@@ -111,9 +111,10 @@ static void ensureSufficientStack() {}
/// Print supported cpus of the given target.
static int PrintSupportedCPUs(std::string TargetStr) {
+ llvm::Triple Triple(TargetStr);
std::string Error;
const llvm::Target *TheTarget =
- llvm::TargetRegistry::lookupTarget(TargetStr, Error);
+ llvm::TargetRegistry::lookupTarget(Triple, Error);
if (!TheTarget) {
llvm::errs() << Error;
return 1;
@@ -122,15 +123,16 @@ static int PrintSupportedCPUs(std::string TargetStr) {
// the target machine will handle the mcpu printing
llvm::TargetOptions Options;
std::unique_ptr<llvm::TargetMachine> TheTargetMachine(
- TheTarget->createTargetMachine(TargetStr, "", "+cpuhelp", Options,
+ TheTarget->createTargetMachine(Triple, "", "+cpuhelp", Options,
std::nullopt));
return 0;
}
static int PrintSupportedExtensions(std::string TargetStr) {
+ llvm::Triple Triple(TargetStr);
std::string Error;
const llvm::Target *TheTarget =
- llvm::TargetRegistry::lookupTarget(TargetStr, Error);
+ llvm::TargetRegistry::lookupTarget(Triple, Error);
if (!TheTarget) {
llvm::errs() << Error;
return 1;
@@ -138,7 +140,7 @@ static int PrintSupportedExtensions(std::string TargetStr) {
llvm::TargetOptions Options;
std::unique_ptr<llvm::TargetMachine> TheTargetMachine(
- TheTarget->createTargetMachine(TargetStr, "", "", Options, std::nullopt));
+ TheTarget->createTargetMachine(Triple, "", "", Options, std::nullopt));
const llvm::Triple &MachineTriple = TheTargetMachine->getTargetTriple();
const llvm::MCSubtargetInfo *MCInfo = TheTargetMachine->getMCSubtargetInfo();
const llvm::ArrayRef<llvm::SubtargetFeatureKV> Features =
@@ -165,9 +167,10 @@ static int PrintSupportedExtensions(std::string TargetStr) {
}
static int PrintEnabledExtensions(const TargetOptions& TargetOpts) {
+ llvm::Triple Triple(TargetOpts.Triple);
std::string Error;
const llvm::Target *TheTarget =
- llvm::TargetRegistry::lookupTarget(TargetOpts.Triple, Error);
+ llvm::TargetRegistry::lookupTarget(Triple, Error);
if (!TheTarget) {
llvm::errs() << Error;
return 1;
@@ -179,7 +182,8 @@ static int PrintEnabledExtensions(const TargetOptions& TargetOpts) {
llvm::TargetOptions BackendOptions;
std::string FeaturesStr = llvm::join(TargetOpts.FeaturesAsWritten, ",");
std::unique_ptr<llvm::TargetMachine> TheTargetMachine(
- TheTarget->createTargetMachine(TargetOpts.Triple, TargetOpts.CPU, FeaturesStr, BackendOptions, std::nullopt));
+ TheTarget->createTargetMachine(Triple, TargetOpts.CPU, FeaturesStr,
+ BackendOptions, std::nullopt));
const llvm::Triple &MachineTriple = TheTargetMachine->getTargetTriple();
const llvm::MCSubtargetInfo *MCInfo = TheTargetMachine->getMCSubtargetInfo();
diff --git a/flang/tools/bbc/bbc.cpp b/flang/tools/bbc/bbc.cpp
index 3b19a1c2a78d9..efaeb0c0a3891 100644
--- a/flang/tools/bbc/bbc.cpp
+++ b/flang/tools/bbc/bbc.cpp
@@ -280,7 +280,7 @@ createTargetMachine(llvm::StringRef targetTriple, std::string &error) {
if (!theTarget)
return nullptr;
return std::unique_ptr<llvm::TargetMachine>{
- theTarget->createTargetMachine(triple, /*CPU=*/"",
+ theTarget->createTargetMachine(llvm::Triple(triple), /*CPU=*/"",
/*Features=*/"", llvm::TargetOptions(),
/*Reloc::Model=*/std::nullopt)};
}
diff --git a/flang/tools/flang-driver/fc1_main.cpp b/flang/tools/flang-driver/fc1_main.cpp
index 561a0dd5524e3..49535275d084d 100644
--- a/flang/tools/flang-driver/fc1_main.cpp
+++ b/flang/tools/flang-driver/fc1_main.cpp
@@ -45,8 +45,8 @@ static int printSupportedCPUs(llvm::StringRef triple) {
// the target machine will handle the mcpu printing
llvm::TargetOptions targetOpts;
std::unique_ptr<llvm::TargetMachine> targetMachine(
- target->createTargetMachine(triple, "", "+cpuhelp", targetOpts,
- std::nullopt));
+ target->createTargetMachine(llvm::Triple(triple), "", "+cpuhelp",
+ targetOpts, std::nullopt));
return 0;
}
diff --git a/llvm/examples/Kaleidoscope/Chapter8/toy.cpp b/llvm/examples/Kaleidoscope/Chapter8/toy.cpp
index e2e54306dd2fd..739b8954aa8b2 100644
--- a/llvm/examples/Kaleidoscope/Chapter8/toy.cpp
+++ b/llvm/examples/Kaleidoscope/Chapter8/toy.cpp
@@ -1243,7 +1243,7 @@ int main() {
TargetOptions opt;
auto TheTargetMachine = Target->createTargetMachine(
- TargetTriple, CPU, Features, opt, Reloc::PIC_);
+ Triple(TargetTriple), CPU, Features, opt, Reloc::PIC_);
TheModule->setDataLayout(TheTargetMachine->createDataLayout());
diff --git a/llvm/include/llvm/MC/TargetRegistry.h b/llvm/include/llvm/MC/TargetRegistry.h
index 363fa03f27a70..0e9fab7c27a8f 100644
--- a/llvm/include/llvm/MC/TargetRegistry.h
+++ b/llvm/include/llvm/MC/TargetRegistry.h
@@ -453,14 +453,14 @@ class Target {
/// either the target triple from the module, or the target triple of the
/// host if that does not exist.
TargetMachine *createTargetMachine(
- StringRef TT, StringRef CPU, StringRef Features,
+ const Triple &TT, StringRef CPU, StringRef Features,
const TargetOptions &Options, std::optional<Reloc::Model> RM,
std::optional<CodeModel::Model> CM = std::nullopt,
CodeGenOptLevel OL = CodeGenOptLevel::Default, bool JIT = false) const {
if (!TargetMachineCtorFn)
return nullptr;
- return TargetMachineCtorFn(*this, Triple(TT), CPU, Features, Options, RM,
- CM, OL, JIT);
+ return TargetMachineCtorFn(*this, TT, CPU, Features, Options, RM, CM, OL,
+ JIT);
}
/// createMCAsmBackend - Create a target specific assembly parser.
diff --git a/llvm/lib/CodeGen/CommandFlags.cpp b/llvm/lib/CodeGen/CommandFlags.cpp
index 023656cde0089..9512f7993bd93 100644
--- a/llvm/lib/CodeGen/CommandFlags.cpp
+++ b/llvm/lib/CodeGen/CommandFlags.cpp
@@ -764,7 +764,7 @@ codegen::createTargetMachineForTriple(StringRef TargetTriple,
if (!TheTarget)
return createStringError(inconvertibleErrorCode(), Error);
auto *Target = TheTarget->createTargetMachine(
- TheTriple.getTriple(), codegen::getCPUStr(), codegen::getFeaturesStr(),
+ TheTriple, codegen::getCPUStr(), codegen::getFeaturesStr(),
codegen::InitTargetOptionsFromCodeGenFlags(TheTriple),
codegen::getExplicitRelocModel(), codegen::getExplicitCodeModel(),
OptLevel);
diff --git a/llvm/lib/DWARFLinker/Classic/DWARFStreamer.cpp b/llvm/lib/DWARFLinker/Classic/DWARFStreamer.cpp
index 947db9cbcd92d..55e40cd779cbf 100644
--- a/llvm/lib/DWARFLinker/Classic/DWARFStreamer.cpp
+++ b/llvm/lib/DWARFLinker/Classic/DWARFStreamer.cpp
@@ -123,7 +123,7 @@ Error DwarfStreamer::init(Triple TheTriple,
TripleName.c_str());
// Finally create the AsmPrinter we'll use to emit the DIEs.
- TM.reset(TheTarget->createTargetMachine(TripleName, "", "", TargetOptions(),
+ TM.reset(TheTarget->createTargetMachine(TheTriple, "", "", TargetOptions(),
std::nullopt));
if (!TM)
return createStringError(std::errc::invalid_argument,
diff --git a/llvm/lib/DWARFLinker/Parallel/DWARFEmitterImpl.cpp b/llvm/lib/DWARFLinker/Parallel/DWARFEmitterImpl.cpp
index fbab6b25ca0f1..4cd1875b37f5b 100644
--- a/llvm/lib/DWARFLinker/Parallel/DWARFEmitterImpl.cpp
+++ b/llvm/lib/DWARFLinker/Parallel/DWARFEmitterImpl.cpp
@@ -102,7 +102,7 @@ Error DwarfEmitterImpl::init(Triple TheTriple,
TripleName.c_str());
// Finally create the AsmPrinter we'll use to emit the DIEs.
- TM.reset(TheTarget->createTargetMachine(TripleName, "", "", TargetOptions(),
+ TM.reset(TheTarget->createTargetMachine(TheTriple, "", "", TargetOptions(),
std::nullopt));
if (!TM)
return createStringError(std::errc::invalid_argument,
diff --git a/llvm/lib/ExecutionEngine/Orc/JITTargetMachineBuilder.cpp b/llvm/lib/ExecutionEngine/Orc/JITTargetMachineBuilder.cpp
index 5ae1ac6e4250d..dfd443c80283f 100644
--- a/llvm/lib/ExecutionEngine/Orc/JITTargetMachineBuilder.cpp
+++ b/llvm/lib/ExecutionEngine/Orc/JITTargetMachineBuilder.cpp
@@ -47,9 +47,8 @@ JITTargetMachineBuilder::createTargetMachine() {
return make_error<StringError>("Target has no JIT support",
inconvertibleErrorCode());
- auto *TM =
- TheTarget->createTargetMachine(TT.getTriple(), CPU, Features.getString(),
- Options, RM, CM, OptLevel, /*JIT*/ true);
+ auto *TM = TheTarget->createTargetMachine(
+ TT, CPU, Features.getString(), Options, RM, CM, OptLevel, /*JIT*/ true);
if (!TM)
return make_error<StringError>("Could not allocate target machine",
inconvertibleErrorCode());
diff --git a/llvm/lib/ExecutionEngine/TargetSelect.cpp b/llvm/lib/ExecutionEngine/TargetSelect.cpp
index 4ce031d8dc337..e1021f835b51f 100644
--- a/llvm/lib/ExecutionEngine/TargetSelect.cpp
+++ b/llvm/lib/ExecutionEngine/TargetSelect.cpp
@@ -84,10 +84,9 @@ TargetMachine *EngineBuilder::selectTarget(const Triple &TargetTriple,
}
// Allocate a target...
- TargetMachine *Target =
- TheTarget->createTargetMachine(TheTriple.getTriple(), MCPU, FeaturesStr,
- Options, RelocModel, CMModel, OptLevel,
- /*JIT*/ true);
+ TargetMachine *Target = TheTarget->createTargetMachine(
+ TheTriple, MCPU, FeaturesStr, Options, RelocModel, CMModel, OptLevel,
+ /*JIT*/ true);
Target->Options.EmulatedTLS = EmulatedTLS;
assert(Target && "Could not allocate target machine!");
diff --git a/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp b/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
index 7718d8a98172f..8dcebcdb8791d 100644
--- a/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
+++ b/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
@@ -5505,7 +5505,7 @@ createTargetMachine(Function *F, CodeGenOptLevel OptLevel) {
StringRef CPU = F->getFnAttribute("target-cpu").getValueAsString();
StringRef Features = F->getFnAttribute("target-features").getValueAsString();
- const std::string &Triple = M->getTargetTriple().str();
+ const llvm::Triple &Triple = M->getTargetTriple();
std::string Error;
const llvm::Target *TheTarget = TargetRegistry::lookupTarget(Triple, Error);
diff --git a/llvm/lib/LTO/LTOBackend.cpp b/llvm/lib/LTO/LTOBackend.cpp
index 139c39abf8e6b..1c764a0188eda 100644
--- a/llvm/lib/LTO/LTOBackend.cpp
+++ b/llvm/lib/LTO/LTOBackend.cpp
@@ -227,7 +227,7 @@ createTargetMachine(const Config &Conf, const Target *TheTarget, Module &M) {
}
std::unique_ptr<TargetMachine> TM(TheTarget->createTargetMachine(
- TheTriple.str(), Conf.CPU, Features.getString(), TargetOpts, RelocModel,
+ TheTriple, Conf.CPU, Features.getString(), TargetOpts, RelocModel,
CodeModel, Conf.CGOptLevel));
assert(TM && "Failed to create target machine");
diff --git a/llvm/lib/LTO/LTOCodeGenerator.cpp b/llvm/lib/LTO/LTOCodeGenerator.cpp
index e855b45915521..6b66a88880053 100644
--- a/llvm/lib/LTO/LTOCodeGenerator.cpp
+++ b/llvm/lib/LTO/LTOCodeGenerator.cpp
@@ -420,8 +420,8 @@ bool LTOCodeGenerator::determineTarget() {
std::unique_ptr<TargetMachine> LTOCodeGenerator::createTargetMachine() {
assert(MArch && "MArch is not set!");
return std::unique_ptr<TargetMachine>(MArch->createTargetMachine(
- TripleStr, Config.CPU, FeatureStr, Config.Options, Config.RelocModel,
- std::nullopt, Config.CGOptLevel));
+ Triple(TripleStr), Config.CPU, FeatureStr, Config.Options,
+ Config.RelocModel, std::nullopt, Config.CGOptLevel));
}
// If a linkonce global is present in the MustPreserveSymbols, we need to make
diff --git a/llvm/lib/LTO/LTOModule.cpp b/llvm/lib/LTO/LTOModule.cpp
index 7e13646bfa0a8..d7d2fcce7bd43 100644
--- a/llvm/lib/LTO/LTOModule.cpp
+++ b/llvm/lib/LTO/LTOModule.cpp
@@ -228,8 +228,8 @@ LTOModule::makeLTOModule(MemoryBufferRef Buffer, const TargetOptions &options,
CPU = "cyclone";
}
- TargetMachine *target = march->createTargetMachine(
- Triple.str(), CPU, FeatureStr, options, std::nullopt);
+ TargetMachine *target = march->createTargetMachine(Triple, CPU, FeatureStr,
+ options, std::nullopt);
std::unique_ptr<LTOModule> Ret(new LTOModule(std::move(M), Buffer, target));
Ret->parseSymbols();
diff --git a/llvm/lib/LTO/ThinLTOCodeGenerator.cpp b/llvm/lib/LTO/ThinLTOCodeGenerator.cpp
index 16326395d0f74..11e88ca4a83eb 100644
--- a/llvm/lib/LTO/ThinLTOCodeGenerator.cpp
+++ b/llvm/lib/LTO/ThinLTOCodeGenerator.cpp
@@ -588,7 +588,7 @@ std::unique_ptr<TargetMachine> TargetMachineBuilder::create() const {
std::string FeatureStr = Features.getString();
std::unique_ptr<TargetMachine> TM(
- TheTarget->createTargetMachine(TheTriple.str(), MCpu, FeatureStr, Options,
+ TheTarget->createTargetMachine(TheTriple, MCpu, FeatureStr, Options,
RelocModel, std::nullopt, CGOptLevel));
assert(TM && "Cannot create target machine");
diff --git a/llvm/lib/Target/SPIRV/SPIRVAPI.cpp b/llvm/lib/Target/SPIRV/SPIRVAPI.cpp
index 052dd296265be..145285a31dc10 100644
--- a/llvm/lib/Target/SPIRV/SPIRVAPI.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVAPI.cpp
@@ -94,7 +94,7 @@ SPIRVTranslate(Module *M, std::string &SpirvObj, std::string &ErrMsg,
std::optional<Reloc::Model> RM;
std::optional<CodeModel::Model> CM;
std::unique_ptr<TargetMachine> Target(TheTarget->createTargetMachine(
- TargetTriple.getTriple(), "", "", Options, RM, CM, OLevel));
+ TargetTriple, "", "", Options, RM, CM, OLevel));
if (!Target) {
ErrMsg = "Could not allocate target machine!";
return false;
diff --git a/llvm/lib/Target/TargetMachineC.cpp b/llvm/lib/Target/TargetMachineC.cpp
index d12fc65047d04..da6d35c8c8b43 100644
--- a/llvm/lib/Target/TargetMachineC.cpp
+++ b/llvm/lib/Target/TargetMachineC.cpp
@@ -197,14 +197,14 @@ void LLVMTargetMachineOptionsSetCodeModel(LLVMTargetMachineOptionsRef Options,
}
LLVMTargetMachineRef
-LLVMCreateTargetMachineWithOptions(LLVMTargetRef T, const char *Triple,
+LLVMCreateTargetMachineWithOptions(LLVMTargetRef T, const char *TripleStr,
LLVMTargetMachineOptionsRef Options) {
auto *Opt = unwrap(Options);
TargetOptions TO;
TO.MCOptions.ABIName = Opt->ABI;
- return wrap(unwrap(T)->createTargetMachine(Triple, Opt->CPU, Opt->Features,
- TO, Opt->RM, Opt->CM, Opt->OL,
- Opt->JIT));
+ return wrap(unwrap(T)->createTargetMachine(Triple(TripleStr), Opt->CPU,
+ Opt->Features, TO, Opt->RM,
+ Opt->CM, Opt->OL, Opt->JIT));
}
LLVMTargetMachineRef
diff --git a/llvm/tools/llc/llc.cpp b/llvm/tools/llc/llc.cpp
index 456d5f8f2a2f8..9f7824040a37d 100644
--- a/llvm/tools/llc/llc.cpp
+++ b/llvm/tools/llc/llc.cpp
@@ -555,7 +555,7 @@ static int compileModule(char **argv, LLVMContext &Context) {
InitializeOptions(TheTriple);
Target = std::unique_ptr<TargetMachine>(TheTarget->createTargetMachine(
- TheTriple.getTriple(), CPUStr, FeaturesStr, Options, RM, CM, OLvl));
+ TheTriple, CPUStr, FeaturesStr, Options, RM, CM, OLvl));
assert(Target && "Could not allocate target machine!");
return Target->createDataLayout().getStrin...
[truncated]
``````````
</details>
https://github.com/llvm/llvm-project/pull/130940
More information about the cfe-commits
mailing list