1 //===-- TargetMachine.cpp - General Target Information ---------------------==//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
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"
22 //---------------------------------------------------------------------------
23 // Command-line options that tend to be useful on more than one back-end.
27 bool LessPreciseFPMADOption
;
28 bool PrintMachineCode
;
29 bool NoFramePointerElim
;
30 bool NoFramePointerElimNonLeaf
;
31 bool NoExcessFPPrecision
;
35 bool HonorSignDependentRoundingFPMathOption
;
37 FloatABI::ABIType FloatABIType
;
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
;
49 bool DisableJumpTables
;
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
),
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
),
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
),
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
),
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
),
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
),
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
),
94 static cl::opt
<bool, true>
95 EnableHonorSignDependentRoundingFPMath("enable-sign-dependent-rounding-fp-math",
97 cl::desc("Force codegen to assume rounding mode can change dynamically"),
98 cl::location(HonorSignDependentRoundingFPMathOption
),
100 static cl::opt
<bool, true>
101 GenerateSoftFloatCalls("soft-float",
102 cl::desc("Generate software floating point library calls"),
103 cl::location(UseSoftFloat
),
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
),
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)"),
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
),
123 static cl::opt
<bool, true>
124 EnableJITExceptionHandling("jit-enable-eh",
125 cl::desc("Emit exception handling information"),
126 cl::location(JITExceptionHandling
),
128 // In debug builds, make this default to true.
130 #define EMIT_DEBUG false
132 #define EMIT_DEBUG true
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
));
140 static cl::opt
<bool, true>
141 EmitJitDebugInfoToDisk("jit-emit-debug-to-disk",
143 cl::desc("Emit debug info objfiles to disk"),
144 cl::location(JITEmitDebugInfoToDisk
),
146 static cl::opt
<bool, true>
147 EnableUnwindTables("unwind-tables",
148 cl::desc("Generate unwinding tables for all functions"),
149 cl::location(UnwindTablesMandatory
),
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
),
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"),
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
),
173 clEnumValN(CodeModel::Default
, "default",
174 "Target default code model"),
175 clEnumValN(CodeModel::Small
, "small",
177 clEnumValN(CodeModel::Kernel
, "kernel",
178 "Kernel code model"),
179 clEnumValN(CodeModel::Medium
, "medium",
180 "Medium code model"),
181 clEnumValN(CodeModel::Large
, "large",
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
),
189 static cl::opt
<unsigned, true>
190 OverrideStackAlignment("stack-alignment",
191 cl::desc("Override default stack alignment"),
192 cl::location(StackAlignment
),
194 static cl::opt
<bool, true>
195 EnableRealignStack("realign-stack",
196 cl::desc("Realign stack if needed"),
197 cl::location(RealignStack
),
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
),
204 static cl::opt
<bool, true>
205 EnableStrongPHIElim(cl::Hidden
, "strong-phi-elim",
206 cl::desc("Use strong PHI elimination."),
207 cl::location(StrongPHIElim
),
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
),
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"),
219 DataSections("fdata-sections",
220 cl::desc("Emit data into separate sections"),
223 FunctionSections("ffunction-sections",
224 cl::desc("Emit functions into separate sections"),
226 //---------------------------------------------------------------------------
227 // TargetMachine Class
230 TargetMachine::TargetMachine(const Target
&T
)
231 : TheTarget(T
), AsmInfo(0),
233 MCNoExecStack(false),
234 MCSaveTempLabels(false),
236 // Typically it will be subtargets that will adjust FloatABIType from Default
239 FloatABIType
= FloatABI::Soft
;
242 TargetMachine::~TargetMachine() {
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() {
263 /// setCodeModel - Sets the code model.
264 void TargetMachine::setCodeModel(CodeModel::Model 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() {
284 void TargetMachine::setFunctionSections(bool V
) {
285 FunctionSections
= V
;
288 void TargetMachine::setDataSections(bool V
) {
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() {