LLVM API Documentation
00001 //===-- AlphaTargetMachine.cpp - Define TargetMachine for Alpha -----------===// 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 // 00011 //===----------------------------------------------------------------------===// 00012 00013 #include "Alpha.h" 00014 #include "AlphaJITInfo.h" 00015 #include "AlphaTargetAsmInfo.h" 00016 #include "AlphaTargetMachine.h" 00017 #include "llvm/Module.h" 00018 #include "llvm/PassManager.h" 00019 #include "llvm/Target/TargetMachineRegistry.h" 00020 #include "llvm/Support/raw_ostream.h" 00021 00022 using namespace llvm; 00023 00024 /// AlphaTargetMachineModule - Note that this is used on hosts that cannot link 00025 /// in a library unless there are references into the library. In particular, 00026 /// it seems that it is not possible to get things to work on Win32 without 00027 /// this. Though it is unused, do not remove it. 00028 extern "C" int AlphaTargetMachineModule; 00029 int AlphaTargetMachineModule = 0; 00030 00031 // Register the targets 00032 static RegisterTarget<AlphaTargetMachine> X("alpha", "Alpha [experimental]"); 00033 00034 const TargetAsmInfo *AlphaTargetMachine::createTargetAsmInfo() const { 00035 return new AlphaTargetAsmInfo(*this); 00036 } 00037 00038 unsigned AlphaTargetMachine::getModuleMatchQuality(const Module &M) { 00039 // We strongly match "alpha*". 00040 std::string TT = M.getTargetTriple(); 00041 if (TT.size() >= 5 && TT[0] == 'a' && TT[1] == 'l' && TT[2] == 'p' && 00042 TT[3] == 'h' && TT[4] == 'a') 00043 return 20; 00044 // If the target triple is something non-alpha, we don't match. 00045 if (!TT.empty()) return 0; 00046 00047 if (M.getEndianness() == Module::LittleEndian && 00048 M.getPointerSize() == Module::Pointer64) 00049 return 10; // Weak match 00050 else if (M.getEndianness() != Module::AnyEndianness || 00051 M.getPointerSize() != Module::AnyPointerSize) 00052 return 0; // Match for some other target 00053 00054 return getJITMatchQuality()/2; 00055 } 00056 00057 unsigned AlphaTargetMachine::getJITMatchQuality() { 00058 #ifdef __alpha 00059 return 10; 00060 #else 00061 return 0; 00062 #endif 00063 } 00064 00065 AlphaTargetMachine::AlphaTargetMachine(const Module &M, const std::string &FS) 00066 : DataLayout("e-f128:128:128"), 00067 FrameInfo(TargetFrameInfo::StackGrowsDown, 16, 0), 00068 JITInfo(*this), 00069 Subtarget(M, FS), 00070 TLInfo(*this) { 00071 setRelocationModel(Reloc::PIC_); 00072 } 00073 00074 00075 //===----------------------------------------------------------------------===// 00076 // Pass Pipeline Configuration 00077 //===----------------------------------------------------------------------===// 00078 00079 bool AlphaTargetMachine::addInstSelector(PassManagerBase &PM, bool Fast) { 00080 PM.add(createAlphaISelDag(*this)); 00081 return false; 00082 } 00083 bool AlphaTargetMachine::addPreEmitPass(PassManagerBase &PM, bool Fast) { 00084 // Must run branch selection immediately preceding the asm printer 00085 PM.add(createAlphaBranchSelectionPass()); 00086 return false; 00087 } 00088 bool AlphaTargetMachine::addAssemblyEmitter(PassManagerBase &PM, bool Fast, 00089 raw_ostream &Out) { 00090 PM.add(createAlphaLLRPPass(*this)); 00091 PM.add(createAlphaCodePrinterPass(Out, *this)); 00092 return false; 00093 } 00094 bool AlphaTargetMachine::addCodeEmitter(PassManagerBase &PM, bool Fast, 00095 bool DumpAsm, MachineCodeEmitter &MCE) { 00096 PM.add(createAlphaCodeEmitterPass(*this, MCE)); 00097 if (DumpAsm) 00098 PM.add(createAlphaCodePrinterPass(errs(), *this)); 00099 return false; 00100 } 00101 bool AlphaTargetMachine::addSimpleCodeEmitter(PassManagerBase &PM, 00102 bool Fast, bool DumpAsm, 00103 MachineCodeEmitter &MCE) { 00104 return addCodeEmitter(PM, Fast, DumpAsm, MCE); 00105 }