blob: c487cb805306ab221becf4ede0f19ca9184da639 [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
Jim Laskeya0f3d172006-09-07 22:06:40 +000014#include "llvm/Target/TargetAsmInfo.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 Laskey1b340dc2007-01-29 20:48:32 +000036 bool ExceptionHandling;
Dale Johannesen3541af72008-04-14 17:54:17 +000037 bool UnwindTablesMandatory;
Evan Cheng4c1aa862006-02-22 20:19:42 +000038 Reloc::Model RelocationModel;
Evan Cheng152ed052006-07-06 01:53:36 +000039 CodeModel::Model CMModel;
Arnold Schwaighoferc85e1712007-10-11 19:40:01 +000040 bool PerformTailCallOpt;
Anton Korobeynikov45709ae2008-04-23 18:18:10 +000041 unsigned StackAlignment;
Evan Cheng6547e402008-07-01 23:18:29 +000042 bool RealignStack;
Dale Johannesen72324642008-07-31 18:13:12 +000043 bool DisableJumpTables;
Owen Anderson95dad832008-10-07 20:22:28 +000044 bool StrongPHIElim;
Evan Cheng42bf74b2009-03-25 01:47:28 +000045 bool AsmVerbosityDefault(false);
Chris Lattnerd74ea2b2006-05-24 17:04:05 +000046}
Misha Brukman0fb5a662004-06-21 21:08:45 +000047
Bill Wendlingf9abd7e2009-03-11 22:30:01 +000048static cl::opt<bool, true>
49PrintCode("print-machineinstrs",
Dan Gohman844731a2008-05-13 00:00:25 +000050 cl::desc("Print generated machine code"),
51 cl::location(PrintMachineCode), cl::init(false));
Dan Gohman844731a2008-05-13 00:00:25 +000052static cl::opt<bool, true>
Evan Cheng89df08c2008-05-30 22:39:18 +000053DisableFPElim("disable-fp-elim",
Bill Wendlingf9abd7e2009-03-11 22:30:01 +000054 cl::desc("Disable frame pointer elimination optimization"),
55 cl::location(NoFramePointerElim),
56 cl::init(false));
Dan Gohman844731a2008-05-13 00:00:25 +000057static cl::opt<bool, true>
58DisableExcessPrecision("disable-excess-fp-precision",
Bill Wendlingf9abd7e2009-03-11 22:30:01 +000059 cl::desc("Disable optimizations that may increase FP precision"),
60 cl::location(NoExcessFPPrecision),
61 cl::init(false));
Dan Gohman844731a2008-05-13 00:00:25 +000062static cl::opt<bool, true>
Mon P Wangbc65ca82009-03-20 05:06:58 +000063EnableFPMAD("enable-fp-mad",
64 cl::desc("Enable less precise MAD instructions to be generated"),
65 cl::location(LessPreciseFPMADOption),
66 cl::init(false));
67static cl::opt<bool, true>
Dan Gohman844731a2008-05-13 00:00:25 +000068EnableUnsafeFPMath("enable-unsafe-fp-math",
Bill Wendlingf9abd7e2009-03-11 22:30:01 +000069 cl::desc("Enable optimizations that may decrease FP precision"),
70 cl::location(UnsafeFPMath),
71 cl::init(false));
Dan Gohman844731a2008-05-13 00:00:25 +000072static cl::opt<bool, true>
73EnableFiniteOnlyFPMath("enable-finite-only-fp-math",
Bill Wendlingf9abd7e2009-03-11 22:30:01 +000074 cl::desc("Enable optimizations that assumes non- NaNs / +-Infs"),
75 cl::location(FiniteOnlyFPMathOption),
76 cl::init(false));
Dan Gohman844731a2008-05-13 00:00:25 +000077static cl::opt<bool, true>
Bill Wendlingf9abd7e2009-03-11 22:30:01 +000078EnableHonorSignDependentRoundingFPMath("enable-sign-dependent-rounding-fp-math",
79 cl::Hidden,
80 cl::desc("Force codegen to assume rounding mode can change dynamically"),
81 cl::location(HonorSignDependentRoundingFPMathOption),
82 cl::init(false));
Dan Gohman844731a2008-05-13 00:00:25 +000083static cl::opt<bool, true>
84GenerateSoftFloatCalls("soft-float",
Bill Wendlingf9abd7e2009-03-11 22:30:01 +000085 cl::desc("Generate software floating point library calls"),
86 cl::location(UseSoftFloat),
87 cl::init(false));
Anton Korobeynikov0eebf652009-06-08 22:53:56 +000088static cl::opt<llvm::FloatABI::ABIType, true>
89FloatABIForCalls("float-abi",
90 cl::desc("Choose float ABI type"),
91 cl::location(FloatABIType),
92 cl::init(FloatABI::Default),
93 cl::values(
94 clEnumValN(FloatABI::Default, "default",
95 "Target default float ABI type"),
96 clEnumValN(FloatABI::Soft, "soft",
97 "Soft float ABI (implied by -soft-float)"),
98 clEnumValN(FloatABI::Hard, "hard",
99 "Hard float ABI (uses FP registers)"),
100 clEnumValEnd));
Bill Wendlingf9abd7e2009-03-11 22:30:01 +0000101static cl::opt<bool, true>
Dan Gohman844731a2008-05-13 00:00:25 +0000102DontPlaceZerosInBSS("nozero-initialized-in-bss",
Bill Wendlingf9abd7e2009-03-11 22:30:01 +0000103 cl::desc("Don't place zero-initialized symbols into bss section"),
104 cl::location(NoZerosInBSS),
105 cl::init(false));
Dan Gohman844731a2008-05-13 00:00:25 +0000106static cl::opt<bool, true>
107EnableExceptionHandling("enable-eh",
Bill Wendlingf9abd7e2009-03-11 22:30:01 +0000108 cl::desc("Emit DWARF exception handling (default if target supports)"),
109 cl::location(ExceptionHandling),
110 cl::init(false));
Dan Gohman844731a2008-05-13 00:00:25 +0000111static cl::opt<bool, true>
112EnableUnwindTables("unwind-tables",
Bill Wendlingf9abd7e2009-03-11 22:30:01 +0000113 cl::desc("Generate unwinding tables for all functions"),
114 cl::location(UnwindTablesMandatory),
115 cl::init(false));
Arnold Schwaighoferc85e1712007-10-11 19:40:01 +0000116
Dan Gohman844731a2008-05-13 00:00:25 +0000117static cl::opt<llvm::Reloc::Model, true>
Bill Wendlingf9abd7e2009-03-11 22:30:01 +0000118DefRelocationModel("relocation-model",
Dan Gohman844731a2008-05-13 00:00:25 +0000119 cl::desc("Choose relocation model"),
120 cl::location(RelocationModel),
121 cl::init(Reloc::Default),
122 cl::values(
123 clEnumValN(Reloc::Default, "default",
Dan Gohmanb8cab922008-10-14 20:25:08 +0000124 "Target default relocation model"),
Dan Gohman844731a2008-05-13 00:00:25 +0000125 clEnumValN(Reloc::Static, "static",
Dan Gohmanb8cab922008-10-14 20:25:08 +0000126 "Non-relocatable code"),
Dan Gohman844731a2008-05-13 00:00:25 +0000127 clEnumValN(Reloc::PIC_, "pic",
Dan Gohmanb8cab922008-10-14 20:25:08 +0000128 "Fully relocatable, position independent code"),
Dan Gohman844731a2008-05-13 00:00:25 +0000129 clEnumValN(Reloc::DynamicNoPIC, "dynamic-no-pic",
Dan Gohmanb8cab922008-10-14 20:25:08 +0000130 "Relocatable external references, non-relocatable code"),
Dan Gohman844731a2008-05-13 00:00:25 +0000131 clEnumValEnd));
132static cl::opt<llvm::CodeModel::Model, true>
Bill Wendlingf9abd7e2009-03-11 22:30:01 +0000133DefCodeModel("code-model",
Dan Gohman844731a2008-05-13 00:00:25 +0000134 cl::desc("Choose code model"),
135 cl::location(CMModel),
136 cl::init(CodeModel::Default),
137 cl::values(
138 clEnumValN(CodeModel::Default, "default",
Dan Gohmanb8cab922008-10-14 20:25:08 +0000139 "Target default code model"),
Dan Gohman844731a2008-05-13 00:00:25 +0000140 clEnumValN(CodeModel::Small, "small",
Dan Gohmanb8cab922008-10-14 20:25:08 +0000141 "Small code model"),
Dan Gohman844731a2008-05-13 00:00:25 +0000142 clEnumValN(CodeModel::Kernel, "kernel",
Dan Gohmanb8cab922008-10-14 20:25:08 +0000143 "Kernel code model"),
Dan Gohman844731a2008-05-13 00:00:25 +0000144 clEnumValN(CodeModel::Medium, "medium",
Dan Gohmanb8cab922008-10-14 20:25:08 +0000145 "Medium code model"),
Dan Gohman844731a2008-05-13 00:00:25 +0000146 clEnumValN(CodeModel::Large, "large",
Dan Gohmanb8cab922008-10-14 20:25:08 +0000147 "Large code model"),
Dan Gohman844731a2008-05-13 00:00:25 +0000148 clEnumValEnd));
Dan Gohman844731a2008-05-13 00:00:25 +0000149static cl::opt<bool, true>
150EnablePerformTailCallOpt("tailcallopt",
Bill Wendlingf9abd7e2009-03-11 22:30:01 +0000151 cl::desc("Turn on tail call optimization."),
152 cl::location(PerformTailCallOpt),
153 cl::init(false));
Evan Cheng6547e402008-07-01 23:18:29 +0000154static cl::opt<unsigned, true>
155OverrideStackAlignment("stack-alignment",
Bill Wendlingf9abd7e2009-03-11 22:30:01 +0000156 cl::desc("Override default stack alignment"),
157 cl::location(StackAlignment),
158 cl::init(0));
Dan Gohman844731a2008-05-13 00:00:25 +0000159static cl::opt<bool, true>
160EnableRealignStack("realign-stack",
Bill Wendlingf9abd7e2009-03-11 22:30:01 +0000161 cl::desc("Realign stack if needed"),
162 cl::location(RealignStack),
163 cl::init(true));
Evan Cheng6547e402008-07-01 23:18:29 +0000164static cl::opt<bool, true>
Dale Johannesen72324642008-07-31 18:13:12 +0000165DisableSwitchTables(cl::Hidden, "disable-jump-tables",
Bill Wendlingf9abd7e2009-03-11 22:30:01 +0000166 cl::desc("Do not generate jump tables."),
167 cl::location(DisableJumpTables),
168 cl::init(false));
Owen Anderson95dad832008-10-07 20:22:28 +0000169static cl::opt<bool, true>
170EnableStrongPHIElim(cl::Hidden, "strong-phi-elim",
Bill Wendlingf9abd7e2009-03-11 22:30:01 +0000171 cl::desc("Use strong PHI elimination."),
172 cl::location(StrongPHIElim),
173 cl::init(false));
Dan Gohman92f4f162009-01-26 22:22:31 +0000174
Brian Gaeke323819e2004-03-04 19:16:23 +0000175//---------------------------------------------------------------------------
Chris Lattnerf70e0c22003-12-28 21:23:38 +0000176// TargetMachine Class
177//
Misha Brukman167deff2004-08-10 23:10:25 +0000178
Stuart Hastings2286f8d2009-07-15 17:27:11 +0000179TargetMachine::TargetMachine()
180 : AsmInfo(0) {
Anton Korobeynikov0eebf652009-06-08 22:53:56 +0000181 // Typically it will be subtargets that will adjust FloatABIType from Default
182 // to Soft or Hard.
183 if (UseSoftFloat)
184 FloatABIType = FloatABI::Soft;
185}
186
Chris Lattnerf70e0c22003-12-28 21:23:38 +0000187TargetMachine::~TargetMachine() {
Jim Laskeyfde1b3b2006-09-07 23:39:26 +0000188 delete AsmInfo;
Chris Lattnerf70e0c22003-12-28 21:23:38 +0000189}
190
Evan Cheng4c1aa862006-02-22 20:19:42 +0000191/// getRelocationModel - Returns the code generation relocation model. The
192/// choices are static, PIC, and dynamic-no-pic, and target default.
193Reloc::Model TargetMachine::getRelocationModel() {
194 return RelocationModel;
195}
196
197/// setRelocationModel - Sets the code generation relocation model.
198void TargetMachine::setRelocationModel(Reloc::Model Model) {
199 RelocationModel = Model;
200}
Evan Cheng80235d52006-05-23 18:18:46 +0000201
Evan Cheng152ed052006-07-06 01:53:36 +0000202/// getCodeModel - Returns the code model. The choices are small, kernel,
203/// medium, large, and target default.
204CodeModel::Model TargetMachine::getCodeModel() {
205 return CMModel;
206}
207
208/// setCodeModel - Sets the code model.
209void TargetMachine::setCodeModel(CodeModel::Model Model) {
210 CMModel = Model;
211}
212
Evan Cheng42bf74b2009-03-25 01:47:28 +0000213bool TargetMachine::getAsmVerbosityDefault() {
214 return AsmVerbosityDefault;
215}
216
217void TargetMachine::setAsmVerbosityDefault(bool V) {
218 AsmVerbosityDefault = V;
219}
220
Evan Cheng80235d52006-05-23 18:18:46 +0000221namespace llvm {
Mon P Wangbc65ca82009-03-20 05:06:58 +0000222 /// LessPreciseFPMAD - This flag return true when -enable-fp-mad option
223 /// is specified on the command line. When this flag is off(default), the
224 /// code generator is not allowed to generate mad (multiply add) if the
225 /// result is "less precise" than doing those operations individually.
226 bool LessPreciseFPMAD() { return UnsafeFPMath || LessPreciseFPMADOption; }
227
Evan Cheng80235d52006-05-23 18:18:46 +0000228 /// FiniteOnlyFPMath - This returns true when the -enable-finite-only-fp-math
229 /// option is specified on the command line. If this returns false (default),
230 /// the code generator is not allowed to assume that FP arithmetic arguments
231 /// and results are never NaNs or +-Infs.
232 bool FiniteOnlyFPMath() { return UnsafeFPMath || FiniteOnlyFPMathOption; }
Chris Lattneraa4f1e12007-05-03 00:16:07 +0000233
234 /// HonorSignDependentRoundingFPMath - Return true if the codegen must assume
235 /// that the rounding mode of the FPU can change from its default.
236 bool HonorSignDependentRoundingFPMath() {
237 return !UnsafeFPMath && HonorSignDependentRoundingFPMathOption;
238 }
Reid Spencer077b3872006-05-24 19:05:21 +0000239}
Chris Lattner3199af22006-09-04 04:06:01 +0000240