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 UnwindTablesMandatory;
39 Reloc::Model RelocationModel;
40 CodeModel::Model CMModel;
41 bool PerformTailCallOpt;
42 unsigned StackAlignment;
44 bool DisableJumpTables;
46 bool AsmVerbosityDefault(false);
49 static cl::opt<bool, true>
50 PrintCode("print-machineinstrs",
51 cl::desc("Print generated machine code"),
52 cl::location(PrintMachineCode), cl::init(false));
53 static cl::opt<bool, true>
54 DisableFPElim("disable-fp-elim",
55 cl::desc("Disable frame pointer elimination optimization"),
56 cl::location(NoFramePointerElim),
58 static cl::opt<bool, true>
59 DisableExcessPrecision("disable-excess-fp-precision",
60 cl::desc("Disable optimizations that may increase FP precision"),
61 cl::location(NoExcessFPPrecision),
63 static cl::opt<bool, true>
64 EnableFPMAD("enable-fp-mad",
65 cl::desc("Enable less precise MAD instructions to be generated"),
66 cl::location(LessPreciseFPMADOption),
68 static cl::opt<bool, true>
69 EnableUnsafeFPMath("enable-unsafe-fp-math",
70 cl::desc("Enable optimizations that may decrease FP precision"),
71 cl::location(UnsafeFPMath),
73 static cl::opt<bool, true>
74 EnableFiniteOnlyFPMath("enable-finite-only-fp-math",
75 cl::desc("Enable optimizations that assumes non- NaNs / +-Infs"),
76 cl::location(FiniteOnlyFPMathOption),
78 static cl::opt<bool, true>
79 EnableHonorSignDependentRoundingFPMath("enable-sign-dependent-rounding-fp-math",
81 cl::desc("Force codegen to assume rounding mode can change dynamically"),
82 cl::location(HonorSignDependentRoundingFPMathOption),
84 static cl::opt<bool, true>
85 GenerateSoftFloatCalls("soft-float",
86 cl::desc("Generate software floating point library calls"),
87 cl::location(UseSoftFloat),
89 static cl::opt<llvm::FloatABI::ABIType, true>
90 FloatABIForCalls("float-abi",
91 cl::desc("Choose float ABI type"),
92 cl::location(FloatABIType),
93 cl::init(FloatABI::Default),
95 clEnumValN(FloatABI::Default, "default",
96 "Target default float ABI type"),
97 clEnumValN(FloatABI::Soft, "soft",
98 "Soft float ABI (implied by -soft-float)"),
99 clEnumValN(FloatABI::Hard, "hard",
100 "Hard float ABI (uses FP registers)"),
102 static cl::opt<bool, true>
103 DontPlaceZerosInBSS("nozero-initialized-in-bss",
104 cl::desc("Don't place zero-initialized symbols into bss section"),
105 cl::location(NoZerosInBSS),
107 static cl::opt<bool, true>
108 EnableDwarfExceptionHandling("enable-eh",
109 cl::desc("Emit DWARF exception handling (default if target supports)"),
110 cl::location(DwarfExceptionHandling),
112 static cl::opt<bool, true>
113 EnableSjLjExceptionHandling("enable-sjlj-eh",
114 cl::desc("Emit SJLJ exception handling (default if target supports)"),
115 cl::location(SjLjExceptionHandling),
117 static cl::opt<bool, true>
118 EnableUnwindTables("unwind-tables",
119 cl::desc("Generate unwinding tables for all functions"),
120 cl::location(UnwindTablesMandatory),
123 static cl::opt<llvm::Reloc::Model, true>
124 DefRelocationModel("relocation-model",
125 cl::desc("Choose relocation model"),
126 cl::location(RelocationModel),
127 cl::init(Reloc::Default),
129 clEnumValN(Reloc::Default, "default",
130 "Target default relocation model"),
131 clEnumValN(Reloc::Static, "static",
132 "Non-relocatable code"),
133 clEnumValN(Reloc::PIC_, "pic",
134 "Fully relocatable, position independent code"),
135 clEnumValN(Reloc::DynamicNoPIC, "dynamic-no-pic",
136 "Relocatable external references, non-relocatable code"),
138 static cl::opt<llvm::CodeModel::Model, true>
139 DefCodeModel("code-model",
140 cl::desc("Choose code model"),
141 cl::location(CMModel),
142 cl::init(CodeModel::Default),
144 clEnumValN(CodeModel::Default, "default",
145 "Target default code model"),
146 clEnumValN(CodeModel::Small, "small",
148 clEnumValN(CodeModel::Kernel, "kernel",
149 "Kernel code model"),
150 clEnumValN(CodeModel::Medium, "medium",
151 "Medium code model"),
152 clEnumValN(CodeModel::Large, "large",
155 static cl::opt<bool, true>
156 EnablePerformTailCallOpt("tailcallopt",
157 cl::desc("Turn on tail call optimization."),
158 cl::location(PerformTailCallOpt),
160 static cl::opt<unsigned, true>
161 OverrideStackAlignment("stack-alignment",
162 cl::desc("Override default stack alignment"),
163 cl::location(StackAlignment),
165 static cl::opt<bool, true>
166 EnableRealignStack("realign-stack",
167 cl::desc("Realign stack if needed"),
168 cl::location(RealignStack),
170 static cl::opt<bool, true>
171 DisableSwitchTables(cl::Hidden, "disable-jump-tables",
172 cl::desc("Do not generate jump tables."),
173 cl::location(DisableJumpTables),
175 static cl::opt<bool, true>
176 EnableStrongPHIElim(cl::Hidden, "strong-phi-elim",
177 cl::desc("Use strong PHI elimination."),
178 cl::location(StrongPHIElim),
181 //---------------------------------------------------------------------------
182 // TargetMachine Class
185 TargetMachine::TargetMachine(const Target &T)
186 : TheTarget(T), AsmInfo(0) {
187 // Typically it will be subtargets that will adjust FloatABIType from Default
190 FloatABIType = FloatABI::Soft;
193 TargetMachine::~TargetMachine() {
197 /// getRelocationModel - Returns the code generation relocation model. The
198 /// choices are static, PIC, and dynamic-no-pic, and target default.
199 Reloc::Model TargetMachine::getRelocationModel() {
200 return RelocationModel;
203 /// setRelocationModel - Sets the code generation relocation model.
204 void TargetMachine::setRelocationModel(Reloc::Model Model) {
205 RelocationModel = Model;
208 /// getCodeModel - Returns the code model. The choices are small, kernel,
209 /// medium, large, and target default.
210 CodeModel::Model TargetMachine::getCodeModel() {
214 /// setCodeModel - Sets the code model.
215 void TargetMachine::setCodeModel(CodeModel::Model Model) {
219 bool TargetMachine::getAsmVerbosityDefault() {
220 return AsmVerbosityDefault;
223 void TargetMachine::setAsmVerbosityDefault(bool V) {
224 AsmVerbosityDefault = V;
228 /// LessPreciseFPMAD - This flag return true when -enable-fp-mad option
229 /// is specified on the command line. When this flag is off(default), the
230 /// code generator is not allowed to generate mad (multiply add) if the
231 /// result is "less precise" than doing those operations individually.
232 bool LessPreciseFPMAD() { return UnsafeFPMath || LessPreciseFPMADOption; }
234 /// FiniteOnlyFPMath - This returns true when the -enable-finite-only-fp-math
235 /// option is specified on the command line. If this returns false (default),
236 /// the code generator is not allowed to assume that FP arithmetic arguments
237 /// and results are never NaNs or +-Infs.
238 bool FiniteOnlyFPMath() { return UnsafeFPMath || FiniteOnlyFPMathOption; }
240 /// HonorSignDependentRoundingFPMath - Return true if the codegen must assume
241 /// that the rounding mode of the FPU can change from its default.
242 bool HonorSignDependentRoundingFPMath() {
243 return !UnsafeFPMath && HonorSignDependentRoundingFPMathOption;