blob: 8d990443be1637e6324c0aaddc16c08ee51e6a89 [file] [log] [blame]
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001//===-- TargetMachine.cpp - General Target Information ---------------------==//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner081ce942007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Dan Gohmanf17a25c2007-07-18 16:29:46 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This file describes the general parts of a Target machine.
11//
12//===----------------------------------------------------------------------===//
13
Chris Lattner621c44d2009-08-22 20:48:53 +000014#include "llvm/MC/MCAsmInfo.h"
Dan Gohmanf17a25c2007-07-18 16:29:46 +000015#include "llvm/Target/TargetMachine.h"
16#include "llvm/Target/TargetOptions.h"
17#include "llvm/Support/CommandLine.h"
18using namespace llvm;
19
20//---------------------------------------------------------------------------
21// Command-line options that tend to be useful on more than one back-end.
22//
23
24namespace llvm {
Mon P Wang473bc862009-03-20 05:06:58 +000025 bool LessPreciseFPMADOption;
Dan Gohmanf17a25c2007-07-18 16:29:46 +000026 bool PrintMachineCode;
27 bool NoFramePointerElim;
28 bool NoExcessFPPrecision;
29 bool UnsafeFPMath;
30 bool FiniteOnlyFPMathOption;
31 bool HonorSignDependentRoundingFPMathOption;
32 bool UseSoftFloat;
Anton Korobeynikov11713322009-06-08 22:53:56 +000033 FloatABI::ABIType FloatABIType;
Bill Wendling042eda32009-03-11 22:30:01 +000034 bool NoImplicitFloat;
Dan Gohmanf17a25c2007-07-18 16:29:46 +000035 bool NoZerosInBSS;
Jim Grosbach29feb6a2009-08-11 00:09:57 +000036 bool DwarfExceptionHandling;
37 bool SjLjExceptionHandling;
Reid Kleckner738b4f22009-09-20 23:52:43 +000038 bool JITEmitDebugInfo;
39 bool JITEmitDebugInfoToDisk;
Dale Johannesenb369e8d2008-04-14 17:54:17 +000040 bool UnwindTablesMandatory;
Dan Gohmanf17a25c2007-07-18 16:29:46 +000041 Reloc::Model RelocationModel;
42 CodeModel::Model CMModel;
Arnold Schwaighofere2d6bbb2007-10-11 19:40:01 +000043 bool PerformTailCallOpt;
Anton Korobeynikovb214a522008-04-23 18:18:10 +000044 unsigned StackAlignment;
Evan Cheng0eeed442008-07-01 23:18:29 +000045 bool RealignStack;
Dale Johannesen493492f2008-07-31 18:13:12 +000046 bool DisableJumpTables;
Owen Andersonbac9ae22008-10-07 20:22:28 +000047 bool StrongPHIElim;
Evan Cheng42ceb472009-03-25 01:47:28 +000048 bool AsmVerbosityDefault(false);
Dan Gohmanf17a25c2007-07-18 16:29:46 +000049}
Dan Gohmanf17a25c2007-07-18 16:29:46 +000050
Bill Wendling042eda32009-03-11 22:30:01 +000051static cl::opt<bool, true>
52PrintCode("print-machineinstrs",
Dan Gohman089efff2008-05-13 00:00:25 +000053 cl::desc("Print generated machine code"),
54 cl::location(PrintMachineCode), cl::init(false));
Dan Gohman089efff2008-05-13 00:00:25 +000055static cl::opt<bool, true>
Evan Cheng94b06762008-05-30 22:39:18 +000056DisableFPElim("disable-fp-elim",
Bill Wendling042eda32009-03-11 22:30:01 +000057 cl::desc("Disable frame pointer elimination optimization"),
58 cl::location(NoFramePointerElim),
59 cl::init(false));
Dan Gohman089efff2008-05-13 00:00:25 +000060static cl::opt<bool, true>
61DisableExcessPrecision("disable-excess-fp-precision",
Bill Wendling042eda32009-03-11 22:30:01 +000062 cl::desc("Disable optimizations that may increase FP precision"),
63 cl::location(NoExcessFPPrecision),
64 cl::init(false));
Dan Gohman089efff2008-05-13 00:00:25 +000065static cl::opt<bool, true>
Mon P Wang473bc862009-03-20 05:06:58 +000066EnableFPMAD("enable-fp-mad",
67 cl::desc("Enable less precise MAD instructions to be generated"),
68 cl::location(LessPreciseFPMADOption),
69 cl::init(false));
70static cl::opt<bool, true>
Dan Gohman089efff2008-05-13 00:00:25 +000071EnableUnsafeFPMath("enable-unsafe-fp-math",
Bill Wendling042eda32009-03-11 22:30:01 +000072 cl::desc("Enable optimizations that may decrease FP precision"),
73 cl::location(UnsafeFPMath),
74 cl::init(false));
Dan Gohman089efff2008-05-13 00:00:25 +000075static cl::opt<bool, true>
76EnableFiniteOnlyFPMath("enable-finite-only-fp-math",
Bill Wendling042eda32009-03-11 22:30:01 +000077 cl::desc("Enable optimizations that assumes non- NaNs / +-Infs"),
78 cl::location(FiniteOnlyFPMathOption),
79 cl::init(false));
Dan Gohman089efff2008-05-13 00:00:25 +000080static cl::opt<bool, true>
Bill Wendling042eda32009-03-11 22:30:01 +000081EnableHonorSignDependentRoundingFPMath("enable-sign-dependent-rounding-fp-math",
82 cl::Hidden,
83 cl::desc("Force codegen to assume rounding mode can change dynamically"),
84 cl::location(HonorSignDependentRoundingFPMathOption),
85 cl::init(false));
Dan Gohman089efff2008-05-13 00:00:25 +000086static cl::opt<bool, true>
87GenerateSoftFloatCalls("soft-float",
Bill Wendling042eda32009-03-11 22:30:01 +000088 cl::desc("Generate software floating point library calls"),
89 cl::location(UseSoftFloat),
90 cl::init(false));
Anton Korobeynikov11713322009-06-08 22:53:56 +000091static cl::opt<llvm::FloatABI::ABIType, true>
92FloatABIForCalls("float-abi",
93 cl::desc("Choose float ABI type"),
94 cl::location(FloatABIType),
95 cl::init(FloatABI::Default),
96 cl::values(
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)"),
103 clEnumValEnd));
Bill Wendling042eda32009-03-11 22:30:01 +0000104static cl::opt<bool, true>
Dan Gohman089efff2008-05-13 00:00:25 +0000105DontPlaceZerosInBSS("nozero-initialized-in-bss",
Bill Wendling042eda32009-03-11 22:30:01 +0000106 cl::desc("Don't place zero-initialized symbols into bss section"),
107 cl::location(NoZerosInBSS),
108 cl::init(false));
Dan Gohman089efff2008-05-13 00:00:25 +0000109static cl::opt<bool, true>
Jim Grosbach29feb6a2009-08-11 00:09:57 +0000110EnableDwarfExceptionHandling("enable-eh",
Bill Wendling042eda32009-03-11 22:30:01 +0000111 cl::desc("Emit DWARF exception handling (default if target supports)"),
Jim Grosbach29feb6a2009-08-11 00:09:57 +0000112 cl::location(DwarfExceptionHandling),
113 cl::init(false));
114static cl::opt<bool, true>
115EnableSjLjExceptionHandling("enable-sjlj-eh",
116 cl::desc("Emit SJLJ exception handling (default if target supports)"),
117 cl::location(SjLjExceptionHandling),
Bill Wendling042eda32009-03-11 22:30:01 +0000118 cl::init(false));
Reid Kleckner738b4f22009-09-20 23:52:43 +0000119// In debug builds, make this default to true.
120#ifdef NDEBUG
121#define EMIT_DEBUG false
122#else
123#define EMIT_DEBUG true
124#endif
125static cl::opt<bool, true>
126EmitJitDebugInfo("jit-emit-debug",
127 cl::desc("Emit debug information to debugger"),
128 cl::location(JITEmitDebugInfo),
129 cl::init(EMIT_DEBUG));
130#undef EMIT_DEBUG
131static cl::opt<bool, true>
132EmitJitDebugInfoToDisk("jit-emit-debug-to-disk",
133 cl::Hidden,
134 cl::desc("Emit debug info objfiles to disk"),
135 cl::location(JITEmitDebugInfoToDisk),
136 cl::init(false));
Dan Gohman089efff2008-05-13 00:00:25 +0000137static cl::opt<bool, true>
138EnableUnwindTables("unwind-tables",
Bill Wendling042eda32009-03-11 22:30:01 +0000139 cl::desc("Generate unwinding tables for all functions"),
140 cl::location(UnwindTablesMandatory),
141 cl::init(false));
Arnold Schwaighofere2d6bbb2007-10-11 19:40:01 +0000142
Dan Gohman089efff2008-05-13 00:00:25 +0000143static cl::opt<llvm::Reloc::Model, true>
Bill Wendling042eda32009-03-11 22:30:01 +0000144DefRelocationModel("relocation-model",
Dan Gohman089efff2008-05-13 00:00:25 +0000145 cl::desc("Choose relocation model"),
146 cl::location(RelocationModel),
147 cl::init(Reloc::Default),
148 cl::values(
149 clEnumValN(Reloc::Default, "default",
Dan Gohman669b9bf2008-10-14 20:25:08 +0000150 "Target default relocation model"),
Dan Gohman089efff2008-05-13 00:00:25 +0000151 clEnumValN(Reloc::Static, "static",
Dan Gohman669b9bf2008-10-14 20:25:08 +0000152 "Non-relocatable code"),
Dan Gohman089efff2008-05-13 00:00:25 +0000153 clEnumValN(Reloc::PIC_, "pic",
Dan Gohman669b9bf2008-10-14 20:25:08 +0000154 "Fully relocatable, position independent code"),
Dan Gohman089efff2008-05-13 00:00:25 +0000155 clEnumValN(Reloc::DynamicNoPIC, "dynamic-no-pic",
Dan Gohman669b9bf2008-10-14 20:25:08 +0000156 "Relocatable external references, non-relocatable code"),
Dan Gohman089efff2008-05-13 00:00:25 +0000157 clEnumValEnd));
158static cl::opt<llvm::CodeModel::Model, true>
Bill Wendling042eda32009-03-11 22:30:01 +0000159DefCodeModel("code-model",
Dan Gohman089efff2008-05-13 00:00:25 +0000160 cl::desc("Choose code model"),
161 cl::location(CMModel),
162 cl::init(CodeModel::Default),
163 cl::values(
164 clEnumValN(CodeModel::Default, "default",
Dan Gohman669b9bf2008-10-14 20:25:08 +0000165 "Target default code model"),
Dan Gohman089efff2008-05-13 00:00:25 +0000166 clEnumValN(CodeModel::Small, "small",
Dan Gohman669b9bf2008-10-14 20:25:08 +0000167 "Small code model"),
Dan Gohman089efff2008-05-13 00:00:25 +0000168 clEnumValN(CodeModel::Kernel, "kernel",
Dan Gohman669b9bf2008-10-14 20:25:08 +0000169 "Kernel code model"),
Dan Gohman089efff2008-05-13 00:00:25 +0000170 clEnumValN(CodeModel::Medium, "medium",
Dan Gohman669b9bf2008-10-14 20:25:08 +0000171 "Medium code model"),
Dan Gohman089efff2008-05-13 00:00:25 +0000172 clEnumValN(CodeModel::Large, "large",
Dan Gohman669b9bf2008-10-14 20:25:08 +0000173 "Large code model"),
Dan Gohman089efff2008-05-13 00:00:25 +0000174 clEnumValEnd));
Dan Gohman089efff2008-05-13 00:00:25 +0000175static cl::opt<bool, true>
176EnablePerformTailCallOpt("tailcallopt",
Evan Cheng7ec59282010-01-27 00:10:09 +0000177 cl::desc("Turn fastcc calls into tail calls by (potentially) changing ABI."),
Bill Wendling042eda32009-03-11 22:30:01 +0000178 cl::location(PerformTailCallOpt),
179 cl::init(false));
Evan Cheng0eeed442008-07-01 23:18:29 +0000180static cl::opt<unsigned, true>
181OverrideStackAlignment("stack-alignment",
Bill Wendling042eda32009-03-11 22:30:01 +0000182 cl::desc("Override default stack alignment"),
183 cl::location(StackAlignment),
184 cl::init(0));
Dan Gohman089efff2008-05-13 00:00:25 +0000185static cl::opt<bool, true>
186EnableRealignStack("realign-stack",
Bill Wendling042eda32009-03-11 22:30:01 +0000187 cl::desc("Realign stack if needed"),
188 cl::location(RealignStack),
189 cl::init(true));
Evan Cheng0eeed442008-07-01 23:18:29 +0000190static cl::opt<bool, true>
Dale Johannesen493492f2008-07-31 18:13:12 +0000191DisableSwitchTables(cl::Hidden, "disable-jump-tables",
Bill Wendling042eda32009-03-11 22:30:01 +0000192 cl::desc("Do not generate jump tables."),
193 cl::location(DisableJumpTables),
194 cl::init(false));
Owen Andersonbac9ae22008-10-07 20:22:28 +0000195static cl::opt<bool, true>
196EnableStrongPHIElim(cl::Hidden, "strong-phi-elim",
Bill Wendling042eda32009-03-11 22:30:01 +0000197 cl::desc("Use strong PHI elimination."),
198 cl::location(StrongPHIElim),
199 cl::init(false));
Dan Gohmanb3e9a712009-01-26 22:22:31 +0000200
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000201//---------------------------------------------------------------------------
202// TargetMachine Class
203//
204
Daniel Dunbarfe5939f2009-07-15 20:24:03 +0000205TargetMachine::TargetMachine(const Target &T)
206 : TheTarget(T), AsmInfo(0) {
Anton Korobeynikov11713322009-06-08 22:53:56 +0000207 // Typically it will be subtargets that will adjust FloatABIType from Default
208 // to Soft or Hard.
209 if (UseSoftFloat)
210 FloatABIType = FloatABI::Soft;
211}
212
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000213TargetMachine::~TargetMachine() {
214 delete AsmInfo;
215}
216
217/// getRelocationModel - Returns the code generation relocation model. The
218/// choices are static, PIC, and dynamic-no-pic, and target default.
219Reloc::Model TargetMachine::getRelocationModel() {
220 return RelocationModel;
221}
222
223/// setRelocationModel - Sets the code generation relocation model.
224void TargetMachine::setRelocationModel(Reloc::Model Model) {
225 RelocationModel = Model;
226}
227
228/// getCodeModel - Returns the code model. The choices are small, kernel,
229/// medium, large, and target default.
230CodeModel::Model TargetMachine::getCodeModel() {
231 return CMModel;
232}
233
234/// setCodeModel - Sets the code model.
235void TargetMachine::setCodeModel(CodeModel::Model Model) {
236 CMModel = Model;
237}
238
Evan Cheng42ceb472009-03-25 01:47:28 +0000239bool TargetMachine::getAsmVerbosityDefault() {
240 return AsmVerbosityDefault;
241}
242
243void TargetMachine::setAsmVerbosityDefault(bool V) {
244 AsmVerbosityDefault = V;
245}
246
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000247namespace llvm {
Mon P Wang473bc862009-03-20 05:06:58 +0000248 /// 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; }
253
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000254 /// 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; }
259
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;
264 }
265}