blob: 46bc9a331412f594c30cdf84adad5bb871869174 [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;
Arnold Schwaighoferc85e1712007-10-11 19:40:01 +000043 bool PerformTailCallOpt;
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);
Bill Wendlingb4e6a5d2009-12-18 23:32:53 +000049 bool DisableScheduling;
Chris Lattnerd74ea2b2006-05-24 17:04:05 +000050}
Misha Brukman0fb5a662004-06-21 21:08:45 +000051
Bill Wendlingf9abd7e2009-03-11 22:30:01 +000052static cl::opt<bool, true>
53PrintCode("print-machineinstrs",
Dan Gohman844731a2008-05-13 00:00:25 +000054 cl::desc("Print generated machine code"),
55 cl::location(PrintMachineCode), cl::init(false));
Dan Gohman844731a2008-05-13 00:00:25 +000056static cl::opt<bool, true>
Evan Cheng89df08c2008-05-30 22:39:18 +000057DisableFPElim("disable-fp-elim",
Bill Wendlingf9abd7e2009-03-11 22:30:01 +000058 cl::desc("Disable frame pointer elimination optimization"),
59 cl::location(NoFramePointerElim),
60 cl::init(false));
Dan Gohman844731a2008-05-13 00:00:25 +000061static cl::opt<bool, true>
62DisableExcessPrecision("disable-excess-fp-precision",
Bill Wendlingf9abd7e2009-03-11 22:30:01 +000063 cl::desc("Disable optimizations that may increase FP precision"),
64 cl::location(NoExcessFPPrecision),
65 cl::init(false));
Dan Gohman844731a2008-05-13 00:00:25 +000066static cl::opt<bool, true>
Mon P Wangbc65ca82009-03-20 05:06:58 +000067EnableFPMAD("enable-fp-mad",
68 cl::desc("Enable less precise MAD instructions to be generated"),
69 cl::location(LessPreciseFPMADOption),
70 cl::init(false));
71static cl::opt<bool, true>
Dan Gohman844731a2008-05-13 00:00:25 +000072EnableUnsafeFPMath("enable-unsafe-fp-math",
Bill Wendlingf9abd7e2009-03-11 22:30:01 +000073 cl::desc("Enable optimizations that may decrease FP precision"),
74 cl::location(UnsafeFPMath),
75 cl::init(false));
Dan Gohman844731a2008-05-13 00:00:25 +000076static cl::opt<bool, true>
77EnableFiniteOnlyFPMath("enable-finite-only-fp-math",
Bill Wendlingf9abd7e2009-03-11 22:30:01 +000078 cl::desc("Enable optimizations that assumes non- NaNs / +-Infs"),
79 cl::location(FiniteOnlyFPMathOption),
80 cl::init(false));
Dan Gohman844731a2008-05-13 00:00:25 +000081static cl::opt<bool, true>
Bill Wendlingf9abd7e2009-03-11 22:30:01 +000082EnableHonorSignDependentRoundingFPMath("enable-sign-dependent-rounding-fp-math",
83 cl::Hidden,
84 cl::desc("Force codegen to assume rounding mode can change dynamically"),
85 cl::location(HonorSignDependentRoundingFPMathOption),
86 cl::init(false));
Dan Gohman844731a2008-05-13 00:00:25 +000087static cl::opt<bool, true>
88GenerateSoftFloatCalls("soft-float",
Bill Wendlingf9abd7e2009-03-11 22:30:01 +000089 cl::desc("Generate software floating point library calls"),
90 cl::location(UseSoftFloat),
91 cl::init(false));
Anton Korobeynikov0eebf652009-06-08 22:53:56 +000092static cl::opt<llvm::FloatABI::ABIType, true>
93FloatABIForCalls("float-abi",
94 cl::desc("Choose float ABI type"),
95 cl::location(FloatABIType),
96 cl::init(FloatABI::Default),
97 cl::values(
98 clEnumValN(FloatABI::Default, "default",
99 "Target default float ABI type"),
100 clEnumValN(FloatABI::Soft, "soft",
101 "Soft float ABI (implied by -soft-float)"),
102 clEnumValN(FloatABI::Hard, "hard",
103 "Hard float ABI (uses FP registers)"),
104 clEnumValEnd));
Bill Wendlingf9abd7e2009-03-11 22:30:01 +0000105static cl::opt<bool, true>
Dan Gohman844731a2008-05-13 00:00:25 +0000106DontPlaceZerosInBSS("nozero-initialized-in-bss",
Bill Wendlingf9abd7e2009-03-11 22:30:01 +0000107 cl::desc("Don't place zero-initialized symbols into bss section"),
108 cl::location(NoZerosInBSS),
109 cl::init(false));
Dan Gohman844731a2008-05-13 00:00:25 +0000110static cl::opt<bool, true>
Jim Grosbach1b747ad2009-08-11 00:09:57 +0000111EnableDwarfExceptionHandling("enable-eh",
Bill Wendlingf9abd7e2009-03-11 22:30:01 +0000112 cl::desc("Emit DWARF exception handling (default if target supports)"),
Jim Grosbach1b747ad2009-08-11 00:09:57 +0000113 cl::location(DwarfExceptionHandling),
114 cl::init(false));
115static cl::opt<bool, true>
116EnableSjLjExceptionHandling("enable-sjlj-eh",
117 cl::desc("Emit SJLJ exception handling (default if target supports)"),
118 cl::location(SjLjExceptionHandling),
Bill Wendlingf9abd7e2009-03-11 22:30:01 +0000119 cl::init(false));
Reid Kleckner27632172009-09-20 23:52:43 +0000120// In debug builds, make this default to true.
121#ifdef NDEBUG
122#define EMIT_DEBUG false
123#else
124#define EMIT_DEBUG true
125#endif
126static cl::opt<bool, true>
127EmitJitDebugInfo("jit-emit-debug",
128 cl::desc("Emit debug information to debugger"),
129 cl::location(JITEmitDebugInfo),
130 cl::init(EMIT_DEBUG));
131#undef EMIT_DEBUG
132static cl::opt<bool, true>
133EmitJitDebugInfoToDisk("jit-emit-debug-to-disk",
134 cl::Hidden,
135 cl::desc("Emit debug info objfiles to disk"),
136 cl::location(JITEmitDebugInfoToDisk),
137 cl::init(false));
Dan Gohman844731a2008-05-13 00:00:25 +0000138static cl::opt<bool, true>
139EnableUnwindTables("unwind-tables",
Bill Wendlingf9abd7e2009-03-11 22:30:01 +0000140 cl::desc("Generate unwinding tables for all functions"),
141 cl::location(UnwindTablesMandatory),
142 cl::init(false));
Arnold Schwaighoferc85e1712007-10-11 19:40:01 +0000143
Dan Gohman844731a2008-05-13 00:00:25 +0000144static cl::opt<llvm::Reloc::Model, true>
Bill Wendlingf9abd7e2009-03-11 22:30:01 +0000145DefRelocationModel("relocation-model",
Dan Gohman844731a2008-05-13 00:00:25 +0000146 cl::desc("Choose relocation model"),
147 cl::location(RelocationModel),
148 cl::init(Reloc::Default),
149 cl::values(
150 clEnumValN(Reloc::Default, "default",
Dan Gohmanb8cab922008-10-14 20:25:08 +0000151 "Target default relocation model"),
Dan Gohman844731a2008-05-13 00:00:25 +0000152 clEnumValN(Reloc::Static, "static",
Dan Gohmanb8cab922008-10-14 20:25:08 +0000153 "Non-relocatable code"),
Dan Gohman844731a2008-05-13 00:00:25 +0000154 clEnumValN(Reloc::PIC_, "pic",
Dan Gohmanb8cab922008-10-14 20:25:08 +0000155 "Fully relocatable, position independent code"),
Dan Gohman844731a2008-05-13 00:00:25 +0000156 clEnumValN(Reloc::DynamicNoPIC, "dynamic-no-pic",
Dan Gohmanb8cab922008-10-14 20:25:08 +0000157 "Relocatable external references, non-relocatable code"),
Dan Gohman844731a2008-05-13 00:00:25 +0000158 clEnumValEnd));
159static cl::opt<llvm::CodeModel::Model, true>
Bill Wendlingf9abd7e2009-03-11 22:30:01 +0000160DefCodeModel("code-model",
Dan Gohman844731a2008-05-13 00:00:25 +0000161 cl::desc("Choose code model"),
162 cl::location(CMModel),
163 cl::init(CodeModel::Default),
164 cl::values(
165 clEnumValN(CodeModel::Default, "default",
Dan Gohmanb8cab922008-10-14 20:25:08 +0000166 "Target default code model"),
Dan Gohman844731a2008-05-13 00:00:25 +0000167 clEnumValN(CodeModel::Small, "small",
Dan Gohmanb8cab922008-10-14 20:25:08 +0000168 "Small code model"),
Dan Gohman844731a2008-05-13 00:00:25 +0000169 clEnumValN(CodeModel::Kernel, "kernel",
Dan Gohmanb8cab922008-10-14 20:25:08 +0000170 "Kernel code model"),
Dan Gohman844731a2008-05-13 00:00:25 +0000171 clEnumValN(CodeModel::Medium, "medium",
Dan Gohmanb8cab922008-10-14 20:25:08 +0000172 "Medium code model"),
Dan Gohman844731a2008-05-13 00:00:25 +0000173 clEnumValN(CodeModel::Large, "large",
Dan Gohmanb8cab922008-10-14 20:25:08 +0000174 "Large code model"),
Dan Gohman844731a2008-05-13 00:00:25 +0000175 clEnumValEnd));
Dan Gohman844731a2008-05-13 00:00:25 +0000176static cl::opt<bool, true>
177EnablePerformTailCallOpt("tailcallopt",
Bill Wendlingf9abd7e2009-03-11 22:30:01 +0000178 cl::desc("Turn on tail call optimization."),
179 cl::location(PerformTailCallOpt),
180 cl::init(false));
Evan Cheng6547e402008-07-01 23:18:29 +0000181static cl::opt<unsigned, true>
182OverrideStackAlignment("stack-alignment",
Bill Wendlingf9abd7e2009-03-11 22:30:01 +0000183 cl::desc("Override default stack alignment"),
184 cl::location(StackAlignment),
185 cl::init(0));
Dan Gohman844731a2008-05-13 00:00:25 +0000186static cl::opt<bool, true>
187EnableRealignStack("realign-stack",
Bill Wendlingf9abd7e2009-03-11 22:30:01 +0000188 cl::desc("Realign stack if needed"),
189 cl::location(RealignStack),
190 cl::init(true));
Evan Cheng6547e402008-07-01 23:18:29 +0000191static cl::opt<bool, true>
Dale Johannesen72324642008-07-31 18:13:12 +0000192DisableSwitchTables(cl::Hidden, "disable-jump-tables",
Bill Wendlingf9abd7e2009-03-11 22:30:01 +0000193 cl::desc("Do not generate jump tables."),
194 cl::location(DisableJumpTables),
195 cl::init(false));
Owen Anderson95dad832008-10-07 20:22:28 +0000196static cl::opt<bool, true>
197EnableStrongPHIElim(cl::Hidden, "strong-phi-elim",
Bill Wendlingf9abd7e2009-03-11 22:30:01 +0000198 cl::desc("Use strong PHI elimination."),
199 cl::location(StrongPHIElim),
200 cl::init(false));
Bill Wendlingb4e6a5d2009-12-18 23:32:53 +0000201static cl::opt<bool, true>
202DisableInstScheduling("disable-scheduling",
203 cl::desc("Disable instruction scheduling"),
204 cl::location(DisableScheduling),
205 cl::init(false));
Dan Gohman92f4f162009-01-26 22:22:31 +0000206
Brian Gaeke323819e2004-03-04 19:16:23 +0000207//---------------------------------------------------------------------------
Chris Lattnerf70e0c22003-12-28 21:23:38 +0000208// TargetMachine Class
209//
Misha Brukman167deff2004-08-10 23:10:25 +0000210
Daniel Dunbar51b198a2009-07-15 20:24:03 +0000211TargetMachine::TargetMachine(const Target &T)
212 : TheTarget(T), AsmInfo(0) {
Anton Korobeynikov0eebf652009-06-08 22:53:56 +0000213 // Typically it will be subtargets that will adjust FloatABIType from Default
214 // to Soft or Hard.
215 if (UseSoftFloat)
216 FloatABIType = FloatABI::Soft;
217}
218
Chris Lattnerf70e0c22003-12-28 21:23:38 +0000219TargetMachine::~TargetMachine() {
Jim Laskeyfde1b3b2006-09-07 23:39:26 +0000220 delete AsmInfo;
Chris Lattnerf70e0c22003-12-28 21:23:38 +0000221}
222
Evan Cheng4c1aa862006-02-22 20:19:42 +0000223/// getRelocationModel - Returns the code generation relocation model. The
224/// choices are static, PIC, and dynamic-no-pic, and target default.
225Reloc::Model TargetMachine::getRelocationModel() {
226 return RelocationModel;
227}
228
229/// setRelocationModel - Sets the code generation relocation model.
230void TargetMachine::setRelocationModel(Reloc::Model Model) {
231 RelocationModel = Model;
232}
Evan Cheng80235d52006-05-23 18:18:46 +0000233
Evan Cheng152ed052006-07-06 01:53:36 +0000234/// getCodeModel - Returns the code model. The choices are small, kernel,
235/// medium, large, and target default.
236CodeModel::Model TargetMachine::getCodeModel() {
237 return CMModel;
238}
239
240/// setCodeModel - Sets the code model.
241void TargetMachine::setCodeModel(CodeModel::Model Model) {
242 CMModel = Model;
243}
244
Evan Cheng42bf74b2009-03-25 01:47:28 +0000245bool TargetMachine::getAsmVerbosityDefault() {
246 return AsmVerbosityDefault;
247}
248
249void TargetMachine::setAsmVerbosityDefault(bool V) {
250 AsmVerbosityDefault = V;
251}
252
Evan Cheng80235d52006-05-23 18:18:46 +0000253namespace llvm {
Mon P Wangbc65ca82009-03-20 05:06:58 +0000254 /// LessPreciseFPMAD - This flag return true when -enable-fp-mad option
255 /// is specified on the command line. When this flag is off(default), the
256 /// code generator is not allowed to generate mad (multiply add) if the
257 /// result is "less precise" than doing those operations individually.
258 bool LessPreciseFPMAD() { return UnsafeFPMath || LessPreciseFPMADOption; }
259
Evan Cheng80235d52006-05-23 18:18:46 +0000260 /// FiniteOnlyFPMath - This returns true when the -enable-finite-only-fp-math
261 /// option is specified on the command line. If this returns false (default),
262 /// the code generator is not allowed to assume that FP arithmetic arguments
263 /// and results are never NaNs or +-Infs.
264 bool FiniteOnlyFPMath() { return UnsafeFPMath || FiniteOnlyFPMathOption; }
Chris Lattneraa4f1e12007-05-03 00:16:07 +0000265
266 /// HonorSignDependentRoundingFPMath - Return true if the codegen must assume
267 /// that the rounding mode of the FPU can change from its default.
268 bool HonorSignDependentRoundingFPMath() {
269 return !UnsafeFPMath && HonorSignDependentRoundingFPMathOption;
270 }
Reid Spencer077b3872006-05-24 19:05:21 +0000271}