diff --git a/lib/Target/PowerPC/PPCSubtarget.cpp b/lib/Target/PowerPC/PPCSubtarget.cpp index 0ef85dfd292..607771b2ca4 100644 --- a/lib/Target/PowerPC/PPCSubtarget.cpp +++ b/lib/Target/PowerPC/PPCSubtarget.cpp @@ -69,7 +69,7 @@ static const char *GetCurrentPowerPCCPU() { #endif -PPCSubtarget::PPCSubtarget(const Module &M, const std::string &FS) +PPCSubtarget::PPCSubtarget(const Module &M, const std::string &FS, bool is64Bit) : StackAlignment(16) , InstrItins() , IsGigaProcessor(false) diff --git a/lib/Target/PowerPC/PPCSubtarget.h b/lib/Target/PowerPC/PPCSubtarget.h index 4f838741ad0..c98291e1620 100644 --- a/lib/Target/PowerPC/PPCSubtarget.h +++ b/lib/Target/PowerPC/PPCSubtarget.h @@ -44,7 +44,7 @@ public: /// This constructor initializes the data members to match that /// of the specified module. /// - PPCSubtarget(const Module &M, const std::string &FS); + PPCSubtarget(const Module &M, const std::string &FS, bool is64Bit); /// ParseSubtargetFeatures - Parses features string setting specified /// subtarget options. Definition of function is auto generated by tblgen. @@ -59,6 +59,10 @@ public: /// selection. const InstrItineraryData getInstrItineraryData() const { return InstrItins; } + const char *getTargetDataString() const { + // FIXME: Make is64Bit be for the processor, not the target. + return true ? "E-p:32:32-d:32-l:32" : "E-p:64:64-d:32-l:32"; + } bool hasFSQRT() const { return HasFSQRT; } bool hasSTFIWX() const { return HasSTFIWX; } diff --git a/lib/Target/PowerPC/PPCTargetMachine.cpp b/lib/Target/PowerPC/PPCTargetMachine.cpp index 82ea5c97427..a518f9d69c1 100644 --- a/lib/Target/PowerPC/PPCTargetMachine.cpp +++ b/lib/Target/PowerPC/PPCTargetMachine.cpp @@ -29,19 +29,29 @@ using namespace llvm; namespace { // Register the targets - RegisterTarget - X("ppc32", " PowerPC"); + RegisterTarget + X("ppc32", " PowerPC 32"); + RegisterTarget + Y("ppc64", " PowerPC 64"); } -unsigned PPCTargetMachine::getJITMatchQuality() { +unsigned PPC32TargetMachine::getJITMatchQuality() { #if defined(__POWERPC__) || defined (__ppc__) || defined(_POWER) - return 10; + if (sizeof(void*) == 4) + return 10; #else return 0; #endif } +unsigned PPC64TargetMachine::getJITMatchQuality() { +#if defined(__POWERPC__) || defined (__ppc__) || defined(_POWER) + if (sizeof(void*) == 8) + return 10 * 0/*FIXME: not PPC64-JIT support yet! */; +#endif + return 0; +} -unsigned PPCTargetMachine::getModuleMatchQuality(const Module &M) { +unsigned PPC32TargetMachine::getModuleMatchQuality(const Module &M) { // We strongly match "powerpc-*". std::string TT = M.getTargetTriple(); if (TT.size() >= 8 && std::string(TT.begin(), TT.begin()+8) == "powerpc-") @@ -57,11 +67,31 @@ unsigned PPCTargetMachine::getModuleMatchQuality(const Module &M) { return getJITMatchQuality()/2; } -PPCTargetMachine::PPCTargetMachine(const Module &M, const std::string &FS) -: TargetMachine("PowerPC"), - DataLayout(std::string("PowerPC"), std::string("E-p:32:32-d:32-l:32")), - Subtarget(M, FS), FrameInfo(*this, false), JITInfo(*this), - TLInfo(*this), InstrItins(Subtarget.getInstrItineraryData()) { +unsigned PPC64TargetMachine::getModuleMatchQuality(const Module &M) { + // We strongly match "powerpc64-*". + std::string TT = M.getTargetTriple(); + if (TT.size() >= 10 && std::string(TT.begin(), TT.begin()+10) == "powerpc64-") + return 20; + + if (M.getEndianness() == Module::BigEndian && + M.getPointerSize() == Module::Pointer64) + return 10; // Weak match + else if (M.getEndianness() != Module::AnyEndianness || + M.getPointerSize() != Module::AnyPointerSize) + return 0; // Match for some other target + + return getJITMatchQuality()/2; +} + + +PPCTargetMachine::PPCTargetMachine(const Module &M, const std::string &FS, + bool is64Bit) + : TargetMachine("PowerPC"), Subtarget(M, FS, is64Bit), + DataLayout(std::string("PowerPC"), + std::string(Subtarget.getTargetDataString())), + FrameInfo(*this, false), JITInfo(*this), TLInfo(*this), + InstrItins(Subtarget.getInstrItineraryData()) { + if (TargetDefault == PPCTarget) { if (Subtarget.isAIX()) PPCTarget = TargetAIX; if (Subtarget.isDarwin()) PPCTarget = TargetDarwin; @@ -73,6 +103,15 @@ PPCTargetMachine::PPCTargetMachine(const Module &M, const std::string &FS) setRelocationModel(Reloc::PIC); } +PPC32TargetMachine::PPC32TargetMachine(const Module &M, const std::string &FS) + : PPCTargetMachine(M, FS, false) { +} + + +PPC64TargetMachine::PPC64TargetMachine(const Module &M, const std::string &FS) + : PPCTargetMachine(M, FS, true) { +} + /// addPassesToEmitFile - Add passes to the specified pass manager to implement /// a static compiler for this target. /// diff --git a/lib/Target/PowerPC/PPCTargetMachine.h b/lib/Target/PowerPC/PPCTargetMachine.h index 06799457418..266ef18044f 100644 --- a/lib/Target/PowerPC/PPCTargetMachine.h +++ b/lib/Target/PowerPC/PPCTargetMachine.h @@ -26,44 +26,63 @@ namespace llvm { class PassManager; class GlobalValue; +/// PPCTargetMachine - Common code between 32-bit and 64-bit PowerPC targets. +/// class PPCTargetMachine : public TargetMachine { - const TargetData DataLayout; // Calculates type size & alignment - PPCInstrInfo InstrInfo; - PPCSubtarget Subtarget; - PPCFrameInfo FrameInfo; - PPCJITInfo JITInfo; - PPCTargetLowering TLInfo; - InstrItineraryData InstrItins; + PPCSubtarget Subtarget; + const TargetData DataLayout; // Calculates type size & alignment + PPCInstrInfo InstrInfo; + PPCFrameInfo FrameInfo; + PPCJITInfo JITInfo; + PPCTargetLowering TLInfo; + InstrItineraryData InstrItins; public: - PPCTargetMachine(const Module &M, const std::string &FS); + PPCTargetMachine(const Module &M, const std::string &FS, bool is64Bit); virtual const PPCInstrInfo *getInstrInfo() const { return &InstrInfo; } virtual const TargetFrameInfo *getFrameInfo() const { return &FrameInfo; } virtual TargetJITInfo *getJITInfo() { return &JITInfo; } - virtual const TargetSubtarget *getSubtargetImpl() const{ return &Subtarget; } virtual PPCTargetLowering *getTargetLowering() const { return const_cast(&TLInfo); } virtual const MRegisterInfo *getRegisterInfo() const { return &InstrInfo.getRegisterInfo(); } - virtual const TargetData *getTargetData() const { return &DataLayout; } + + virtual const TargetData *getTargetData() const { return &DataLayout; } + virtual const PPCSubtarget *getSubtargetImpl() const { return &Subtarget; } virtual const InstrItineraryData getInstrItineraryData() const { return InstrItins; } - static unsigned getJITMatchQuality(); - - static unsigned getModuleMatchQuality(const Module &M); - virtual bool addPassesToEmitFile(PassManager &PM, std::ostream &Out, CodeGenFileType FileType, bool Fast); bool addPassesToEmitMachineCode(FunctionPassManager &PM, MachineCodeEmitter &MCE); }; + +/// PPC32TargetMachine - PowerPC 32-bit target machine. +/// +class PPC32TargetMachine : public PPCTargetMachine { +public: + PPC32TargetMachine(const Module &M, const std::string &FS); + static unsigned getJITMatchQuality(); + static unsigned getModuleMatchQuality(const Module &M); +}; + +/// PPC64TargetMachine - PowerPC 64-bit target machine. +/// +class PPC64TargetMachine : public PPCTargetMachine { +public: + PPC64TargetMachine(const Module &M, const std::string &FS); + + static unsigned getJITMatchQuality(); + static unsigned getModuleMatchQuality(const Module &M); +}; + } // end namespace llvm #endif