Use %ull here.
[llvm/stm8.git] / lib / Target / TargetMachine.cpp
blob93eae250dfc7d4dfa62f7b8ccc7b75aca95bbd2c
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.
12 //===----------------------------------------------------------------------===//
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;
22 //---------------------------------------------------------------------------
23 // Command-line options that tend to be useful on more than one back-end.
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);
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));
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<std::string>
215 TrapFuncName("trap-func", cl::Hidden,
216 cl::desc("Emit a call to trap function rather than a trap instruction"),
217 cl::init(""));
218 static cl::opt<bool>
219 DataSections("fdata-sections",
220 cl::desc("Emit data into separate sections"),
221 cl::init(false));
222 static cl::opt<bool>
223 FunctionSections("ffunction-sections",
224 cl::desc("Emit functions into separate sections"),
225 cl::init(false));
226 //---------------------------------------------------------------------------
227 // TargetMachine Class
230 TargetMachine::TargetMachine(const Target &T)
231 : TheTarget(T), AsmInfo(0),
232 MCRelaxAll(false),
233 MCNoExecStack(false),
234 MCSaveTempLabels(false),
235 MCUseLoc(true) {
236 // Typically it will be subtargets that will adjust FloatABIType from Default
237 // to Soft or Hard.
238 if (UseSoftFloat)
239 FloatABIType = FloatABI::Soft;
242 TargetMachine::~TargetMachine() {
243 delete AsmInfo;
246 /// getRelocationModel - Returns the code generation relocation model. The
247 /// choices are static, PIC, and dynamic-no-pic, and target default.
248 Reloc::Model TargetMachine::getRelocationModel() {
249 return RelocationModel;
252 /// setRelocationModel - Sets the code generation relocation model.
253 void TargetMachine::setRelocationModel(Reloc::Model Model) {
254 RelocationModel = Model;
257 /// getCodeModel - Returns the code model. The choices are small, kernel,
258 /// medium, large, and target default.
259 CodeModel::Model TargetMachine::getCodeModel() {
260 return CMModel;
263 /// setCodeModel - Sets the code model.
264 void TargetMachine::setCodeModel(CodeModel::Model Model) {
265 CMModel = Model;
268 bool TargetMachine::getAsmVerbosityDefault() {
269 return AsmVerbosityDefault;
272 void TargetMachine::setAsmVerbosityDefault(bool V) {
273 AsmVerbosityDefault = V;
276 bool TargetMachine::getFunctionSections() {
277 return FunctionSections;
280 bool TargetMachine::getDataSections() {
281 return DataSections;
284 void TargetMachine::setFunctionSections(bool V) {
285 FunctionSections = V;
288 void TargetMachine::setDataSections(bool V) {
289 DataSections = V;
292 namespace llvm {
293 /// DisableFramePointerElim - This returns true if frame pointer elimination
294 /// optimization should be disabled for the given machine function.
295 bool DisableFramePointerElim(const MachineFunction &MF) {
296 // Check to see if we should eliminate non-leaf frame pointers and then
297 // check to see if we should eliminate all frame pointers.
298 if (NoFramePointerElimNonLeaf && !NoFramePointerElim) {
299 const MachineFrameInfo *MFI = MF.getFrameInfo();
300 return MFI->hasCalls();
303 return NoFramePointerElim;
306 /// LessPreciseFPMAD - This flag return true when -enable-fp-mad option
307 /// is specified on the command line. When this flag is off(default), the
308 /// code generator is not allowed to generate mad (multiply add) if the
309 /// result is "less precise" than doing those operations individually.
310 bool LessPreciseFPMAD() { return UnsafeFPMath || LessPreciseFPMADOption; }
312 /// HonorSignDependentRoundingFPMath - Return true if the codegen must assume
313 /// that the rounding mode of the FPU can change from its default.
314 bool HonorSignDependentRoundingFPMath() {
315 return !UnsafeFPMath && HonorSignDependentRoundingFPMathOption;
318 /// getTrapFunctionName - If this returns a non-empty string, this means isel
319 /// should lower Intrinsic::trap to a call to the specified function name
320 /// instead of an ISD::TRAP node.
321 StringRef getTrapFunctionName() {
322 return TrapFuncName;