Skip to content

[TargetRegistry] Accept Triple in createTargetMachine() (NFC) #130940

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 12, 2025

Conversation

nikic
Copy link
Contributor

@nikic nikic commented Mar 12, 2025

This avoids doing a Triple -> std::string -> Triple round trip in lots of places, now that the Module stores a Triple.

This avoids doing a Triple -> std::string -> Triple round trip
in lots of places, now that the Module stores a Triple.
@nikic nikic requested review from arsenm and dtcxzyw March 12, 2025 10:45
@llvmbot llvmbot added clang Clang issues not falling into any other category backend:AMDGPU backend:RISC-V backend:WebAssembly clang:frontend Language frontend issues, e.g. anything involving "Sema" clang:codegen IR generation bugs: mangling, exceptions, etc. tools:llvm-exegesis mc Machine (object) code llvm:globalisel mlir:llvm flang:driver mlir BOLT flang Flang issues not falling into any other category backend:SPIR-V LTO Link time optimization (regular/full LTO or ThinLTO) flang:openmp clang:openmp OpenMP related changes to Clang offload labels Mar 12, 2025
@llvmbot
Copy link
Member

llvmbot commented Mar 12, 2025

@llvm/pr-subscribers-offload
@llvm/pr-subscribers-clang
@llvm/pr-subscribers-bolt
@llvm/pr-subscribers-lto
@llvm/pr-subscribers-flang-openmp
@llvm/pr-subscribers-clang-codegen
@llvm/pr-subscribers-backend-webassembly

@llvm/pr-subscribers-backend-amdgpu

Author: Nikita Popov (nikic)

Changes

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 --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]

@llvmbot
Copy link
Member

llvmbot commented Mar 12, 2025

@llvm/pr-subscribers-backend-risc-v

Author: Nikita Popov (nikic)

Changes

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 --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]

@@ -116,7 +116,7 @@ body: |
successors: %bb.2, %bb.4
liveins: $rdi, $rsi

%1:gr32 = COPY $rsi
%1:gr64 = COPY $rsi
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this test was previously creating a 32-bit TM by accident.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verifier should have rejected using $rsi in the first place too

Copy link

github-actions bot commented Mar 12, 2025

✅ With the latest revision this PR passed the C/C++ code formatter.

@@ -116,7 +116,7 @@ body: |
successors: %bb.2, %bb.4
liveins: $rdi, $rsi

%1:gr32 = COPY $rsi
%1:gr64 = COPY $rsi
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verifier should have rejected using $rsi in the first place too

@@ -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,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we keep a StringRef overload, at least for a while? As-is this is going to break a lot of downstream builds

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Restored StringRef overload with deprecation.

@nikic nikic merged commit f137c3d into llvm:main Mar 12, 2025
10 of 11 checks passed
@nikic nikic deleted the create-targetmachine-triple branch March 12, 2025 16:35
@llvm-ci
Copy link
Collaborator

llvm-ci commented Mar 12, 2025

LLVM Buildbot has detected a new failure on builder flang-aarch64-libcxx running on linaro-flang-aarch64-libcxx while building bolt,clang,flang,llvm,mlir,offload at step 5 "build-unified-tree".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/89/builds/18479

Here is the relevant piece of the build log for the reference
Step 5 (build-unified-tree) failure: build (failure)
...
149.293 [146/8/7229] Linking CXX executable bin/llvm-jitlink
151.487 [146/7/7230] Building CXX object tools/sancov/CMakeFiles/sancov.dir/sancov.cpp.o
151.588 [145/7/7231] Linking CXX executable bin/sancov
157.261 [145/6/7232] Building CXX object tools/llvm-opt-fuzzer/CMakeFiles/llvm-opt-fuzzer.dir/llvm-opt-fuzzer.cpp.o
157.422 [144/6/7233] Linking CXX executable bin/llvm-opt-fuzzer
157.505 [144/5/7234] Building CXX object tools/llvm-objdump/CMakeFiles/llvm-objdump.dir/MachODump.cpp.o
166.380 [144/4/7235] Building CXX object tools/llvm-objdump/CMakeFiles/llvm-objdump.dir/llvm-objdump.cpp.o
166.509 [143/4/7236] Linking CXX executable bin/llvm-objdump
166.516 [142/4/7237] Generating ../../bin/llvm-otool
167.594 [142/3/7238] Building CXX object tools/flang/lib/Frontend/CMakeFiles/flangFrontend.dir/CompilerInstance.cpp.o
FAILED: tools/flang/lib/Frontend/CMakeFiles/flangFrontend.dir/CompilerInstance.cpp.o 
/usr/local/bin/c++ -DFLANG_INCLUDE_TESTS=1 -DFLANG_LITTLE_ENDIAN=1 -DGTEST_HAS_RTTI=0 -D_DEBUG -D_GLIBCXX_ASSERTIONS -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/home/tcwg-buildbot/worker/flang-aarch64-libcxx/build/tools/flang/lib/Frontend -I/home/tcwg-buildbot/worker/flang-aarch64-libcxx/llvm-project/flang/lib/Frontend -I/home/tcwg-buildbot/worker/flang-aarch64-libcxx/llvm-project/flang/include -I/home/tcwg-buildbot/worker/flang-aarch64-libcxx/build/tools/flang/include -I/home/tcwg-buildbot/worker/flang-aarch64-libcxx/build/include -I/home/tcwg-buildbot/worker/flang-aarch64-libcxx/llvm-project/llvm/include -isystem /home/tcwg-buildbot/worker/flang-aarch64-libcxx/llvm-project/flang/../mlir/include -isystem /home/tcwg-buildbot/worker/flang-aarch64-libcxx/build/tools/mlir/include -isystem /home/tcwg-buildbot/worker/flang-aarch64-libcxx/build/tools/clang/include -isystem /home/tcwg-buildbot/worker/flang-aarch64-libcxx/llvm-project/llvm/../clang/include -stdlib=libc++ -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wc++98-compat-extra-semi -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion -Wmisleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -ffunction-sections -fdata-sections -Werror -Wno-deprecated-copy -Wno-string-conversion -Wno-ctad-maybe-unsupported -Wno-unused-command-line-argument -Wstring-conversion           -Wcovered-switch-default -Wno-nested-anon-types -O3 -DNDEBUG -std=c++17 -fPIC  -fno-exceptions -funwind-tables -fno-rtti -UNDEBUG -MD -MT tools/flang/lib/Frontend/CMakeFiles/flangFrontend.dir/CompilerInstance.cpp.o -MF tools/flang/lib/Frontend/CMakeFiles/flangFrontend.dir/CompilerInstance.cpp.o.d -o tools/flang/lib/Frontend/CMakeFiles/flangFrontend.dir/CompilerInstance.cpp.o -c /home/tcwg-buildbot/worker/flang-aarch64-libcxx/llvm-project/flang/lib/Frontend/CompilerInstance.cpp
../llvm-project/flang/lib/Frontend/CompilerInstance.cpp:375:34: error: 'createTargetMachine' is deprecated: Use overload accepting Triple instead [-Werror,-Wdeprecated-declarations]
  375 |   targetMachine.reset(theTarget->createTargetMachine(
      |                                  ^
../llvm-project/llvm/include/llvm/MC/TargetRegistry.h:466:5: note: 'createTargetMachine' has been explicitly marked deprecated here
  466 |   [[deprecated("Use overload accepting Triple instead")]]
      |     ^
1 error generated.
171.864 [142/2/7239] Building CXX object tools/flang/tools/flang-driver/CMakeFiles/flang.dir/fc1_main.cpp.o
244.098 [142/1/7240] Building CXX object tools/flang/tools/bbc/CMakeFiles/bbc.dir/bbc.cpp.o
ninja: build stopped: subcommand failed.

nikic added a commit that referenced this pull request Mar 12, 2025
@llvm-ci
Copy link
Collaborator

llvm-ci commented Mar 12, 2025

LLVM Buildbot has detected a new failure on builder ppc64le-flang-rhel-clang running on ppc64le-flang-rhel-test while building bolt,clang,flang,llvm,mlir,offload at step 5 "build-unified-tree".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/157/builds/22293

Here is the relevant piece of the build log for the reference
Step 5 (build-unified-tree) failure: build (failure)
...
87.281 [105/8/6645] Linking CXX executable bin/mlir-opt
87.357 [105/7/6646] Building CXX object tools/llvm-objdump/CMakeFiles/llvm-objdump.dir/MachODump.cpp.o
87.471 [104/7/6647] Linking CXX executable bin/llvm-objdump
87.477 [103/7/6648] Generating ../../bin/llvm-otool
88.047 [103/6/6649] Linking CXX shared library lib/libclang-cpp.so.21.0git
88.054 [102/6/6650] Creating library symlink lib/libclang-cpp.so
94.354 [102/5/6651] Building CXX object tools/clang/tools/clang-linker-wrapper/CMakeFiles/clang-linker-wrapper.dir/ClangLinkerWrapper.cpp.o
94.626 [101/5/6652] Linking CXX executable bin/clang-linker-wrapper
95.214 [101/4/6653] Building CXX object tools/flang/tools/flang-driver/CMakeFiles/flang.dir/fc1_main.cpp.o
95.388 [101/3/6654] Building CXX object tools/flang/lib/Frontend/CMakeFiles/flangFrontend.dir/CompilerInstance.cpp.o
FAILED: tools/flang/lib/Frontend/CMakeFiles/flangFrontend.dir/CompilerInstance.cpp.o 
ccache /home/buildbots/llvm-external-buildbots/clang.19.1.7/bin/clang++ -DFLANG_INCLUDE_TESTS=1 -DFLANG_LITTLE_ENDIAN=1 -DGTEST_HAS_RTTI=0 -D_DEBUG -D_GLIBCXX_ASSERTIONS -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/home/buildbots/llvm-external-buildbots/workers/ppc64le-flang-rhel-test/ppc64le-flang-rhel-clang-build/build/tools/flang/lib/Frontend -I/home/buildbots/llvm-external-buildbots/workers/ppc64le-flang-rhel-test/ppc64le-flang-rhel-clang-build/llvm-project/flang/lib/Frontend -I/home/buildbots/llvm-external-buildbots/workers/ppc64le-flang-rhel-test/ppc64le-flang-rhel-clang-build/llvm-project/flang/include -I/home/buildbots/llvm-external-buildbots/workers/ppc64le-flang-rhel-test/ppc64le-flang-rhel-clang-build/build/tools/flang/include -I/home/buildbots/llvm-external-buildbots/workers/ppc64le-flang-rhel-test/ppc64le-flang-rhel-clang-build/build/include -I/home/buildbots/llvm-external-buildbots/workers/ppc64le-flang-rhel-test/ppc64le-flang-rhel-clang-build/llvm-project/llvm/include -isystem /home/buildbots/llvm-external-buildbots/workers/ppc64le-flang-rhel-test/ppc64le-flang-rhel-clang-build/llvm-project/flang/../mlir/include -isystem /home/buildbots/llvm-external-buildbots/workers/ppc64le-flang-rhel-test/ppc64le-flang-rhel-clang-build/build/tools/mlir/include -isystem /home/buildbots/llvm-external-buildbots/workers/ppc64le-flang-rhel-test/ppc64le-flang-rhel-clang-build/build/tools/clang/include -isystem /home/buildbots/llvm-external-buildbots/workers/ppc64le-flang-rhel-test/ppc64le-flang-rhel-clang-build/llvm-project/llvm/../clang/include -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wc++98-compat-extra-semi -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion -Wmisleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -ffunction-sections -fdata-sections -Werror -Wno-deprecated-copy -Wno-string-conversion -Wno-ctad-maybe-unsupported -Wno-unused-command-line-argument -Wstring-conversion           -Wcovered-switch-default -Wno-nested-anon-types -O3 -DNDEBUG -std=c++17  -fno-exceptions -funwind-tables -fno-rtti -UNDEBUG -MD -MT tools/flang/lib/Frontend/CMakeFiles/flangFrontend.dir/CompilerInstance.cpp.o -MF tools/flang/lib/Frontend/CMakeFiles/flangFrontend.dir/CompilerInstance.cpp.o.d -o tools/flang/lib/Frontend/CMakeFiles/flangFrontend.dir/CompilerInstance.cpp.o -c /home/buildbots/llvm-external-buildbots/workers/ppc64le-flang-rhel-test/ppc64le-flang-rhel-clang-build/llvm-project/flang/lib/Frontend/CompilerInstance.cpp
/home/buildbots/llvm-external-buildbots/workers/ppc64le-flang-rhel-test/ppc64le-flang-rhel-clang-build/llvm-project/flang/lib/Frontend/CompilerInstance.cpp:375:34: error: 'createTargetMachine' is deprecated: Use overload accepting Triple instead [-Werror,-Wdeprecated-declarations]
  375 |   targetMachine.reset(theTarget->createTargetMachine(
      |                                  ^
/home/buildbots/llvm-external-buildbots/workers/ppc64le-flang-rhel-test/ppc64le-flang-rhel-clang-build/llvm-project/llvm/include/llvm/MC/TargetRegistry.h:466:5: note: 'createTargetMachine' has been explicitly marked deprecated here
  466 |   [[deprecated("Use overload accepting Triple instead")]]
      |     ^
1 error generated.
117.751 [101/2/6655] Building CXX object tools/llvm-jitlink/CMakeFiles/llvm-jitlink.dir/llvm-jitlink.cpp.o
366.474 [101/1/6656] Building CXX object tools/flang/tools/bbc/CMakeFiles/bbc.dir/bbc.cpp.o
ninja: build stopped: subcommand failed.

frederik-h pushed a commit to frederik-h/llvm-project that referenced this pull request Mar 18, 2025
…30940)

This avoids doing a Triple -> std::string -> Triple round trip in lots
of places, now that the Module stores a Triple.
frederik-h pushed a commit to frederik-h/llvm-project that referenced this pull request Mar 18, 2025
ThomasRaoux pushed a commit to triton-lang/triton that referenced this pull request Mar 22, 2025
Pulls in these changes:

- Fp8/BF8 type conversion ops
(llvm/llvm-project#131850)
- Accept Triples in createTargetMachine()
(llvm/llvm-project#130940)

Co-authored-by: Lei Zhang <[email protected]>
erickt added a commit to erickt/rust that referenced this pull request May 1, 2025
In LLVM 21 PR llvm/llvm-project#130940
`TargetRegistry::createTargetMachine` was changed to take a `const
Triple&` and has deprecated the old `StringRef` method.

@rustbot label llvm-main
erickt added a commit to erickt/rust that referenced this pull request May 1, 2025
In LLVM 21 PR llvm/llvm-project#130940
`TargetRegistry::createTargetMachine` was changed to take a `const
Triple&` and has deprecated the old `StringRef` method.

@rustbot label llvm-main
VlaDexa added a commit to VlaDexa/rust that referenced this pull request May 2, 2025
PassWrapper: adapt for llvm/llvm-project@f137c3d592e96330e450a8fd63ef…

…7e8877fc1908

In LLVM 21 PR llvm/llvm-project#130940 `TargetRegistry::createTargetMachine` was changed to take a `const Triple&` and has deprecated the old `StringRef` method.

`@rustbot` label llvm-main
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request May 3, 2025
PassWrapper: adapt for llvm/llvm-project@f137c3d592e96330e450a8fd63ef…

…7e8877fc1908

In LLVM 21 PR llvm/llvm-project#130940 `TargetRegistry::createTargetMachine` was changed to take a `const Triple&` and has deprecated the old `StringRef` method.

``@rustbot`` label llvm-main
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request May 3, 2025
Rollup merge of rust-lang#140534 - erickt:llvm-21, r=cuviper

PassWrapper: adapt for llvm/llvm-project@f137c3d592e96330e450a8fd63ef…

…7e8877fc1908

In LLVM 21 PR llvm/llvm-project#130940 `TargetRegistry::createTargetMachine` was changed to take a `const Triple&` and has deprecated the old `StringRef` method.

``@rustbot`` label llvm-main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend:AMDGPU backend:RISC-V backend:SPIR-V backend:WebAssembly BOLT clang:codegen IR generation bugs: mangling, exceptions, etc. clang:frontend Language frontend issues, e.g. anything involving "Sema" clang:openmp OpenMP related changes to Clang clang Clang issues not falling into any other category flang:driver flang:openmp flang Flang issues not falling into any other category llvm:globalisel LTO Link time optimization (regular/full LTO or ThinLTO) mc Machine (object) code mlir:llvm mlir offload tools:llvm-exegesis
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants