blob: 0764968b23011f2d287c3cc17afd3d04d97ab409 [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;
Devang Patela2101692008-03-25 21:02:35 +000038 bool OptimizeForSize;
Anton Korobeynikovb214a522008-04-23 18:18:10 +000039 unsigned StackAlignment;
Evan Cheng0eeed442008-07-01 23:18:29 +000040 bool RealignStack;
41 bool VerboseAsm;
Dan Gohmanf17a25c2007-07-18 16:29:46 +000042}
Dan Gohmanf17a25c2007-07-18 16:29:46 +000043
Dan Gohman089efff2008-05-13 00:00:25 +000044static cl::opt<bool, true> PrintCode("print-machineinstrs",
45 cl::desc("Print generated machine code"),
46 cl::location(PrintMachineCode), cl::init(false));
Dan Gohmanf17a25c2007-07-18 16:29:46 +000047
Dan Gohman089efff2008-05-13 00:00:25 +000048static cl::opt<bool, true>
Evan Cheng94b06762008-05-30 22:39:18 +000049DisableFPElim("disable-fp-elim",
50 cl::desc("Disable frame pointer elimination optimization"),
51 cl::location(NoFramePointerElim),
52 cl::init(false));
Dan Gohman089efff2008-05-13 00:00:25 +000053static cl::opt<bool, true>
54DisableExcessPrecision("disable-excess-fp-precision",
55 cl::desc("Disable optimizations that may increase FP precision"),
56 cl::location(NoExcessFPPrecision),
57 cl::init(false));
58static cl::opt<bool, true>
59EnableUnsafeFPMath("enable-unsafe-fp-math",
60 cl::desc("Enable optimizations that may decrease FP precision"),
61 cl::location(UnsafeFPMath),
62 cl::init(false));
63static cl::opt<bool, true>
64EnableFiniteOnlyFPMath("enable-finite-only-fp-math",
65 cl::desc("Enable optimizations that assumes non- NaNs / +-Infs"),
66 cl::location(FiniteOnlyFPMathOption),
67 cl::init(false));
68static cl::opt<bool, true>
69EnableHonorSignDependentRoundingFPMath(cl::Hidden,
70 "enable-sign-dependent-rounding-fp-math",
71 cl::desc("Force codegen to assume rounding mode can change dynamically"),
72 cl::location(HonorSignDependentRoundingFPMathOption),
73 cl::init(false));
Dan Gohmanf17a25c2007-07-18 16:29:46 +000074
Dan Gohman089efff2008-05-13 00:00:25 +000075static cl::opt<bool, true>
76GenerateSoftFloatCalls("soft-float",
77 cl::desc("Generate software floating point library calls"),
78 cl::location(UseSoftFloat),
79 cl::init(false));
80static cl::opt<bool, true>
81DontPlaceZerosInBSS("nozero-initialized-in-bss",
82 cl::desc("Don't place zero-initialized symbols into bss section"),
83 cl::location(NoZerosInBSS),
84 cl::init(false));
85static cl::opt<bool, true>
86EnableExceptionHandling("enable-eh",
87 cl::desc("Emit DWARF exception handling (default if target supports)"),
88 cl::location(ExceptionHandling),
89 cl::init(false));
90static cl::opt<bool, true>
91EnableUnwindTables("unwind-tables",
92 cl::desc("Generate unwinding tables for all functions"),
93 cl::location(UnwindTablesMandatory),
94 cl::init(false));
Arnold Schwaighofere2d6bbb2007-10-11 19:40:01 +000095
Dan Gohman089efff2008-05-13 00:00:25 +000096static cl::opt<llvm::Reloc::Model, true>
97DefRelocationModel(
98 "relocation-model",
99 cl::desc("Choose relocation model"),
100 cl::location(RelocationModel),
101 cl::init(Reloc::Default),
102 cl::values(
103 clEnumValN(Reloc::Default, "default",
104 " Target default relocation model"),
105 clEnumValN(Reloc::Static, "static",
106 " Non-relocatable code"),
107 clEnumValN(Reloc::PIC_, "pic",
108 " Fully relocatable, position independent code"),
109 clEnumValN(Reloc::DynamicNoPIC, "dynamic-no-pic",
110 " Relocatable external references, non-relocatable code"),
111 clEnumValEnd));
112static cl::opt<llvm::CodeModel::Model, true>
113DefCodeModel(
114 "code-model",
115 cl::desc("Choose code model"),
116 cl::location(CMModel),
117 cl::init(CodeModel::Default),
118 cl::values(
119 clEnumValN(CodeModel::Default, "default",
120 " Target default code model"),
121 clEnumValN(CodeModel::Small, "small",
122 " Small code model"),
123 clEnumValN(CodeModel::Kernel, "kernel",
124 " Kernel code model"),
125 clEnumValN(CodeModel::Medium, "medium",
126 " Medium code model"),
127 clEnumValN(CodeModel::Large, "large",
128 " Large code model"),
129 clEnumValEnd));
Anton Korobeynikovb214a522008-04-23 18:18:10 +0000130
Dan Gohman089efff2008-05-13 00:00:25 +0000131static cl::opt<bool, true>
132EnablePerformTailCallOpt("tailcallopt",
133 cl::desc("Turn on tail call optimization."),
134 cl::location(PerformTailCallOpt),
135 cl::init(false));
136static cl::opt<bool, true>
137EnableOptimizeForSize("optimize-size",
138 cl::desc("Optimize for size."),
Evan Cheng94b06762008-05-30 22:39:18 +0000139 cl::location(OptimizeForSize),
140 cl::init(false));
Anton Korobeynikovb214a522008-04-23 18:18:10 +0000141
Evan Cheng0eeed442008-07-01 23:18:29 +0000142static cl::opt<unsigned, true>
143OverrideStackAlignment("stack-alignment",
144 cl::desc("Override default stack alignment"),
145 cl::location(StackAlignment),
146 cl::init(0));
147
Dan Gohman089efff2008-05-13 00:00:25 +0000148static cl::opt<bool, true>
149EnableRealignStack("realign-stack",
150 cl::desc("Realign stack if needed"),
151 cl::location(RealignStack),
152 cl::init(true));
153
Evan Cheng0eeed442008-07-01 23:18:29 +0000154static cl::opt<bool, true>
155AsmVerbose("asm-verbose", cl::desc("Add comments to directives."),
156 cl::location(VerboseAsm),
157 cl::init(false));
158
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000159
160//---------------------------------------------------------------------------
161// TargetMachine Class
162//
163
164TargetMachine::~TargetMachine() {
165 delete AsmInfo;
166}
167
168/// getRelocationModel - Returns the code generation relocation model. The
169/// choices are static, PIC, and dynamic-no-pic, and target default.
170Reloc::Model TargetMachine::getRelocationModel() {
171 return RelocationModel;
172}
173
174/// setRelocationModel - Sets the code generation relocation model.
175void TargetMachine::setRelocationModel(Reloc::Model Model) {
176 RelocationModel = Model;
177}
178
179/// getCodeModel - Returns the code model. The choices are small, kernel,
180/// medium, large, and target default.
181CodeModel::Model TargetMachine::getCodeModel() {
182 return CMModel;
183}
184
185/// setCodeModel - Sets the code model.
186void TargetMachine::setCodeModel(CodeModel::Model Model) {
187 CMModel = Model;
188}
189
190namespace llvm {
191 /// FiniteOnlyFPMath - This returns true when the -enable-finite-only-fp-math
192 /// option is specified on the command line. If this returns false (default),
193 /// the code generator is not allowed to assume that FP arithmetic arguments
194 /// and results are never NaNs or +-Infs.
195 bool FiniteOnlyFPMath() { return UnsafeFPMath || FiniteOnlyFPMathOption; }
196
197 /// HonorSignDependentRoundingFPMath - Return true if the codegen must assume
198 /// that the rounding mode of the FPU can change from its default.
199 bool HonorSignDependentRoundingFPMath() {
200 return !UnsafeFPMath && HonorSignDependentRoundingFPMathOption;
201 }
202}
203