1. Use SubtargetFeatures in llc/lli.
[oota-llvm.git] / lib / Target / SparcV8 / SparcV8TargetMachine.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                                            const std::string &FS)
36   : TargetMachine("SparcV8", IL, false, 4, 4),
37     FrameInfo(TargetFrameInfo::StackGrowsDown, 8, 0), JITInfo(*this) {
38 }
39
40 unsigned SparcV8TargetMachine::getJITMatchQuality() {
41   return 0; // No JIT yet.
42 }
43
44 unsigned SparcV8TargetMachine::getModuleMatchQuality(const Module &M) {
45   std::string TT = M.getTargetTriple();
46   if (TT.size() >= 6 && std::string(TT.begin(), TT.begin()+6) == "sparc-")
47     return 20;
48
49   if (M.getEndianness()  == Module::BigEndian &&
50       M.getPointerSize() == Module::Pointer32)
51 #ifdef __sparc__
52     return 20;   // BE/32 ==> Prefer sparcv8 on sparc
53 #else
54     return 5;    // BE/32 ==> Prefer ppc elsewhere
55 #endif
56   else if (M.getEndianness() != Module::AnyEndianness ||
57            M.getPointerSize() != Module::AnyPointerSize)
58     return 0;                                    // Match for some other target
59
60   return getJITMatchQuality()/2;
61 }
62
63 /// addPassesToEmitFile - Add passes to the specified pass manager
64 /// to implement a static compiler for this target.
65 ///
66 bool SparcV8TargetMachine::addPassesToEmitFile(PassManager &PM,
67                                                std::ostream &Out,
68                                                CodeGenFileType FileType) {
69   if (FileType != TargetMachine::AssemblyFile) return true;
70
71   // FIXME: Implement efficient support for garbage collection intrinsics.
72   PM.add(createLowerGCPass());
73
74   // Replace malloc and free instructions with library calls.
75   PM.add(createLowerAllocationsPass());
76
77   // FIXME: implement the switch instruction in the instruction selector.
78   PM.add(createLowerSwitchPass());
79
80   // FIXME: implement the invoke/unwind instructions!
81   PM.add(createLowerInvokePass());
82
83   PM.add(createLowerConstantExpressionsPass());
84
85   // Make sure that no unreachable blocks are instruction selected.
86   PM.add(createUnreachableBlockEliminationPass());
87
88   // FIXME: implement the select instruction in the instruction selector.
89   PM.add(createLowerSelectPass());
90
91   // Print LLVM code input to instruction selector:
92   if (PrintMachineCode)
93     PM.add(new PrintFunctionPass());
94
95   PM.add(createSparcV8SimpleInstructionSelector(*this));
96
97   // Print machine instructions as they were initially generated.
98   if (PrintMachineCode)
99     PM.add(createMachineFunctionPrinterPass(&std::cerr));
100
101   PM.add(createRegisterAllocator());
102   PM.add(createPrologEpilogCodeInserter());
103
104   // Print machine instructions after register allocation and prolog/epilog
105   // insertion.
106   if (PrintMachineCode)
107     PM.add(createMachineFunctionPrinterPass(&std::cerr));
108
109   PM.add(createSparcV8FPMoverPass(*this));
110   PM.add(createSparcV8DelaySlotFillerPass(*this));
111
112   // Print machine instructions after filling delay slots.
113   if (PrintMachineCode)
114     PM.add(createMachineFunctionPrinterPass(&std::cerr));
115
116   // Output assembly language.
117   PM.add(createSparcV8CodePrinterPass(Out, *this));
118
119   // Delete the MachineInstrs we generated, since they're no longer needed.
120   PM.add(createMachineCodeDeleter());
121   return false;
122 }
123
124 /// addPassesToJITCompile - Add passes to the specified pass manager to
125 /// implement a fast dynamic compiler for this target.
126 ///
127 void SparcV8JITInfo::addPassesToJITCompile(FunctionPassManager &PM) {
128   // FIXME: Implement efficient support for garbage collection intrinsics.
129   PM.add(createLowerGCPass());
130
131   // Replace malloc and free instructions with library calls.
132   PM.add(createLowerAllocationsPass());
133
134   // FIXME: implement the switch instruction in the instruction selector.
135   PM.add(createLowerSwitchPass());
136
137   // FIXME: implement the invoke/unwind instructions!
138   PM.add(createLowerInvokePass());
139
140   PM.add(createLowerConstantExpressionsPass());
141
142   // Make sure that no unreachable blocks are instruction selected.
143   PM.add(createUnreachableBlockEliminationPass());
144
145   // FIXME: implement the select instruction in the instruction selector.
146   PM.add(createLowerSelectPass());
147
148   // Print LLVM code input to instruction selector:
149   if (PrintMachineCode)
150     PM.add(new PrintFunctionPass());
151
152   PM.add(createSparcV8SimpleInstructionSelector(TM));
153
154   // Print machine instructions as they were initially generated.
155   if (PrintMachineCode)
156     PM.add(createMachineFunctionPrinterPass(&std::cerr));
157
158   PM.add(createRegisterAllocator());
159   PM.add(createPrologEpilogCodeInserter());
160
161   // Print machine instructions after register allocation and prolog/epilog
162   // insertion.
163   if (PrintMachineCode)
164     PM.add(createMachineFunctionPrinterPass(&std::cerr));
165
166   PM.add(createSparcV8FPMoverPass(TM));
167   PM.add(createSparcV8DelaySlotFillerPass(TM));
168
169   // Print machine instructions after filling delay slots.
170   if (PrintMachineCode)
171     PM.add(createMachineFunctionPrinterPass(&std::cerr));
172 }