Skip to content

Commit 0b07de2

Browse files
committed
[IR] Make DataLayout compute canonical data layouts
Clang and other frontends generally need the LLVM data layout string in order to generate LLVM IR modules for LLVM. MLIR clients often need it as well, since MLIR users often lower to LLVM IR. Before this change, the LLVM datalayout string was computed in the LLVM${TGT}CodeGen library in the relevant TargetMachine subclass. However, none of the logic for computing the data layout string requires any details of code generation. Clients who want to avoid duplicating this information were forced to link in LLVMCodeGen and all registered targets, leading to bloated binaries. By moving this information to the DataLayout class in the IR file, we can delete the duplicate datalayout strings in Clang, and retain the ability to generate IR for unregistered targets.
1 parent 3119945 commit 0b07de2

32 files changed

+699
-587
lines changed

llvm/include/llvm/IR/DataLayout.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,12 @@ class DataLayout {
194194
/// description on failure.
195195
LLVM_ABI static Expected<DataLayout> parse(StringRef LayoutString);
196196

197+
/// Given an LLVM target triple, compute the well-known datalayout string.
198+
/// TODO: Create a static factor helper version of this method and refactor
199+
/// the TargetMachine callers to use it.
200+
LLVM_ABI static std::string computeStringForTriple(const Triple &T,
201+
StringRef ABIName = "");
202+
197203
/// Layout endianness...
198204
bool isLittleEndian() const { return !BigEndian; }
199205
bool isBigEndian() const { return BigEndian; }

0 commit comments

Comments
 (0)