Implement -disable-non-leaf-fp-elim which disable frame pointer elimination
[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 FiniteOnlyFPMathOption;
34   bool HonorSignDependentRoundingFPMathOption;
35   bool UseSoftFloat;
36   FloatABI::ABIType FloatABIType;
37   bool NoImplicitFloat;
38   bool NoZerosInBSS;
39   bool DwarfExceptionHandling;
40   bool SjLjExceptionHandling;
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 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 EnableFiniteOnlyFPMath("enable-finite-only-fp-math",
85   cl::desc("Enable optimizations that assumes non- NaNs / +-Infs"),
86   cl::location(FiniteOnlyFPMathOption),
87   cl::init(false));
88 static cl::opt<bool, true>
89 EnableHonorSignDependentRoundingFPMath("enable-sign-dependent-rounding-fp-math",
90   cl::Hidden,
91   cl::desc("Force codegen to assume rounding mode can change dynamically"),
92   cl::location(HonorSignDependentRoundingFPMathOption),
93   cl::init(false));
94 static cl::opt<bool, true>
95 GenerateSoftFloatCalls("soft-float",
96   cl::desc("Generate software floating point library calls"),
97   cl::location(UseSoftFloat),
98   cl::init(false));
99 static cl::opt<llvm::FloatABI::ABIType, true>
100 FloatABIForCalls("float-abi",
101   cl::desc("Choose float ABI type"),
102   cl::location(FloatABIType),
103   cl::init(FloatABI::Default),
104   cl::values(
105     clEnumValN(FloatABI::Default, "default",
106                "Target default float ABI type"),
107     clEnumValN(FloatABI::Soft, "soft",
108                "Soft float ABI (implied by -soft-float)"),
109     clEnumValN(FloatABI::Hard, "hard",
110                "Hard float ABI (uses FP registers)"),
111     clEnumValEnd));
112 static cl::opt<bool, true>
113 DontPlaceZerosInBSS("nozero-initialized-in-bss",
114   cl::desc("Don't place zero-initialized symbols into bss section"),
115   cl::location(NoZerosInBSS),
116   cl::init(false));
117 static cl::opt<bool, true>
118 EnableDwarfExceptionHandling("enable-eh",
119   cl::desc("Emit DWARF exception handling (default if target supports)"),
120   cl::location(DwarfExceptionHandling),
121   cl::init(false));
122 static cl::opt<bool, true>
123 EnableSjLjExceptionHandling("enable-sjlj-eh",
124   cl::desc("Emit SJLJ exception handling (default if target supports)"),
125   cl::location(SjLjExceptionHandling),
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 static cl::opt<bool, true>
146 EnableUnwindTables("unwind-tables",
147   cl::desc("Generate unwinding tables for all functions"),
148   cl::location(UnwindTablesMandatory),
149   cl::init(false));
150
151 static cl::opt<llvm::Reloc::Model, true>
152 DefRelocationModel("relocation-model",
153   cl::desc("Choose relocation model"),
154   cl::location(RelocationModel),
155   cl::init(Reloc::Default),
156   cl::values(
157     clEnumValN(Reloc::Default, "default",
158                "Target default relocation model"),
159     clEnumValN(Reloc::Static, "static",
160                "Non-relocatable code"),
161     clEnumValN(Reloc::PIC_, "pic",
162                "Fully relocatable, position independent code"),
163     clEnumValN(Reloc::DynamicNoPIC, "dynamic-no-pic",
164                "Relocatable external references, non-relocatable code"),
165     clEnumValEnd));
166 static cl::opt<llvm::CodeModel::Model, true>
167 DefCodeModel("code-model",
168   cl::desc("Choose code model"),
169   cl::location(CMModel),
170   cl::init(CodeModel::Default),
171   cl::values(
172     clEnumValN(CodeModel::Default, "default",
173                "Target default code model"),
174     clEnumValN(CodeModel::Small, "small",
175                "Small code model"),
176     clEnumValN(CodeModel::Kernel, "kernel",
177                "Kernel code model"),
178     clEnumValN(CodeModel::Medium, "medium",
179                "Medium code model"),
180     clEnumValN(CodeModel::Large, "large",
181                "Large code model"),
182     clEnumValEnd));
183 static cl::opt<bool, true>
184 EnableGuaranteedTailCallOpt("tailcallopt",
185   cl::desc("Turn fastcc calls into tail calls by (potentially) changing ABI."),
186   cl::location(GuaranteedTailCallOpt),
187   cl::init(false));
188 static cl::opt<unsigned, true>
189 OverrideStackAlignment("stack-alignment",
190   cl::desc("Override default stack alignment"),
191   cl::location(StackAlignment),
192   cl::init(0));
193 static cl::opt<bool, true>
194 EnableRealignStack("realign-stack",
195   cl::desc("Realign stack if needed"),
196   cl::location(RealignStack),
197   cl::init(true));
198 static cl::opt<bool, true>
199 DisableSwitchTables(cl::Hidden, "disable-jump-tables", 
200   cl::desc("Do not generate jump tables."),
201   cl::location(DisableJumpTables),
202   cl::init(false));
203 static cl::opt<bool, true>
204 EnableStrongPHIElim(cl::Hidden, "strong-phi-elim",
205   cl::desc("Use strong PHI elimination."),
206   cl::location(StrongPHIElim),
207   cl::init(false));
208 static cl::opt<bool>
209 DataSections("fdata-sections",
210   cl::desc("Emit data into separate sections"),
211   cl::init(false));
212 static cl::opt<bool>
213 FunctionSections("ffunction-sections",
214   cl::desc("Emit functions into separate sections"),
215   cl::init(false));
216 //---------------------------------------------------------------------------
217 // TargetMachine Class
218 //
219
220 TargetMachine::TargetMachine(const Target &T) 
221   : TheTarget(T), AsmInfo(0) {
222   // Typically it will be subtargets that will adjust FloatABIType from Default
223   // to Soft or Hard.
224   if (UseSoftFloat)
225     FloatABIType = FloatABI::Soft;
226 }
227
228 TargetMachine::~TargetMachine() {
229   delete AsmInfo;
230 }
231
232 /// getRelocationModel - Returns the code generation relocation model. The
233 /// choices are static, PIC, and dynamic-no-pic, and target default.
234 Reloc::Model TargetMachine::getRelocationModel() {
235   return RelocationModel;
236 }
237
238 /// setRelocationModel - Sets the code generation relocation model.
239 void TargetMachine::setRelocationModel(Reloc::Model Model) {
240   RelocationModel = Model;
241 }
242
243 /// getCodeModel - Returns the code model. The choices are small, kernel,
244 /// medium, large, and target default.
245 CodeModel::Model TargetMachine::getCodeModel() {
246   return CMModel;
247 }
248
249 /// setCodeModel - Sets the code model.
250 void TargetMachine::setCodeModel(CodeModel::Model Model) {
251   CMModel = Model;
252 }
253
254 bool TargetMachine::getAsmVerbosityDefault() {
255   return AsmVerbosityDefault;
256 }
257
258 void TargetMachine::setAsmVerbosityDefault(bool V) {
259   AsmVerbosityDefault = V;
260 }
261
262 bool TargetMachine::getFunctionSections() {
263   return FunctionSections;
264 }
265
266 bool TargetMachine::getDataSections() {
267   return DataSections;
268 }
269
270 void TargetMachine::setFunctionSections(bool V) {
271   FunctionSections = V;
272 }
273
274 void TargetMachine::setDataSections(bool V) {
275   DataSections = V;
276 }
277
278 namespace llvm {
279   /// DisableFramePointerElim - This returns true if frame pointer elimination
280   /// optimization should be disabled for the given machine function.
281   bool DisableFramePointerElim(const MachineFunction &MF) {
282     if (NoFramePointerElim)
283       return true;
284     if (NoFramePointerElimNonLeaf) {
285       const MachineFrameInfo *MFI = MF.getFrameInfo();
286       return MFI->hasCalls();
287     }
288     return false;
289   }
290
291   /// LessPreciseFPMAD - This flag return true when -enable-fp-mad option
292   /// is specified on the command line.  When this flag is off(default), the
293   /// code generator is not allowed to generate mad (multiply add) if the
294   /// result is "less precise" than doing those operations individually.
295   bool LessPreciseFPMAD() { return UnsafeFPMath || LessPreciseFPMADOption; }
296
297   /// FiniteOnlyFPMath - This returns true when the -enable-finite-only-fp-math
298   /// option is specified on the command line. If this returns false (default),
299   /// the code generator is not allowed to assume that FP arithmetic arguments
300   /// and results are never NaNs or +-Infs.
301   bool FiniteOnlyFPMath() { return UnsafeFPMath || FiniteOnlyFPMathOption; }
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 }