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/Target/TargetAsmInfo.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
;
35 bool ExceptionHandling
;
36 bool UnwindTablesMandatory
;
37 Reloc::Model RelocationModel
;
38 CodeModel::Model CMModel
;
39 bool PerformTailCallOpt
;
40 unsigned StackAlignment
;
42 bool DisableJumpTables
;
45 bool AsmVerbosityDefault(false);
48 static cl::opt
<bool, true>
49 PrintCode("print-machineinstrs",
50 cl::desc("Print generated machine code"),
51 cl::location(PrintMachineCode
), cl::init(false));
52 static cl::opt
<bool, true>
53 DisableFPElim("disable-fp-elim",
54 cl::desc("Disable frame pointer elimination optimization"),
55 cl::location(NoFramePointerElim
),
57 static cl::opt
<bool, true>
58 DisableExcessPrecision("disable-excess-fp-precision",
59 cl::desc("Disable optimizations that may increase FP precision"),
60 cl::location(NoExcessFPPrecision
),
62 static cl::opt
<bool, true>
63 EnableFPMAD("enable-fp-mad",
64 cl::desc("Enable less precise MAD instructions to be generated"),
65 cl::location(LessPreciseFPMADOption
),
67 static cl::opt
<bool, true>
68 EnableUnsafeFPMath("enable-unsafe-fp-math",
69 cl::desc("Enable optimizations that may decrease FP precision"),
70 cl::location(UnsafeFPMath
),
72 static cl::opt
<bool, true>
73 EnableFiniteOnlyFPMath("enable-finite-only-fp-math",
74 cl::desc("Enable optimizations that assumes non- NaNs / +-Infs"),
75 cl::location(FiniteOnlyFPMathOption
),
77 static cl::opt
<bool, true>
78 EnableHonorSignDependentRoundingFPMath("enable-sign-dependent-rounding-fp-math",
80 cl::desc("Force codegen to assume rounding mode can change dynamically"),
81 cl::location(HonorSignDependentRoundingFPMathOption
),
83 static cl::opt
<bool, true>
84 GenerateSoftFloatCalls("soft-float",
85 cl::desc("Generate software floating point library calls"),
86 cl::location(UseSoftFloat
),
88 static cl::opt
<bool, true>
89 GenerateNoImplicitFloats("no-implicit-float",
90 cl::desc("Don't generate implicit floating point instructions (x86-only)"),
91 cl::location(NoImplicitFloat
),
93 static cl::opt
<bool, true>
94 DontPlaceZerosInBSS("nozero-initialized-in-bss",
95 cl::desc("Don't place zero-initialized symbols into bss section"),
96 cl::location(NoZerosInBSS
),
98 static cl::opt
<bool, true>
99 EnableExceptionHandling("enable-eh",
100 cl::desc("Emit DWARF exception handling (default if target supports)"),
101 cl::location(ExceptionHandling
),
103 static cl::opt
<bool, true>
104 EnableUnwindTables("unwind-tables",
105 cl::desc("Generate unwinding tables for all functions"),
106 cl::location(UnwindTablesMandatory
),
109 static cl::opt
<llvm::Reloc::Model
, true>
110 DefRelocationModel("relocation-model",
111 cl::desc("Choose relocation model"),
112 cl::location(RelocationModel
),
113 cl::init(Reloc::Default
),
115 clEnumValN(Reloc::Default
, "default",
116 "Target default relocation model"),
117 clEnumValN(Reloc::Static
, "static",
118 "Non-relocatable code"),
119 clEnumValN(Reloc::PIC_
, "pic",
120 "Fully relocatable, position independent code"),
121 clEnumValN(Reloc::DynamicNoPIC
, "dynamic-no-pic",
122 "Relocatable external references, non-relocatable code"),
124 static cl::opt
<llvm::CodeModel::Model
, true>
125 DefCodeModel("code-model",
126 cl::desc("Choose code model"),
127 cl::location(CMModel
),
128 cl::init(CodeModel::Default
),
130 clEnumValN(CodeModel::Default
, "default",
131 "Target default code model"),
132 clEnumValN(CodeModel::Small
, "small",
134 clEnumValN(CodeModel::Kernel
, "kernel",
135 "Kernel code model"),
136 clEnumValN(CodeModel::Medium
, "medium",
137 "Medium code model"),
138 clEnumValN(CodeModel::Large
, "large",
141 static cl::opt
<bool, true>
142 EnablePerformTailCallOpt("tailcallopt",
143 cl::desc("Turn on tail call optimization."),
144 cl::location(PerformTailCallOpt
),
146 static cl::opt
<unsigned, true>
147 OverrideStackAlignment("stack-alignment",
148 cl::desc("Override default stack alignment"),
149 cl::location(StackAlignment
),
151 static cl::opt
<bool, true>
152 EnableRealignStack("realign-stack",
153 cl::desc("Realign stack if needed"),
154 cl::location(RealignStack
),
156 static cl::opt
<bool, true>
157 DisableSwitchTables(cl::Hidden
, "disable-jump-tables",
158 cl::desc("Do not generate jump tables."),
159 cl::location(DisableJumpTables
),
161 static cl::opt
<bool, true>
162 EnableStrongPHIElim(cl::Hidden
, "strong-phi-elim",
163 cl::desc("Use strong PHI elimination."),
164 cl::location(StrongPHIElim
),
166 static cl::opt
<bool, true>
167 DisableRedZoneOption("disable-red-zone",
168 cl::desc("Do not emit code that uses the red zone."),
169 cl::location(DisableRedZone
),
172 //---------------------------------------------------------------------------
173 // TargetMachine Class
176 TargetMachine::~TargetMachine() {
180 /// getRelocationModel - Returns the code generation relocation model. The
181 /// choices are static, PIC, and dynamic-no-pic, and target default.
182 Reloc::Model
TargetMachine::getRelocationModel() {
183 return RelocationModel
;
186 /// setRelocationModel - Sets the code generation relocation model.
187 void TargetMachine::setRelocationModel(Reloc::Model Model
) {
188 RelocationModel
= Model
;
191 /// getCodeModel - Returns the code model. The choices are small, kernel,
192 /// medium, large, and target default.
193 CodeModel::Model
TargetMachine::getCodeModel() {
197 /// setCodeModel - Sets the code model.
198 void TargetMachine::setCodeModel(CodeModel::Model Model
) {
202 bool TargetMachine::getAsmVerbosityDefault() {
203 return AsmVerbosityDefault
;
206 void TargetMachine::setAsmVerbosityDefault(bool V
) {
207 AsmVerbosityDefault
= V
;
211 /// LessPreciseFPMAD - This flag return true when -enable-fp-mad option
212 /// is specified on the command line. When this flag is off(default), the
213 /// code generator is not allowed to generate mad (multiply add) if the
214 /// result is "less precise" than doing those operations individually.
215 bool LessPreciseFPMAD() { return UnsafeFPMath
|| LessPreciseFPMADOption
; }
217 /// FiniteOnlyFPMath - This returns true when the -enable-finite-only-fp-math
218 /// option is specified on the command line. If this returns false (default),
219 /// the code generator is not allowed to assume that FP arithmetic arguments
220 /// and results are never NaNs or +-Infs.
221 bool FiniteOnlyFPMath() { return UnsafeFPMath
|| FiniteOnlyFPMathOption
; }
223 /// HonorSignDependentRoundingFPMath - Return true if the codegen must assume
224 /// that the rounding mode of the FPU can change from its default.
225 bool HonorSignDependentRoundingFPMath() {
226 return !UnsafeFPMath
&& HonorSignDependentRoundingFPMathOption
;