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;
33 bool FiniteOnlyFPMathOption;
34 bool HonorSignDependentRoundingFPMathOption;
36 FloatABI::ABIType FloatABIType;
39 bool JITExceptionHandling;
40 bool JITEmitDebugInfo;
41 bool JITEmitDebugInfoToDisk;
42 bool UnwindTablesMandatory;
43 Reloc::Model RelocationModel;
44 CodeModel::Model CMModel;
45 bool GuaranteedTailCallOpt;
46 unsigned StackAlignment;
48 bool DisableJumpTables;
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 EnableFiniteOnlyFPMath("enable-finite-only-fp-math",
84 cl::desc("Enable optimizations that assumes non- NaNs / +-Infs"),
85 cl::location(FiniteOnlyFPMathOption),
87 static cl::opt<bool, true>
88 EnableHonorSignDependentRoundingFPMath("enable-sign-dependent-rounding-fp-math",
90 cl::desc("Force codegen to assume rounding mode can change dynamically"),
91 cl::location(HonorSignDependentRoundingFPMathOption),
93 static cl::opt<bool, true>
94 GenerateSoftFloatCalls("soft-float",
95 cl::desc("Generate software floating point library calls"),
96 cl::location(UseSoftFloat),
98 static cl::opt<llvm::FloatABI::ABIType, true>
99 FloatABIForCalls("float-abi",
100 cl::desc("Choose float ABI type"),
101 cl::location(FloatABIType),
102 cl::init(FloatABI::Default),
104 clEnumValN(FloatABI::Default, "default",
105 "Target default float ABI type"),
106 clEnumValN(FloatABI::Soft, "soft",
107 "Soft float ABI (implied by -soft-float)"),
108 clEnumValN(FloatABI::Hard, "hard",
109 "Hard float ABI (uses FP registers)"),
111 static cl::opt<bool, true>
112 DontPlaceZerosInBSS("nozero-initialized-in-bss",
113 cl::desc("Don't place zero-initialized symbols into bss section"),
114 cl::location(NoZerosInBSS),
116 static cl::opt<bool, true>
117 EnableJITExceptionHandling("jit-enable-eh",
118 cl::desc("Emit exception handling information"),
119 cl::location(JITExceptionHandling),
121 // In debug builds, make this default to true.
123 #define EMIT_DEBUG false
125 #define EMIT_DEBUG true
127 static cl::opt<bool, true>
128 EmitJitDebugInfo("jit-emit-debug",
129 cl::desc("Emit debug information to debugger"),
130 cl::location(JITEmitDebugInfo),
131 cl::init(EMIT_DEBUG));
133 static cl::opt<bool, true>
134 EmitJitDebugInfoToDisk("jit-emit-debug-to-disk",
136 cl::desc("Emit debug info objfiles to disk"),
137 cl::location(JITEmitDebugInfoToDisk),
139 static cl::opt<bool, true>
140 EnableUnwindTables("unwind-tables",
141 cl::desc("Generate unwinding tables for all functions"),
142 cl::location(UnwindTablesMandatory),
145 static cl::opt<llvm::Reloc::Model, true>
146 DefRelocationModel("relocation-model",
147 cl::desc("Choose relocation model"),
148 cl::location(RelocationModel),
149 cl::init(Reloc::Default),
151 clEnumValN(Reloc::Default, "default",
152 "Target default relocation model"),
153 clEnumValN(Reloc::Static, "static",
154 "Non-relocatable code"),
155 clEnumValN(Reloc::PIC_, "pic",
156 "Fully relocatable, position independent code"),
157 clEnumValN(Reloc::DynamicNoPIC, "dynamic-no-pic",
158 "Relocatable external references, non-relocatable code"),
160 static cl::opt<llvm::CodeModel::Model, true>
161 DefCodeModel("code-model",
162 cl::desc("Choose code model"),
163 cl::location(CMModel),
164 cl::init(CodeModel::Default),
166 clEnumValN(CodeModel::Default, "default",
167 "Target default code model"),
168 clEnumValN(CodeModel::Small, "small",
170 clEnumValN(CodeModel::Kernel, "kernel",
171 "Kernel code model"),
172 clEnumValN(CodeModel::Medium, "medium",
173 "Medium code model"),
174 clEnumValN(CodeModel::Large, "large",
177 static cl::opt<bool, true>
178 EnableGuaranteedTailCallOpt("tailcallopt",
179 cl::desc("Turn fastcc calls into tail calls by (potentially) changing ABI."),
180 cl::location(GuaranteedTailCallOpt),
182 static cl::opt<unsigned, true>
183 OverrideStackAlignment("stack-alignment",
184 cl::desc("Override default stack alignment"),
185 cl::location(StackAlignment),
187 static cl::opt<bool, true>
188 EnableRealignStack("realign-stack",
189 cl::desc("Realign stack if needed"),
190 cl::location(RealignStack),
192 static cl::opt<bool, true>
193 DisableSwitchTables(cl::Hidden, "disable-jump-tables",
194 cl::desc("Do not generate jump tables."),
195 cl::location(DisableJumpTables),
197 static cl::opt<bool, true>
198 EnableStrongPHIElim(cl::Hidden, "strong-phi-elim",
199 cl::desc("Use strong PHI elimination."),
200 cl::location(StrongPHIElim),
203 DataSections("fdata-sections",
204 cl::desc("Emit data into separate sections"),
207 FunctionSections("ffunction-sections",
208 cl::desc("Emit functions into separate sections"),
210 //---------------------------------------------------------------------------
211 // TargetMachine Class
214 TargetMachine::TargetMachine(const Target &T)
215 : TheTarget(T), AsmInfo(0),
217 // Typically it will be subtargets that will adjust FloatABIType from Default
220 FloatABIType = FloatABI::Soft;
223 TargetMachine::~TargetMachine() {
227 /// getRelocationModel - Returns the code generation relocation model. The
228 /// choices are static, PIC, and dynamic-no-pic, and target default.
229 Reloc::Model TargetMachine::getRelocationModel() {
230 return RelocationModel;
233 /// setRelocationModel - Sets the code generation relocation model.
234 void TargetMachine::setRelocationModel(Reloc::Model Model) {
235 RelocationModel = Model;
238 /// getCodeModel - Returns the code model. The choices are small, kernel,
239 /// medium, large, and target default.
240 CodeModel::Model TargetMachine::getCodeModel() {
244 /// setCodeModel - Sets the code model.
245 void TargetMachine::setCodeModel(CodeModel::Model Model) {
249 bool TargetMachine::getAsmVerbosityDefault() {
250 return AsmVerbosityDefault;
253 void TargetMachine::setAsmVerbosityDefault(bool V) {
254 AsmVerbosityDefault = V;
257 bool TargetMachine::getFunctionSections() {
258 return FunctionSections;
261 bool TargetMachine::getDataSections() {
265 void TargetMachine::setFunctionSections(bool V) {
266 FunctionSections = V;
269 void TargetMachine::setDataSections(bool V) {
274 /// DisableFramePointerElim - This returns true if frame pointer elimination
275 /// optimization should be disabled for the given machine function.
276 bool DisableFramePointerElim(const MachineFunction &MF) {
277 // Check to see if we should eliminate non-leaf frame pointers and then
278 // check to see if we should eliminate all frame pointers.
279 if (NoFramePointerElimNonLeaf && !NoFramePointerElim) {
280 const MachineFrameInfo *MFI = MF.getFrameInfo();
281 return MFI->hasCalls();
284 return NoFramePointerElim;
287 /// LessPreciseFPMAD - This flag return true when -enable-fp-mad option
288 /// is specified on the command line. When this flag is off(default), the
289 /// code generator is not allowed to generate mad (multiply add) if the
290 /// result is "less precise" than doing those operations individually.
291 bool LessPreciseFPMAD() { return UnsafeFPMath || LessPreciseFPMADOption; }
293 /// FiniteOnlyFPMath - This returns true when the -enable-finite-only-fp-math
294 /// option is specified on the command line. If this returns false (default),
295 /// the code generator is not allowed to assume that FP arithmetic arguments
296 /// and results are never NaNs or +-Infs.
297 bool FiniteOnlyFPMath() { return UnsafeFPMath || FiniteOnlyFPMathOption; }
299 /// HonorSignDependentRoundingFPMath - Return true if the codegen must assume
300 /// that the rounding mode of the FPU can change from its default.
301 bool HonorSignDependentRoundingFPMath() {
302 return !UnsafeFPMath && HonorSignDependentRoundingFPMathOption;