[llvm-branch-commits] [llvm] TargetMachine: Remove DataLayout field (PR #226407)
Matt Arsenault via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Fri Sep 25 02:12:40 PDT 2026
https://github.com/arsenm created https://github.com/llvm/llvm-project/pull/226407
Keep createDataLayout around but mark it as deprecated. Eventually
the ABIName field will move out of MCTargetOptions, which can change
the datalayout.
Co-authored-by: Claude (Claude-Opus-4.8) <noreply at anthropic.com>
>From fb1b13ef31447492f73d8c43c48db5a668e706c9 Mon Sep 17 00:00:00 2001
From: Matt Arsenault <Matthew.Arsenault at amd.com>
Date: Wed, 19 Aug 2026 01:18:16 +0200
Subject: [PATCH] TargetMachine: Remove DataLayout field
Keep createDataLayout around but mark it as deprecated. Eventually
the ABIName field will move out of MCTargetOptions, which can change
the datalayout.
Co-authored-by: Claude (Claude-Opus-4.8) <noreply at anthropic.com>
---
llvm/include/llvm/Target/TargetMachine.h | 46 +++----------------
llvm/lib/CodeGen/CodeGenTargetMachineImpl.cpp | 3 +-
llvm/lib/CodeGen/MachineFunction.cpp | 10 ----
llvm/lib/Target/TargetMachine.cpp | 18 +++++---
4 files changed, 18 insertions(+), 59 deletions(-)
diff --git a/llvm/include/llvm/Target/TargetMachine.h b/llvm/include/llvm/Target/TargetMachine.h
index 7c52c72cc400e5..45754ebaa19d9c 100644
--- a/llvm/include/llvm/Target/TargetMachine.h
+++ b/llvm/include/llvm/Target/TargetMachine.h
@@ -83,21 +83,12 @@ struct MachineFunctionInfo;
///
class LLVM_ABI TargetMachine {
protected: // Can only create subclasses.
- TargetMachine(const Target &T, StringRef DataLayoutString,
- const Triple &TargetTriple, StringRef CPU, StringRef FS,
- const TargetOptions &Options);
+ TargetMachine(const Target &T, const Triple &TargetTriple, StringRef CPU,
+ StringRef FS, const TargetOptions &Options);
/// The Target that this machine was created for.
const Target &TheTarget;
- /// DataLayout for the target: keep ABI type size and alignment.
- ///
- /// The DataLayout is created based on the string representation provided
- /// during construction. It is kept here only to avoid reparsing the string
- /// but should not really be used during compilation, because it has an
- /// internal cache that is context specific.
- const DataLayout DL;
-
/// Triple string, CPU name, and target feature strings the TargetMachine
/// instance is created with.
Triple TargetTriple;
@@ -215,35 +206,10 @@ class LLVM_ABI TargetMachine {
}
/// Create a DataLayout.
- const DataLayout createDataLayout() const { return DL; }
-
- /// Test if a DataLayout if compatible with the CodeGen for this target.
- ///
- /// The LLVM Module owns a DataLayout that is used for the target independent
- /// optimizations and code generation. This hook provides a target specific
- /// check on the validity of this DataLayout.
- bool isCompatibleDataLayout(const DataLayout &Candidate) const {
- return DL == Candidate;
- }
-
- /// Get the pointer size for this target.
- ///
- /// This is the only time the DataLayout in the TargetMachine is used.
- unsigned getPointerSize(unsigned AS) const {
- return DL.getPointerSize(AS);
- }
-
- unsigned getPointerSizeInBits(unsigned AS) const {
- return DL.getPointerSizeInBits(AS);
- }
-
- unsigned getProgramPointerSize() const {
- return DL.getPointerSize(DL.getProgramAddressSpace());
- }
-
- unsigned getAllocaPointerSize() const {
- return DL.getPointerSize(DL.getAllocaAddrSpace());
- }
+ LLVM_DEPRECATED("Use the Module's DataLayout, or compute one with "
+ "Triple::computeDataLayout",
+ "")
+ DataLayout createDataLayout() const;
/// Return target specific asm information.
const MCAsmInfo &getMCAsmInfo() const { return *AsmInfo; }
diff --git a/llvm/lib/CodeGen/CodeGenTargetMachineImpl.cpp b/llvm/lib/CodeGen/CodeGenTargetMachineImpl.cpp
index 0f6b627935e3bd..f0d9f7be794f60 100644
--- a/llvm/lib/CodeGen/CodeGenTargetMachineImpl.cpp
+++ b/llvm/lib/CodeGen/CodeGenTargetMachineImpl.cpp
@@ -94,8 +94,7 @@ CodeGenTargetMachineImpl::CodeGenTargetMachineImpl(
const Target &T, const Triple &TT, StringRef CPU, StringRef FS,
const TargetOptions &Options, Reloc::Model RM, CodeModel::Model CM,
CodeGenOptLevel OL)
- : TargetMachine(T, TT.computeDataLayout(Options.MCOptions.getABIName()), TT,
- CPU, FS, Options) {
+ : TargetMachine(T, TT, CPU, FS, Options) {
this->RM = RM;
this->CMModel = CM;
this->OptLevel = OL;
diff --git a/llvm/lib/CodeGen/MachineFunction.cpp b/llvm/lib/CodeGen/MachineFunction.cpp
index 282cce8667deb6..415786315962b1 100644
--- a/llvm/lib/CodeGen/MachineFunction.cpp
+++ b/llvm/lib/CodeGen/MachineFunction.cpp
@@ -63,7 +63,6 @@
#include "llvm/Support/Compiler.h"
#include "llvm/Support/DOTGraphTraits.h"
#include "llvm/Support/ErrorHandling.h"
-#include "llvm/Support/FormatVariadic.h"
#include "llvm/Support/GraphWriter.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Target/TargetMachine.h"
@@ -246,15 +245,6 @@ void MachineFunction::init() {
WinEHInfo = new (Allocator) WinEHFuncInfo();
}
- if (!Target.isCompatibleDataLayout(getDataLayout())) {
- report_fatal_error(
- formatv("Can't create a MachineFunction using a Module with a "
- "Target-incompatible DataLayout attached\n Target "
- "DataLayout: {0}\n Module DataLayout: {1}\n",
- Target.createDataLayout().getStringRepresentation(),
- getDataLayout().getStringRepresentation()));
- }
-
PSVManager = std::make_unique<PseudoSourceValueManager>(getTarget());
}
diff --git a/llvm/lib/Target/TargetMachine.cpp b/llvm/lib/Target/TargetMachine.cpp
index abf3afcc6969be..f203d89de6fa4d 100644
--- a/llvm/lib/Target/TargetMachine.cpp
+++ b/llvm/lib/Target/TargetMachine.cpp
@@ -37,16 +37,20 @@ cl::opt<bool> llvm::NoKernelInfoEndLTO(
// TargetMachine Class
//
-TargetMachine::TargetMachine(const Target &T, StringRef DataLayoutString,
- const Triple &TT, StringRef CPU, StringRef FS,
- const TargetOptions &Options)
- : TheTarget(T), DL(DataLayoutString), TargetTriple(TT),
- TargetCPU(std::string(CPU)), TargetFS(std::string(FS)), AsmInfo(nullptr),
- MRI(nullptr), MII(nullptr), STI(nullptr), RequireStructuredCFG(false),
- O0WantsFastISel(false), Options(Options) {}
+TargetMachine::TargetMachine(const Target &T, const Triple &TT, StringRef CPU,
+ StringRef FS, const TargetOptions &Options)
+ : TheTarget(T), TargetTriple(TT), TargetCPU(std::string(CPU)),
+ TargetFS(std::string(FS)), AsmInfo(nullptr), MRI(nullptr), MII(nullptr),
+ STI(nullptr), RequireStructuredCFG(false), O0WantsFastISel(false),
+ Options(Options) {}
TargetMachine::~TargetMachine() = default;
+DataLayout TargetMachine::createDataLayout() const {
+ return DataLayout(
+ TargetTriple.computeDataLayout(Options.MCOptions.getABIName()));
+}
+
Expected<std::unique_ptr<MCStreamer>>
TargetMachine::createMCStreamer(raw_pwrite_stream &Out,
raw_pwrite_stream *DwoOut,
More information about the llvm-branch-commits
mailing list