[llvm-branch-commits] [clang] [clang-tools-extra] [llvm] [flang] [lldb] [mlir] [libcxx] [compiler-rt] [libcxxabi] [lld] Refactor ModuleToObject to offer more flexibility to subclass (NFC) (PR #71165)

Mehdi Amini via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Fri Nov 3 13:29:58 PDT 2023


https://github.com/joker-eph updated https://github.com/llvm/llvm-project/pull/71165

>From 183f5094ff7da09beed46f760a857af449a24245 Mon Sep 17 00:00:00 2001
From: Mehdi Amini <mamini at nvidia.com>
Date: Fri, 3 Nov 2023 13:26:56 -0700
Subject: [PATCH] use cached TM

Created using spr 1.3.4
---
 mlir/lib/Target/LLVM/ModuleToObject.cpp | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/mlir/lib/Target/LLVM/ModuleToObject.cpp b/mlir/lib/Target/LLVM/ModuleToObject.cpp
index 6af3d49ab23bf74..d94c10de8d7c424 100644
--- a/mlir/lib/Target/LLVM/ModuleToObject.cpp
+++ b/mlir/lib/Target/LLVM/ModuleToObject.cpp
@@ -45,8 +45,10 @@ Operation &ModuleToObject::getOperation() { return module; }
 
 std::optional<llvm::TargetMachine *>
 ModuleToObject::getOrCreateTargetMachine() {
-  std::string error;
+  if (targetMachine)
+    return targetMachine.get();
   // Load the target.
+  std::string error;
   const llvm::Target *target =
       llvm::TargetRegistry::lookupTarget(triple, error);
   if (!target) {



More information about the llvm-branch-commits mailing list