Position Independent Code (PIC) support [2]
[oota-llvm.git] / lib / Target / Mips / MipsTargetMachine.cpp
1 //===-- MipsTargetMachine.cpp - Define TargetMachine for Mips -------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file was developed by Bruno Cardoso Lopes and is distributed under the
6 // University of Illinois Open Source License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // Implements the info about Mips target spec.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #include "Mips.h"
15 #include "MipsTargetAsmInfo.h"
16 #include "MipsTargetMachine.h"
17 #include "llvm/Module.h"
18 #include "llvm/PassManager.h"
19 #include "llvm/Target/TargetMachineRegistry.h"
20 using namespace llvm;
21
22 namespace {
23   // Register the target.
24   RegisterTarget<MipsTargetMachine> X("mips", "  Mips");
25 }
26
27 const TargetAsmInfo *MipsTargetMachine::
28 createTargetAsmInfo() const 
29 {
30   return new MipsTargetAsmInfo(*this);
31 }
32
33 // DataLayout --> Big-endian, 32-bit pointer/ABI/alignment
34 // The stack is always 8 byte aligned
35 // On function prologue, the stack is created by decrementing
36 // its pointer. Once decremented, all references are done with positive
37 // offset from the stack/frame pointer, so StackGrowsUp is used.
38 MipsTargetMachine::
39 MipsTargetMachine(const Module &M, const std::string &FS): 
40   Subtarget(*this, M, FS), DataLayout("E-p:32:32:32"), 
41   InstrInfo(*this), FrameInfo(TargetFrameInfo::StackGrowsUp, 8, 0),
42   TLInfo(*this) 
43 {
44   if (getRelocationModel() != Reloc::Static)
45     setRelocationModel(Reloc::PIC_);  
46 }
47
48 // return 0 and must specify -march to gen MIPS code.
49 unsigned MipsTargetMachine::
50 getModuleMatchQuality(const Module &M) 
51 {
52   // We strongly match "mips-*".
53   std::string TT = M.getTargetTriple();
54   if (TT.size() >= 5 && std::string(TT.begin(), TT.begin()+5) == "mips-")
55     return 20;
56   
57   return 0;
58 }
59
60 // Install an instruction selector pass using 
61 // the ISelDag to gen Mips code.
62 bool MipsTargetMachine::
63 addInstSelector(FunctionPassManager &PM, bool Fast) 
64 {
65   PM.add(createMipsISelDag(*this));
66   return false;
67 }
68
69 // Implemented by targets that want to run passes immediately before 
70 // machine code is emitted. return true if -print-machineinstrs should 
71 // print out the code after the passes.
72 bool MipsTargetMachine::
73 addPreEmitPass(FunctionPassManager &PM, bool Fast) 
74 {
75   PM.add(createMipsDelaySlotFillerPass(*this));
76   return true;
77 }
78
79 // Implements the AssemblyEmitter for the target. Must return
80 // true if AssemblyEmitter is supported
81 bool MipsTargetMachine::
82 addAssemblyEmitter(FunctionPassManager &PM, bool Fast, 
83                    std::ostream &Out) 
84 {
85   // Output assembly language.
86   PM.add(createMipsCodePrinterPass(Out, *this));
87   return false;
88 }