[PATCH] D66843: Change datalayout compatibility check for X86 to allow datalayouts without the new address spaces.

Eric Christopher via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 9 13:53:46 PDT 2019


Not just add addrspace 0 to all of them?

-eric

On Tue, Aug 27, 2019 at 4:06 PM Amy Huang via Phabricator via
llvm-commits <llvm-commits at lists.llvm.org> wrote:
>
> akhuang created this revision.
> akhuang added a reviewer: rnk.
> Herald added subscribers: llvm-commits, hiraditya.
> Herald added a project: LLVM.
>
> Follow up to https://reviews.llvm.org/D64931 to allow existing IR with the old datalayout to compile.
>
>
> Repository:
>   rG LLVM Github Monorepo
>
> https://reviews.llvm.org/D66843
>
> Files:
>   llvm/include/llvm/Target/TargetMachine.h
>   llvm/lib/Target/X86/X86TargetMachine.cpp
>   llvm/lib/Target/X86/X86TargetMachine.h
>
>
> Index: llvm/lib/Target/X86/X86TargetMachine.h
> ===================================================================
> --- llvm/lib/Target/X86/X86TargetMachine.h
> +++ llvm/lib/Target/X86/X86TargetMachine.h
> @@ -30,6 +30,7 @@
>  class X86TargetMachine final : public LLVMTargetMachine {
>    std::unique_ptr<TargetLoweringObjectFile> TLOF;
>    mutable StringMap<std::unique_ptr<X86Subtarget>> 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
> Index: llvm/lib/Target/X86/X86TargetMachine.cpp
> ===================================================================
> --- llvm/lib/Target/X86/X86TargetMachine.cpp
> +++ 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
>  //===----------------------------------------------------------------------===//
> Index: llvm/include/llvm/Target/TargetMachine.h
> ===================================================================
> --- llvm/include/llvm/Target/TargetMachine.h
> +++ 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;
>    }
>
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits


More information about the llvm-commits mailing list