blob: 49f1e4dfaae6c29e61d2a7de94e2d0b152b0d3b4 [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 {
25 bool PrintMachineCode;
26 bool NoFramePointerElim;
27 bool NoExcessFPPrecision;
28 bool UnsafeFPMath;
29 bool FiniteOnlyFPMathOption;
30 bool HonorSignDependentRoundingFPMathOption;
31 bool UseSoftFloat;
32 bool NoZerosInBSS;
33 bool ExceptionHandling;
Dale Johannesenb369e8d2008-04-14 17:54:17 +000034 bool UnwindTablesMandatory;
Dan Gohmanf17a25c2007-07-18 16:29:46 +000035 Reloc::Model RelocationModel;
36 CodeModel::Model CMModel;
Arnold Schwaighofere2d6bbb2007-10-11 19:40:01 +000037 bool PerformTailCallOpt;
Anton Korobeynikovb214a522008-04-23 18:18:10 +000038 unsigned StackAlignment;
Evan Cheng0eeed442008-07-01 23:18:29 +000039 bool RealignStack;
40 bool VerboseAsm;
Dale Johannesen493492f2008-07-31 18:13:12 +000041 bool DisableJumpTables;
Owen Andersonbac9ae22008-10-07 20:22:28 +000042 bool StrongPHIElim;
Dan Gohmanb3e9a712009-01-26 22:22:31 +000043 bool DisableRedZone;
Dan Gohmanf17a25c2007-07-18 16:29:46 +000044}
Dan Gohmanf17a25c2007-07-18 16:29:46 +000045
Dan Gohman089efff2008-05-13 00:00:25 +000046static cl::opt<bool, true> PrintCode("print-machineinstrs",
47 cl::desc("Print generated machine code"),
48 cl::location(PrintMachineCode), cl::init(false));
Dan Gohmanf17a25c2007-07-18 16:29:46 +000049
Dan Gohman089efff2008-05-13 00:00:25 +000050static cl::opt<bool, true>
Evan Cheng94b06762008-05-30 22:39:18 +000051DisableFPElim("disable-fp-elim",
52 cl::desc("Disable frame pointer elimination optimization"),
53 cl::location(NoFramePointerElim),
54 cl::init(false));
Dan Gohman089efff2008-05-13 00:00:25 +000055static cl::opt<bool, true>
56DisableExcessPrecision("disable-excess-fp-precision",
57 cl::desc("Disable optimizations that may increase FP precision"),
58 cl::location(NoExcessFPPrecision),
59 cl::init(false));
60static cl::opt<bool, true>
61EnableUnsafeFPMath("enable-unsafe-fp-math",
62 cl::desc("Enable optimizations that may decrease FP precision"),
63 cl::location(UnsafeFPMath),
64 cl::init(false));
65static cl::opt<bool, true>
66EnableFiniteOnlyFPMath("enable-finite-only-fp-math",
67 cl::desc("Enable optimizations that assumes non- NaNs / +-Infs"),
68 cl::location(FiniteOnlyFPMathOption),
69 cl::init(false));
70static cl::opt<bool, true>
71EnableHonorSignDependentRoundingFPMath(cl::Hidden,
72 "enable-sign-dependent-rounding-fp-math",
73 cl::desc("Force codegen to assume rounding mode can change dynamically"),
74 cl::location(HonorSignDependentRoundingFPMathOption),
75 cl::init(false));
Dan Gohmanf17a25c2007-07-18 16:29:46 +000076
Dan Gohman089efff2008-05-13 00:00:25 +000077static cl::opt<bool, true>
78GenerateSoftFloatCalls("soft-float",
79 cl::desc("Generate software floating point library calls"),
80 cl::location(UseSoftFloat),
81 cl::init(false));
82static cl::opt<bool, true>
83DontPlaceZerosInBSS("nozero-initialized-in-bss",
84 cl::desc("Don't place zero-initialized symbols into bss section"),
85 cl::location(NoZerosInBSS),
86 cl::init(false));
87static cl::opt<bool, true>
88EnableExceptionHandling("enable-eh",
89 cl::desc("Emit DWARF exception handling (default if target supports)"),
90 cl::location(ExceptionHandling),
91 cl::init(false));
92static cl::opt<bool, true>
93EnableUnwindTables("unwind-tables",
94 cl::desc("Generate unwinding tables for all functions"),
95 cl::location(UnwindTablesMandatory),
96 cl::init(false));
Arnold Schwaighofere2d6bbb2007-10-11 19:40:01 +000097
Dan Gohman089efff2008-05-13 00:00:25 +000098static cl::opt<llvm::Reloc::Model, true>
99DefRelocationModel(
100 "relocation-model",
101 cl::desc("Choose relocation model"),
102 cl::location(RelocationModel),
103 cl::init(Reloc::Default),
104 cl::values(
105 clEnumValN(Reloc::Default, "default",
Dan Gohman669b9bf2008-10-14 20:25:08 +0000106 "Target default relocation model"),
Dan Gohman089efff2008-05-13 00:00:25 +0000107 clEnumValN(Reloc::Static, "static",
Dan Gohman669b9bf2008-10-14 20:25:08 +0000108 "Non-relocatable code"),
Dan Gohman089efff2008-05-13 00:00:25 +0000109 clEnumValN(Reloc::PIC_, "pic",
Dan Gohman669b9bf2008-10-14 20:25:08 +0000110 "Fully relocatable, position independent code"),
Dan Gohman089efff2008-05-13 00:00:25 +0000111 clEnumValN(Reloc::DynamicNoPIC, "dynamic-no-pic",
Dan Gohman669b9bf2008-10-14 20:25:08 +0000112 "Relocatable external references, non-relocatable code"),
Dan Gohman089efff2008-05-13 00:00:25 +0000113 clEnumValEnd));
114static cl::opt<llvm::CodeModel::Model, true>
115DefCodeModel(
116 "code-model",
117 cl::desc("Choose code model"),
118 cl::location(CMModel),
119 cl::init(CodeModel::Default),
120 cl::values(
121 clEnumValN(CodeModel::Default, "default",
Dan Gohman669b9bf2008-10-14 20:25:08 +0000122 "Target default code model"),
Dan Gohman089efff2008-05-13 00:00:25 +0000123 clEnumValN(CodeModel::Small, "small",
Dan Gohman669b9bf2008-10-14 20:25:08 +0000124 "Small code model"),
Dan Gohman089efff2008-05-13 00:00:25 +0000125 clEnumValN(CodeModel::Kernel, "kernel",
Dan Gohman669b9bf2008-10-14 20:25:08 +0000126 "Kernel code model"),
Dan Gohman089efff2008-05-13 00:00:25 +0000127 clEnumValN(CodeModel::Medium, "medium",
Dan Gohman669b9bf2008-10-14 20:25:08 +0000128 "Medium code model"),
Dan Gohman089efff2008-05-13 00:00:25 +0000129 clEnumValN(CodeModel::Large, "large",
Dan Gohman669b9bf2008-10-14 20:25:08 +0000130 "Large code model"),
Dan Gohman089efff2008-05-13 00:00:25 +0000131 clEnumValEnd));
Anton Korobeynikovb214a522008-04-23 18:18:10 +0000132
Dan Gohman089efff2008-05-13 00:00:25 +0000133static cl::opt<bool, true>
134EnablePerformTailCallOpt("tailcallopt",
135 cl::desc("Turn on tail call optimization."),
136 cl::location(PerformTailCallOpt),
137 cl::init(false));
Anton Korobeynikovb214a522008-04-23 18:18:10 +0000138
Evan Cheng0eeed442008-07-01 23:18:29 +0000139static cl::opt<unsigned, true>
140OverrideStackAlignment("stack-alignment",
141 cl::desc("Override default stack alignment"),
142 cl::location(StackAlignment),
143 cl::init(0));
144
Dan Gohman089efff2008-05-13 00:00:25 +0000145static cl::opt<bool, true>
146EnableRealignStack("realign-stack",
147 cl::desc("Realign stack if needed"),
148 cl::location(RealignStack),
149 cl::init(true));
150
Evan Cheng0eeed442008-07-01 23:18:29 +0000151static cl::opt<bool, true>
152AsmVerbose("asm-verbose", cl::desc("Add comments to directives."),
153 cl::location(VerboseAsm),
154 cl::init(false));
155
Dale Johannesen493492f2008-07-31 18:13:12 +0000156static cl::opt<bool, true>
157DisableSwitchTables(cl::Hidden, "disable-jump-tables",
158 cl::desc("Do not generate jump tables."),
159 cl::location(DisableJumpTables),
160 cl::init(false));
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000161
Owen Andersonbac9ae22008-10-07 20:22:28 +0000162static cl::opt<bool, true>
163EnableStrongPHIElim(cl::Hidden, "strong-phi-elim",
164 cl::desc("Use strong PHI elimination."),
165 cl::location(StrongPHIElim),
166 cl::init(false));
167
Dan Gohmanb3e9a712009-01-26 22:22:31 +0000168static cl::opt<bool, true>
169DisableRedZoneOption("disable-red-zone",
170 cl::desc("Do not emit code that uses the red zone."),
171 cl::location(DisableRedZone),
Dan Gohmand37535f2009-01-27 00:58:47 +0000172 cl::init(false));
Dan Gohmanb3e9a712009-01-26 22:22:31 +0000173
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000174//---------------------------------------------------------------------------
175// TargetMachine Class
176//
177
178TargetMachine::~TargetMachine() {
179 delete AsmInfo;
180}
181
182/// getRelocationModel - Returns the code generation relocation model. The
183/// choices are static, PIC, and dynamic-no-pic, and target default.
184Reloc::Model TargetMachine::getRelocationModel() {
185 return RelocationModel;
186}
187
188/// setRelocationModel - Sets the code generation relocation model.
189void TargetMachine::setRelocationModel(Reloc::Model Model) {
190 RelocationModel = Model;
191}
192
193/// getCodeModel - Returns the code model. The choices are small, kernel,
194/// medium, large, and target default.
195CodeModel::Model TargetMachine::getCodeModel() {
196 return CMModel;
197}
198
199/// setCodeModel - Sets the code model.
200void TargetMachine::setCodeModel(CodeModel::Model Model) {
201 CMModel = Model;
202}
203
204namespace llvm {
205 /// FiniteOnlyFPMath - This returns true when the -enable-finite-only-fp-math
206 /// option is specified on the command line. If this returns false (default),
207 /// the code generator is not allowed to assume that FP arithmetic arguments
208 /// and results are never NaNs or +-Infs.
209 bool FiniteOnlyFPMath() { return UnsafeFPMath || FiniteOnlyFPMathOption; }
210
211 /// HonorSignDependentRoundingFPMath - Return true if the codegen must assume
212 /// that the rounding mode of the FPU can change from its default.
213 bool HonorSignDependentRoundingFPMath() {
214 return !UnsafeFPMath && HonorSignDependentRoundingFPMathOption;
215 }
216}
217