From: Eric Christopher Date: Tue, 17 Feb 2015 06:45:15 +0000 (+0000) Subject: Move ABI handling and 64-bitness to the PowerPC target machine. X-Git-Url: http://plrg.eecs.uci.edu/git/?p=oota-llvm.git;a=commitdiff_plain;h=fb031eee53a29db17a122f99c2e3048ed643d55e Move ABI handling and 64-bitness to the PowerPC target machine. This required changing how the computation of the ABI is handled and how some of the checks for ABI/target are done. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@229471 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Target/PowerPC/PPC.td b/lib/Target/PowerPC/PPC.td index 63160b2a07a..f53add506ca 100644 --- a/lib/Target/PowerPC/PPC.td +++ b/lib/Target/PowerPC/PPC.td @@ -132,16 +132,6 @@ def DeprecatedDST : SubtargetFeature<"", "DeprecatedDST", "true", // DFP p6, p6x, p7 decimal floating-point instructions // POPCNTB p5 through p7 popcntb and related instructions -//===----------------------------------------------------------------------===// -// ABI Selection // -//===----------------------------------------------------------------------===// - -def FeatureELFv1 : SubtargetFeature<"elfv1", "TargetABI", "PPC_ABI_ELFv1", - "Use the ELFv1 ABI">; - -def FeatureELFv2 : SubtargetFeature<"elfv2", "TargetABI", "PPC_ABI_ELFv2", - "Use the ELFv2 ABI">; - //===----------------------------------------------------------------------===// // Classes used for relation maps. //===----------------------------------------------------------------------===// diff --git a/lib/Target/PowerPC/PPCSubtarget.cpp b/lib/Target/PowerPC/PPCSubtarget.cpp index 6f70218337a..0f3f72eac31 100644 --- a/lib/Target/PowerPC/PPCSubtarget.cpp +++ b/lib/Target/PowerPC/PPCSubtarget.cpp @@ -49,9 +49,8 @@ PPCSubtarget::PPCSubtarget(const std::string &TT, const std::string &CPU, : PPCGenSubtargetInfo(TT, CPU, FS), TargetTriple(TT), IsPPC64(TargetTriple.getArch() == Triple::ppc64 || TargetTriple.getArch() == Triple::ppc64le), - TargetABI(PPC_ABI_UNKNOWN), TM(TM), - FrameLowering(initializeSubtargetDependencies(CPU, FS)), InstrInfo(*this), - TLInfo(TM, *this), TSInfo(TM.getDataLayout()) {} + TM(TM), FrameLowering(initializeSubtargetDependencies(CPU, FS)), + InstrInfo(*this), TLInfo(TM, *this), TSInfo(TM.getDataLayout()) {} void PPCSubtarget::initializeEnvironment() { StackAlignment = 16; @@ -132,16 +131,6 @@ void PPCSubtarget::initSubtargetFeatures(StringRef CPU, StringRef FS) { // Determine endianness. IsLittleEndian = (TargetTriple.getArch() == Triple::ppc64le); - - // Determine default ABI. - if (TargetABI == PPC_ABI_UNKNOWN) { - if (!isDarwin() && IsPPC64) { - if (IsLittleEndian) - TargetABI = PPC_ABI_ELFv2; - else - TargetABI = PPC_ABI_ELFv1; - } - } } /// hasLazyResolverStub - Return true if accesses to the specified global have @@ -215,3 +204,5 @@ bool PPCSubtarget::enableSubRegLiveness() const { return UseSubRegLiveness; } +bool PPCSubtarget::isELFv2ABI() const { return TM.isELFv2ABI(); } +bool PPCSubtarget::isPPC64() const { return TM.isPPC64(); } diff --git a/lib/Target/PowerPC/PPCSubtarget.h b/lib/Target/PowerPC/PPCSubtarget.h index ce17c1ea779..704a226ed33 100644 --- a/lib/Target/PowerPC/PPCSubtarget.h +++ b/lib/Target/PowerPC/PPCSubtarget.h @@ -114,11 +114,6 @@ protected: bool HasICBT; bool HasInvariantFunctionDescriptors; - enum { - PPC_ABI_UNKNOWN, - PPC_ABI_ELFv1, - PPC_ABI_ELFv2 - } TargetABI; const PPCTargetMachine &TM; PPCFrameLowering FrameLowering; PPCInstrInfo InstrInfo; @@ -177,7 +172,7 @@ private: public: /// isPPC64 - Return true if we are generating code for 64-bit pointer mode. /// - bool isPPC64() const { return IsPPC64; } + bool isPPC64() const; /// has64BitSupport - Return true if the selected CPU supports 64-bit /// instructions, regardless of whether we are in 32-bit or 64-bit mode. @@ -245,9 +240,9 @@ public: bool isTargetELF() const { return TargetTriple.isOSBinFormatELF(); } bool isTargetMachO() const { return TargetTriple.isOSBinFormatMachO(); } - bool isDarwinABI() const { return isDarwin(); } - bool isSVR4ABI() const { return !isDarwin(); } - bool isELFv2ABI() const { return TargetABI == PPC_ABI_ELFv2; } + bool isDarwinABI() const { return isTargetMachO() || isDarwin(); } + bool isSVR4ABI() const { return !isDarwinABI(); } + bool isELFv2ABI() const; bool enableEarlyIfConversion() const override { return hasISEL(); } diff --git a/lib/Target/PowerPC/PPCTargetMachine.cpp b/lib/Target/PowerPC/PPCTargetMachine.cpp index 04cb4f9979e..a81f7fbfc1c 100644 --- a/lib/Target/PowerPC/PPCTargetMachine.cpp +++ b/lib/Target/PowerPC/PPCTargetMachine.cpp @@ -123,6 +123,30 @@ static std::unique_ptr createTLOF(const Triple &TT) { return make_unique(); } +static PPCTargetMachine::PPCABI computeTargetABI(const Triple &TT, + const TargetOptions &Options) { + if (Options.MCOptions.getABIName().startswith("elfv1")) + return PPCTargetMachine::PPC_ABI_ELFv1; + else if (Options.MCOptions.getABIName().startswith("elfv2")) + return PPCTargetMachine::PPC_ABI_ELFv2; + + assert(Options.MCOptions.getABIName().empty() && + "Unknown target-abi option!"); + + if (!TT.isMacOSX()) { + switch (TT.getArch()) { + case Triple::ppc64le: + return PPCTargetMachine::PPC_ABI_ELFv2; + case Triple::ppc64: + return PPCTargetMachine::PPC_ABI_ELFv1; + default: + // Fallthrough. + ; + } + } + return PPCTargetMachine::PPC_ABI_UNKNOWN; +} + // The FeatureString here is a little subtle. We are modifying the feature string // with what are (currently) non-function specific overrides as it goes into the // LLVMTargetMachine constructor and then using the stored value in the @@ -134,6 +158,7 @@ PPCTargetMachine::PPCTargetMachine(const Target &T, StringRef TT, StringRef CPU, : LLVMTargetMachine(T, TT, CPU, computeFSAdditions(FS, OL, TT), Options, RM, CM, OL), TLOF(createTLOF(Triple(getTargetTriple()))), + TargetABI(computeTargetABI(Triple(TT), Options)), DL(getDataLayoutString(Triple(TT))), Subtarget(TT, CPU, TargetFS, *this) { initAsmInfo(); } diff --git a/lib/Target/PowerPC/PPCTargetMachine.h b/lib/Target/PowerPC/PPCTargetMachine.h index 4499219b833..65084842bc8 100644 --- a/lib/Target/PowerPC/PPCTargetMachine.h +++ b/lib/Target/PowerPC/PPCTargetMachine.h @@ -24,7 +24,11 @@ namespace llvm { /// PPCTargetMachine - Common code between 32-bit and 64-bit PowerPC targets. /// class PPCTargetMachine : public LLVMTargetMachine { +public: + enum PPCABI { PPC_ABI_UNKNOWN, PPC_ABI_ELFv1, PPC_ABI_ELFv2 }; +private: std::unique_ptr TLOF; + PPCABI TargetABI; // Calculates type size & alignment const DataLayout DL; PPCSubtarget Subtarget; @@ -50,6 +54,11 @@ public: TargetLoweringObjectFile *getObjFileLowering() const override { return TLOF.get(); } + bool isELFv2ABI() const { return TargetABI == PPC_ABI_ELFv2; } + bool isPPC64() const { + Triple TT(getTargetTriple()); + return (TT.getArch() == Triple::ppc64 || TT.getArch() == Triple::ppc64le); + }; }; /// PPC32TargetMachine - PowerPC 32-bit target machine. diff --git a/test/CodeGen/PowerPC/ppc64-elf-abi.ll b/test/CodeGen/PowerPC/ppc64-elf-abi.ll index d82122d58ee..53443376e4d 100644 --- a/test/CodeGen/PowerPC/ppc64-elf-abi.ll +++ b/test/CodeGen/PowerPC/ppc64-elf-abi.ll @@ -1,9 +1,9 @@ ; RUN: llc -mtriple=powerpc64-unknown-linux-gnu < %s | FileCheck %s -check-prefix=CHECK-ELFv1 -; RUN: llc -mtriple=powerpc64-unknown-linux-gnu -mattr=+elfv1 < %s | FileCheck %s -check-prefix=CHECK-ELFv1 -; RUN: llc -mtriple=powerpc64-unknown-linux-gnu -mattr=+elfv2 < %s | FileCheck %s -check-prefix=CHECK-ELFv2 +; RUN: llc -mtriple=powerpc64-unknown-linux-gnu -target-abi elfv1 < %s | FileCheck %s -check-prefix=CHECK-ELFv1 +; RUN: llc -mtriple=powerpc64-unknown-linux-gnu -target-abi elfv2 < %s | FileCheck %s -check-prefix=CHECK-ELFv2 ; RUN: llc -mtriple=powerpc64le-unknown-linux-gnu < %s | FileCheck %s -check-prefix=CHECK-ELFv2 -; RUN: llc -mtriple=powerpc64le-unknown-linux-gnu -mattr=+elfv1 < %s | FileCheck %s -check-prefix=CHECK-ELFv1 -; RUN: llc -mtriple=powerpc64le-unknown-linux-gnu -mattr=+elfv2 < %s | FileCheck %s -check-prefix=CHECK-ELFv2 +; RUN: llc -mtriple=powerpc64le-unknown-linux-gnu -target-abi elfv1 < %s | FileCheck %s -check-prefix=CHECK-ELFv1 +; RUN: llc -mtriple=powerpc64le-unknown-linux-gnu -target-abi elfv2 < %s | FileCheck %s -check-prefix=CHECK-ELFv2 ; CHECK-ELFv2: .abiversion 2 ; CHECK-ELFv1-NOT: .abiversion 2