blob: dea293b502ca870afe841276dc340ab744a35b20 [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;
Evan Cheng42ceb472009-03-25 01:47:28 +000044 bool AsmVerbosityDefault(false);
Dan Gohmanf17a25c2007-07-18 16:29:46 +000045}
Dan Gohmanf17a25c2007-07-18 16:29:46 +000046
Bill Wendling042eda32009-03-11 22:30:01 +000047static cl::opt<bool, true>
48PrintCode("print-machineinstrs",
Dan Gohman089efff2008-05-13 00:00:25 +000049 cl::desc("Print generated machine code"),
50 cl::location(PrintMachineCode), cl::init(false));
Dan Gohman089efff2008-05-13 00:00:25 +000051static cl::opt<bool, true>
Evan Cheng94b06762008-05-30 22:39:18 +000052DisableFPElim("disable-fp-elim",
Bill Wendling042eda32009-03-11 22:30:01 +000053 cl::desc("Disable frame pointer elimination optimization"),
54 cl::location(NoFramePointerElim),
55 cl::init(false));
Dan Gohman089efff2008-05-13 00:00:25 +000056static cl::opt<bool, true>
57DisableExcessPrecision("disable-excess-fp-precision",
Bill Wendling042eda32009-03-11 22:30:01 +000058 cl::desc("Disable optimizations that may increase FP precision"),
59 cl::location(NoExcessFPPrecision),
60 cl::init(false));
Dan Gohman089efff2008-05-13 00:00:25 +000061static cl::opt<bool, true>
Mon P Wang473bc862009-03-20 05:06:58 +000062EnableFPMAD("enable-fp-mad",
63 cl::desc("Enable less precise MAD instructions to be generated"),
64 cl::location(LessPreciseFPMADOption),
65 cl::init(false));
66static cl::opt<bool, true>
Dan Gohman089efff2008-05-13 00:00:25 +000067EnableUnsafeFPMath("enable-unsafe-fp-math",
Bill Wendling042eda32009-03-11 22:30:01 +000068 cl::desc("Enable optimizations that may decrease FP precision"),
69 cl::location(UnsafeFPMath),
70 cl::init(false));
Dan Gohman089efff2008-05-13 00:00:25 +000071static cl::opt<bool, true>
72EnableFiniteOnlyFPMath("enable-finite-only-fp-math",
Bill Wendling042eda32009-03-11 22:30:01 +000073 cl::desc("Enable optimizations that assumes non- NaNs / +-Infs"),
74 cl::location(FiniteOnlyFPMathOption),
75 cl::init(false));
Dan Gohman089efff2008-05-13 00:00:25 +000076static cl::opt<bool, true>
Bill Wendling042eda32009-03-11 22:30:01 +000077EnableHonorSignDependentRoundingFPMath("enable-sign-dependent-rounding-fp-math",
78 cl::Hidden,
79 cl::desc("Force codegen to assume rounding mode can change dynamically"),
80 cl::location(HonorSignDependentRoundingFPMathOption),
81 cl::init(false));
Dan Gohman089efff2008-05-13 00:00:25 +000082static cl::opt<bool, true>
83GenerateSoftFloatCalls("soft-float",
Bill Wendling042eda32009-03-11 22:30:01 +000084 cl::desc("Generate software floating point library calls"),
85 cl::location(UseSoftFloat),
86 cl::init(false));
87static cl::opt<bool, true>
Dan Gohman089efff2008-05-13 00:00:25 +000088DontPlaceZerosInBSS("nozero-initialized-in-bss",
Bill Wendling042eda32009-03-11 22:30:01 +000089 cl::desc("Don't place zero-initialized symbols into bss section"),
90 cl::location(NoZerosInBSS),
91 cl::init(false));
Dan Gohman089efff2008-05-13 00:00:25 +000092static cl::opt<bool, true>
93EnableExceptionHandling("enable-eh",
Bill Wendling042eda32009-03-11 22:30:01 +000094 cl::desc("Emit DWARF exception handling (default if target supports)"),
95 cl::location(ExceptionHandling),
96 cl::init(false));
Dan Gohman089efff2008-05-13 00:00:25 +000097static cl::opt<bool, true>
98EnableUnwindTables("unwind-tables",
Bill Wendling042eda32009-03-11 22:30:01 +000099 cl::desc("Generate unwinding tables for all functions"),
100 cl::location(UnwindTablesMandatory),
101 cl::init(false));
Arnold Schwaighofere2d6bbb2007-10-11 19:40:01 +0000102
Dan Gohman089efff2008-05-13 00:00:25 +0000103static cl::opt<llvm::Reloc::Model, true>
Bill Wendling042eda32009-03-11 22:30:01 +0000104DefRelocationModel("relocation-model",
Dan Gohman089efff2008-05-13 00:00:25 +0000105 cl::desc("Choose relocation model"),
106 cl::location(RelocationModel),
107 cl::init(Reloc::Default),
108 cl::values(
109 clEnumValN(Reloc::Default, "default",
Dan Gohman669b9bf2008-10-14 20:25:08 +0000110 "Target default relocation model"),
Dan Gohman089efff2008-05-13 00:00:25 +0000111 clEnumValN(Reloc::Static, "static",
Dan Gohman669b9bf2008-10-14 20:25:08 +0000112 "Non-relocatable code"),
Dan Gohman089efff2008-05-13 00:00:25 +0000113 clEnumValN(Reloc::PIC_, "pic",
Dan Gohman669b9bf2008-10-14 20:25:08 +0000114 "Fully relocatable, position independent code"),
Dan Gohman089efff2008-05-13 00:00:25 +0000115 clEnumValN(Reloc::DynamicNoPIC, "dynamic-no-pic",
Dan Gohman669b9bf2008-10-14 20:25:08 +0000116 "Relocatable external references, non-relocatable code"),
Dan Gohman089efff2008-05-13 00:00:25 +0000117 clEnumValEnd));
118static cl::opt<llvm::CodeModel::Model, true>
Bill Wendling042eda32009-03-11 22:30:01 +0000119DefCodeModel("code-model",
Dan Gohman089efff2008-05-13 00:00:25 +0000120 cl::desc("Choose code model"),
121 cl::location(CMModel),
122 cl::init(CodeModel::Default),
123 cl::values(
124 clEnumValN(CodeModel::Default, "default",
Dan Gohman669b9bf2008-10-14 20:25:08 +0000125 "Target default code model"),
Dan Gohman089efff2008-05-13 00:00:25 +0000126 clEnumValN(CodeModel::Small, "small",
Dan Gohman669b9bf2008-10-14 20:25:08 +0000127 "Small code model"),
Dan Gohman089efff2008-05-13 00:00:25 +0000128 clEnumValN(CodeModel::Kernel, "kernel",
Dan Gohman669b9bf2008-10-14 20:25:08 +0000129 "Kernel code model"),
Dan Gohman089efff2008-05-13 00:00:25 +0000130 clEnumValN(CodeModel::Medium, "medium",
Dan Gohman669b9bf2008-10-14 20:25:08 +0000131 "Medium code model"),
Dan Gohman089efff2008-05-13 00:00:25 +0000132 clEnumValN(CodeModel::Large, "large",
Dan Gohman669b9bf2008-10-14 20:25:08 +0000133 "Large code model"),
Dan Gohman089efff2008-05-13 00:00:25 +0000134 clEnumValEnd));
Dan Gohman089efff2008-05-13 00:00:25 +0000135static cl::opt<bool, true>
136EnablePerformTailCallOpt("tailcallopt",
Bill Wendling042eda32009-03-11 22:30:01 +0000137 cl::desc("Turn on tail call optimization."),
138 cl::location(PerformTailCallOpt),
139 cl::init(false));
Evan Cheng0eeed442008-07-01 23:18:29 +0000140static cl::opt<unsigned, true>
141OverrideStackAlignment("stack-alignment",
Bill Wendling042eda32009-03-11 22:30:01 +0000142 cl::desc("Override default stack alignment"),
143 cl::location(StackAlignment),
144 cl::init(0));
Dan Gohman089efff2008-05-13 00:00:25 +0000145static cl::opt<bool, true>
146EnableRealignStack("realign-stack",
Bill Wendling042eda32009-03-11 22:30:01 +0000147 cl::desc("Realign stack if needed"),
148 cl::location(RealignStack),
149 cl::init(true));
Evan Cheng0eeed442008-07-01 23:18:29 +0000150static cl::opt<bool, true>
Dale Johannesen493492f2008-07-31 18:13:12 +0000151DisableSwitchTables(cl::Hidden, "disable-jump-tables",
Bill Wendling042eda32009-03-11 22:30:01 +0000152 cl::desc("Do not generate jump tables."),
153 cl::location(DisableJumpTables),
154 cl::init(false));
Owen Andersonbac9ae22008-10-07 20:22:28 +0000155static cl::opt<bool, true>
156EnableStrongPHIElim(cl::Hidden, "strong-phi-elim",
Bill Wendling042eda32009-03-11 22:30:01 +0000157 cl::desc("Use strong PHI elimination."),
158 cl::location(StrongPHIElim),
159 cl::init(false));
Dan Gohmanb3e9a712009-01-26 22:22:31 +0000160
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000161//---------------------------------------------------------------------------
162// TargetMachine Class
163//
164
165TargetMachine::~TargetMachine() {
166 delete AsmInfo;
167}
168
169/// getRelocationModel - Returns the code generation relocation model. The
170/// choices are static, PIC, and dynamic-no-pic, and target default.
171Reloc::Model TargetMachine::getRelocationModel() {
172 return RelocationModel;
173}
174
175/// setRelocationModel - Sets the code generation relocation model.
176void TargetMachine::setRelocationModel(Reloc::Model Model) {
177 RelocationModel = Model;
178}
179
180/// getCodeModel - Returns the code model. The choices are small, kernel,
181/// medium, large, and target default.
182CodeModel::Model TargetMachine::getCodeModel() {
183 return CMModel;
184}
185
186/// setCodeModel - Sets the code model.
187void TargetMachine::setCodeModel(CodeModel::Model Model) {
188 CMModel = Model;
189}
190
Evan Cheng42ceb472009-03-25 01:47:28 +0000191bool TargetMachine::getAsmVerbosityDefault() {
192 return AsmVerbosityDefault;
193}
194
195void TargetMachine::setAsmVerbosityDefault(bool V) {
196 AsmVerbosityDefault = V;
197}
198
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000199namespace llvm {
Mon P Wang473bc862009-03-20 05:06:58 +0000200 /// LessPreciseFPMAD - This flag return true when -enable-fp-mad option
201 /// is specified on the command line. When this flag is off(default), the
202 /// code generator is not allowed to generate mad (multiply add) if the
203 /// result is "less precise" than doing those operations individually.
204 bool LessPreciseFPMAD() { return UnsafeFPMath || LessPreciseFPMADOption; }
205
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000206 /// FiniteOnlyFPMath - This returns true when the -enable-finite-only-fp-math
207 /// option is specified on the command line. If this returns false (default),
208 /// the code generator is not allowed to assume that FP arithmetic arguments
209 /// and results are never NaNs or +-Infs.
210 bool FiniteOnlyFPMath() { return UnsafeFPMath || FiniteOnlyFPMathOption; }
211
212 /// HonorSignDependentRoundingFPMath - Return true if the codegen must assume
213 /// that the rounding mode of the FPU can change from its default.
214 bool HonorSignDependentRoundingFPMath() {
215 return !UnsafeFPMath && HonorSignDependentRoundingFPMathOption;
216 }
217}
218