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/PassManager.h"
00018 #include "llvm/Target/TargetRegistry.h"
00019 using namespace llvm;
00020 
00021 extern "C" void LLVMInitializeMipsTarget() {
00022   // Register the target.
00023   RegisterTargetMachine<MipsTargetMachine> X(TheMipsTarget);
00024   RegisterTargetMachine<MipselTargetMachine> Y(TheMipselTarget);
00025   RegisterAsmInfo<MipsTargetAsmInfo> A(TheMipsTarget);
00026   RegisterAsmInfo<MipsTargetAsmInfo> B(TheMipselTarget);
00027 }
00028 
00029 // DataLayout --> Big-endian, 32-bit pointer/ABI/alignment
00030 // The stack is always 8 byte aligned
00031 // On function prologue, the stack is created by decrementing
00032 // its pointer. Once decremented, all references are done with positive
00033 // offset from the stack/frame pointer, using StackGrowsUp enables 
00034 // an easier handling.
00035 // Using CodeModel::Large enables different CALL behavior.
00036 MipsTargetMachine::
00037 MipsTargetMachine(const Target &T, const std::string &TT, const std::string &FS,
00038                   bool isLittle=false):
00039   LLVMTargetMachine(T, TT),
00040   Subtarget(TT, FS, isLittle), 
00041   DataLayout(isLittle ? std::string("e-p:32:32:32-i8:8:32-i16:16:32") :
00042                         std::string("E-p:32:32:32-i8:8:32-i16:16:32")), 
00043   InstrInfo(*this), 
00044   FrameInfo(TargetFrameInfo::StackGrowsUp, 8, 0),
00045   TLInfo(*this) {
00046   // Abicall enables PIC by default
00047   if (getRelocationModel() == Reloc::Default) {
00048     if (Subtarget.isABI_O32())
00049       setRelocationModel(Reloc::PIC_);
00050     else
00051       setRelocationModel(Reloc::Static);
00052   }
00053 
00054   // TODO: create an option to enable long calls, like -mlong-calls, 
00055   // that would be our CodeModel::Large. It must not work with Abicall.
00056   if (getCodeModel() == CodeModel::Default)
00057     setCodeModel(CodeModel::Small);
00058 }
00059 
00060 MipselTargetMachine::
00061 MipselTargetMachine(const Target &T, const std::string &TT,
00062                     const std::string &FS) :
00063   MipsTargetMachine(T, TT, FS, true) {}
00064 
00065 // Install an instruction selector pass using 
00066 // the ISelDag to gen Mips code.
00067 bool MipsTargetMachine::
00068 addInstSelector(PassManagerBase &PM, CodeGenOpt::Level OptLevel) 
00069 {
00070   PM.add(createMipsISelDag(*this));
00071   return false;
00072 }
00073 
00074 // Implemented by targets that want to run passes immediately before 
00075 // machine code is emitted. return true if -print-machineinstrs should 
00076 // print out the code after the passes.
00077 bool MipsTargetMachine::
00078 addPreEmitPass(PassManagerBase &PM, CodeGenOpt::Level OptLevel) 
00079 {
00080   PM.add(createMipsDelaySlotFillerPass(*this));
00081   return true;
00082 }