Change -arm-divmod-libcall to a target neutral option.
[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<bool, true>
210 UseDivMod("use-divmod-libcall",
211   cl::desc("Use __{u}divmod libcalls for div / rem pairs"),
212   cl::location(HasDivModLibcall),
213   cl::init(false));
214 static cl::opt<bool>
215 DataSections("fdata-sections",
216   cl::desc("Emit data into separate sections"),
217   cl::init(false));
218 static cl::opt<bool>
219 FunctionSections("ffunction-sections",
220   cl::desc("Emit functions into separate sections"),
221   cl::init(false));
222 //---------------------------------------------------------------------------
223 // TargetMachine Class
224 //
225
226 TargetMachine::TargetMachine(const Target &T) 
227   : TheTarget(T), AsmInfo(0),
228     MCRelaxAll(false),
229     MCNoExecStack(false),
230     MCSaveTempLabels(false),
231     MCUseLoc(true) {
232   // Typically it will be subtargets that will adjust FloatABIType from Default
233   // to Soft or Hard.
234   if (UseSoftFloat)
235     FloatABIType = FloatABI::Soft;
236 }
237
238 TargetMachine::~TargetMachine() {
239   delete AsmInfo;
240 }
241
242 /// getRelocationModel - Returns the code generation relocation model. The
243 /// choices are static, PIC, and dynamic-no-pic, and target default.
244 Reloc::Model TargetMachine::getRelocationModel() {
245   return RelocationModel;
246 }
247
248 /// setRelocationModel - Sets the code generation relocation model.
249 void TargetMachine::setRelocationModel(Reloc::Model Model) {
250   RelocationModel = Model;
251 }
252
253 /// getCodeModel - Returns the code model. The choices are small, kernel,
254 /// medium, large, and target default.
255 CodeModel::Model TargetMachine::getCodeModel() {
256   return CMModel;
257 }
258
259 /// setCodeModel - Sets the code model.
260 void TargetMachine::setCodeModel(CodeModel::Model Model) {
261   CMModel = Model;
262 }
263
264 bool TargetMachine::getAsmVerbosityDefault() {
265   return AsmVerbosityDefault;
266 }
267
268 void TargetMachine::setAsmVerbosityDefault(bool V) {
269   AsmVerbosityDefault = V;
270 }
271
272 bool TargetMachine::getFunctionSections() {
273   return FunctionSections;
274 }
275
276 bool TargetMachine::getDataSections() {
277   return DataSections;
278 }
279
280 void TargetMachine::setFunctionSections(bool V) {
281   FunctionSections = V;
282 }
283
284 void TargetMachine::setDataSections(bool V) {
285   DataSections = V;
286 }
287
288 namespace llvm {
289   /// DisableFramePointerElim - This returns true if frame pointer elimination
290   /// optimization should be disabled for the given machine function.
291   bool DisableFramePointerElim(const MachineFunction &MF) {
292     // Check to see if we should eliminate non-leaf frame pointers and then
293     // check to see if we should eliminate all frame pointers.
294     if (NoFramePointerElimNonLeaf && !NoFramePointerElim) {
295       const MachineFrameInfo *MFI = MF.getFrameInfo();
296       return MFI->hasCalls();
297     }
298
299     return NoFramePointerElim;
300   }
301
302   /// LessPreciseFPMAD - This flag return true when -enable-fp-mad option
303   /// is specified on the command line.  When this flag is off(default), the
304   /// code generator is not allowed to generate mad (multiply add) if the
305   /// result is "less precise" than doing those operations individually.
306   bool LessPreciseFPMAD() { return UnsafeFPMath || LessPreciseFPMADOption; }
307
308   /// HonorSignDependentRoundingFPMath - Return true if the codegen must assume
309   /// that the rounding mode of the FPU can change from its default.
310   bool HonorSignDependentRoundingFPMath() {
311     return !UnsafeFPMath && HonorSignDependentRoundingFPMathOption;
312   }
313 }