LLVM API Documentation

PPCTargetMachine.cpp

Go to the documentation of this file.
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 "PPC.h"
00015 #include "PPCTargetAsmInfo.h"
00016 #include "PPCTargetMachine.h"
00017 #include "llvm/PassManager.h"
00018 #include "llvm/Target/TargetOptions.h"
00019 #include "llvm/Target/TargetRegistry.h"
00020 #include "llvm/Support/FormattedStream.h"
00021 using namespace llvm;
00022 
00023 static const TargetAsmInfo *createTargetAsmInfo(const Target &T,
00024                                                 const StringRef &TT) {
00025   Triple TheTriple(TT);
00026   bool isPPC64 = TheTriple.getArch() == Triple::ppc64;
00027   if (TheTriple.getOS() == Triple::Darwin)
00028     return new PPCDarwinTargetAsmInfo(isPPC64);
00029   return new PPCLinuxTargetAsmInfo(isPPC64);
00030   
00031 }
00032 
00033 extern "C" void LLVMInitializePowerPCTarget() {
00034   // Register the targets
00035   RegisterTargetMachine<PPC32TargetMachine> A(ThePPC32Target);  
00036   RegisterTargetMachine<PPC64TargetMachine> B(ThePPC64Target);
00037   
00038   RegisterAsmInfoFn C(ThePPC32Target, createTargetAsmInfo);
00039   RegisterAsmInfoFn D(ThePPC64Target, createTargetAsmInfo);
00040 }
00041 
00042 
00043 PPCTargetMachine::PPCTargetMachine(const Target &T, const std::string &TT,
00044                                    const std::string &FS, bool is64Bit)
00045   : LLVMTargetMachine(T, TT),
00046     Subtarget(TT, FS, is64Bit),
00047     DataLayout(Subtarget.getTargetDataString()), InstrInfo(*this),
00048     FrameInfo(*this, is64Bit), JITInfo(*this, is64Bit), TLInfo(*this),
00049     InstrItins(Subtarget.getInstrItineraryData()), MachOWriterInfo(*this) {
00050 
00051   if (getRelocationModel() == Reloc::Default) {
00052     if (Subtarget.isDarwin())
00053       setRelocationModel(Reloc::DynamicNoPIC);
00054     else
00055       setRelocationModel(Reloc::Static);
00056   }
00057 }
00058 
00059 /// Override this for PowerPC.  Tail merging happily breaks up instruction issue
00060 /// groups, which typically degrades performance.
00061 bool PPCTargetMachine::getEnableTailMergeDefault() const { return false; }
00062 
00063 PPC32TargetMachine::PPC32TargetMachine(const Target &T, const std::string &TT, 
00064                                        const std::string &FS) 
00065   : PPCTargetMachine(T, TT, FS, false) {
00066 }
00067 
00068 
00069 PPC64TargetMachine::PPC64TargetMachine(const Target &T, const std::string &TT, 
00070                                        const std::string &FS)
00071   : PPCTargetMachine(T, TT, FS, true) {
00072 }
00073 
00074 
00075 //===----------------------------------------------------------------------===//
00076 // Pass Pipeline Configuration
00077 //===----------------------------------------------------------------------===//
00078 
00079 bool PPCTargetMachine::addInstSelector(PassManagerBase &PM,
00080                                        CodeGenOpt::Level OptLevel) {
00081   // Install an instruction selector.
00082   PM.add(createPPCISelDag(*this));
00083   return false;
00084 }
00085 
00086 bool PPCTargetMachine::addPreEmitPass(PassManagerBase &PM,
00087                                       CodeGenOpt::Level OptLevel) {
00088   // Must run branch selection immediately preceding the asm printer.
00089   PM.add(createPPCBranchSelectionPass());
00090   return false;
00091 }
00092 
00093 bool PPCTargetMachine::addCodeEmitter(PassManagerBase &PM,
00094                                       CodeGenOpt::Level OptLevel,
00095                                       MachineCodeEmitter &MCE) {
00096   // The JIT should use the static relocation model in ppc32 mode, PIC in ppc64.
00097   // FIXME: This should be moved to TargetJITInfo!!
00098   if (Subtarget.isPPC64()) {
00099     // We use PIC codegen in ppc64 mode, because otherwise we'd have to use many
00100     // instructions to materialize arbitrary global variable + function +
00101     // constant pool addresses.
00102     setRelocationModel(Reloc::PIC_);
00103     // Temporary workaround for the inability of PPC64 JIT to handle jump
00104     // tables.
00105     DisableJumpTables = true;      
00106   } else {
00107     setRelocationModel(Reloc::Static);
00108   }
00109   
00110   // Inform the subtarget that we are in JIT mode.  FIXME: does this break macho
00111   // writing?
00112   Subtarget.SetJITMode();
00113   
00114   // Machine code emitter pass for PowerPC.
00115   PM.add(createPPCCodeEmitterPass(*this, MCE));
00116 
00117   return false;
00118 }
00119 
00120 bool PPCTargetMachine::addCodeEmitter(PassManagerBase &PM,
00121                                       CodeGenOpt::Level OptLevel,
00122                                       JITCodeEmitter &JCE) {
00123   // The JIT should use the static relocation model in ppc32 mode, PIC in ppc64.
00124   // FIXME: This should be moved to TargetJITInfo!!
00125   if (Subtarget.isPPC64()) {
00126     // We use PIC codegen in ppc64 mode, because otherwise we'd have to use many
00127     // instructions to materialize arbitrary global variable + function +
00128     // constant pool addresses.
00129     setRelocationModel(Reloc::PIC_);
00130     // Temporary workaround for the inability of PPC64 JIT to handle jump
00131     // tables.
00132     DisableJumpTables = true;      
00133   } else {
00134     setRelocationModel(Reloc::Static);
00135   }
00136   
00137   // Inform the subtarget that we are in JIT mode.  FIXME: does this break macho
00138   // writing?
00139   Subtarget.SetJITMode();
00140   
00141   // Machine code emitter pass for PowerPC.
00142   PM.add(createPPCJITCodeEmitterPass(*this, JCE));
00143 
00144   return false;
00145 }
00146 
00147 bool PPCTargetMachine::addCodeEmitter(PassManagerBase &PM,
00148                                       CodeGenOpt::Level OptLevel,
00149                                       ObjectCodeEmitter &OCE) {
00150   // The JIT should use the static relocation model in ppc32 mode, PIC in ppc64.
00151   // FIXME: This should be moved to TargetJITInfo!!
00152   if (Subtarget.isPPC64()) {
00153     // We use PIC codegen in ppc64 mode, because otherwise we'd have to use many
00154     // instructions to materialize arbitrary global variable + function +
00155     // constant pool addresses.
00156     setRelocationModel(Reloc::PIC_);
00157     // Temporary workaround for the inability of PPC64 JIT to handle jump
00158     // tables.
00159     DisableJumpTables = true;      
00160   } else {
00161     setRelocationModel(Reloc::Static);
00162   }
00163   
00164   // Inform the subtarget that we are in JIT mode.  FIXME: does this break macho
00165   // writing?
00166   Subtarget.SetJITMode();
00167   
00168   // Machine code emitter pass for PowerPC.
00169   PM.add(createPPCObjectCodeEmitterPass(*this, OCE));
00170 
00171   return false;
00172 }
00173 
00174 bool PPCTargetMachine::addSimpleCodeEmitter(PassManagerBase &PM,
00175                                             CodeGenOpt::Level OptLevel,
00176                                             MachineCodeEmitter &MCE) {
00177   // Machine code emitter pass for PowerPC.
00178   PM.add(createPPCCodeEmitterPass(*this, MCE));
00179   return false;
00180 }
00181 
00182 bool PPCTargetMachine::addSimpleCodeEmitter(PassManagerBase &PM,
00183                                             CodeGenOpt::Level OptLevel,
00184                                             JITCodeEmitter &JCE) {
00185   // Machine code emitter pass for PowerPC.
00186   PM.add(createPPCJITCodeEmitterPass(*this, JCE));
00187   return false;
00188 }
00189 
00190 bool PPCTargetMachine::addSimpleCodeEmitter(PassManagerBase &PM,
00191                                             CodeGenOpt::Level OptLevel,
00192                                             ObjectCodeEmitter &OCE) {
00193   // Machine code emitter pass for PowerPC.
00194   PM.add(createPPCObjectCodeEmitterPass(*this, OCE));
00195   return false;
00196 }
00197 
00198