blob: 871b148adb395773412769a0d8c8c1d3ea100eb2 [file] [log] [blame]
Chris Lattnerb26bcc52001-09-14 05:34:53 +00001//===-- TargetMachine.cpp - General Target Information ---------------------==//
Misha Brukmanf976c852005-04-21 22:55:34 +00002//
John Criswellb576c942003-10-20 19:43:21 +00003// The LLVM Compiler Infrastructure
4//
Chris Lattner4ee451d2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Misha Brukmanf976c852005-04-21 22:55:34 +00007//
John Criswellb576c942003-10-20 19:43:21 +00008//===----------------------------------------------------------------------===//
Chris Lattnerb26bcc52001-09-14 05:34:53 +00009//
10// This file describes the general parts of a Target machine.
11//
12//===----------------------------------------------------------------------===//
Vikram S. Advedaae6992001-07-21 12:42:08 +000013
Chris Lattneraf76e592009-08-22 20:48:53 +000014#include "llvm/MC/MCAsmInfo.h"
Misha Brukmane67d5fb2004-06-21 21:20:23 +000015#include "llvm/Target/TargetMachine.h"
Evan Cheng4c1aa862006-02-22 20:19:42 +000016#include "llvm/Target/TargetOptions.h"
Reid Spencer551ccae2004-09-01 22:55:40 +000017#include "llvm/Support/CommandLine.h"
Chris Lattnerf70e0c22003-12-28 21:23:38 +000018using namespace llvm;
Brian Gaeked0fde302003-11-11 22:41:34 +000019
Vikram S. Advee1f72802002-09-16 15:39:26 +000020//---------------------------------------------------------------------------
Brian Gaeke323819e2004-03-04 19:16:23 +000021// Command-line options that tend to be useful on more than one back-end.
22//
23
Misha Brukmanf90e4022004-06-21 21:44:12 +000024namespace llvm {
Mon P Wangbc65ca82009-03-20 05:06:58 +000025 bool LessPreciseFPMADOption;
Misha Brukmanf90e4022004-06-21 21:44:12 +000026 bool PrintMachineCode;
27 bool NoFramePointerElim;
Chris Lattner45554a62005-01-15 06:00:32 +000028 bool NoExcessFPPrecision;
Chris Lattner34f74a62005-04-30 04:09:52 +000029 bool UnsafeFPMath;
Evan Cheng80235d52006-05-23 18:18:46 +000030 bool FiniteOnlyFPMathOption;
Chris Lattnera7ad3d12007-05-03 00:27:11 +000031 bool HonorSignDependentRoundingFPMathOption;
Evan Chengc9ab2f32006-12-09 02:41:30 +000032 bool UseSoftFloat;
Anton Korobeynikov0eebf652009-06-08 22:53:56 +000033 FloatABI::ABIType FloatABIType;
Bill Wendlingf9abd7e2009-03-11 22:30:01 +000034 bool NoImplicitFloat;
Anton Korobeynikov5032e5a2007-01-17 10:33:08 +000035 bool NoZerosInBSS;
Jim Grosbach1b747ad2009-08-11 00:09:57 +000036 bool DwarfExceptionHandling;
37 bool SjLjExceptionHandling;
Reid Kleckner27632172009-09-20 23:52:43 +000038 bool JITEmitDebugInfo;
39 bool JITEmitDebugInfoToDisk;
Dale Johannesen3541af72008-04-14 17:54:17 +000040 bool UnwindTablesMandatory;
Evan Cheng4c1aa862006-02-22 20:19:42 +000041 Reloc::Model RelocationModel;
Evan Cheng152ed052006-07-06 01:53:36 +000042 CodeModel::Model CMModel;
Dan Gohman1797ed52010-02-08 20:27:50 +000043 bool GuaranteedTailCallOpt;
Anton Korobeynikov45709ae2008-04-23 18:18:10 +000044 unsigned StackAlignment;
Evan Cheng6547e402008-07-01 23:18:29 +000045 bool RealignStack;
Dale Johannesen72324642008-07-31 18:13:12 +000046 bool DisableJumpTables;
Owen Anderson95dad832008-10-07 20:22:28 +000047 bool StrongPHIElim;
Evan Cheng42bf74b2009-03-25 01:47:28 +000048 bool AsmVerbosityDefault(false);
Chris Lattnerd74ea2b2006-05-24 17:04:05 +000049}
Misha Brukman0fb5a662004-06-21 21:08:45 +000050
Bill Wendlingf9abd7e2009-03-11 22:30:01 +000051static cl::opt<bool, true>
52PrintCode("print-machineinstrs",
Dan Gohman844731a2008-05-13 00:00:25 +000053 cl::desc("Print generated machine code"),
54 cl::location(PrintMachineCode), cl::init(false));
Dan Gohman844731a2008-05-13 00:00:25 +000055static cl::opt<bool, true>
Evan Cheng89df08c2008-05-30 22:39:18 +000056DisableFPElim("disable-fp-elim",
Bill Wendlingf9abd7e2009-03-11 22:30:01 +000057 cl::desc("Disable frame pointer elimination optimization"),
58 cl::location(NoFramePointerElim),
59 cl::init(false));
Dan Gohman844731a2008-05-13 00:00:25 +000060static cl::opt<bool, true>
61DisableExcessPrecision("disable-excess-fp-precision",
Bill Wendlingf9abd7e2009-03-11 22:30:01 +000062 cl::desc("Disable optimizations that may increase FP precision"),
63 cl::location(NoExcessFPPrecision),
64 cl::init(false));
Dan Gohman844731a2008-05-13 00:00:25 +000065static cl::opt<bool, true>
Mon P Wangbc65ca82009-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 Gohman844731a2008-05-13 00:00:25 +000071EnableUnsafeFPMath("enable-unsafe-fp-math",
Bill Wendlingf9abd7e2009-03-11 22:30:01 +000072 cl::desc("Enable optimizations that may decrease FP precision"),
73 cl::location(UnsafeFPMath),
74 cl::init(false));
Dan Gohman844731a2008-05-13 00:00:25 +000075static cl::opt<bool, true>
76EnableFiniteOnlyFPMath("enable-finite-only-fp-math",
Bill Wendlingf9abd7e2009-03-11 22:30:01 +000077 cl::desc("Enable optimizations that assumes non- NaNs / +-Infs"),
78 cl::location(FiniteOnlyFPMathOption),
79 cl::init(false));
Dan Gohman844731a2008-05-13 00:00:25 +000080static cl::opt<bool, true>
Bill Wendlingf9abd7e2009-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 Gohman844731a2008-05-13 00:00:25 +000086static cl::opt<bool, true>
87GenerateSoftFloatCalls("soft-float",
Bill Wendlingf9abd7e2009-03-11 22:30:01 +000088 cl::desc("Generate software floating point library calls"),
89 cl::location(UseSoftFloat),
90 cl::init(false));
Anton Korobeynikov0eebf652009-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 Wendlingf9abd7e2009-03-11 22:30:01 +0000104static cl::opt<bool, true>
Dan Gohman844731a2008-05-13 00:00:25 +0000105DontPlaceZerosInBSS("nozero-initialized-in-bss",
Bill Wendlingf9abd7e2009-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 Gohman844731a2008-05-13 00:00:25 +0000109static cl::opt<bool, true>
Jim Grosbach1b747ad2009-08-11 00:09:57 +0000110EnableDwarfExceptionHandling("enable-eh",
Bill Wendlingf9abd7e2009-03-11 22:30:01 +0000111 cl::desc("Emit DWARF exception handling (default if target supports)"),
Jim Grosbach1b747ad2009-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 Wendlingf9abd7e2009-03-11 22:30:01 +0000118 cl::init(false));
Reid Kleckner27632172009-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 Gohman844731a2008-05-13 00:00:25 +0000137static cl::opt<bool, true>
138EnableUnwindTables("unwind-tables",
Bill Wendlingf9abd7e2009-03-11 22:30:01 +0000139 cl::desc("Generate unwinding tables for all functions"),
140 cl::location(UnwindTablesMandatory),
141 cl::init(false));
Arnold Schwaighoferc85e1712007-10-11 19:40:01 +0000142
Dan Gohman844731a2008-05-13 00:00:25 +0000143static cl::opt<llvm::Reloc::Model, true>
Bill Wendlingf9abd7e2009-03-11 22:30:01 +0000144DefRelocationModel("relocation-model",
Dan Gohman844731a2008-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 Gohmanb8cab922008-10-14 20:25:08 +0000150 "Target default relocation model"),
Dan Gohman844731a2008-05-13 00:00:25 +0000151 clEnumValN(Reloc::Static, "static",
Dan Gohmanb8cab922008-10-14 20:25:08 +0000152 "Non-relocatable code"),
Dan Gohman844731a2008-05-13 00:00:25 +0000153 clEnumValN(Reloc::PIC_, "pic",
Dan Gohmanb8cab922008-10-14 20:25:08 +0000154 "Fully relocatable, position independent code"),
Dan Gohman844731a2008-05-13 00:00:25 +0000155 clEnumValN(Reloc::DynamicNoPIC, "dynamic-no-pic",
Dan Gohmanb8cab922008-10-14 20:25:08 +0000156 "Relocatable external references, non-relocatable code"),
Dan Gohman844731a2008-05-13 00:00:25 +0000157 clEnumValEnd));
158static cl::opt<llvm::CodeModel::Model, true>
Bill Wendlingf9abd7e2009-03-11 22:30:01 +0000159DefCodeModel("code-model",
Dan Gohman844731a2008-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 Gohmanb8cab922008-10-14 20:25:08 +0000165 "Target default code model"),
Dan Gohman844731a2008-05-13 00:00:25 +0000166 clEnumValN(CodeModel::Small, "small",
Dan Gohmanb8cab922008-10-14 20:25:08 +0000167 "Small code model"),
Dan Gohman844731a2008-05-13 00:00:25 +0000168 clEnumValN(CodeModel::Kernel, "kernel",
Dan Gohmanb8cab922008-10-14 20:25:08 +0000169 "Kernel code model"),
Dan Gohman844731a2008-05-13 00:00:25 +0000170 clEnumValN(CodeModel::Medium, "medium",
Dan Gohmanb8cab922008-10-14 20:25:08 +0000171 "Medium code model"),
Dan Gohman844731a2008-05-13 00:00:25 +0000172 clEnumValN(CodeModel::Large, "large",
Dan Gohmanb8cab922008-10-14 20:25:08 +0000173 "Large code model"),
Dan Gohman844731a2008-05-13 00:00:25 +0000174 clEnumValEnd));
Dan Gohman844731a2008-05-13 00:00:25 +0000175static cl::opt<bool, true>
Dan Gohman1797ed52010-02-08 20:27:50 +0000176EnableGuaranteedTailCallOpt("tailcallopt",
Evan Cheng8c86db52010-01-27 00:10:09 +0000177 cl::desc("Turn fastcc calls into tail calls by (potentially) changing ABI."),
Dan Gohman1797ed52010-02-08 20:27:50 +0000178 cl::location(GuaranteedTailCallOpt),
Bill Wendlingf9abd7e2009-03-11 22:30:01 +0000179 cl::init(false));
Evan Cheng6547e402008-07-01 23:18:29 +0000180static cl::opt<unsigned, true>
181OverrideStackAlignment("stack-alignment",
Bill Wendlingf9abd7e2009-03-11 22:30:01 +0000182 cl::desc("Override default stack alignment"),
183 cl::location(StackAlignment),
184 cl::init(0));
Dan Gohman844731a2008-05-13 00:00:25 +0000185static cl::opt<bool, true>
186EnableRealignStack("realign-stack",
Bill Wendlingf9abd7e2009-03-11 22:30:01 +0000187 cl::desc("Realign stack if needed"),
188 cl::location(RealignStack),
189 cl::init(true));
Evan Cheng6547e402008-07-01 23:18:29 +0000190static cl::opt<bool, true>
Dale Johannesen72324642008-07-31 18:13:12 +0000191DisableSwitchTables(cl::Hidden, "disable-jump-tables",
Bill Wendlingf9abd7e2009-03-11 22:30:01 +0000192 cl::desc("Do not generate jump tables."),
193 cl::location(DisableJumpTables),
194 cl::init(false));
Owen Anderson95dad832008-10-07 20:22:28 +0000195static cl::opt<bool, true>
196EnableStrongPHIElim(cl::Hidden, "strong-phi-elim",
Bill Wendlingf9abd7e2009-03-11 22:30:01 +0000197 cl::desc("Use strong PHI elimination."),
198 cl::location(StrongPHIElim),
199 cl::init(false));
Chris Lattner43ac7212010-04-13 00:36:43 +0000200static cl::opt<bool>
201DataSections("fdata-sections",
202 cl::desc("Emit data into separate sections"),
203 cl::init(false));
204static cl::opt<bool>
205FunctionSections("ffunction-sections",
206 cl::desc("Emit functions into separate sections"),
207 cl::init(false));
Brian Gaeke323819e2004-03-04 19:16:23 +0000208//---------------------------------------------------------------------------
Chris Lattnerf70e0c22003-12-28 21:23:38 +0000209// TargetMachine Class
210//
Misha Brukman167deff2004-08-10 23:10:25 +0000211
Daniel Dunbar51b198a2009-07-15 20:24:03 +0000212TargetMachine::TargetMachine(const Target &T)
213 : TheTarget(T), AsmInfo(0) {
Anton Korobeynikov0eebf652009-06-08 22:53:56 +0000214 // Typically it will be subtargets that will adjust FloatABIType from Default
215 // to Soft or Hard.
216 if (UseSoftFloat)
217 FloatABIType = FloatABI::Soft;
218}
219
Chris Lattnerf70e0c22003-12-28 21:23:38 +0000220TargetMachine::~TargetMachine() {
Jim Laskeyfde1b3b2006-09-07 23:39:26 +0000221 delete AsmInfo;
Chris Lattnerf70e0c22003-12-28 21:23:38 +0000222}
223
Evan Cheng4c1aa862006-02-22 20:19:42 +0000224/// getRelocationModel - Returns the code generation relocation model. The
225/// choices are static, PIC, and dynamic-no-pic, and target default.
226Reloc::Model TargetMachine::getRelocationModel() {
227 return RelocationModel;
228}
229
230/// setRelocationModel - Sets the code generation relocation model.
231void TargetMachine::setRelocationModel(Reloc::Model Model) {
232 RelocationModel = Model;
233}
Evan Cheng80235d52006-05-23 18:18:46 +0000234
Evan Cheng152ed052006-07-06 01:53:36 +0000235/// getCodeModel - Returns the code model. The choices are small, kernel,
236/// medium, large, and target default.
237CodeModel::Model TargetMachine::getCodeModel() {
238 return CMModel;
239}
240
241/// setCodeModel - Sets the code model.
242void TargetMachine::setCodeModel(CodeModel::Model Model) {
243 CMModel = Model;
244}
245
Evan Cheng42bf74b2009-03-25 01:47:28 +0000246bool TargetMachine::getAsmVerbosityDefault() {
247 return AsmVerbosityDefault;
248}
249
250void TargetMachine::setAsmVerbosityDefault(bool V) {
251 AsmVerbosityDefault = V;
252}
253
Chris Lattner43ac7212010-04-13 00:36:43 +0000254bool TargetMachine::getFunctionSections() {
255 return FunctionSections;
256}
257
258bool TargetMachine::getDataSections() {
259 return DataSections;
260}
261
262void TargetMachine::setFunctionSections(bool V) {
263 FunctionSections = V;
264}
265
266void TargetMachine::setDataSections(bool V) {
267 DataSections = V;
268}
269
Evan Cheng80235d52006-05-23 18:18:46 +0000270namespace llvm {
Mon P Wangbc65ca82009-03-20 05:06:58 +0000271 /// LessPreciseFPMAD - This flag return true when -enable-fp-mad option
272 /// is specified on the command line. When this flag is off(default), the
273 /// code generator is not allowed to generate mad (multiply add) if the
274 /// result is "less precise" than doing those operations individually.
275 bool LessPreciseFPMAD() { return UnsafeFPMath || LessPreciseFPMADOption; }
276
Evan Cheng80235d52006-05-23 18:18:46 +0000277 /// FiniteOnlyFPMath - This returns true when the -enable-finite-only-fp-math
278 /// option is specified on the command line. If this returns false (default),
279 /// the code generator is not allowed to assume that FP arithmetic arguments
280 /// and results are never NaNs or +-Infs.
281 bool FiniteOnlyFPMath() { return UnsafeFPMath || FiniteOnlyFPMathOption; }
Chris Lattneraa4f1e12007-05-03 00:16:07 +0000282
283 /// HonorSignDependentRoundingFPMath - Return true if the codegen must assume
284 /// that the rounding mode of the FPU can change from its default.
285 bool HonorSignDependentRoundingFPMath() {
286 return !UnsafeFPMath && HonorSignDependentRoundingFPMathOption;
287 }
Reid Spencer077b3872006-05-24 19:05:21 +0000288}