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 GuaranteedTailCallOpt;
44
unsigned StackAlignment;
46
bool DisableJumpTables;
48
bool AsmVerbosityDefault(false);
51
static cl::opt<bool, true>
52
PrintCode("print-machineinstrs",
53
cl::desc("Print generated machine code"),
54
cl::location(PrintMachineCode), cl::init(false));
55
static cl::opt<bool, true>
56
DisableFPElim("disable-fp-elim",
57
cl::desc("Disable frame pointer elimination optimization"),
58
cl::location(NoFramePointerElim),
60
static cl::opt<bool, true>
61
DisableExcessPrecision("disable-excess-fp-precision",
62
cl::desc("Disable optimizations that may increase FP precision"),
63
cl::location(NoExcessFPPrecision),
65
static cl::opt<bool, true>
66
EnableFPMAD("enable-fp-mad",
67
cl::desc("Enable less precise MAD instructions to be generated"),
68
cl::location(LessPreciseFPMADOption),
70
static cl::opt<bool, true>
71
EnableUnsafeFPMath("enable-unsafe-fp-math",
72
cl::desc("Enable optimizations that may decrease FP precision"),
73
cl::location(UnsafeFPMath),
75
static cl::opt<bool, true>
76
EnableFiniteOnlyFPMath("enable-finite-only-fp-math",
77
cl::desc("Enable optimizations that assumes non- NaNs / +-Infs"),
78
cl::location(FiniteOnlyFPMathOption),
80
static cl::opt<bool, true>
81
EnableHonorSignDependentRoundingFPMath("enable-sign-dependent-rounding-fp-math",
83
cl::desc("Force codegen to assume rounding mode can change dynamically"),
84
cl::location(HonorSignDependentRoundingFPMathOption),
86
static cl::opt<bool, true>
87
GenerateSoftFloatCalls("soft-float",
88
cl::desc("Generate software floating point library calls"),
89
cl::location(UseSoftFloat),
91
static cl::opt<llvm::FloatABI::ABIType, true>
92
FloatABIForCalls("float-abi",
93
cl::desc("Choose float ABI type"),
94
cl::location(FloatABIType),
95
cl::init(FloatABI::Default),
97
clEnumValN(FloatABI::Default, "default",
98
"Target default float ABI type"),
99
clEnumValN(FloatABI::Soft, "soft",
100
"Soft float ABI (implied by -soft-float)"),
101
clEnumValN(FloatABI::Hard, "hard",
102
"Hard float ABI (uses FP registers)"),
104
static cl::opt<bool, true>
105
DontPlaceZerosInBSS("nozero-initialized-in-bss",
106
cl::desc("Don't place zero-initialized symbols into bss section"),
107
cl::location(NoZerosInBSS),
109
static cl::opt<bool, true>
110
EnableDwarfExceptionHandling("enable-eh",
111
cl::desc("Emit DWARF exception handling (default if target supports)"),
112
cl::location(DwarfExceptionHandling),
114
static cl::opt<bool, true>
115
EnableSjLjExceptionHandling("enable-sjlj-eh",
116
cl::desc("Emit SJLJ exception handling (default if target supports)"),
117
cl::location(SjLjExceptionHandling),
119
// In debug builds, make this default to true.
121
#define EMIT_DEBUG false
123
#define EMIT_DEBUG true
125
static cl::opt<bool, true>
126
EmitJitDebugInfo("jit-emit-debug",
127
cl::desc("Emit debug information to debugger"),
128
cl::location(JITEmitDebugInfo),
129
cl::init(EMIT_DEBUG));
131
static cl::opt<bool, true>
132
EmitJitDebugInfoToDisk("jit-emit-debug-to-disk",
134
cl::desc("Emit debug info objfiles to disk"),
135
cl::location(JITEmitDebugInfoToDisk),
137
static cl::opt<bool, true>
138
EnableUnwindTables("unwind-tables",
139
cl::desc("Generate unwinding tables for all functions"),
140
cl::location(UnwindTablesMandatory),
143
static cl::opt<llvm::Reloc::Model, true>
144
DefRelocationModel("relocation-model",
145
cl::desc("Choose relocation model"),
146
cl::location(RelocationModel),
147
cl::init(Reloc::Default),
149
clEnumValN(Reloc::Default, "default",
150
"Target default relocation model"),
151
clEnumValN(Reloc::Static, "static",
152
"Non-relocatable code"),
153
clEnumValN(Reloc::PIC_, "pic",
154
"Fully relocatable, position independent code"),
155
clEnumValN(Reloc::DynamicNoPIC, "dynamic-no-pic",
156
"Relocatable external references, non-relocatable code"),
158
static cl::opt<llvm::CodeModel::Model, true>
159
DefCodeModel("code-model",
160
cl::desc("Choose code model"),
161
cl::location(CMModel),
162
cl::init(CodeModel::Default),
164
clEnumValN(CodeModel::Default, "default",
165
"Target default code model"),
166
clEnumValN(CodeModel::Small, "small",
168
clEnumValN(CodeModel::Kernel, "kernel",
169
"Kernel code model"),
170
clEnumValN(CodeModel::Medium, "medium",
171
"Medium code model"),
172
clEnumValN(CodeModel::Large, "large",
175
static cl::opt<bool, true>
176
EnableGuaranteedTailCallOpt("tailcallopt",
177
cl::desc("Turn fastcc calls into tail calls by (potentially) changing ABI."),
178
cl::location(GuaranteedTailCallOpt),
180
static cl::opt<unsigned, true>
181
OverrideStackAlignment("stack-alignment",
182
cl::desc("Override default stack alignment"),
183
cl::location(StackAlignment),
185
static cl::opt<bool, true>
186
EnableRealignStack("realign-stack",
187
cl::desc("Realign stack if needed"),
188
cl::location(RealignStack),
190
static cl::opt<bool, true>
191
DisableSwitchTables(cl::Hidden, "disable-jump-tables",
192
cl::desc("Do not generate jump tables."),
193
cl::location(DisableJumpTables),
195
static cl::opt<bool, true>
196
EnableStrongPHIElim(cl::Hidden, "strong-phi-elim",
197
cl::desc("Use strong PHI elimination."),
198
cl::location(StrongPHIElim),
201
//---------------------------------------------------------------------------
202
// TargetMachine Class
205
TargetMachine::TargetMachine(const Target &T)
206
: TheTarget(T), AsmInfo(0) {
207
// Typically it will be subtargets that will adjust FloatABIType from Default
210
FloatABIType = FloatABI::Soft;
213
TargetMachine::~TargetMachine() {
217
/// getRelocationModel - Returns the code generation relocation model. The
218
/// choices are static, PIC, and dynamic-no-pic, and target default.
219
Reloc::Model TargetMachine::getRelocationModel() {
220
return RelocationModel;
223
/// setRelocationModel - Sets the code generation relocation model.
224
void TargetMachine::setRelocationModel(Reloc::Model Model) {
225
RelocationModel = Model;
228
/// getCodeModel - Returns the code model. The choices are small, kernel,
229
/// medium, large, and target default.
230
CodeModel::Model TargetMachine::getCodeModel() {
234
/// setCodeModel - Sets the code model.
235
void TargetMachine::setCodeModel(CodeModel::Model Model) {
239
bool TargetMachine::getAsmVerbosityDefault() {
240
return AsmVerbosityDefault;
243
void TargetMachine::setAsmVerbosityDefault(bool V) {
244
AsmVerbosityDefault = V;
248
/// LessPreciseFPMAD - This flag return true when -enable-fp-mad option
249
/// is specified on the command line. When this flag is off(default), the
250
/// code generator is not allowed to generate mad (multiply add) if the
251
/// result is "less precise" than doing those operations individually.
252
bool LessPreciseFPMAD() { return UnsafeFPMath || LessPreciseFPMADOption; }
254
/// FiniteOnlyFPMath - This returns true when the -enable-finite-only-fp-math
255
/// option is specified on the command line. If this returns false (default),
256
/// the code generator is not allowed to assume that FP arithmetic arguments
257
/// and results are never NaNs or +-Infs.
258
bool FiniteOnlyFPMath() { return UnsafeFPMath || FiniteOnlyFPMathOption; }
260
/// HonorSignDependentRoundingFPMath - Return true if the codegen must assume
261
/// that the rounding mode of the FPU can change from its default.
262
bool HonorSignDependentRoundingFPMath() {
263
return !UnsafeFPMath && HonorSignDependentRoundingFPMathOption;