[llvm] opt: Stop creating TargetMachine to infer the datalayout (PR #169585)

Alexander Richardson via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 25 19:52:25 PST 2025


================
@@ -538,15 +538,15 @@ optMain(int argc, char **argv,
     // the IR, we should default to an empty (default) DataLayout.
     if (TripleStr.empty())
       return std::nullopt;
-    // Otherwise we infer the DataLayout from the target machine.
-    Expected<std::unique_ptr<TargetMachine>> ExpectedTM =
-        codegen::createTargetMachineForTriple(TripleStr, GetCodeGenOptLevel());
-    if (!ExpectedTM) {
-      errs() << argv[0] << ": warning: failed to infer data layout: "
-             << toString(ExpectedTM.takeError()) << "\n";
+
+    Triple TT(TripleStr);
+
+    std::string Str = TT.computeDataLayout();
----------------
arichardson wrote:

Yeah it seems to be mostly ignored which causes a bunch of issues with LTO (especially on RISC-V) such as https://github.com/llvm/llvm-project/issues/50591 / https://github.com/llvm/llvm-project/issues/69780. Probably easiest to ignore that attribute for now and only look at command line flags.

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


More information about the llvm-commits mailing list