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 UnwindTablesMandatory;
44
Reloc::Model RelocationModel;
45
CodeModel::Model CMModel;
46
bool GuaranteedTailCallOpt;
47
unsigned StackAlignment;
49
bool DisableJumpTables;
51
bool AsmVerbosityDefault(false);
54
static cl::opt<bool, true>
55
PrintCode("print-machineinstrs",
56
cl::desc("Print generated machine code"),
57
cl::location(PrintMachineCode), cl::init(false));
58
static cl::opt<bool, true>
59
DisableFPElim("disable-fp-elim",
60
cl::desc("Disable frame pointer elimination optimization"),
61
cl::location(NoFramePointerElim),
63
static cl::opt<bool, true>
64
DisableFPElimNonLeaf("disable-non-leaf-fp-elim",
65
cl::desc("Disable frame pointer elimination optimization for non-leaf funcs"),
66
cl::location(NoFramePointerElimNonLeaf),
68
static cl::opt<bool, true>
69
DisableExcessPrecision("disable-excess-fp-precision",
70
cl::desc("Disable optimizations that may increase FP precision"),
71
cl::location(NoExcessFPPrecision),
73
static cl::opt<bool, true>
74
EnableFPMAD("enable-fp-mad",
75
cl::desc("Enable less precise MAD instructions to be generated"),
76
cl::location(LessPreciseFPMADOption),
78
static cl::opt<bool, true>
79
EnableUnsafeFPMath("enable-unsafe-fp-math",
80
cl::desc("Enable optimizations that may decrease FP precision"),
81
cl::location(UnsafeFPMath),
83
static cl::opt<bool, true>
84
EnableNoInfsFPMath("enable-no-infs-fp-math",
85
cl::desc("Enable FP math optimizations that assume no +-Infs"),
86
cl::location(NoInfsFPMath),
88
static cl::opt<bool, true>
89
EnableNoNaNsFPMath("enable-no-nans-fp-math",
90
cl::desc("Enable FP math optimizations that assume no NaNs"),
91
cl::location(NoNaNsFPMath),
93
static cl::opt<bool, true>
94
EnableHonorSignDependentRoundingFPMath("enable-sign-dependent-rounding-fp-math",
96
cl::desc("Force codegen to assume rounding mode can change dynamically"),
97
cl::location(HonorSignDependentRoundingFPMathOption),
99
static cl::opt<bool, true>
100
GenerateSoftFloatCalls("soft-float",
101
cl::desc("Generate software floating point library calls"),
102
cl::location(UseSoftFloat),
104
static cl::opt<llvm::FloatABI::ABIType, true>
105
FloatABIForCalls("float-abi",
106
cl::desc("Choose float ABI type"),
107
cl::location(FloatABIType),
108
cl::init(FloatABI::Default),
110
clEnumValN(FloatABI::Default, "default",
111
"Target default float ABI type"),
112
clEnumValN(FloatABI::Soft, "soft",
113
"Soft float ABI (implied by -soft-float)"),
114
clEnumValN(FloatABI::Hard, "hard",
115
"Hard float ABI (uses FP registers)"),
117
static cl::opt<bool, true>
118
DontPlaceZerosInBSS("nozero-initialized-in-bss",
119
cl::desc("Don't place zero-initialized symbols into bss section"),
120
cl::location(NoZerosInBSS),
122
static cl::opt<bool, true>
123
EnableJITExceptionHandling("jit-enable-eh",
124
cl::desc("Emit exception handling information"),
125
cl::location(JITExceptionHandling),
127
// In debug builds, make this default to true.
129
#define EMIT_DEBUG false
131
#define EMIT_DEBUG true
133
static cl::opt<bool, true>
134
EmitJitDebugInfo("jit-emit-debug",
135
cl::desc("Emit debug information to debugger"),
136
cl::location(JITEmitDebugInfo),
137
cl::init(EMIT_DEBUG));
139
static cl::opt<bool, true>
140
EmitJitDebugInfoToDisk("jit-emit-debug-to-disk",
142
cl::desc("Emit debug info objfiles to disk"),
143
cl::location(JITEmitDebugInfoToDisk),
145
static cl::opt<bool, true>
146
EnableUnwindTables("unwind-tables",
147
cl::desc("Generate unwinding tables for all functions"),
148
cl::location(UnwindTablesMandatory),
151
static cl::opt<llvm::Reloc::Model, true>
152
DefRelocationModel("relocation-model",
153
cl::desc("Choose relocation model"),
154
cl::location(RelocationModel),
155
cl::init(Reloc::Default),
157
clEnumValN(Reloc::Default, "default",
158
"Target default relocation model"),
159
clEnumValN(Reloc::Static, "static",
160
"Non-relocatable code"),
161
clEnumValN(Reloc::PIC_, "pic",
162
"Fully relocatable, position independent code"),
163
clEnumValN(Reloc::DynamicNoPIC, "dynamic-no-pic",
164
"Relocatable external references, non-relocatable code"),
166
static cl::opt<llvm::CodeModel::Model, true>
167
DefCodeModel("code-model",
168
cl::desc("Choose code model"),
169
cl::location(CMModel),
170
cl::init(CodeModel::Default),
172
clEnumValN(CodeModel::Default, "default",
173
"Target default code model"),
174
clEnumValN(CodeModel::Small, "small",
176
clEnumValN(CodeModel::Kernel, "kernel",
177
"Kernel code model"),
178
clEnumValN(CodeModel::Medium, "medium",
179
"Medium code model"),
180
clEnumValN(CodeModel::Large, "large",
183
static cl::opt<bool, true>
184
EnableGuaranteedTailCallOpt("tailcallopt",
185
cl::desc("Turn fastcc calls into tail calls by (potentially) changing ABI."),
186
cl::location(GuaranteedTailCallOpt),
188
static cl::opt<unsigned, true>
189
OverrideStackAlignment("stack-alignment",
190
cl::desc("Override default stack alignment"),
191
cl::location(StackAlignment),
193
static cl::opt<bool, true>
194
EnableRealignStack("realign-stack",
195
cl::desc("Realign stack if needed"),
196
cl::location(RealignStack),
198
static cl::opt<bool, true>
199
DisableSwitchTables(cl::Hidden, "disable-jump-tables",
200
cl::desc("Do not generate jump tables."),
201
cl::location(DisableJumpTables),
203
static cl::opt<bool, true>
204
EnableStrongPHIElim(cl::Hidden, "strong-phi-elim",
205
cl::desc("Use strong PHI elimination."),
206
cl::location(StrongPHIElim),
209
DataSections("fdata-sections",
210
cl::desc("Emit data into separate sections"),
213
FunctionSections("ffunction-sections",
214
cl::desc("Emit functions into separate sections"),
216
//---------------------------------------------------------------------------
217
// TargetMachine Class
220
TargetMachine::TargetMachine(const Target &T)
221
: TheTarget(T), AsmInfo(0),
223
// Typically it will be subtargets that will adjust FloatABIType from Default
226
FloatABIType = FloatABI::Soft;
229
TargetMachine::~TargetMachine() {
233
/// getRelocationModel - Returns the code generation relocation model. The
234
/// choices are static, PIC, and dynamic-no-pic, and target default.
235
Reloc::Model TargetMachine::getRelocationModel() {
236
return RelocationModel;
239
/// setRelocationModel - Sets the code generation relocation model.
240
void TargetMachine::setRelocationModel(Reloc::Model Model) {
241
RelocationModel = Model;
244
/// getCodeModel - Returns the code model. The choices are small, kernel,
245
/// medium, large, and target default.
246
CodeModel::Model TargetMachine::getCodeModel() {
250
/// setCodeModel - Sets the code model.
251
void TargetMachine::setCodeModel(CodeModel::Model Model) {
255
bool TargetMachine::getAsmVerbosityDefault() {
256
return AsmVerbosityDefault;
259
void TargetMachine::setAsmVerbosityDefault(bool V) {
260
AsmVerbosityDefault = V;
263
bool TargetMachine::getFunctionSections() {
264
return FunctionSections;
267
bool TargetMachine::getDataSections() {
271
void TargetMachine::setFunctionSections(bool V) {
272
FunctionSections = V;
275
void TargetMachine::setDataSections(bool V) {
280
/// DisableFramePointerElim - This returns true if frame pointer elimination
281
/// optimization should be disabled for the given machine function.
282
bool DisableFramePointerElim(const MachineFunction &MF) {
283
// Check to see if we should eliminate non-leaf frame pointers and then
284
// check to see if we should eliminate all frame pointers.
285
if (NoFramePointerElimNonLeaf && !NoFramePointerElim) {
286
const MachineFrameInfo *MFI = MF.getFrameInfo();
287
return MFI->hasCalls();
290
return NoFramePointerElim;
293
/// LessPreciseFPMAD - This flag return true when -enable-fp-mad option
294
/// is specified on the command line. When this flag is off(default), the
295
/// code generator is not allowed to generate mad (multiply add) if the
296
/// result is "less precise" than doing those operations individually.
297
bool LessPreciseFPMAD() { return UnsafeFPMath || LessPreciseFPMADOption; }
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;