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 CodeModel::Model CMModel;
44 bool GuaranteedTailCallOpt;
45 unsigned StackAlignmentOverride;
47 bool DisableJumpTables;
49 bool HasDivModLibcall;
50 bool AsmVerbosityDefault(false);
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),
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),
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),
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),
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),
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),
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),
92 static cl::opt<bool, true>
93 EnableHonorSignDependentRoundingFPMath("enable-sign-dependent-rounding-fp-math",
95 cl::desc("Force codegen to assume rounding mode can change dynamically"),
96 cl::location(HonorSignDependentRoundingFPMathOption),
98 static cl::opt<bool, true>
99 GenerateSoftFloatCalls("soft-float",
100 cl::desc("Generate software floating point library calls"),
101 cl::location(UseSoftFloat),
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),
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)"),
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),
121 static cl::opt<bool, true>
122 EnableJITExceptionHandling("jit-enable-eh",
123 cl::desc("Emit exception handling information"),
124 cl::location(JITExceptionHandling),
126 // In debug builds, make this default to true.
128 #define EMIT_DEBUG false
130 #define EMIT_DEBUG true
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));
138 static cl::opt<bool, true>
139 EmitJitDebugInfoToDisk("jit-emit-debug-to-disk",
141 cl::desc("Emit debug info objfiles to disk"),
142 cl::location(JITEmitDebugInfoToDisk),
145 static cl::opt<llvm::CodeModel::Model, true>
146 DefCodeModel("code-model",
147 cl::desc("Choose code model"),
148 cl::location(CMModel),
149 cl::init(CodeModel::Default),
151 clEnumValN(CodeModel::Default, "default",
152 "Target default code model"),
153 clEnumValN(CodeModel::Small, "small",
155 clEnumValN(CodeModel::Kernel, "kernel",
156 "Kernel code model"),
157 clEnumValN(CodeModel::Medium, "medium",
158 "Medium code model"),
159 clEnumValN(CodeModel::Large, "large",
162 static cl::opt<bool, true>
163 EnableGuaranteedTailCallOpt("tailcallopt",
164 cl::desc("Turn fastcc calls into tail calls by (potentially) changing ABI."),
165 cl::location(GuaranteedTailCallOpt),
167 static cl::opt<unsigned, true>
168 OverrideStackAlignment("stack-alignment",
169 cl::desc("Override default stack alignment"),
170 cl::location(StackAlignmentOverride),
172 static cl::opt<bool, true>
173 EnableRealignStack("realign-stack",
174 cl::desc("Realign stack if needed"),
175 cl::location(RealignStack),
177 static cl::opt<bool, true>
178 DisableSwitchTables(cl::Hidden, "disable-jump-tables",
179 cl::desc("Do not generate jump tables."),
180 cl::location(DisableJumpTables),
182 static cl::opt<bool, true>
183 EnableStrongPHIElim(cl::Hidden, "strong-phi-elim",
184 cl::desc("Use strong PHI elimination."),
185 cl::location(StrongPHIElim),
187 static cl::opt<std::string>
188 TrapFuncName("trap-func", cl::Hidden,
189 cl::desc("Emit a call to trap function rather than a trap instruction"),
192 DataSections("fdata-sections",
193 cl::desc("Emit data into separate sections"),
196 FunctionSections("ffunction-sections",
197 cl::desc("Emit functions into separate sections"),
199 //---------------------------------------------------------------------------
200 // TargetMachine Class
203 TargetMachine::TargetMachine(const Target &T,
204 StringRef TT, StringRef CPU, StringRef FS)
205 : TheTarget(T), TargetTriple(TT), TargetCPU(CPU), TargetFS(FS), AsmInfo(0),
207 MCNoExecStack(false),
208 MCSaveTempLabels(false),
211 // Typically it will be subtargets that will adjust FloatABIType from Default
214 FloatABIType = FloatABI::Soft;
217 TargetMachine::~TargetMachine() {
221 /// getRelocationModel - Returns the code generation relocation model. The
222 /// choices are static, PIC, and dynamic-no-pic, and target default.
223 Reloc::Model TargetMachine::getRelocationModel() const {
225 return Reloc::Default;
226 return CodeGenInfo->getRelocationModel();
229 /// getCodeModel - Returns the code model. The choices are small, kernel,
230 /// medium, large, and target default.
231 CodeModel::Model TargetMachine::getCodeModel() {
235 /// setCodeModel - Sets the code model.
236 void TargetMachine::setCodeModel(CodeModel::Model Model) {
240 bool TargetMachine::getAsmVerbosityDefault() {
241 return AsmVerbosityDefault;
244 void TargetMachine::setAsmVerbosityDefault(bool V) {
245 AsmVerbosityDefault = V;
248 bool TargetMachine::getFunctionSections() {
249 return FunctionSections;
252 bool TargetMachine::getDataSections() {
256 void TargetMachine::setFunctionSections(bool V) {
257 FunctionSections = V;
260 void TargetMachine::setDataSections(bool V) {
265 /// DisableFramePointerElim - This returns true if frame pointer elimination
266 /// optimization should be disabled for the given machine function.
267 bool DisableFramePointerElim(const MachineFunction &MF) {
268 // Check to see if we should eliminate non-leaf frame pointers and then
269 // check to see if we should eliminate all frame pointers.
270 if (NoFramePointerElimNonLeaf && !NoFramePointerElim) {
271 const MachineFrameInfo *MFI = MF.getFrameInfo();
272 return MFI->hasCalls();
275 return NoFramePointerElim;
278 /// LessPreciseFPMAD - This flag return true when -enable-fp-mad option
279 /// is specified on the command line. When this flag is off(default), the
280 /// code generator is not allowed to generate mad (multiply add) if the
281 /// result is "less precise" than doing those operations individually.
282 bool LessPreciseFPMAD() { return UnsafeFPMath || LessPreciseFPMADOption; }
284 /// HonorSignDependentRoundingFPMath - Return true if the codegen must assume
285 /// that the rounding mode of the FPU can change from its default.
286 bool HonorSignDependentRoundingFPMath() {
287 return !UnsafeFPMath && HonorSignDependentRoundingFPMathOption;
290 /// getTrapFunctionName - If this returns a non-empty string, this means isel
291 /// should lower Intrinsic::trap to a call to the specified function name
292 /// instead of an ISD::TRAP node.
293 StringRef getTrapFunctionName() {