Clean up the use of static and anonymous namespaces. This turned up
[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 is distributed under the University of Illinois Open Source
6 // 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 // Register the target.
23 static RegisterTarget<MipsTargetMachine> X("mips", "  Mips");
24
25 const TargetAsmInfo *MipsTargetMachine::
26 createTargetAsmInfo() const 
27 {
28   return new MipsTargetAsmInfo(*this);
29 }
30
31 // DataLayout --> Big-endian, 32-bit pointer/ABI/alignment
32 // The stack is always 8 byte aligned
33 // On function prologue, the stack is created by decrementing
34 // its pointer. Once decremented, all references are done with positive
35 // offset from the stack/frame pointer, so StackGrowsUp is used.
36 // When using CodeModel::Large the behaviour 
37 //
38 // 
39 MipsTargetMachine::
40 MipsTargetMachine(const Module &M, const std::string &FS): 
41   Subtarget(*this, M, FS), DataLayout("E-p:32:32:32"), 
42   InstrInfo(*this), FrameInfo(TargetFrameInfo::StackGrowsUp, 8, 0),
43   TLInfo(*this) 
44 {
45   if (getRelocationModel() != Reloc::Static)
46     setRelocationModel(Reloc::PIC_);  
47   if (getCodeModel() == CodeModel::Default)
48     setCodeModel(CodeModel::Small);
49 }
50
51 // return 0 and must specify -march to gen MIPS code.
52 unsigned MipsTargetMachine::
53 getModuleMatchQuality(const Module &M) 
54 {
55   // We strongly match "mips-*".
56   std::string TT = M.getTargetTriple();
57   if (TT.size() >= 5 && std::string(TT.begin(), TT.begin()+5) == "mips-")
58     return 20;
59   
60   return 0;
61 }
62
63 // Install an instruction selector pass using 
64 // the ISelDag to gen Mips code.
65 bool MipsTargetMachine::
66 addInstSelector(PassManagerBase &PM, bool Fast) 
67 {
68   PM.add(createMipsISelDag(*this));
69   return false;
70 }
71
72 // Implemented by targets that want to run passes immediately before 
73 // machine code is emitted. return true if -print-machineinstrs should 
74 // print out the code after the passes.
75 bool MipsTargetMachine::
76 addPreEmitPass(PassManagerBase &PM, bool Fast) 
77 {
78   PM.add(createMipsDelaySlotFillerPass(*this));
79   return true;
80 }
81
82 // Implements the AssemblyEmitter for the target. Must return
83 // true if AssemblyEmitter is supported
84 bool MipsTargetMachine::
85 addAssemblyEmitter(PassManagerBase &PM, bool Fast, 
86                    std::ostream &Out) 
87 {
88   // Output assembly language.
89   PM.add(createMipsCodePrinterPass(Out, *this));
90   return false;
91 }