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 GuaranteedTailCallOpt;
44 unsigned StackAlignmentOverride;
46 bool DisableJumpTables;
48 bool HasDivModLibcall;
49 bool AsmVerbosityDefault(false);
52 static cl::opt<bool, true>
53 PrintCode("print-machineinstrs",
54 cl::desc("Print generated machine code"),
55 cl::location(PrintMachineCode), cl::init(false));
56 static cl::opt<bool, true>
57 DisableFPElim("disable-fp-elim",
58 cl::desc("Disable frame pointer elimination optimization"),
59 cl::location(NoFramePointerElim),
61 static cl::opt<bool, true>
62 DisableFPElimNonLeaf("disable-non-leaf-fp-elim",
63 cl::desc("Disable frame pointer elimination optimization for non-leaf funcs"),
64 cl::location(NoFramePointerElimNonLeaf),
66 static cl::opt<bool, true>
67 DisableExcessPrecision("disable-excess-fp-precision",
68 cl::desc("Disable optimizations that may increase FP precision"),
69 cl::location(NoExcessFPPrecision),
71 static cl::opt<bool, true>
72 EnableFPMAD("enable-fp-mad",
73 cl::desc("Enable less precise MAD instructions to be generated"),
74 cl::location(LessPreciseFPMADOption),
76 static cl::opt<bool, true>
77 EnableUnsafeFPMath("enable-unsafe-fp-math",
78 cl::desc("Enable optimizations that may decrease FP precision"),
79 cl::location(UnsafeFPMath),
81 static cl::opt<bool, true>
82 EnableNoInfsFPMath("enable-no-infs-fp-math",
83 cl::desc("Enable FP math optimizations that assume no +-Infs"),
84 cl::location(NoInfsFPMath),
86 static cl::opt<bool, true>
87 EnableNoNaNsFPMath("enable-no-nans-fp-math",
88 cl::desc("Enable FP math optimizations that assume no NaNs"),
89 cl::location(NoNaNsFPMath),
91 static cl::opt<bool, true>
92 EnableHonorSignDependentRoundingFPMath("enable-sign-dependent-rounding-fp-math",
94 cl::desc("Force codegen to assume rounding mode can change dynamically"),
95 cl::location(HonorSignDependentRoundingFPMathOption),
97 static cl::opt<bool, true>
98 GenerateSoftFloatCalls("soft-float",
99 cl::desc("Generate software floating point library calls"),
100 cl::location(UseSoftFloat),
102 static cl::opt<llvm::FloatABI::ABIType, true>
103 FloatABIForCalls("float-abi",
104 cl::desc("Choose float ABI type"),
105 cl::location(FloatABIType),
106 cl::init(FloatABI::Default),
108 clEnumValN(FloatABI::Default, "default",
109 "Target default float ABI type"),
110 clEnumValN(FloatABI::Soft, "soft",
111 "Soft float ABI (implied by -soft-float)"),
112 clEnumValN(FloatABI::Hard, "hard",
113 "Hard float ABI (uses FP registers)"),
115 static cl::opt<bool, true>
116 DontPlaceZerosInBSS("nozero-initialized-in-bss",
117 cl::desc("Don't place zero-initialized symbols into bss section"),
118 cl::location(NoZerosInBSS),
120 static cl::opt<bool, true>
121 EnableJITExceptionHandling("jit-enable-eh",
122 cl::desc("Emit exception handling information"),
123 cl::location(JITExceptionHandling),
125 // In debug builds, make this default to true.
127 #define EMIT_DEBUG false
129 #define EMIT_DEBUG true
131 static cl::opt<bool, true>
132 EmitJitDebugInfo("jit-emit-debug",
133 cl::desc("Emit debug information to debugger"),
134 cl::location(JITEmitDebugInfo),
135 cl::init(EMIT_DEBUG));
137 static cl::opt<bool, true>
138 EmitJitDebugInfoToDisk("jit-emit-debug-to-disk",
140 cl::desc("Emit debug info objfiles to disk"),
141 cl::location(JITEmitDebugInfoToDisk),
144 static cl::opt<bool, true>
145 EnableGuaranteedTailCallOpt("tailcallopt",
146 cl::desc("Turn fastcc calls into tail calls by (potentially) changing ABI."),
147 cl::location(GuaranteedTailCallOpt),
149 static cl::opt<unsigned, true>
150 OverrideStackAlignment("stack-alignment",
151 cl::desc("Override default stack alignment"),
152 cl::location(StackAlignmentOverride),
154 static cl::opt<bool, true>
155 EnableRealignStack("realign-stack",
156 cl::desc("Realign stack if needed"),
157 cl::location(RealignStack),
159 static cl::opt<bool, true>
160 DisableSwitchTables(cl::Hidden, "disable-jump-tables",
161 cl::desc("Do not generate jump tables."),
162 cl::location(DisableJumpTables),
164 static cl::opt<bool, true>
165 EnableStrongPHIElim(cl::Hidden, "strong-phi-elim",
166 cl::desc("Use strong PHI elimination."),
167 cl::location(StrongPHIElim),
169 static cl::opt<std::string>
170 TrapFuncName("trap-func", cl::Hidden,
171 cl::desc("Emit a call to trap function rather than a trap instruction"),
174 DataSections("fdata-sections",
175 cl::desc("Emit data into separate sections"),
178 FunctionSections("ffunction-sections",
179 cl::desc("Emit functions into separate sections"),
181 //---------------------------------------------------------------------------
182 // TargetMachine Class
185 TargetMachine::TargetMachine(const Target &T,
186 StringRef TT, StringRef CPU, StringRef FS)
187 : TheTarget(T), TargetTriple(TT), TargetCPU(CPU), TargetFS(FS),
188 CodeGenInfo(0), AsmInfo(0),
190 MCNoExecStack(false),
191 MCSaveTempLabels(false),
194 // Typically it will be subtargets that will adjust FloatABIType from Default
197 FloatABIType = FloatABI::Soft;
200 TargetMachine::~TargetMachine() {
205 /// getRelocationModel - Returns the code generation relocation model. The
206 /// choices are static, PIC, and dynamic-no-pic, and target default.
207 Reloc::Model TargetMachine::getRelocationModel() const {
209 return Reloc::Default;
210 return CodeGenInfo->getRelocationModel();
213 /// getCodeModel - Returns the code model. The choices are small, kernel,
214 /// medium, large, and target default.
215 CodeModel::Model TargetMachine::getCodeModel() const {
217 return CodeModel::Default;
218 return CodeGenInfo->getCodeModel();
221 bool TargetMachine::getAsmVerbosityDefault() {
222 return AsmVerbosityDefault;
225 void TargetMachine::setAsmVerbosityDefault(bool V) {
226 AsmVerbosityDefault = V;
229 bool TargetMachine::getFunctionSections() {
230 return FunctionSections;
233 bool TargetMachine::getDataSections() {
237 void TargetMachine::setFunctionSections(bool V) {
238 FunctionSections = V;
241 void TargetMachine::setDataSections(bool V) {
246 /// DisableFramePointerElim - This returns true if frame pointer elimination
247 /// optimization should be disabled for the given machine function.
248 bool DisableFramePointerElim(const MachineFunction &MF) {
249 // Check to see if we should eliminate non-leaf frame pointers and then
250 // check to see if we should eliminate all frame pointers.
251 if (NoFramePointerElimNonLeaf && !NoFramePointerElim) {
252 const MachineFrameInfo *MFI = MF.getFrameInfo();
253 return MFI->hasCalls();
256 return NoFramePointerElim;
259 /// LessPreciseFPMAD - This flag return true when -enable-fp-mad option
260 /// is specified on the command line. When this flag is off(default), the
261 /// code generator is not allowed to generate mad (multiply add) if the
262 /// result is "less precise" than doing those operations individually.
263 bool LessPreciseFPMAD() { return UnsafeFPMath || LessPreciseFPMADOption; }
265 /// HonorSignDependentRoundingFPMath - Return true if the codegen must assume
266 /// that the rounding mode of the FPU can change from its default.
267 bool HonorSignDependentRoundingFPMath() {
268 return !UnsafeFPMath && HonorSignDependentRoundingFPMathOption;
271 /// getTrapFunctionName - If this returns a non-empty string, this means isel
272 /// should lower Intrinsic::trap to a call to the specified function name
273 /// instead of an ISD::TRAP node.
274 StringRef getTrapFunctionName() {