blob: 600a120e867c559d70e7eb1ac597ad9de4ade752 [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;
Chris Lattnerd74ea2b2006-05-24 17:04:05 +000043}
Misha Brukman0fb5a662004-06-21 21:08:45 +000044
Dan Gohman844731a2008-05-13 00:00:25 +000045static cl::opt<bool, true> PrintCode("print-machineinstrs",
46 cl::desc("Print generated machine code"),
47 cl::location(PrintMachineCode), cl::init(false));
Chris Lattneraa4f1e12007-05-03 00:16:07 +000048
Dan Gohman844731a2008-05-13 00:00:25 +000049static cl::opt<bool, true>
Evan Cheng89df08c2008-05-30 22:39:18 +000050DisableFPElim("disable-fp-elim",
51 cl::desc("Disable frame pointer elimination optimization"),
52 cl::location(NoFramePointerElim),
53 cl::init(false));
Dan Gohman844731a2008-05-13 00:00:25 +000054static cl::opt<bool, true>
55DisableExcessPrecision("disable-excess-fp-precision",
56 cl::desc("Disable optimizations that may increase FP precision"),
57 cl::location(NoExcessFPPrecision),
58 cl::init(false));
59static cl::opt<bool, true>
60EnableUnsafeFPMath("enable-unsafe-fp-math",
61 cl::desc("Enable optimizations that may decrease FP precision"),
62 cl::location(UnsafeFPMath),
63 cl::init(false));
64static cl::opt<bool, true>
65EnableFiniteOnlyFPMath("enable-finite-only-fp-math",
66 cl::desc("Enable optimizations that assumes non- NaNs / +-Infs"),
67 cl::location(FiniteOnlyFPMathOption),
68 cl::init(false));
69static cl::opt<bool, true>
70EnableHonorSignDependentRoundingFPMath(cl::Hidden,
71 "enable-sign-dependent-rounding-fp-math",
72 cl::desc("Force codegen to assume rounding mode can change dynamically"),
73 cl::location(HonorSignDependentRoundingFPMathOption),
74 cl::init(false));
Evan Chengc9ab2f32006-12-09 02:41:30 +000075
Dan Gohman844731a2008-05-13 00:00:25 +000076static cl::opt<bool, true>
77GenerateSoftFloatCalls("soft-float",
78 cl::desc("Generate software floating point library calls"),
79 cl::location(UseSoftFloat),
80 cl::init(false));
81static cl::opt<bool, true>
82DontPlaceZerosInBSS("nozero-initialized-in-bss",
83 cl::desc("Don't place zero-initialized symbols into bss section"),
84 cl::location(NoZerosInBSS),
85 cl::init(false));
86static cl::opt<bool, true>
87EnableExceptionHandling("enable-eh",
88 cl::desc("Emit DWARF exception handling (default if target supports)"),
89 cl::location(ExceptionHandling),
90 cl::init(false));
91static cl::opt<bool, true>
92EnableUnwindTables("unwind-tables",
93 cl::desc("Generate unwinding tables for all functions"),
94 cl::location(UnwindTablesMandatory),
95 cl::init(false));
Arnold Schwaighoferc85e1712007-10-11 19:40:01 +000096
Dan Gohman844731a2008-05-13 00:00:25 +000097static cl::opt<llvm::Reloc::Model, true>
98DefRelocationModel(
99 "relocation-model",
100 cl::desc("Choose relocation model"),
101 cl::location(RelocationModel),
102 cl::init(Reloc::Default),
103 cl::values(
104 clEnumValN(Reloc::Default, "default",
105 " Target default relocation model"),
106 clEnumValN(Reloc::Static, "static",
107 " Non-relocatable code"),
108 clEnumValN(Reloc::PIC_, "pic",
109 " Fully relocatable, position independent code"),
110 clEnumValN(Reloc::DynamicNoPIC, "dynamic-no-pic",
111 " Relocatable external references, non-relocatable code"),
112 clEnumValEnd));
113static cl::opt<llvm::CodeModel::Model, true>
114DefCodeModel(
115 "code-model",
116 cl::desc("Choose code model"),
117 cl::location(CMModel),
118 cl::init(CodeModel::Default),
119 cl::values(
120 clEnumValN(CodeModel::Default, "default",
121 " Target default code model"),
122 clEnumValN(CodeModel::Small, "small",
123 " Small code model"),
124 clEnumValN(CodeModel::Kernel, "kernel",
125 " Kernel code model"),
126 clEnumValN(CodeModel::Medium, "medium",
127 " Medium code model"),
128 clEnumValN(CodeModel::Large, "large",
129 " Large code model"),
130 clEnumValEnd));
Anton Korobeynikov45709ae2008-04-23 18:18:10 +0000131
Dan Gohman844731a2008-05-13 00:00:25 +0000132static cl::opt<bool, true>
133EnablePerformTailCallOpt("tailcallopt",
134 cl::desc("Turn on tail call optimization."),
135 cl::location(PerformTailCallOpt),
136 cl::init(false));
137static cl::opt<bool, true>
138EnableOptimizeForSize("optimize-size",
139 cl::desc("Optimize for size."),
Evan Cheng89df08c2008-05-30 22:39:18 +0000140 cl::location(OptimizeForSize),
141 cl::init(false));
Anton Korobeynikov45709ae2008-04-23 18:18:10 +0000142
Evan Cheng6547e402008-07-01 23:18:29 +0000143static cl::opt<unsigned, true>
144OverrideStackAlignment("stack-alignment",
145 cl::desc("Override default stack alignment"),
146 cl::location(StackAlignment),
147 cl::init(0));
148
Dan Gohman844731a2008-05-13 00:00:25 +0000149static cl::opt<bool, true>
150EnableRealignStack("realign-stack",
151 cl::desc("Realign stack if needed"),
152 cl::location(RealignStack),
153 cl::init(true));
154
Evan Cheng6547e402008-07-01 23:18:29 +0000155static cl::opt<bool, true>
156AsmVerbose("asm-verbose", cl::desc("Add comments to directives."),
157 cl::location(VerboseAsm),
158 cl::init(false));
159
Dale Johannesen72324642008-07-31 18:13:12 +0000160static cl::opt<bool, true>
161DisableSwitchTables(cl::Hidden, "disable-jump-tables",
162 cl::desc("Do not generate jump tables."),
163 cl::location(DisableJumpTables),
164 cl::init(false));
Brian Gaeke323819e2004-03-04 19:16:23 +0000165
166//---------------------------------------------------------------------------
Chris Lattnerf70e0c22003-12-28 21:23:38 +0000167// TargetMachine Class
168//
Misha Brukman167deff2004-08-10 23:10:25 +0000169
Chris Lattnerf70e0c22003-12-28 21:23:38 +0000170TargetMachine::~TargetMachine() {
Jim Laskeyfde1b3b2006-09-07 23:39:26 +0000171 delete AsmInfo;
Chris Lattnerf70e0c22003-12-28 21:23:38 +0000172}
173
Evan Cheng4c1aa862006-02-22 20:19:42 +0000174/// getRelocationModel - Returns the code generation relocation model. The
175/// choices are static, PIC, and dynamic-no-pic, and target default.
176Reloc::Model TargetMachine::getRelocationModel() {
177 return RelocationModel;
178}
179
180/// setRelocationModel - Sets the code generation relocation model.
181void TargetMachine::setRelocationModel(Reloc::Model Model) {
182 RelocationModel = Model;
183}
Evan Cheng80235d52006-05-23 18:18:46 +0000184
Evan Cheng152ed052006-07-06 01:53:36 +0000185/// getCodeModel - Returns the code model. The choices are small, kernel,
186/// medium, large, and target default.
187CodeModel::Model TargetMachine::getCodeModel() {
188 return CMModel;
189}
190
191/// setCodeModel - Sets the code model.
192void TargetMachine::setCodeModel(CodeModel::Model Model) {
193 CMModel = Model;
194}
195
Evan Cheng80235d52006-05-23 18:18:46 +0000196namespace llvm {
197 /// FiniteOnlyFPMath - This returns true when the -enable-finite-only-fp-math
198 /// option is specified on the command line. If this returns false (default),
199 /// the code generator is not allowed to assume that FP arithmetic arguments
200 /// and results are never NaNs or +-Infs.
201 bool FiniteOnlyFPMath() { return UnsafeFPMath || FiniteOnlyFPMathOption; }
Chris Lattneraa4f1e12007-05-03 00:16:07 +0000202
203 /// HonorSignDependentRoundingFPMath - Return true if the codegen must assume
204 /// that the rounding mode of the FPU can change from its default.
205 bool HonorSignDependentRoundingFPMath() {
206 return !UnsafeFPMath && HonorSignDependentRoundingFPMathOption;
207 }
Reid Spencer077b3872006-05-24 19:05:21 +0000208}
Chris Lattner3199af22006-09-04 04:06:01 +0000209