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),
215 DataSections("fdata-sections",
216 cl::desc("Emit data into separate sections"),
219 FunctionSections("ffunction-sections",
220 cl::desc("Emit functions into separate sections"),
222 //---------------------------------------------------------------------------
223 // TargetMachine Class
226 TargetMachine::TargetMachine(const Target &T)
227 : TheTarget(T), AsmInfo(0),
229 MCNoExecStack(false),
230 MCSaveTempLabels(false),
232 // Typically it will be subtargets that will adjust FloatABIType from Default
235 FloatABIType = FloatABI::Soft;
238 TargetMachine::~TargetMachine() {
242 /// getRelocationModel - Returns the code generation relocation model. The
243 /// choices are static, PIC, and dynamic-no-pic, and target default.
244 Reloc::Model TargetMachine::getRelocationModel() {
245 return RelocationModel;
248 /// setRelocationModel - Sets the code generation relocation model.
249 void TargetMachine::setRelocationModel(Reloc::Model Model) {
250 RelocationModel = Model;
253 /// getCodeModel - Returns the code model. The choices are small, kernel,
254 /// medium, large, and target default.
255 CodeModel::Model TargetMachine::getCodeModel() {
259 /// setCodeModel - Sets the code model.
260 void TargetMachine::setCodeModel(CodeModel::Model Model) {
264 bool TargetMachine::getAsmVerbosityDefault() {
265 return AsmVerbosityDefault;
268 void TargetMachine::setAsmVerbosityDefault(bool V) {
269 AsmVerbosityDefault = V;
272 bool TargetMachine::getFunctionSections() {
273 return FunctionSections;
276 bool TargetMachine::getDataSections() {
280 void TargetMachine::setFunctionSections(bool V) {
281 FunctionSections = V;
284 void TargetMachine::setDataSections(bool V) {
289 /// DisableFramePointerElim - This returns true if frame pointer elimination
290 /// optimization should be disabled for the given machine function.
291 bool DisableFramePointerElim(const MachineFunction &MF) {
292 // Check to see if we should eliminate non-leaf frame pointers and then
293 // check to see if we should eliminate all frame pointers.
294 if (NoFramePointerElimNonLeaf && !NoFramePointerElim) {
295 const MachineFrameInfo *MFI = MF.getFrameInfo();
296 return MFI->hasCalls();
299 return NoFramePointerElim;
302 /// LessPreciseFPMAD - This flag return true when -enable-fp-mad option
303 /// is specified on the command line. When this flag is off(default), the
304 /// code generator is not allowed to generate mad (multiply add) if the
305 /// result is "less precise" than doing those operations individually.
306 bool LessPreciseFPMAD() { return UnsafeFPMath || LessPreciseFPMADOption; }
308 /// HonorSignDependentRoundingFPMath - Return true if the codegen must assume
309 /// that the rounding mode of the FPU can change from its default.
310 bool HonorSignDependentRoundingFPMath() {
311 return !UnsafeFPMath && HonorSignDependentRoundingFPMathOption;