Eliminate asm parser's dependency on TargetMachine:
[oota-llvm.git] / lib / Target / TargetMachine.cpp
1 //===-- TargetMachine.cpp - General Target Information ---------------------==//
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 // This file describes the general parts of a Target machine.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #include "llvm/CodeGen/MachineFunction.h"
15 #include "llvm/CodeGen/MachineFrameInfo.h"
16 #include "llvm/MC/MCAsmInfo.h"
17 #include "llvm/Target/TargetMachine.h"
18 #include "llvm/Target/TargetOptions.h"
19 #include "llvm/Support/CommandLine.h"
20 using namespace llvm;
21
22 //---------------------------------------------------------------------------
23 // Command-line options that tend to be useful on more than one back-end.
24 //
25
26 namespace llvm {
27   bool LessPreciseFPMADOption;
28   bool PrintMachineCode;
29   bool NoFramePointerElim;
30   bool NoFramePointerElimNonLeaf;
31   bool NoExcessFPPrecision;
32   bool UnsafeFPMath;
33   bool NoInfsFPMath;
34   bool NoNaNsFPMath;
35   bool HonorSignDependentRoundingFPMathOption;
36   bool UseSoftFloat;
37   FloatABI::ABIType FloatABIType;
38   bool NoImplicitFloat;
39   bool NoZerosInBSS;
40   bool JITExceptionHandling;
41   bool JITEmitDebugInfo;
42   bool JITEmitDebugInfoToDisk;
43   Reloc::Model RelocationModel;
44   CodeModel::Model CMModel;
45   bool GuaranteedTailCallOpt;
46   unsigned StackAlignmentOverride;
47   bool RealignStack;
48   bool DisableJumpTables;
49   bool StrongPHIElim;
50   bool HasDivModLibcall;
51   bool AsmVerbosityDefault(false);
52 }
53
54 static cl::opt<bool, true>
55 PrintCode("print-machineinstrs",
56   cl::desc("Print generated machine code"),
57   cl::location(PrintMachineCode), cl::init(false));
58 static cl::opt<bool, true>
59 DisableFPElim("disable-fp-elim",
60   cl::desc("Disable frame pointer elimination optimization"),
61   cl::location(NoFramePointerElim),
62   cl::init(false));
63 static cl::opt<bool, true>
64 DisableFPElimNonLeaf("disable-non-leaf-fp-elim",
65   cl::desc("Disable frame pointer elimination optimization for non-leaf funcs"),
66   cl::location(NoFramePointerElimNonLeaf),
67   cl::init(false));
68 static cl::opt<bool, true>
69 DisableExcessPrecision("disable-excess-fp-precision",
70   cl::desc("Disable optimizations that may increase FP precision"),
71   cl::location(NoExcessFPPrecision),
72   cl::init(false));
73 static cl::opt<bool, true>
74 EnableFPMAD("enable-fp-mad",
75   cl::desc("Enable less precise MAD instructions to be generated"),
76   cl::location(LessPreciseFPMADOption),
77   cl::init(false));
78 static cl::opt<bool, true>
79 EnableUnsafeFPMath("enable-unsafe-fp-math",
80   cl::desc("Enable optimizations that may decrease FP precision"),
81   cl::location(UnsafeFPMath),
82   cl::init(false));
83 static cl::opt<bool, true>
84 EnableNoInfsFPMath("enable-no-infs-fp-math",
85   cl::desc("Enable FP math optimizations that assume no +-Infs"),
86   cl::location(NoInfsFPMath),
87   cl::init(false));
88 static cl::opt<bool, true>
89 EnableNoNaNsFPMath("enable-no-nans-fp-math",
90   cl::desc("Enable FP math optimizations that assume no NaNs"),
91   cl::location(NoNaNsFPMath),
92   cl::init(false));
93 static cl::opt<bool, true>
94 EnableHonorSignDependentRoundingFPMath("enable-sign-dependent-rounding-fp-math",
95   cl::Hidden,
96   cl::desc("Force codegen to assume rounding mode can change dynamically"),
97   cl::location(HonorSignDependentRoundingFPMathOption),
98   cl::init(false));
99 static cl::opt<bool, true>
100 GenerateSoftFloatCalls("soft-float",
101   cl::desc("Generate software floating point library calls"),
102   cl::location(UseSoftFloat),
103   cl::init(false));
104 static cl::opt<llvm::FloatABI::ABIType, true>
105 FloatABIForCalls("float-abi",
106   cl::desc("Choose float ABI type"),
107   cl::location(FloatABIType),
108   cl::init(FloatABI::Default),
109   cl::values(
110     clEnumValN(FloatABI::Default, "default",
111                "Target default float ABI type"),
112     clEnumValN(FloatABI::Soft, "soft",
113                "Soft float ABI (implied by -soft-float)"),
114     clEnumValN(FloatABI::Hard, "hard",
115                "Hard float ABI (uses FP registers)"),
116     clEnumValEnd));
117 static cl::opt<bool, true>
118 DontPlaceZerosInBSS("nozero-initialized-in-bss",
119   cl::desc("Don't place zero-initialized symbols into bss section"),
120   cl::location(NoZerosInBSS),
121   cl::init(false));
122 static cl::opt<bool, true>
123 EnableJITExceptionHandling("jit-enable-eh",
124   cl::desc("Emit exception handling information"),
125   cl::location(JITExceptionHandling),
126   cl::init(false));
127 // In debug builds, make this default to true.
128 #ifdef NDEBUG
129 #define EMIT_DEBUG false
130 #else
131 #define EMIT_DEBUG true
132 #endif
133 static cl::opt<bool, true>
134 EmitJitDebugInfo("jit-emit-debug",
135   cl::desc("Emit debug information to debugger"),
136   cl::location(JITEmitDebugInfo),
137   cl::init(EMIT_DEBUG));
138 #undef EMIT_DEBUG
139 static cl::opt<bool, true>
140 EmitJitDebugInfoToDisk("jit-emit-debug-to-disk",
141   cl::Hidden,
142   cl::desc("Emit debug info objfiles to disk"),
143   cl::location(JITEmitDebugInfoToDisk),
144   cl::init(false));
145
146 static cl::opt<llvm::Reloc::Model, true>
147 DefRelocationModel("relocation-model",
148   cl::desc("Choose relocation model"),
149   cl::location(RelocationModel),
150   cl::init(Reloc::Default),
151   cl::values(
152     clEnumValN(Reloc::Default, "default",
153                "Target default relocation model"),
154     clEnumValN(Reloc::Static, "static",
155                "Non-relocatable code"),
156     clEnumValN(Reloc::PIC_, "pic",
157                "Fully relocatable, position independent code"),
158     clEnumValN(Reloc::DynamicNoPIC, "dynamic-no-pic",
159                "Relocatable external references, non-relocatable code"),
160     clEnumValEnd));
161 static cl::opt<llvm::CodeModel::Model, true>
162 DefCodeModel("code-model",
163   cl::desc("Choose code model"),
164   cl::location(CMModel),
165   cl::init(CodeModel::Default),
166   cl::values(
167     clEnumValN(CodeModel::Default, "default",
168                "Target default code model"),
169     clEnumValN(CodeModel::Small, "small",
170                "Small code model"),
171     clEnumValN(CodeModel::Kernel, "kernel",
172                "Kernel code model"),
173     clEnumValN(CodeModel::Medium, "medium",
174                "Medium code model"),
175     clEnumValN(CodeModel::Large, "large",
176                "Large code model"),
177     clEnumValEnd));
178 static cl::opt<bool, true>
179 EnableGuaranteedTailCallOpt("tailcallopt",
180   cl::desc("Turn fastcc calls into tail calls by (potentially) changing ABI."),
181   cl::location(GuaranteedTailCallOpt),
182   cl::init(false));
183 static cl::opt<unsigned, true>
184 OverrideStackAlignment("stack-alignment",
185   cl::desc("Override default stack alignment"),
186   cl::location(StackAlignmentOverride),
187   cl::init(0));
188 static cl::opt<bool, true>
189 EnableRealignStack("realign-stack",
190   cl::desc("Realign stack if needed"),
191   cl::location(RealignStack),
192   cl::init(true));
193 static cl::opt<bool, true>
194 DisableSwitchTables(cl::Hidden, "disable-jump-tables", 
195   cl::desc("Do not generate jump tables."),
196   cl::location(DisableJumpTables),
197   cl::init(false));
198 static cl::opt<bool, true>
199 EnableStrongPHIElim(cl::Hidden, "strong-phi-elim",
200   cl::desc("Use strong PHI elimination."),
201   cl::location(StrongPHIElim),
202   cl::init(false));
203 static cl::opt<std::string>
204 TrapFuncName("trap-func", cl::Hidden,
205   cl::desc("Emit a call to trap function rather than a trap instruction"),
206   cl::init(""));
207 static cl::opt<bool>
208 DataSections("fdata-sections",
209   cl::desc("Emit data into separate sections"),
210   cl::init(false));
211 static cl::opt<bool>
212 FunctionSections("ffunction-sections",
213   cl::desc("Emit functions into separate sections"),
214   cl::init(false));
215 //---------------------------------------------------------------------------
216 // TargetMachine Class
217 //
218
219 TargetMachine::TargetMachine(const Target &T,
220                              StringRef TT, StringRef CPU, StringRef FS)
221   : TheTarget(T), TargetTriple(TT), TargetCPU(CPU), TargetFS(FS), AsmInfo(0),
222     MCRelaxAll(false),
223     MCNoExecStack(false),
224     MCSaveTempLabels(false),
225     MCUseLoc(true),
226     MCUseCFI(true) {
227   // Typically it will be subtargets that will adjust FloatABIType from Default
228   // to Soft or Hard.
229   if (UseSoftFloat)
230     FloatABIType = FloatABI::Soft;
231 }
232
233 TargetMachine::~TargetMachine() {
234   delete AsmInfo;
235 }
236
237 /// getRelocationModel - Returns the code generation relocation model. The
238 /// choices are static, PIC, and dynamic-no-pic, and target default.
239 Reloc::Model TargetMachine::getRelocationModel() {
240   return RelocationModel;
241 }
242
243 /// setRelocationModel - Sets the code generation relocation model.
244 void TargetMachine::setRelocationModel(Reloc::Model Model) {
245   RelocationModel = Model;
246 }
247
248 /// getCodeModel - Returns the code model. The choices are small, kernel,
249 /// medium, large, and target default.
250 CodeModel::Model TargetMachine::getCodeModel() {
251   return CMModel;
252 }
253
254 /// setCodeModel - Sets the code model.
255 void TargetMachine::setCodeModel(CodeModel::Model Model) {
256   CMModel = Model;
257 }
258
259 bool TargetMachine::getAsmVerbosityDefault() {
260   return AsmVerbosityDefault;
261 }
262
263 void TargetMachine::setAsmVerbosityDefault(bool V) {
264   AsmVerbosityDefault = V;
265 }
266
267 bool TargetMachine::getFunctionSections() {
268   return FunctionSections;
269 }
270
271 bool TargetMachine::getDataSections() {
272   return DataSections;
273 }
274
275 void TargetMachine::setFunctionSections(bool V) {
276   FunctionSections = V;
277 }
278
279 void TargetMachine::setDataSections(bool V) {
280   DataSections = V;
281 }
282
283 namespace llvm {
284   /// DisableFramePointerElim - This returns true if frame pointer elimination
285   /// optimization should be disabled for the given machine function.
286   bool DisableFramePointerElim(const MachineFunction &MF) {
287     // Check to see if we should eliminate non-leaf frame pointers and then
288     // check to see if we should eliminate all frame pointers.
289     if (NoFramePointerElimNonLeaf && !NoFramePointerElim) {
290       const MachineFrameInfo *MFI = MF.getFrameInfo();
291       return MFI->hasCalls();
292     }
293
294     return NoFramePointerElim;
295   }
296
297   /// LessPreciseFPMAD - This flag return true when -enable-fp-mad option
298   /// is specified on the command line.  When this flag is off(default), the
299   /// code generator is not allowed to generate mad (multiply add) if the
300   /// result is "less precise" than doing those operations individually.
301   bool LessPreciseFPMAD() { return UnsafeFPMath || LessPreciseFPMADOption; }
302
303   /// HonorSignDependentRoundingFPMath - Return true if the codegen must assume
304   /// that the rounding mode of the FPU can change from its default.
305   bool HonorSignDependentRoundingFPMath() {
306     return !UnsafeFPMath && HonorSignDependentRoundingFPMathOption;
307   }
308
309   /// getTrapFunctionName - If this returns a non-empty string, this means isel
310   /// should lower Intrinsic::trap to a call to the specified function name
311   /// instead of an ISD::TRAP node.
312   StringRef getTrapFunctionName() {
313     return TrapFuncName;
314   }
315 }