diff --git a/llvm/include/llvm/Target/TargetMachine.h b/llvm/include/llvm/Target/TargetMachine.h --- a/llvm/include/llvm/Target/TargetMachine.h +++ b/llvm/include/llvm/Target/TargetMachine.h @@ -157,7 +157,7 @@ /// 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 { + virtual bool isCompatibleDataLayout(const DataLayout &Candidate) const { return DL == Candidate; } diff --git a/llvm/lib/Target/X86/X86TargetMachine.h b/llvm/lib/Target/X86/X86TargetMachine.h --- a/llvm/lib/Target/X86/X86TargetMachine.h +++ b/llvm/lib/Target/X86/X86TargetMachine.h @@ -30,6 +30,7 @@ class X86TargetMachine final : public LLVMTargetMachine { std::unique_ptr TLOF; mutable StringMap> SubtargetMap; + const DataLayout DLNoAddrSpaces; public: X86TargetMachine(const Target &T, const Triple &TT, StringRef CPU, @@ -52,6 +53,8 @@ TargetLoweringObjectFile *getObjFileLowering() const override { return TLOF.get(); } + + bool isCompatibleDataLayout(const DataLayout &Candidate) const override; }; } // end namespace llvm diff --git a/llvm/lib/Target/X86/X86TargetMachine.cpp b/llvm/lib/Target/X86/X86TargetMachine.cpp --- a/llvm/lib/Target/X86/X86TargetMachine.cpp +++ b/llvm/lib/Target/X86/X86TargetMachine.cpp @@ -106,7 +106,8 @@ llvm_unreachable("unknown subtarget type"); } -static std::string computeDataLayout(const Triple &TT) { +static std::string computeDataLayout(const Triple &TT, + bool AddressSpaces = true) { // X86 is little endian std::string Ret = "e"; @@ -118,7 +119,8 @@ Ret += "-p:32:32"; // Address spaces for 32 bit signed, 32 bit unsigned, and 64 bit pointers. - Ret += "-p270:32:32-p271:32:32-p272:64:64"; + if (AddressSpaces) + Ret += "-p270:32:32-p271:32:32-p272:64:64"; // Some ABIs align 64 bit integers and doubles to 64 bits, others to 32. if (TT.isArch64Bit() || TT.isOSWindows() || TT.isOSNaCl()) @@ -221,7 +223,8 @@ getEffectiveRelocModel(TT, JIT, RM), getEffectiveX86CodeModel(CM, JIT, TT.getArch() == Triple::x86_64), OL), - TLOF(createTLOF(getTargetTriple())) { + TLOF(createTLOF(getTargetTriple())), + DLNoAddrSpaces(computeDataLayout(TT, /*AddressSpaces=*/false)) { // Windows stack unwinder gets confused when execution flow "falls through" // after a call to 'noreturn' function. // To prevent that, we emit a trap for 'unreachable' IR instructions. @@ -323,6 +326,13 @@ return I.get(); } +bool X86TargetMachine::isCompatibleDataLayout( + const DataLayout &Candidate) const { + // Maintain compatibility with datalayouts that don't have address space + // pointer sizes. + return DL == Candidate || DLNoAddrSpaces == Candidate; +} + //===----------------------------------------------------------------------===// // Command line options for x86 //===----------------------------------------------------------------------===//