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
This commit is contained in:
Eric Christopher
2015-02-17 06:45:15 +00:00
parent cdc4c07360
commit fb031eee53
6 changed files with 46 additions and 36 deletions

View File

@@ -132,16 +132,6 @@ def DeprecatedDST : SubtargetFeature<"", "DeprecatedDST", "true",
// DFP p6, p6x, p7 decimal floating-point instructions // DFP p6, p6x, p7 decimal floating-point instructions
// POPCNTB p5 through p7 popcntb and related 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. // Classes used for relation maps.
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//

View File

@@ -49,9 +49,8 @@ PPCSubtarget::PPCSubtarget(const std::string &TT, const std::string &CPU,
: PPCGenSubtargetInfo(TT, CPU, FS), TargetTriple(TT), : PPCGenSubtargetInfo(TT, CPU, FS), TargetTriple(TT),
IsPPC64(TargetTriple.getArch() == Triple::ppc64 || IsPPC64(TargetTriple.getArch() == Triple::ppc64 ||
TargetTriple.getArch() == Triple::ppc64le), TargetTriple.getArch() == Triple::ppc64le),
TargetABI(PPC_ABI_UNKNOWN), TM(TM), TM(TM), FrameLowering(initializeSubtargetDependencies(CPU, FS)),
FrameLowering(initializeSubtargetDependencies(CPU, FS)), InstrInfo(*this), InstrInfo(*this), TLInfo(TM, *this), TSInfo(TM.getDataLayout()) {}
TLInfo(TM, *this), TSInfo(TM.getDataLayout()) {}
void PPCSubtarget::initializeEnvironment() { void PPCSubtarget::initializeEnvironment() {
StackAlignment = 16; StackAlignment = 16;
@@ -132,16 +131,6 @@ void PPCSubtarget::initSubtargetFeatures(StringRef CPU, StringRef FS) {
// Determine endianness. // Determine endianness.
IsLittleEndian = (TargetTriple.getArch() == Triple::ppc64le); 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 /// hasLazyResolverStub - Return true if accesses to the specified global have
@@ -215,3 +204,5 @@ bool PPCSubtarget::enableSubRegLiveness() const {
return UseSubRegLiveness; return UseSubRegLiveness;
} }
bool PPCSubtarget::isELFv2ABI() const { return TM.isELFv2ABI(); }
bool PPCSubtarget::isPPC64() const { return TM.isPPC64(); }

View File

@@ -114,11 +114,6 @@ protected:
bool HasICBT; bool HasICBT;
bool HasInvariantFunctionDescriptors; bool HasInvariantFunctionDescriptors;
enum {
PPC_ABI_UNKNOWN,
PPC_ABI_ELFv1,
PPC_ABI_ELFv2
} TargetABI;
const PPCTargetMachine &TM; const PPCTargetMachine &TM;
PPCFrameLowering FrameLowering; PPCFrameLowering FrameLowering;
PPCInstrInfo InstrInfo; PPCInstrInfo InstrInfo;
@@ -177,7 +172,7 @@ private:
public: public:
/// isPPC64 - Return true if we are generating code for 64-bit pointer mode. /// 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 /// has64BitSupport - Return true if the selected CPU supports 64-bit
/// instructions, regardless of whether we are in 32-bit or 64-bit mode. /// 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 isTargetELF() const { return TargetTriple.isOSBinFormatELF(); }
bool isTargetMachO() const { return TargetTriple.isOSBinFormatMachO(); } bool isTargetMachO() const { return TargetTriple.isOSBinFormatMachO(); }
bool isDarwinABI() const { return isDarwin(); } bool isDarwinABI() const { return isTargetMachO() || isDarwin(); }
bool isSVR4ABI() const { return !isDarwin(); } bool isSVR4ABI() const { return !isDarwinABI(); }
bool isELFv2ABI() const { return TargetABI == PPC_ABI_ELFv2; } bool isELFv2ABI() const;
bool enableEarlyIfConversion() const override { return hasISEL(); } bool enableEarlyIfConversion() const override { return hasISEL(); }

View File

@@ -123,6 +123,30 @@ static std::unique_ptr<TargetLoweringObjectFile> createTLOF(const Triple &TT) {
return make_unique<PPC64LinuxTargetObjectFile>(); return make_unique<PPC64LinuxTargetObjectFile>();
} }
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 // 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 // with what are (currently) non-function specific overrides as it goes into the
// LLVMTargetMachine constructor and then using the stored value in 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, : LLVMTargetMachine(T, TT, CPU, computeFSAdditions(FS, OL, TT), Options, RM,
CM, OL), CM, OL),
TLOF(createTLOF(Triple(getTargetTriple()))), TLOF(createTLOF(Triple(getTargetTriple()))),
TargetABI(computeTargetABI(Triple(TT), Options)),
DL(getDataLayoutString(Triple(TT))), Subtarget(TT, CPU, TargetFS, *this) { DL(getDataLayoutString(Triple(TT))), Subtarget(TT, CPU, TargetFS, *this) {
initAsmInfo(); initAsmInfo();
} }

View File

@@ -24,7 +24,11 @@ namespace llvm {
/// PPCTargetMachine - Common code between 32-bit and 64-bit PowerPC targets. /// PPCTargetMachine - Common code between 32-bit and 64-bit PowerPC targets.
/// ///
class PPCTargetMachine : public LLVMTargetMachine { class PPCTargetMachine : public LLVMTargetMachine {
public:
enum PPCABI { PPC_ABI_UNKNOWN, PPC_ABI_ELFv1, PPC_ABI_ELFv2 };
private:
std::unique_ptr<TargetLoweringObjectFile> TLOF; std::unique_ptr<TargetLoweringObjectFile> TLOF;
PPCABI TargetABI;
// Calculates type size & alignment // Calculates type size & alignment
const DataLayout DL; const DataLayout DL;
PPCSubtarget Subtarget; PPCSubtarget Subtarget;
@@ -50,6 +54,11 @@ public:
TargetLoweringObjectFile *getObjFileLowering() const override { TargetLoweringObjectFile *getObjFileLowering() const override {
return TLOF.get(); 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. /// PPC32TargetMachine - PowerPC 32-bit target machine.

View File

@@ -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 < %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 -target-abi 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 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 < %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 -target-abi 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 elfv2 < %s | FileCheck %s -check-prefix=CHECK-ELFv2
; CHECK-ELFv2: .abiversion 2 ; CHECK-ELFv2: .abiversion 2
; CHECK-ELFv1-NOT: .abiversion 2 ; CHECK-ELFv1-NOT: .abiversion 2