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