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