LLVM API Documentation

MipsTargetMachine.cpp

Go to the documentation of this file.
00001 //===-- MipsTargetMachine.cpp - Define TargetMachine for Mips -------------===//
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 // Implements the info about Mips target spec.
00011 //
00012 //===----------------------------------------------------------------------===//
00013 
00014 #include "Mips.h"
00015 #include "MipsTargetAsmInfo.h"
00016 #include "MipsTargetMachine.h"
00017 #include "llvm/Module.h"
00018 #include "llvm/PassManager.h"
00019 #include "llvm/Target/TargetMachineRegistry.h"
00020 using namespace llvm;
00021 
00022 /// MipsTargetMachineModule - Note that this is used on hosts that
00023 /// cannot link in a library unless there are references into the
00024 /// library.  In particular, it seems that it is not possible to get
00025 /// things to work on Win32 without this.  Though it is unused, do not
00026 /// remove it.
00027 extern "C" int MipsTargetMachineModule;
00028 int MipsTargetMachineModule = 0;
00029 
00030 // Register the target.
00031 static RegisterTarget<MipsTargetMachine>    X("mips", "Mips");
00032 static RegisterTarget<MipselTargetMachine>  Y("mipsel", "Mipsel");
00033 
00034 const TargetAsmInfo *MipsTargetMachine::
00035 createTargetAsmInfo() const 
00036 {
00037   return new MipsTargetAsmInfo(*this);
00038 }
00039 
00040 // DataLayout --> Big-endian, 32-bit pointer/ABI/alignment
00041 // The stack is always 8 byte aligned
00042 // On function prologue, the stack is created by decrementing
00043 // its pointer. Once decremented, all references are done with positive
00044 // offset from the stack/frame pointer, using StackGrowsUp enables 
00045 // an easier handling.
00046 // Using CodeModel::Large enables different CALL behavior.
00047 MipsTargetMachine::
00048 MipsTargetMachine(const Module &M, const std::string &FS, bool isLittle=false):
00049   Subtarget(*this, M, FS, isLittle), 
00050   DataLayout(isLittle ? std::string("e-p:32:32:32-i8:8:32-i16:16:32") :
00051                         std::string("E-p:32:32:32-i8:8:32-i16:16:32")), 
00052   InstrInfo(*this), 
00053   FrameInfo(TargetFrameInfo::StackGrowsUp, 8, 0),
00054   TLInfo(*this) 
00055 {
00056   // Abicall enables PIC by default
00057   if (Subtarget.hasABICall())
00058     setRelocationModel(Reloc::PIC_);  
00059 
00060   // TODO: create an option to enable long calls, like -mlong-calls, 
00061   // that would be our CodeModel::Large. It must not work with Abicall.
00062   if (getCodeModel() == CodeModel::Default)
00063     setCodeModel(CodeModel::Small);
00064 }
00065 
00066 MipselTargetMachine::
00067 MipselTargetMachine(const Module &M, const std::string &FS) :
00068   MipsTargetMachine(M, FS, true) {}
00069 
00070 // return 0 and must specify -march to gen MIPS code.
00071 unsigned MipsTargetMachine::
00072 getModuleMatchQuality(const Module &M) 
00073 {
00074   // We strongly match "mips*-*".
00075   std::string TT = M.getTargetTriple();
00076   if (TT.size() >= 5 && std::string(TT.begin(), TT.begin()+5) == "mips-")
00077     return 20;
00078   
00079   if (TT.size() >= 13 && std::string(TT.begin(), 
00080       TT.begin()+13) == "mipsallegrex-")
00081     return 20;
00082 
00083   return 0;
00084 }
00085 
00086 // return 0 and must specify -march to gen MIPSEL code.
00087 unsigned MipselTargetMachine::
00088 getModuleMatchQuality(const Module &M) 
00089 {
00090   // We strongly match "mips*el-*".
00091   std::string TT = M.getTargetTriple();
00092   if (TT.size() >= 7 && std::string(TT.begin(), TT.begin()+7) == "mipsel-")
00093     return 20;
00094 
00095   if (TT.size() >= 15 && std::string(TT.begin(), 
00096       TT.begin()+15) == "mipsallegrexel-")
00097     return 20;
00098 
00099   if (TT.size() == 3 && std::string(TT.begin(), TT.begin()+3) == "psp")
00100     return 20;
00101   
00102   return 0;
00103 }
00104 
00105 // Install an instruction selector pass using 
00106 // the ISelDag to gen Mips code.
00107 bool MipsTargetMachine::
00108 addInstSelector(PassManagerBase &PM, bool Fast) 
00109 {
00110   PM.add(createMipsISelDag(*this));
00111   return false;
00112 }
00113 
00114 // Implemented by targets that want to run passes immediately before 
00115 // machine code is emitted. return true if -print-machineinstrs should 
00116 // print out the code after the passes.
00117 bool MipsTargetMachine::
00118 addPreEmitPass(PassManagerBase &PM, bool Fast) 
00119 {
00120   PM.add(createMipsDelaySlotFillerPass(*this));
00121   return true;
00122 }
00123 
00124 // Implements the AssemblyEmitter for the target. Must return
00125 // true if AssemblyEmitter is supported
00126 bool MipsTargetMachine::
00127 addAssemblyEmitter(PassManagerBase &PM, bool Fast, 
00128                    raw_ostream &Out) 
00129 {
00130   // Output assembly language.
00131   PM.add(createMipsCodePrinterPass(Out, *this));
00132   return false;
00133 }