some call work
[oota-llvm.git] / lib / Target / Sparc / SparcTargetMachine.cpp
1 //===-- SparcV8TargetMachine.cpp - Define TargetMachine for SparcV8 -------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file was developed by the LLVM research group and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 //
11 //===----------------------------------------------------------------------===//
12
13 #include "SparcV8TargetMachine.h"
14 #include "SparcV8.h"
15 #include "llvm/Assembly/PrintModulePass.h"
16 #include "llvm/Module.h"
17 #include "llvm/PassManager.h"
18 #include "llvm/CodeGen/MachineFunction.h"
19 #include "llvm/CodeGen/Passes.h"
20 #include "llvm/Target/TargetOptions.h"
21 #include "llvm/Target/TargetMachineRegistry.h"
22 #include "llvm/Transforms/Scalar.h"
23 #include <iostream>
24 using namespace llvm;
25
26 namespace {
27   // Register the target.
28   RegisterTarget<SparcV8TargetMachine> X("sparcv8","  SPARC V8 (experimental)");
29 }
30
31 /// SparcV8TargetMachine ctor - Create an ILP32 architecture model
32 ///
33 SparcV8TargetMachine::SparcV8TargetMachine(const Module &M,
34                                            IntrinsicLowering *IL)
35   : TargetMachine("SparcV8", IL, false, 4, 4),
36     FrameInfo(TargetFrameInfo::StackGrowsDown, 8, 0), JITInfo(*this) {
37 }
38
39 unsigned SparcV8TargetMachine::getJITMatchQuality() {
40   return 0; // No JIT yet.
41 }
42
43 unsigned SparcV8TargetMachine::getModuleMatchQuality(const Module &M) {
44   std::string TT = M.getTargetTriple();
45   if (TT.size() >= 6 && std::string(TT.begin(), TT.begin()+6) == "sparc-")
46     return 20;
47
48   if (M.getEndianness()  == Module::BigEndian &&
49       M.getPointerSize() == Module::Pointer32)
50 #ifdef __sparc__
51     return 20;   // BE/32 ==> Prefer sparcv8 on sparc
52 #else
53     return 5;    // BE/32 ==> Prefer ppc elsewhere
54 #endif
55   else if (M.getEndianness() != Module::AnyEndianness ||
56            M.getPointerSize() != Module::AnyPointerSize)
57     return 0;                                    // Match for some other target
58
59   return getJITMatchQuality()/2;
60 }
61
62 /// addPassesToEmitFile - Add passes to the specified pass manager
63 /// to implement a static compiler for this target.
64 ///
65 bool SparcV8TargetMachine::addPassesToEmitFile(PassManager &PM,
66                                                std::ostream &Out,
67                                                CodeGenFileType FileType) {
68   if (FileType != TargetMachine::AssemblyFile) return true;
69
70   // FIXME: Implement efficient support for garbage collection intrinsics.
71   PM.add(createLowerGCPass());
72
73   // Replace malloc and free instructions with library calls.
74   PM.add(createLowerAllocationsPass());
75
76   // FIXME: implement the switch instruction in the instruction selector.
77   PM.add(createLowerSwitchPass());
78
79   // FIXME: implement the invoke/unwind instructions!
80   PM.add(createLowerInvokePass());
81
82   PM.add(createLowerConstantExpressionsPass());
83
84   // Make sure that no unreachable blocks are instruction selected.
85   PM.add(createUnreachableBlockEliminationPass());
86
87   // FIXME: implement the select instruction in the instruction selector.
88   PM.add(createLowerSelectPass());
89
90   // Print LLVM code input to instruction selector:
91   if (PrintMachineCode)
92     PM.add(new PrintFunctionPass());
93
94   PM.add(createSparcV8SimpleInstructionSelector(*this));
95
96   // Print machine instructions as they were initially generated.
97   if (PrintMachineCode)
98     PM.add(createMachineFunctionPrinterPass(&std::cerr));
99
100   PM.add(createRegisterAllocator());
101   PM.add(createPrologEpilogCodeInserter());
102
103   // Print machine instructions after register allocation and prolog/epilog
104   // insertion.
105   if (PrintMachineCode)
106     PM.add(createMachineFunctionPrinterPass(&std::cerr));
107
108   PM.add(createSparcV8FPMoverPass(*this));
109   PM.add(createSparcV8DelaySlotFillerPass(*this));
110
111   // Print machine instructions after filling delay slots.
112   if (PrintMachineCode)
113     PM.add(createMachineFunctionPrinterPass(&std::cerr));
114
115   // Output assembly language.
116   PM.add(createSparcV8CodePrinterPass(Out, *this));
117
118   // Delete the MachineInstrs we generated, since they're no longer needed.
119   PM.add(createMachineCodeDeleter());
120   return false;
121 }
122
123 /// addPassesToJITCompile - Add passes to the specified pass manager to
124 /// implement a fast dynamic compiler for this target.
125 ///
126 void SparcV8JITInfo::addPassesToJITCompile(FunctionPassManager &PM) {
127   // FIXME: Implement efficient support for garbage collection intrinsics.
128   PM.add(createLowerGCPass());
129
130   // Replace malloc and free instructions with library calls.
131   PM.add(createLowerAllocationsPass());
132
133   // FIXME: implement the switch instruction in the instruction selector.
134   PM.add(createLowerSwitchPass());
135
136   // FIXME: implement the invoke/unwind instructions!
137   PM.add(createLowerInvokePass());
138
139   PM.add(createLowerConstantExpressionsPass());
140
141   // Make sure that no unreachable blocks are instruction selected.
142   PM.add(createUnreachableBlockEliminationPass());
143
144   // FIXME: implement the select instruction in the instruction selector.
145   PM.add(createLowerSelectPass());
146
147   // Print LLVM code input to instruction selector:
148   if (PrintMachineCode)
149     PM.add(new PrintFunctionPass());
150
151   PM.add(createSparcV8SimpleInstructionSelector(TM));
152
153   // Print machine instructions as they were initially generated.
154   if (PrintMachineCode)
155     PM.add(createMachineFunctionPrinterPass(&std::cerr));
156
157   PM.add(createRegisterAllocator());
158   PM.add(createPrologEpilogCodeInserter());
159
160   // Print machine instructions after register allocation and prolog/epilog
161   // insertion.
162   if (PrintMachineCode)
163     PM.add(createMachineFunctionPrinterPass(&std::cerr));
164
165   PM.add(createSparcV8FPMoverPass(TM));
166   PM.add(createSparcV8DelaySlotFillerPass(TM));
167
168   // Print machine instructions after filling delay slots.
169   if (PrintMachineCode)
170     PM.add(createMachineFunctionPrinterPass(&std::cerr));
171 }