[Mlir-commits] [mlir] [NFC][MLIR] Prefer triple overload of lookupTarget (PR #162187)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Mon Oct 6 15:41:57 PDT 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-mlir-llvm

Author: Aiden Grossman (boomanaiden154)

<details>
<summary>Changes</summary>

The overloads accepting a string will be deprecated soon, similar to other functions in TargetRegistry.

---
Full diff: https://github.com/llvm/llvm-project/pull/162187.diff


3 Files Affected:

- (modified) mlir/lib/Target/LLVM/ModuleToObject.cpp (+3-2) 
- (modified) mlir/lib/Target/LLVM/ROCDL/Target.cpp (+1-1) 
- (modified) mlir/lib/Target/LLVMIR/Transforms/TargetUtils.cpp (+3-2) 


``````````diff
diff --git a/mlir/lib/Target/LLVM/ModuleToObject.cpp b/mlir/lib/Target/LLVM/ModuleToObject.cpp
index 5055cd9938c72..08e7f7e6156c0 100644
--- a/mlir/lib/Target/LLVM/ModuleToObject.cpp
+++ b/mlir/lib/Target/LLVM/ModuleToObject.cpp
@@ -56,8 +56,9 @@ ModuleToObject::getOrCreateTargetMachine() {
     return targetMachine.get();
   // Load the target.
   std::string error;
+  llvm::Triple parsedTriple(triple);
   const llvm::Target *target =
-      llvm::TargetRegistry::lookupTarget(triple, error);
+      llvm::TargetRegistry::lookupTarget(parsedTriple, error);
   if (!target) {
     getOperation().emitError()
         << "Failed to lookup target for triple '" << triple << "' " << error;
@@ -65,7 +66,7 @@ ModuleToObject::getOrCreateTargetMachine() {
   }
 
   // Create the target machine using the target.
-  targetMachine.reset(target->createTargetMachine(llvm::Triple(triple), chip,
+  targetMachine.reset(target->createTargetMachine(parsedTriple, chip,
                                                   features, {}, {}));
   if (!targetMachine)
     return std::nullopt;
diff --git a/mlir/lib/Target/LLVM/ROCDL/Target.cpp b/mlir/lib/Target/LLVM/ROCDL/Target.cpp
index c9888c39ac891..f813f8db8fc94 100644
--- a/mlir/lib/Target/LLVM/ROCDL/Target.cpp
+++ b/mlir/lib/Target/LLVM/ROCDL/Target.cpp
@@ -289,7 +289,7 @@ SerializeGPUModuleBase::assembleIsa(StringRef isa) {
   llvm::Triple triple(llvm::Triple::normalize(targetTriple));
   std::string error;
   const llvm::Target *target =
-      llvm::TargetRegistry::lookupTarget(triple.normalize(), error);
+      llvm::TargetRegistry::lookupTarget(triple, error);
   if (!target) {
     emitError(loc, Twine("failed to lookup target: ") + error);
     return std::nullopt;
diff --git a/mlir/lib/Target/LLVMIR/Transforms/TargetUtils.cpp b/mlir/lib/Target/LLVMIR/Transforms/TargetUtils.cpp
index f1d36228bef1f..437f6fc28bf1c 100644
--- a/mlir/lib/Target/LLVMIR/Transforms/TargetUtils.cpp
+++ b/mlir/lib/Target/LLVMIR/Transforms/TargetUtils.cpp
@@ -43,16 +43,17 @@ getTargetMachine(mlir::LLVM::TargetAttrInterface attr) {
       llvm::cast_if_present<LLVM::TargetFeaturesAttr>(attr.getFeatures());
   std::string features = featuresAttr ? featuresAttr.getFeaturesString() : "";
 
+  llvm::Triple parsedTriple(triple);
   std::string error;
   const llvm::Target *target =
-      llvm::TargetRegistry::lookupTarget(triple, error);
+      llvm::TargetRegistry::lookupTarget(parsedTriple, error);
   if (!target || !error.empty()) {
     LDBG() << "Looking up target '" << triple << "' failed: " << error << "\n";
     return failure();
   }
 
   return std::unique_ptr<llvm::TargetMachine>(target->createTargetMachine(
-      llvm::Triple(triple), chipAKAcpu, features, {}, {}));
+      parsedTriple, chipAKAcpu, features, {}, {}));
 }
 
 FailureOr<llvm::DataLayout>

``````````

</details>


https://github.com/llvm/llvm-project/pull/162187


More information about the Mlir-commits mailing list