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/MC/MCAsmInfo.h"
15 #include "llvm/Target/TargetMachine.h"
16 #include "llvm/Target/TargetOptions.h"
17 #include "llvm/Support/CommandLine.h"
20 //---------------------------------------------------------------------------
21 // Command-line options that tend to be useful on more than one back-end.
25 bool LessPreciseFPMADOption;
26 bool PrintMachineCode;
27 bool NoFramePointerElim;
28 bool NoExcessFPPrecision;
30 bool FiniteOnlyFPMathOption;
31 bool HonorSignDependentRoundingFPMathOption;
33 FloatABI::ABIType FloatABIType;
36 bool DwarfExceptionHandling;
37 bool SjLjExceptionHandling;
38 bool JITEmitDebugInfo;
39 bool JITEmitDebugInfoToDisk;
40 bool UnwindTablesMandatory;
41 Reloc::Model RelocationModel;
42 CodeModel::Model CMModel;
43 bool PerformTailCallOpt;
44 unsigned StackAlignment;
46 bool DisableJumpTables;
48 bool AsmVerbosityDefault(false);
49 bool DisableScheduling;
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 DisableExcessPrecision("disable-excess-fp-precision",
63 cl::desc("Disable optimizations that may increase FP precision"),
64 cl::location(NoExcessFPPrecision),
66 static cl::opt<bool, true>
67 EnableFPMAD("enable-fp-mad",
68 cl::desc("Enable less precise MAD instructions to be generated"),
69 cl::location(LessPreciseFPMADOption),
71 static cl::opt<bool, true>
72 EnableUnsafeFPMath("enable-unsafe-fp-math",
73 cl::desc("Enable optimizations that may decrease FP precision"),
74 cl::location(UnsafeFPMath),
76 static cl::opt<bool, true>
77 EnableFiniteOnlyFPMath("enable-finite-only-fp-math",
78 cl::desc("Enable optimizations that assumes non- NaNs / +-Infs"),
79 cl::location(FiniteOnlyFPMathOption),
81 static cl::opt<bool, true>
82 EnableHonorSignDependentRoundingFPMath("enable-sign-dependent-rounding-fp-math",
84 cl::desc("Force codegen to assume rounding mode can change dynamically"),
85 cl::location(HonorSignDependentRoundingFPMathOption),
87 static cl::opt<bool, true>
88 GenerateSoftFloatCalls("soft-float",
89 cl::desc("Generate software floating point library calls"),
90 cl::location(UseSoftFloat),
92 static cl::opt<llvm::FloatABI::ABIType, true>
93 FloatABIForCalls("float-abi",
94 cl::desc("Choose float ABI type"),
95 cl::location(FloatABIType),
96 cl::init(FloatABI::Default),
98 clEnumValN(FloatABI::Default, "default",
99 "Target default float ABI type"),
100 clEnumValN(FloatABI::Soft, "soft",
101 "Soft float ABI (implied by -soft-float)"),
102 clEnumValN(FloatABI::Hard, "hard",
103 "Hard float ABI (uses FP registers)"),
105 static cl::opt<bool, true>
106 DontPlaceZerosInBSS("nozero-initialized-in-bss",
107 cl::desc("Don't place zero-initialized symbols into bss section"),
108 cl::location(NoZerosInBSS),
110 static cl::opt<bool, true>
111 EnableDwarfExceptionHandling("enable-eh",
112 cl::desc("Emit DWARF exception handling (default if target supports)"),
113 cl::location(DwarfExceptionHandling),
115 static cl::opt<bool, true>
116 EnableSjLjExceptionHandling("enable-sjlj-eh",
117 cl::desc("Emit SJLJ exception handling (default if target supports)"),
118 cl::location(SjLjExceptionHandling),
120 // In debug builds, make this default to true.
122 #define EMIT_DEBUG false
124 #define EMIT_DEBUG true
126 static cl::opt<bool, true>
127 EmitJitDebugInfo("jit-emit-debug",
128 cl::desc("Emit debug information to debugger"),
129 cl::location(JITEmitDebugInfo),
130 cl::init(EMIT_DEBUG));
132 static cl::opt<bool, true>
133 EmitJitDebugInfoToDisk("jit-emit-debug-to-disk",
135 cl::desc("Emit debug info objfiles to disk"),
136 cl::location(JITEmitDebugInfoToDisk),
138 static cl::opt<bool, true>
139 EnableUnwindTables("unwind-tables",
140 cl::desc("Generate unwinding tables for all functions"),
141 cl::location(UnwindTablesMandatory),
144 static cl::opt<llvm::Reloc::Model, true>
145 DefRelocationModel("relocation-model",
146 cl::desc("Choose relocation model"),
147 cl::location(RelocationModel),
148 cl::init(Reloc::Default),
150 clEnumValN(Reloc::Default, "default",
151 "Target default relocation model"),
152 clEnumValN(Reloc::Static, "static",
153 "Non-relocatable code"),
154 clEnumValN(Reloc::PIC_, "pic",
155 "Fully relocatable, position independent code"),
156 clEnumValN(Reloc::DynamicNoPIC, "dynamic-no-pic",
157 "Relocatable external references, non-relocatable code"),
159 static cl::opt<llvm::CodeModel::Model, true>
160 DefCodeModel("code-model",
161 cl::desc("Choose code model"),
162 cl::location(CMModel),
163 cl::init(CodeModel::Default),
165 clEnumValN(CodeModel::Default, "default",
166 "Target default code model"),
167 clEnumValN(CodeModel::Small, "small",
169 clEnumValN(CodeModel::Kernel, "kernel",
170 "Kernel code model"),
171 clEnumValN(CodeModel::Medium, "medium",
172 "Medium code model"),
173 clEnumValN(CodeModel::Large, "large",
176 static cl::opt<bool, true>
177 EnablePerformTailCallOpt("tailcallopt",
178 cl::desc("Turn on tail call optimization."),
179 cl::location(PerformTailCallOpt),
181 static cl::opt<unsigned, true>
182 OverrideStackAlignment("stack-alignment",
183 cl::desc("Override default stack alignment"),
184 cl::location(StackAlignment),
186 static cl::opt<bool, true>
187 EnableRealignStack("realign-stack",
188 cl::desc("Realign stack if needed"),
189 cl::location(RealignStack),
191 static cl::opt<bool, true>
192 DisableSwitchTables(cl::Hidden, "disable-jump-tables",
193 cl::desc("Do not generate jump tables."),
194 cl::location(DisableJumpTables),
196 static cl::opt<bool, true>
197 EnableStrongPHIElim(cl::Hidden, "strong-phi-elim",
198 cl::desc("Use strong PHI elimination."),
199 cl::location(StrongPHIElim),
201 static cl::opt<bool, true>
202 DisableInstScheduling("disable-scheduling",
203 cl::desc("Disable instruction scheduling"),
204 cl::location(DisableScheduling),
207 //---------------------------------------------------------------------------
208 // TargetMachine Class
211 TargetMachine::TargetMachine(const Target &T)
212 : TheTarget(T), AsmInfo(0) {
213 // Typically it will be subtargets that will adjust FloatABIType from Default
216 FloatABIType = FloatABI::Soft;
219 TargetMachine::~TargetMachine() {
223 /// getRelocationModel - Returns the code generation relocation model. The
224 /// choices are static, PIC, and dynamic-no-pic, and target default.
225 Reloc::Model TargetMachine::getRelocationModel() {
226 return RelocationModel;
229 /// setRelocationModel - Sets the code generation relocation model.
230 void TargetMachine::setRelocationModel(Reloc::Model Model) {
231 RelocationModel = Model;
234 /// getCodeModel - Returns the code model. The choices are small, kernel,
235 /// medium, large, and target default.
236 CodeModel::Model TargetMachine::getCodeModel() {
240 /// setCodeModel - Sets the code model.
241 void TargetMachine::setCodeModel(CodeModel::Model Model) {
245 bool TargetMachine::getAsmVerbosityDefault() {
246 return AsmVerbosityDefault;
249 void TargetMachine::setAsmVerbosityDefault(bool V) {
250 AsmVerbosityDefault = V;
254 /// LessPreciseFPMAD - This flag return true when -enable-fp-mad option
255 /// is specified on the command line. When this flag is off(default), the
256 /// code generator is not allowed to generate mad (multiply add) if the
257 /// result is "less precise" than doing those operations individually.
258 bool LessPreciseFPMAD() { return UnsafeFPMath || LessPreciseFPMADOption; }
260 /// FiniteOnlyFPMath - This returns true when the -enable-finite-only-fp-math
261 /// option is specified on the command line. If this returns false (default),
262 /// the code generator is not allowed to assume that FP arithmetic arguments
263 /// and results are never NaNs or +-Infs.
264 bool FiniteOnlyFPMath() { return UnsafeFPMath || FiniteOnlyFPMathOption; }
266 /// HonorSignDependentRoundingFPMath - Return true if the codegen must assume
267 /// that the rounding mode of the FPU can change from its default.
268 bool HonorSignDependentRoundingFPMath() {
269 return !UnsafeFPMath && HonorSignDependentRoundingFPMathOption;