LLVM API Documentation
00001 //===-- PPCTargetMachine.cpp - Define TargetMachine for PowerPC -----------===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file was developed by the LLVM research group and is distributed under 00006 // the University of Illinois Open Source 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 "PPCFrameInfo.h" 00016 #include "PPCTargetMachine.h" 00017 #include "PPCJITInfo.h" 00018 #include "llvm/Module.h" 00019 #include "llvm/PassManager.h" 00020 #include "llvm/Analysis/Verifier.h" 00021 #include "llvm/CodeGen/MachineFunction.h" 00022 #include "llvm/CodeGen/Passes.h" 00023 #include "llvm/Target/TargetOptions.h" 00024 #include "llvm/Target/TargetMachineRegistry.h" 00025 #include "llvm/Transforms/Scalar.h" 00026 #include "llvm/Support/CommandLine.h" 00027 #include <iostream> 00028 using namespace llvm; 00029 00030 namespace { 00031 // Register the targets 00032 RegisterTarget<PPCTargetMachine> 00033 X("ppc32", " PowerPC"); 00034 } 00035 00036 unsigned PPCTargetMachine::getJITMatchQuality() { 00037 #if defined(__POWERPC__) || defined (__ppc__) || defined(_POWER) 00038 return 10; 00039 #else 00040 return 0; 00041 #endif 00042 } 00043 00044 unsigned PPCTargetMachine::getModuleMatchQuality(const Module &M) { 00045 // We strongly match "powerpc-*". 00046 std::string TT = M.getTargetTriple(); 00047 if (TT.size() >= 8 && std::string(TT.begin(), TT.begin()+8) == "powerpc-") 00048 return 20; 00049 00050 if (M.getEndianness() == Module::BigEndian && 00051 M.getPointerSize() == Module::Pointer32) 00052 return 10; // Weak match 00053 else if (M.getEndianness() != Module::AnyEndianness || 00054 M.getPointerSize() != Module::AnyPointerSize) 00055 return 0; // Match for some other target 00056 00057 return getJITMatchQuality()/2; 00058 } 00059 00060 PPCTargetMachine::PPCTargetMachine(const Module &M, const std::string &FS) 00061 : TargetMachine("PowerPC", false, 4, 4, 4, 4, 4, 4, 2, 1, 1), 00062 Subtarget(M, FS), FrameInfo(*this, false), JITInfo(*this), 00063 TLInfo(*this), InstrItins(Subtarget.getInstrItineraryData()) { 00064 if (TargetDefault == PPCTarget) { 00065 if (Subtarget.isAIX()) PPCTarget = TargetAIX; 00066 if (Subtarget.isDarwin()) PPCTarget = TargetDarwin; 00067 } 00068 if (getRelocationModel() == Reloc::Default) 00069 if (Subtarget.isDarwin()) 00070 setRelocationModel(Reloc::DynamicNoPIC); 00071 else 00072 setRelocationModel(Reloc::PIC); 00073 } 00074 00075 /// addPassesToEmitFile - Add passes to the specified pass manager to implement 00076 /// a static compiler for this target. 00077 /// 00078 bool PPCTargetMachine::addPassesToEmitFile(PassManager &PM, 00079 std::ostream &Out, 00080 CodeGenFileType FileType, 00081 bool Fast) { 00082 if (FileType != TargetMachine::AssemblyFile) return true; 00083 00084 // Run loop strength reduction before anything else. 00085 if (!Fast) PM.add(createLoopStrengthReducePass(&TLInfo)); 00086 00087 // FIXME: Implement efficient support for garbage collection intrinsics. 00088 PM.add(createLowerGCPass()); 00089 00090 // FIXME: Implement the invoke/unwind instructions! 00091 PM.add(createLowerInvokePass()); 00092 00093 // Clean up after other passes, e.g. merging critical edges. 00094 if (!Fast) PM.add(createCFGSimplificationPass()); 00095 00096 // Make sure that no unreachable blocks are instruction selected. 00097 PM.add(createUnreachableBlockEliminationPass()); 00098 00099 // Install an instruction selector. 00100 PM.add(createPPCISelDag(*this)); 00101 00102 if (PrintMachineCode) 00103 PM.add(createMachineFunctionPrinterPass(&std::cerr)); 00104 00105 PM.add(createRegisterAllocator()); 00106 00107 if (PrintMachineCode) 00108 PM.add(createMachineFunctionPrinterPass(&std::cerr)); 00109 00110 PM.add(createPrologEpilogCodeInserter()); 00111 00112 // Must run branch selection immediately preceding the asm printer 00113 PM.add(createPPCBranchSelectionPass()); 00114 00115 // Decide which asm printer to use. If the user has not specified one on 00116 // the command line, choose whichever one matches the default (current host). 00117 switch (PPCTarget) { 00118 case TargetAIX: 00119 PM.add(createAIXAsmPrinter(Out, *this)); 00120 break; 00121 case TargetDefault: 00122 case TargetDarwin: 00123 PM.add(createDarwinAsmPrinter(Out, *this)); 00124 break; 00125 } 00126 00127 PM.add(createMachineCodeDeleter()); 00128 return false; 00129 } 00130 00131 void PPCJITInfo::addPassesToJITCompile(FunctionPassManager &PM) { 00132 // The JIT should use dynamic-no-pic relocation model. 00133 TM.setRelocationModel(Reloc::DynamicNoPIC); 00134 00135 // Run loop strength reduction before anything else. 00136 PM.add(createLoopStrengthReducePass(TM.getTargetLowering())); 00137 00138 // FIXME: Implement efficient support for garbage collection intrinsics. 00139 PM.add(createLowerGCPass()); 00140 00141 // FIXME: Implement the invoke/unwind instructions! 00142 PM.add(createLowerInvokePass()); 00143 00144 // Clean up after other passes, e.g. merging critical edges. 00145 PM.add(createCFGSimplificationPass()); 00146 00147 // Make sure that no unreachable blocks are instruction selected. 00148 PM.add(createUnreachableBlockEliminationPass()); 00149 00150 // Install an instruction selector. 00151 PM.add(createPPCISelDag(TM)); 00152 00153 PM.add(createRegisterAllocator()); 00154 PM.add(createPrologEpilogCodeInserter()); 00155 00156 // Must run branch selection immediately preceding the asm printer 00157 PM.add(createPPCBranchSelectionPass()); 00158 00159 if (PrintMachineCode) 00160 PM.add(createMachineFunctionPrinterPass(&std::cerr)); 00161 } 00162