blob: 1b042ddef9b86c92cdf1b80ef204cd99bd1a3f72 [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
14#include "llvm/Target/TargetAsmInfo.h"
15#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;
Bill Wendling042eda32009-03-11 22:30:01 +000033 bool NoImplicitFloat;
Dan Gohmanf17a25c2007-07-18 16:29:46 +000034 bool NoZerosInBSS;
35 bool ExceptionHandling;
Dale Johannesenb369e8d2008-04-14 17:54:17 +000036 bool UnwindTablesMandatory;
Dan Gohmanf17a25c2007-07-18 16:29:46 +000037 Reloc::Model RelocationModel;
38 CodeModel::Model CMModel;
Arnold Schwaighofere2d6bbb2007-10-11 19:40:01 +000039 bool PerformTailCallOpt;
Anton Korobeynikovb214a522008-04-23 18:18:10 +000040 unsigned StackAlignment;
Evan Cheng0eeed442008-07-01 23:18:29 +000041 bool RealignStack;
Dale Johannesen493492f2008-07-31 18:13:12 +000042 bool DisableJumpTables;
Owen Andersonbac9ae22008-10-07 20:22:28 +000043 bool StrongPHIElim;
Dan Gohmanb3e9a712009-01-26 22:22:31 +000044 bool DisableRedZone;
Evan Cheng42ceb472009-03-25 01:47:28 +000045 bool AsmVerbosityDefault(false);
Dan Gohmanf17a25c2007-07-18 16:29:46 +000046}
Dan Gohmanf17a25c2007-07-18 16:29:46 +000047
Bill Wendling042eda32009-03-11 22:30:01 +000048static cl::opt<bool, true>
49PrintCode("print-machineinstrs",
Dan Gohman089efff2008-05-13 00:00:25 +000050 cl::desc("Print generated machine code"),
51 cl::location(PrintMachineCode), cl::init(false));
Dan Gohman089efff2008-05-13 00:00:25 +000052static cl::opt<bool, true>
Evan Cheng94b06762008-05-30 22:39:18 +000053DisableFPElim("disable-fp-elim",
Bill Wendling042eda32009-03-11 22:30:01 +000054 cl::desc("Disable frame pointer elimination optimization"),
55 cl::location(NoFramePointerElim),
56 cl::init(false));
Dan Gohman089efff2008-05-13 00:00:25 +000057static cl::opt<bool, true>
58DisableExcessPrecision("disable-excess-fp-precision",
Bill Wendling042eda32009-03-11 22:30:01 +000059 cl::desc("Disable optimizations that may increase FP precision"),
60 cl::location(NoExcessFPPrecision),
61 cl::init(false));
Dan Gohman089efff2008-05-13 00:00:25 +000062static cl::opt<bool, true>
Mon P Wang473bc862009-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 Gohman089efff2008-05-13 00:00:25 +000068EnableUnsafeFPMath("enable-unsafe-fp-math",
Bill Wendling042eda32009-03-11 22:30:01 +000069 cl::desc("Enable optimizations that may decrease FP precision"),
70 cl::location(UnsafeFPMath),
71 cl::init(false));
Dan Gohman089efff2008-05-13 00:00:25 +000072static cl::opt<bool, true>
73EnableFiniteOnlyFPMath("enable-finite-only-fp-math",
Bill Wendling042eda32009-03-11 22:30:01 +000074 cl::desc("Enable optimizations that assumes non- NaNs / +-Infs"),
75 cl::location(FiniteOnlyFPMathOption),
76 cl::init(false));
Dan Gohman089efff2008-05-13 00:00:25 +000077static cl::opt<bool, true>
Bill Wendling042eda32009-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 Gohman089efff2008-05-13 00:00:25 +000083static cl::opt<bool, true>
84GenerateSoftFloatCalls("soft-float",
Bill Wendling042eda32009-03-11 22:30:01 +000085 cl::desc("Generate software floating point library calls"),
86 cl::location(UseSoftFloat),
87 cl::init(false));
88static cl::opt<bool, true>
89GenerateNoImplicitFloats("no-implicit-float",
90 cl::desc("Don't generate implicit floating point instructions (x86-only)"),
91 cl::location(NoImplicitFloat),
92 cl::init(false));
Dan Gohman089efff2008-05-13 00:00:25 +000093static cl::opt<bool, true>
94DontPlaceZerosInBSS("nozero-initialized-in-bss",
Bill Wendling042eda32009-03-11 22:30:01 +000095 cl::desc("Don't place zero-initialized symbols into bss section"),
96 cl::location(NoZerosInBSS),
97 cl::init(false));
Dan Gohman089efff2008-05-13 00:00:25 +000098static cl::opt<bool, true>
99EnableExceptionHandling("enable-eh",
Bill Wendling042eda32009-03-11 22:30:01 +0000100 cl::desc("Emit DWARF exception handling (default if target supports)"),
101 cl::location(ExceptionHandling),
102 cl::init(false));
Dan Gohman089efff2008-05-13 00:00:25 +0000103static cl::opt<bool, true>
104EnableUnwindTables("unwind-tables",
Bill Wendling042eda32009-03-11 22:30:01 +0000105 cl::desc("Generate unwinding tables for all functions"),
106 cl::location(UnwindTablesMandatory),
107 cl::init(false));
Arnold Schwaighofere2d6bbb2007-10-11 19:40:01 +0000108
Dan Gohman089efff2008-05-13 00:00:25 +0000109static cl::opt<llvm::Reloc::Model, true>
Bill Wendling042eda32009-03-11 22:30:01 +0000110DefRelocationModel("relocation-model",
Dan Gohman089efff2008-05-13 00:00:25 +0000111 cl::desc("Choose relocation model"),
112 cl::location(RelocationModel),
113 cl::init(Reloc::Default),
114 cl::values(
115 clEnumValN(Reloc::Default, "default",
Dan Gohman669b9bf2008-10-14 20:25:08 +0000116 "Target default relocation model"),
Dan Gohman089efff2008-05-13 00:00:25 +0000117 clEnumValN(Reloc::Static, "static",
Dan Gohman669b9bf2008-10-14 20:25:08 +0000118 "Non-relocatable code"),
Dan Gohman089efff2008-05-13 00:00:25 +0000119 clEnumValN(Reloc::PIC_, "pic",
Dan Gohman669b9bf2008-10-14 20:25:08 +0000120 "Fully relocatable, position independent code"),
Dan Gohman089efff2008-05-13 00:00:25 +0000121 clEnumValN(Reloc::DynamicNoPIC, "dynamic-no-pic",
Dan Gohman669b9bf2008-10-14 20:25:08 +0000122 "Relocatable external references, non-relocatable code"),
Dan Gohman089efff2008-05-13 00:00:25 +0000123 clEnumValEnd));
124static cl::opt<llvm::CodeModel::Model, true>
Bill Wendling042eda32009-03-11 22:30:01 +0000125DefCodeModel("code-model",
Dan Gohman089efff2008-05-13 00:00:25 +0000126 cl::desc("Choose code model"),
127 cl::location(CMModel),
128 cl::init(CodeModel::Default),
129 cl::values(
130 clEnumValN(CodeModel::Default, "default",
Dan Gohman669b9bf2008-10-14 20:25:08 +0000131 "Target default code model"),
Dan Gohman089efff2008-05-13 00:00:25 +0000132 clEnumValN(CodeModel::Small, "small",
Dan Gohman669b9bf2008-10-14 20:25:08 +0000133 "Small code model"),
Dan Gohman089efff2008-05-13 00:00:25 +0000134 clEnumValN(CodeModel::Kernel, "kernel",
Dan Gohman669b9bf2008-10-14 20:25:08 +0000135 "Kernel code model"),
Dan Gohman089efff2008-05-13 00:00:25 +0000136 clEnumValN(CodeModel::Medium, "medium",
Dan Gohman669b9bf2008-10-14 20:25:08 +0000137 "Medium code model"),
Dan Gohman089efff2008-05-13 00:00:25 +0000138 clEnumValN(CodeModel::Large, "large",
Dan Gohman669b9bf2008-10-14 20:25:08 +0000139 "Large code model"),
Dan Gohman089efff2008-05-13 00:00:25 +0000140 clEnumValEnd));
Dan Gohman089efff2008-05-13 00:00:25 +0000141static cl::opt<bool, true>
142EnablePerformTailCallOpt("tailcallopt",
Bill Wendling042eda32009-03-11 22:30:01 +0000143 cl::desc("Turn on tail call optimization."),
144 cl::location(PerformTailCallOpt),
145 cl::init(false));
Evan Cheng0eeed442008-07-01 23:18:29 +0000146static cl::opt<unsigned, true>
147OverrideStackAlignment("stack-alignment",
Bill Wendling042eda32009-03-11 22:30:01 +0000148 cl::desc("Override default stack alignment"),
149 cl::location(StackAlignment),
150 cl::init(0));
Dan Gohman089efff2008-05-13 00:00:25 +0000151static cl::opt<bool, true>
152EnableRealignStack("realign-stack",
Bill Wendling042eda32009-03-11 22:30:01 +0000153 cl::desc("Realign stack if needed"),
154 cl::location(RealignStack),
155 cl::init(true));
Evan Cheng0eeed442008-07-01 23:18:29 +0000156static cl::opt<bool, true>
Dale Johannesen493492f2008-07-31 18:13:12 +0000157DisableSwitchTables(cl::Hidden, "disable-jump-tables",
Bill Wendling042eda32009-03-11 22:30:01 +0000158 cl::desc("Do not generate jump tables."),
159 cl::location(DisableJumpTables),
160 cl::init(false));
Owen Andersonbac9ae22008-10-07 20:22:28 +0000161static cl::opt<bool, true>
162EnableStrongPHIElim(cl::Hidden, "strong-phi-elim",
Bill Wendling042eda32009-03-11 22:30:01 +0000163 cl::desc("Use strong PHI elimination."),
164 cl::location(StrongPHIElim),
165 cl::init(false));
Dan Gohmanb3e9a712009-01-26 22:22:31 +0000166static cl::opt<bool, true>
167DisableRedZoneOption("disable-red-zone",
Bill Wendling042eda32009-03-11 22:30:01 +0000168 cl::desc("Do not emit code that uses the red zone."),
169 cl::location(DisableRedZone),
170 cl::init(false));
Dan Gohmanb3e9a712009-01-26 22:22:31 +0000171
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000172//---------------------------------------------------------------------------
173// TargetMachine Class
174//
175
176TargetMachine::~TargetMachine() {
177 delete AsmInfo;
178}
179
180/// getRelocationModel - Returns the code generation relocation model. The
181/// choices are static, PIC, and dynamic-no-pic, and target default.
182Reloc::Model TargetMachine::getRelocationModel() {
183 return RelocationModel;
184}
185
186/// setRelocationModel - Sets the code generation relocation model.
187void TargetMachine::setRelocationModel(Reloc::Model Model) {
188 RelocationModel = Model;
189}
190
191/// getCodeModel - Returns the code model. The choices are small, kernel,
192/// medium, large, and target default.
193CodeModel::Model TargetMachine::getCodeModel() {
194 return CMModel;
195}
196
197/// setCodeModel - Sets the code model.
198void TargetMachine::setCodeModel(CodeModel::Model Model) {
199 CMModel = Model;
200}
201
Evan Cheng42ceb472009-03-25 01:47:28 +0000202bool TargetMachine::getAsmVerbosityDefault() {
203 return AsmVerbosityDefault;
204}
205
206void TargetMachine::setAsmVerbosityDefault(bool V) {
207 AsmVerbosityDefault = V;
208}
209
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000210namespace llvm {
Mon P Wang473bc862009-03-20 05:06:58 +0000211 /// LessPreciseFPMAD - This flag return true when -enable-fp-mad option
212 /// is specified on the command line. When this flag is off(default), the
213 /// code generator is not allowed to generate mad (multiply add) if the
214 /// result is "less precise" than doing those operations individually.
215 bool LessPreciseFPMAD() { return UnsafeFPMath || LessPreciseFPMADOption; }
216
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000217 /// FiniteOnlyFPMath - This returns true when the -enable-finite-only-fp-math
218 /// option is specified on the command line. If this returns false (default),
219 /// the code generator is not allowed to assume that FP arithmetic arguments
220 /// and results are never NaNs or +-Infs.
221 bool FiniteOnlyFPMath() { return UnsafeFPMath || FiniteOnlyFPMathOption; }
222
223 /// HonorSignDependentRoundingFPMath - Return true if the codegen must assume
224 /// that the rounding mode of the FPU can change from its default.
225 bool HonorSignDependentRoundingFPMath() {
226 return !UnsafeFPMath && HonorSignDependentRoundingFPMathOption;
227 }
228}
229