blob: 29167631baab5769bee412f8aeba67dc39fc2fb0 [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 {
25 bool PrintMachineCode;
26 bool NoFramePointerElim;
Chris Lattner45554a62005-01-15 06:00:32 +000027 bool NoExcessFPPrecision;
Chris Lattner34f74a62005-04-30 04:09:52 +000028 bool UnsafeFPMath;
Evan Cheng80235d52006-05-23 18:18:46 +000029 bool FiniteOnlyFPMathOption;
Chris Lattnera7ad3d12007-05-03 00:27:11 +000030 bool HonorSignDependentRoundingFPMathOption;
Evan Chengc9ab2f32006-12-09 02:41:30 +000031 bool UseSoftFloat;
Anton Korobeynikov5032e5a2007-01-17 10:33:08 +000032 bool NoZerosInBSS;
Jim Laskey1b340dc2007-01-29 20:48:32 +000033 bool ExceptionHandling;
Dale Johannesen3541af72008-04-14 17:54:17 +000034 bool UnwindTablesMandatory;
Evan Cheng4c1aa862006-02-22 20:19:42 +000035 Reloc::Model RelocationModel;
Evan Cheng152ed052006-07-06 01:53:36 +000036 CodeModel::Model CMModel;
Arnold Schwaighoferc85e1712007-10-11 19:40:01 +000037 bool PerformTailCallOpt;
Devang Patel55c666a2008-03-25 21:02:35 +000038 bool OptimizeForSize;
Anton Korobeynikov45709ae2008-04-23 18:18:10 +000039 unsigned StackAlignment;
Evan Cheng6547e402008-07-01 23:18:29 +000040 bool RealignStack;
41 bool VerboseAsm;
Dale Johannesen72324642008-07-31 18:13:12 +000042 bool DisableJumpTables;
Owen Andersonbd3ba462008-08-04 23:54:43 +000043 bool DisableCorrectBranchFolding;
Chris Lattnerd74ea2b2006-05-24 17:04:05 +000044}
Misha Brukman0fb5a662004-06-21 21:08:45 +000045
Dan Gohman844731a2008-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));
Chris Lattneraa4f1e12007-05-03 00:16:07 +000049
Dan Gohman844731a2008-05-13 00:00:25 +000050static cl::opt<bool, true>
Evan Cheng89df08c2008-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 Gohman844731a2008-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));
Evan Chengc9ab2f32006-12-09 02:41:30 +000076
Dan Gohman844731a2008-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 Schwaighoferc85e1712007-10-11 19:40:01 +000097
Dan Gohman844731a2008-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",
106 " Target default relocation model"),
107 clEnumValN(Reloc::Static, "static",
108 " Non-relocatable code"),
109 clEnumValN(Reloc::PIC_, "pic",
110 " Fully relocatable, position independent code"),
111 clEnumValN(Reloc::DynamicNoPIC, "dynamic-no-pic",
112 " Relocatable external references, non-relocatable code"),
113 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",
122 " Target default code model"),
123 clEnumValN(CodeModel::Small, "small",
124 " Small code model"),
125 clEnumValN(CodeModel::Kernel, "kernel",
126 " Kernel code model"),
127 clEnumValN(CodeModel::Medium, "medium",
128 " Medium code model"),
129 clEnumValN(CodeModel::Large, "large",
130 " Large code model"),
131 clEnumValEnd));
Anton Korobeynikov45709ae2008-04-23 18:18:10 +0000132
Dan Gohman844731a2008-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));
138static cl::opt<bool, true>
139EnableOptimizeForSize("optimize-size",
140 cl::desc("Optimize for size."),
Evan Cheng89df08c2008-05-30 22:39:18 +0000141 cl::location(OptimizeForSize),
142 cl::init(false));
Anton Korobeynikov45709ae2008-04-23 18:18:10 +0000143
Evan Cheng6547e402008-07-01 23:18:29 +0000144static cl::opt<unsigned, true>
145OverrideStackAlignment("stack-alignment",
146 cl::desc("Override default stack alignment"),
147 cl::location(StackAlignment),
148 cl::init(0));
149
Dan Gohman844731a2008-05-13 00:00:25 +0000150static cl::opt<bool, true>
151EnableRealignStack("realign-stack",
152 cl::desc("Realign stack if needed"),
153 cl::location(RealignStack),
154 cl::init(true));
155
Evan Cheng6547e402008-07-01 23:18:29 +0000156static cl::opt<bool, true>
157AsmVerbose("asm-verbose", cl::desc("Add comments to directives."),
158 cl::location(VerboseAsm),
159 cl::init(false));
160
Dale Johannesen72324642008-07-31 18:13:12 +0000161static cl::opt<bool, true>
162DisableSwitchTables(cl::Hidden, "disable-jump-tables",
163 cl::desc("Do not generate jump tables."),
164 cl::location(DisableJumpTables),
165 cl::init(false));
Brian Gaeke323819e2004-03-04 19:16:23 +0000166
Owen Andersonbd3ba462008-08-04 23:54:43 +0000167static cl::opt<bool, true>
168DisableCorrectISelFolding(cl::Hidden, "disable-correct-folding",
169cl::desc("Do not perform correct branch folding in the instruction selector."),
170cl::location(DisableCorrectBranchFolding), cl::init(false));
171
Brian Gaeke323819e2004-03-04 19:16:23 +0000172//---------------------------------------------------------------------------
Chris Lattnerf70e0c22003-12-28 21:23:38 +0000173// TargetMachine Class
174//
Misha Brukman167deff2004-08-10 23:10:25 +0000175
Chris Lattnerf70e0c22003-12-28 21:23:38 +0000176TargetMachine::~TargetMachine() {
Jim Laskeyfde1b3b2006-09-07 23:39:26 +0000177 delete AsmInfo;
Chris Lattnerf70e0c22003-12-28 21:23:38 +0000178}
179
Evan Cheng4c1aa862006-02-22 20:19:42 +0000180/// 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}
Evan Cheng80235d52006-05-23 18:18:46 +0000190
Evan Cheng152ed052006-07-06 01:53:36 +0000191/// 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 Cheng80235d52006-05-23 18:18:46 +0000202namespace llvm {
203 /// FiniteOnlyFPMath - This returns true when the -enable-finite-only-fp-math
204 /// option is specified on the command line. If this returns false (default),
205 /// the code generator is not allowed to assume that FP arithmetic arguments
206 /// and results are never NaNs or +-Infs.
207 bool FiniteOnlyFPMath() { return UnsafeFPMath || FiniteOnlyFPMathOption; }
Chris Lattneraa4f1e12007-05-03 00:16:07 +0000208
209 /// HonorSignDependentRoundingFPMath - Return true if the codegen must assume
210 /// that the rounding mode of the FPU can change from its default.
211 bool HonorSignDependentRoundingFPMath() {
212 return !UnsafeFPMath && HonorSignDependentRoundingFPMathOption;
213 }
Reid Spencer077b3872006-05-24 19:05:21 +0000214}
Chris Lattner3199af22006-09-04 04:06:01 +0000215