LLVM API Documentation
00001 //===-- PPCTargetMachine.cpp - Define TargetMachine for PowerPC -----------===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // Top-level implementation for the PowerPC target. 00011 // 00012 //===----------------------------------------------------------------------===// 00013 00014 #include "PPCTargetMachine.h" 00015 #include "PPC.h" 00016 #include "llvm/CodeGen/Passes.h" 00017 #include "llvm/MC/MCStreamer.h" 00018 #include "llvm/PassManager.h" 00019 #include "llvm/Support/CommandLine.h" 00020 #include "llvm/Support/FormattedStream.h" 00021 #include "llvm/Support/TargetRegistry.h" 00022 #include "llvm/Target/TargetOptions.h" 00023 using namespace llvm; 00024 00025 static cl:: 00026 opt<bool> DisableCTRLoops("disable-ppc-ctrloops", cl::Hidden, 00027 cl::desc("Disable CTR loops for PPC")); 00028 00029 extern "C" void LLVMInitializePowerPCTarget() { 00030 // Register the targets 00031 RegisterTargetMachine<PPC32TargetMachine> A(ThePPC32Target); 00032 RegisterTargetMachine<PPC64TargetMachine> B(ThePPC64Target); 00033 } 00034 00035 PPCTargetMachine::PPCTargetMachine(const Target &T, StringRef TT, 00036 StringRef CPU, StringRef FS, 00037 const TargetOptions &Options, 00038 Reloc::Model RM, CodeModel::Model CM, 00039 CodeGenOpt::Level OL, 00040 bool is64Bit) 00041 : LLVMTargetMachine(T, TT, CPU, FS, Options, RM, CM, OL), 00042 Subtarget(TT, CPU, FS, is64Bit), 00043 DL(Subtarget.getDataLayoutString()), InstrInfo(*this), 00044 FrameLowering(Subtarget), JITInfo(*this, is64Bit), 00045 TLInfo(*this), TSInfo(*this), 00046 InstrItins(Subtarget.getInstrItineraryData()) { 00047 00048 // The binutils for the BG/P are too old for CFI. 00049 if (Subtarget.isBGP()) 00050 setMCUseCFI(false); 00051 initAsmInfo(); 00052 } 00053 00054 void PPC32TargetMachine::anchor() { } 00055 00056 PPC32TargetMachine::PPC32TargetMachine(const Target &T, StringRef TT, 00057 StringRef CPU, StringRef FS, 00058 const TargetOptions &Options, 00059 Reloc::Model RM, CodeModel::Model CM, 00060 CodeGenOpt::Level OL) 00061 : PPCTargetMachine(T, TT, CPU, FS, Options, RM, CM, OL, false) { 00062 } 00063 00064 void PPC64TargetMachine::anchor() { } 00065 00066 PPC64TargetMachine::PPC64TargetMachine(const Target &T, StringRef TT, 00067 StringRef CPU, StringRef FS, 00068 const TargetOptions &Options, 00069 Reloc::Model RM, CodeModel::Model CM, 00070 CodeGenOpt::Level OL) 00071 : PPCTargetMachine(T, TT, CPU, FS, Options, RM, CM, OL, true) { 00072 } 00073 00074 00075 //===----------------------------------------------------------------------===// 00076 // Pass Pipeline Configuration 00077 //===----------------------------------------------------------------------===// 00078 00079 namespace { 00080 /// PPC Code Generator Pass Configuration Options. 00081 class PPCPassConfig : public TargetPassConfig { 00082 public: 00083 PPCPassConfig(PPCTargetMachine *TM, PassManagerBase &PM) 00084 : TargetPassConfig(TM, PM) {} 00085 00086 PPCTargetMachine &getPPCTargetMachine() const { 00087 return getTM<PPCTargetMachine>(); 00088 } 00089 00090 const PPCSubtarget &getPPCSubtarget() const { 00091 return *getPPCTargetMachine().getSubtargetImpl(); 00092 } 00093 00094 virtual bool addPreISel(); 00095 virtual bool addILPOpts(); 00096 virtual bool addInstSelector(); 00097 virtual bool addPreSched2(); 00098 virtual bool addPreEmitPass(); 00099 }; 00100 } // namespace 00101 00102 TargetPassConfig *PPCTargetMachine::createPassConfig(PassManagerBase &PM) { 00103 return new PPCPassConfig(this, PM); 00104 } 00105 00106 bool PPCPassConfig::addPreISel() { 00107 if (!DisableCTRLoops && getOptLevel() != CodeGenOpt::None) 00108 addPass(createPPCCTRLoops(getPPCTargetMachine())); 00109 00110 return false; 00111 } 00112 00113 bool PPCPassConfig::addILPOpts() { 00114 if (getPPCSubtarget().hasISEL()) { 00115 addPass(&EarlyIfConverterID); 00116 return true; 00117 } 00118 00119 return false; 00120 } 00121 00122 bool PPCPassConfig::addInstSelector() { 00123 // Install an instruction selector. 00124 addPass(createPPCISelDag(getPPCTargetMachine())); 00125 00126 #ifndef NDEBUG 00127 if (!DisableCTRLoops && getOptLevel() != CodeGenOpt::None) 00128 addPass(createPPCCTRLoopsVerify()); 00129 #endif 00130 00131 return false; 00132 } 00133 00134 bool PPCPassConfig::addPreSched2() { 00135 if (getOptLevel() != CodeGenOpt::None) 00136 addPass(&IfConverterID); 00137 00138 return true; 00139 } 00140 00141 bool PPCPassConfig::addPreEmitPass() { 00142 if (getOptLevel() != CodeGenOpt::None) 00143 addPass(createPPCEarlyReturnPass()); 00144 // Must run branch selection immediately preceding the asm printer. 00145 addPass(createPPCBranchSelectionPass()); 00146 return false; 00147 } 00148 00149 bool PPCTargetMachine::addCodeEmitter(PassManagerBase &PM, 00150 JITCodeEmitter &JCE) { 00151 // Inform the subtarget that we are in JIT mode. FIXME: does this break macho 00152 // writing? 00153 Subtarget.SetJITMode(); 00154 00155 // Machine code emitter pass for PowerPC. 00156 PM.add(createPPCJITCodeEmitterPass(*this, JCE)); 00157 00158 return false; 00159 } 00160 00161 void PPCTargetMachine::addAnalysisPasses(PassManagerBase &PM) { 00162 // Add first the target-independent BasicTTI pass, then our PPC pass. This 00163 // allows the PPC pass to delegate to the target independent layer when 00164 // appropriate. 00165 PM.add(createBasicTargetTransformInfoPass(getTargetLowering())); 00166 PM.add(createPPCTargetTransformInfoPass(this)); 00167 } 00168