LLVM API Documentation
00001 //===-- AlphaTargetMachine.cpp - Define TargetMachine for Alpha -----------===// 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 // 00011 //===----------------------------------------------------------------------===// 00012 00013 #include "Alpha.h" 00014 #include "AlphaJITInfo.h" 00015 #include "AlphaTargetMachine.h" 00016 #include "llvm/Module.h" 00017 #include "llvm/CodeGen/Passes.h" 00018 #include "llvm/Target/TargetOptions.h" 00019 #include "llvm/Target/TargetMachineRegistry.h" 00020 #include "llvm/Transforms/Scalar.h" 00021 #include "llvm/Support/Debug.h" 00022 #include <iostream> 00023 00024 using namespace llvm; 00025 00026 namespace { 00027 // Register the targets 00028 RegisterTarget<AlphaTargetMachine> X("alpha", " Alpha (incomplete)"); 00029 } 00030 00031 unsigned AlphaTargetMachine::getModuleMatchQuality(const Module &M) { 00032 // We strongly match "alpha*". 00033 std::string TT = M.getTargetTriple(); 00034 if (TT.size() >= 5 && TT[0] == 'a' && TT[1] == 'l' && TT[2] == 'p' && 00035 TT[3] == 'h' && TT[4] == 'a') 00036 return 20; 00037 00038 if (M.getEndianness() == Module::LittleEndian && 00039 M.getPointerSize() == Module::Pointer64) 00040 return 10; // Weak match 00041 else if (M.getEndianness() != Module::AnyEndianness || 00042 M.getPointerSize() != Module::AnyPointerSize) 00043 return 0; // Match for some other target 00044 00045 return getJITMatchQuality()/2; 00046 } 00047 00048 unsigned AlphaTargetMachine::getJITMatchQuality() { 00049 #ifdef __alpha 00050 return 10; 00051 #else 00052 return 0; 00053 #endif 00054 } 00055 00056 AlphaTargetMachine::AlphaTargetMachine(const Module &M, const std::string &FS) 00057 : TargetMachine("alpha", true), 00058 FrameInfo(TargetFrameInfo::StackGrowsDown, 16, 0), 00059 JITInfo(*this), 00060 Subtarget(M, FS) 00061 { 00062 DEBUG(std::cerr << "FS is " << FS << "\n"); 00063 } 00064 00065 /// addPassesToEmitFile - Add passes to the specified pass manager to implement 00066 /// a static compiler for this target. 00067 /// 00068 bool AlphaTargetMachine::addPassesToEmitFile(PassManager &PM, 00069 std::ostream &Out, 00070 CodeGenFileType FileType, 00071 bool Fast) { 00072 if (FileType != TargetMachine::AssemblyFile) return true; 00073 00074 PM.add(createLoopStrengthReducePass()); 00075 PM.add(createCFGSimplificationPass()); 00076 00077 00078 // FIXME: Implement efficient support for garbage collection intrinsics. 00079 PM.add(createLowerGCPass()); 00080 00081 // FIXME: Implement the invoke/unwind instructions! 00082 PM.add(createLowerInvokePass()); 00083 00084 // Make sure that no unreachable blocks are instruction selected. 00085 PM.add(createUnreachableBlockEliminationPass()); 00086 00087 PM.add(createAlphaISelDag(*this)); 00088 00089 if (PrintMachineCode) 00090 PM.add(createMachineFunctionPrinterPass(&std::cerr)); 00091 00092 PM.add(createRegisterAllocator()); 00093 00094 if (PrintMachineCode) 00095 PM.add(createMachineFunctionPrinterPass(&std::cerr)); 00096 00097 PM.add(createPrologEpilogCodeInserter()); 00098 00099 // Must run branch selection immediately preceding the asm printer 00100 //PM.add(createAlphaBranchSelectionPass()); 00101 00102 PM.add(createAlphaCodePrinterPass(Out, *this)); 00103 00104 PM.add(createMachineCodeDeleter()); 00105 return false; 00106 } 00107 00108 void AlphaJITInfo::addPassesToJITCompile(FunctionPassManager &PM) { 00109 00110 PM.add(createLoopStrengthReducePass()); 00111 PM.add(createCFGSimplificationPass()); 00112 00113 // FIXME: Implement efficient support for garbage collection intrinsics. 00114 PM.add(createLowerGCPass()); 00115 00116 // FIXME: Implement the invoke/unwind instructions! 00117 PM.add(createLowerInvokePass()); 00118 00119 // Make sure that no unreachable blocks are instruction selected. 00120 PM.add(createUnreachableBlockEliminationPass()); 00121 00122 PM.add(createAlphaISelDag(TM)); 00123 00124 if (PrintMachineCode) 00125 PM.add(createMachineFunctionPrinterPass(&std::cerr)); 00126 00127 PM.add(createRegisterAllocator()); 00128 00129 if (PrintMachineCode) 00130 PM.add(createMachineFunctionPrinterPass(&std::cerr)); 00131 00132 PM.add(createPrologEpilogCodeInserter()); 00133 00134 // Must run branch selection immediately preceding the asm printer 00135 //PM.add(createAlphaBranchSelectionPass()); 00136 00137 } 00138 00139 bool AlphaTargetMachine::addPassesToEmitMachineCode(FunctionPassManager &PM, 00140 MachineCodeEmitter &MCE) { 00141 PM.add(createAlphaCodeEmitterPass(MCE)); 00142 // Delete machine code for this function 00143 PM.add(createMachineCodeDeleter()); 00144 return false; 00145 }