[llvm] 10a3774 - tools: Compute the module DataLayout from the triple, not the TargetMachine (#224259)

via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 17 11:58:08 PDT 2026


Author: Matt Arsenault
Date: 2026-09-17T20:58:02+02:00
New Revision: 10a37743cd3b5a15f800e16d4f8cf34a9e9f1c46

URL: https://github.com/llvm/llvm-project/commit/10a37743cd3b5a15f800e16d4f8cf34a9e9f1c46
DIFF: https://github.com/llvm/llvm-project/commit/10a37743cd3b5a15f800e16d4f8cf34a9e9f1c46.diff

LOG: tools: Compute the module DataLayout from the triple, not the TargetMachine (#224259)

TargetMachine::createDataLayout is an unreliable cache given the
existence of module flags which change the datalayout, so this should be removed.
Migrate tool users to directly compute the datalayout.

Co-authored-by: Claude (Claude-Opus-4.8) <noreply at anthropic.com>

Added: 
    

Modified: 
    llvm/tools/llvm-exegesis/lib/Assembler.cpp
    llvm/tools/llvm-ir2vec/llvm-ir2vec.cpp
    llvm/tools/llvm-isel-fuzzer/llvm-isel-fuzzer.cpp
    llvm/tools/llvm-opt-fuzzer/llvm-opt-fuzzer.cpp
    llvm/tools/llvm-reduce/ReducerWorkItem.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/tools/llvm-exegesis/lib/Assembler.cpp b/llvm/tools/llvm-exegesis/lib/Assembler.cpp
index 25aff57faa879..240ca8ba435b9 100644
--- a/llvm/tools/llvm-exegesis/lib/Assembler.cpp
+++ b/llvm/tools/llvm-exegesis/lib/Assembler.cpp
@@ -233,7 +233,8 @@ createModule(const std::unique_ptr<LLVMContext> &Context, const DataLayout &DL)
 
 BitVector getFunctionReservedRegs(const TargetMachine &TM) {
   std::unique_ptr<LLVMContext> Context = std::make_unique<LLVMContext>();
-  std::unique_ptr<Module> Module = createModule(Context, TM.createDataLayout());
+  std::unique_ptr<Module> Module = createModule(
+      Context, DataLayout(TM.getTargetTriple().computeDataLayout()));
   auto MMIWP = std::make_unique<MachineModuleInfoWrapperPass>(&TM);
   MachineFunction &MF = createVoidVoidPtrMachineFunction(
       FunctionID, Module.get(), &MMIWP->getMMI());
@@ -247,8 +248,8 @@ Error assembleToStream(const ExegesisTarget &ET,
                        raw_pwrite_stream &AsmStream, const BenchmarkKey &Key,
                        bool GenerateMemoryInstructions) {
   auto Context = std::make_unique<LLVMContext>();
-  std::unique_ptr<Module> Module =
-      createModule(Context, TM->createDataLayout());
+  std::unique_ptr<Module> Module = createModule(
+      Context, DataLayout(TM->getTargetTriple().computeDataLayout()));
   auto MMIWP = std::make_unique<MachineModuleInfoWrapperPass>(TM.get());
   MachineFunction &MF = createVoidVoidPtrMachineFunction(
       FunctionID, Module.get(), &MMIWP.get()->getMMI());
@@ -382,7 +383,9 @@ Expected<ExecutableFunction> ExecutableFunction::create(
   uintptr_t CodeSize = SymbolIt->second;
 
   auto EJITOrErr =
-      orc::LLJITBuilder().setDataLayout(TM->createDataLayout()).create();
+      orc::LLJITBuilder()
+          .setDataLayout(DataLayout(TM->getTargetTriple().computeDataLayout()))
+          .create();
   if (!EJITOrErr)
     return EJITOrErr.takeError();
 

diff  --git a/llvm/tools/llvm-ir2vec/llvm-ir2vec.cpp b/llvm/tools/llvm-ir2vec/llvm-ir2vec.cpp
index 6a764e48e7fe2..05d62b8ec6ff8 100644
--- a/llvm/tools/llvm-ir2vec/llvm-ir2vec.cpp
+++ b/llvm/tools/llvm-ir2vec/llvm-ir2vec.cpp
@@ -214,7 +214,7 @@ static Error setupMIRContext(const std::string &InputFile, MIRContext &Ctx) {
       exit(1); // Match original behavior
     }
     Ctx.TM = std::move(*TMOrErr);
-    return Ctx.TM->createDataLayout().getStringRepresentation();
+    return TheTriple.computeDataLayout();
   };
 
   Ctx.M = MIR->parseIRModule(SetDataLayout);

diff  --git a/llvm/tools/llvm-isel-fuzzer/llvm-isel-fuzzer.cpp b/llvm/tools/llvm-isel-fuzzer/llvm-isel-fuzzer.cpp
index e28dd636cb7e0..adac7a7bd8db0 100644
--- a/llvm/tools/llvm-isel-fuzzer/llvm-isel-fuzzer.cpp
+++ b/llvm/tools/llvm-isel-fuzzer/llvm-isel-fuzzer.cpp
@@ -92,7 +92,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
 
   // Set up the module to build for our target.
   M->setTargetTriple(TM->getTargetTriple());
-  M->setDataLayout(TM->createDataLayout());
+  M->setDataLayout(TM->getTargetTriple().computeDataLayout());
 
   // Build up a PM to do instruction selection.
   legacy::PassManager PM;

diff  --git a/llvm/tools/llvm-opt-fuzzer/llvm-opt-fuzzer.cpp b/llvm/tools/llvm-opt-fuzzer/llvm-opt-fuzzer.cpp
index 6b366c8245b52..f40d5fdc08483 100644
--- a/llvm/tools/llvm-opt-fuzzer/llvm-opt-fuzzer.cpp
+++ b/llvm/tools/llvm-opt-fuzzer/llvm-opt-fuzzer.cpp
@@ -125,7 +125,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
   //
 
   M->setTargetTriple(TM->getTargetTriple());
-  M->setDataLayout(TM->createDataLayout());
+  M->setDataLayout(TM->getTargetTriple().computeDataLayout());
   codegen::setFunctionAttributes(*M, TM->getTargetCPU(),
                                  TM->getTargetFeatureString());
 

diff  --git a/llvm/tools/llvm-reduce/ReducerWorkItem.cpp b/llvm/tools/llvm-reduce/ReducerWorkItem.cpp
index 913b5663cc89f..6b202aec3e8f8 100644
--- a/llvm/tools/llvm-reduce/ReducerWorkItem.cpp
+++ b/llvm/tools/llvm-reduce/ReducerWorkItem.cpp
@@ -858,7 +858,7 @@ llvm::parseReducerWorkItem(StringRef ToolName, StringRef Filename,
       ExitOnError ExitOnErr(std::string(ToolName) + ": error: ");
       TM = ExitOnErr(codegen::createTargetMachineForTriple(TheTriple));
 
-      return TM->createDataLayout().getStringRepresentation();
+      return TheTriple.computeDataLayout();
     };
 
     std::unique_ptr<Module> M = MParser->parseIRModule(SetDataLayout);


        


More information about the llvm-commits mailing list