Add missing #include, found by modules build.
[oota-llvm.git] / include / llvm / CodeGen / CommandFlags.h
1 //===-- CommandFlags.h - Command Line Flags Interface -----------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file contains codegen-specific flags that are shared between different
11 // command line tools. The tools "llc" and "opt" both use this file to prevent
12 // flag duplication.
13 //
14 //===----------------------------------------------------------------------===//
15
16 #ifndef LLVM_CODEGEN_COMMANDFLAGS_H
17 #define LLVM_CODEGEN_COMMANDFLAGS_H
18
19 #include "llvm/IR/Module.h"
20 #include "llvm/MC/MCTargetOptionsCommandFlags.h"
21 #include "llvm//MC/SubtargetFeature.h"
22 #include "llvm/Support/CodeGen.h"
23 #include "llvm/Support/CommandLine.h"
24 #include "llvm/Support/Host.h"
25 #include "llvm/Target/TargetMachine.h"
26 #include "llvm/Target/TargetOptions.h"
27 #include <string>
28 using namespace llvm;
29
30 cl::opt<std::string>
31 MArch("march", cl::desc("Architecture to generate code for (see --version)"));
32
33 cl::opt<std::string>
34 MCPU("mcpu",
35      cl::desc("Target a specific cpu type (-mcpu=help for details)"),
36      cl::value_desc("cpu-name"),
37      cl::init(""));
38
39 cl::list<std::string>
40 MAttrs("mattr",
41        cl::CommaSeparated,
42        cl::desc("Target specific attributes (-mattr=help for details)"),
43        cl::value_desc("a1,+a2,-a3,..."));
44
45 cl::opt<Reloc::Model>
46 RelocModel("relocation-model",
47            cl::desc("Choose relocation model"),
48            cl::init(Reloc::Default),
49            cl::values(
50               clEnumValN(Reloc::Default, "default",
51                       "Target default relocation model"),
52               clEnumValN(Reloc::Static, "static",
53                       "Non-relocatable code"),
54               clEnumValN(Reloc::PIC_, "pic",
55                       "Fully relocatable, position independent code"),
56               clEnumValN(Reloc::DynamicNoPIC, "dynamic-no-pic",
57                       "Relocatable external references, non-relocatable code"),
58               clEnumValEnd));
59
60 cl::opt<ThreadModel::Model>
61 TMModel("thread-model",
62         cl::desc("Choose threading model"),
63         cl::init(ThreadModel::POSIX),
64         cl::values(clEnumValN(ThreadModel::POSIX, "posix",
65                               "POSIX thread model"),
66                    clEnumValN(ThreadModel::Single, "single",
67                               "Single thread model"),
68                    clEnumValEnd));
69
70 cl::opt<llvm::CodeModel::Model>
71 CMModel("code-model",
72         cl::desc("Choose code model"),
73         cl::init(CodeModel::Default),
74         cl::values(clEnumValN(CodeModel::Default, "default",
75                               "Target default code model"),
76                    clEnumValN(CodeModel::Small, "small",
77                               "Small code model"),
78                    clEnumValN(CodeModel::Kernel, "kernel",
79                               "Kernel code model"),
80                    clEnumValN(CodeModel::Medium, "medium",
81                               "Medium code model"),
82                    clEnumValN(CodeModel::Large, "large",
83                               "Large code model"),
84                    clEnumValEnd));
85
86 cl::opt<TargetMachine::CodeGenFileType>
87 FileType("filetype", cl::init(TargetMachine::CGFT_AssemblyFile),
88   cl::desc("Choose a file type (not all types are supported by all targets):"),
89   cl::values(
90              clEnumValN(TargetMachine::CGFT_AssemblyFile, "asm",
91                         "Emit an assembly ('.s') file"),
92              clEnumValN(TargetMachine::CGFT_ObjectFile, "obj",
93                         "Emit a native object ('.o') file"),
94              clEnumValN(TargetMachine::CGFT_Null, "null",
95                         "Emit nothing, for performance testing"),
96              clEnumValEnd));
97
98 cl::opt<bool>
99 EnableFPMAD("enable-fp-mad",
100             cl::desc("Enable less precise MAD instructions to be generated"),
101             cl::init(false));
102
103 cl::opt<bool>
104 DisableFPElim("disable-fp-elim",
105               cl::desc("Disable frame pointer elimination optimization"),
106               cl::init(false));
107
108 cl::opt<bool>
109 EnableUnsafeFPMath("enable-unsafe-fp-math",
110                 cl::desc("Enable optimizations that may decrease FP precision"),
111                 cl::init(false));
112
113 cl::opt<bool>
114 EnableNoInfsFPMath("enable-no-infs-fp-math",
115                 cl::desc("Enable FP math optimizations that assume no +-Infs"),
116                 cl::init(false));
117
118 cl::opt<bool>
119 EnableNoNaNsFPMath("enable-no-nans-fp-math",
120                    cl::desc("Enable FP math optimizations that assume no NaNs"),
121                    cl::init(false));
122
123 cl::opt<bool>
124 EnableHonorSignDependentRoundingFPMath("enable-sign-dependent-rounding-fp-math",
125       cl::Hidden,
126       cl::desc("Force codegen to assume rounding mode can change dynamically"),
127       cl::init(false));
128
129 cl::opt<bool>
130 GenerateSoftFloatCalls("soft-float",
131                     cl::desc("Generate software floating point library calls"),
132                     cl::init(false));
133
134 cl::opt<llvm::FloatABI::ABIType>
135 FloatABIForCalls("float-abi",
136                  cl::desc("Choose float ABI type"),
137                  cl::init(FloatABI::Default),
138                  cl::values(
139                      clEnumValN(FloatABI::Default, "default",
140                                 "Target default float ABI type"),
141                      clEnumValN(FloatABI::Soft, "soft",
142                                 "Soft float ABI (implied by -soft-float)"),
143                      clEnumValN(FloatABI::Hard, "hard",
144                                 "Hard float ABI (uses FP registers)"),
145                      clEnumValEnd));
146
147 cl::opt<llvm::FPOpFusion::FPOpFusionMode>
148 FuseFPOps("fp-contract",
149           cl::desc("Enable aggressive formation of fused FP ops"),
150           cl::init(FPOpFusion::Standard),
151           cl::values(
152               clEnumValN(FPOpFusion::Fast, "fast",
153                          "Fuse FP ops whenever profitable"),
154               clEnumValN(FPOpFusion::Standard, "on",
155                          "Only fuse 'blessed' FP ops."),
156               clEnumValN(FPOpFusion::Strict, "off",
157                          "Only fuse FP ops when the result won't be effected."),
158               clEnumValEnd));
159
160 cl::opt<bool>
161 DontPlaceZerosInBSS("nozero-initialized-in-bss",
162               cl::desc("Don't place zero-initialized symbols into bss section"),
163               cl::init(false));
164
165 cl::opt<bool>
166 EnableGuaranteedTailCallOpt("tailcallopt",
167   cl::desc("Turn fastcc calls into tail calls by (potentially) changing ABI."),
168   cl::init(false));
169
170 cl::opt<bool>
171 DisableTailCalls("disable-tail-calls",
172                  cl::desc("Never emit tail calls"),
173                  cl::init(false));
174
175 cl::opt<unsigned>
176 OverrideStackAlignment("stack-alignment",
177                        cl::desc("Override default stack alignment"),
178                        cl::init(0));
179
180 cl::opt<std::string>
181 TrapFuncName("trap-func", cl::Hidden,
182         cl::desc("Emit a call to trap function rather than a trap instruction"),
183         cl::init(""));
184
185 cl::opt<bool>
186 EnablePIE("enable-pie",
187           cl::desc("Assume the creation of a position independent executable."),
188           cl::init(false));
189
190 cl::opt<bool>
191 UseCtors("use-ctors",
192              cl::desc("Use .ctors instead of .init_array."),
193              cl::init(false));
194
195 cl::opt<std::string> StopAfter("stop-after",
196                             cl::desc("Stop compilation after a specific pass"),
197                             cl::value_desc("pass-name"),
198                                       cl::init(""));
199 cl::opt<std::string> StartAfter("start-after",
200                           cl::desc("Resume compilation after a specific pass"),
201                           cl::value_desc("pass-name"),
202                           cl::init(""));
203
204 cl::opt<bool> DataSections("data-sections",
205                            cl::desc("Emit data into separate sections"),
206                            cl::init(false));
207
208 cl::opt<bool>
209 FunctionSections("function-sections",
210                  cl::desc("Emit functions into separate sections"),
211                  cl::init(false));
212
213 cl::opt<bool> UniqueSectionNames("unique-section-names",
214                                  cl::desc("Give unique names to every section"),
215                                  cl::init(true));
216
217 cl::opt<llvm::JumpTable::JumpTableType>
218 JTableType("jump-table-type",
219           cl::desc("Choose the type of Jump-Instruction Table for jumptable."),
220           cl::init(JumpTable::Single),
221           cl::values(
222               clEnumValN(JumpTable::Single, "single",
223                          "Create a single table for all jumptable functions"),
224               clEnumValN(JumpTable::Arity, "arity",
225                          "Create one table per number of parameters."),
226               clEnumValN(JumpTable::Simplified, "simplified",
227                          "Create one table per simplified function type."),
228               clEnumValN(JumpTable::Full, "full",
229                          "Create one table per unique function type."),
230               clEnumValEnd));
231
232 // Common utility function tightly tied to the options listed here. Initializes
233 // a TargetOptions object with CodeGen flags and returns it.
234 static inline TargetOptions InitTargetOptionsFromCodeGenFlags() {
235   TargetOptions Options;
236   Options.LessPreciseFPMADOption = EnableFPMAD;
237   Options.NoFramePointerElim = DisableFPElim;
238   Options.AllowFPOpFusion = FuseFPOps;
239   Options.UnsafeFPMath = EnableUnsafeFPMath;
240   Options.NoInfsFPMath = EnableNoInfsFPMath;
241   Options.NoNaNsFPMath = EnableNoNaNsFPMath;
242   Options.HonorSignDependentRoundingFPMathOption =
243       EnableHonorSignDependentRoundingFPMath;
244   Options.UseSoftFloat = GenerateSoftFloatCalls;
245   if (FloatABIForCalls != FloatABI::Default)
246     Options.FloatABIType = FloatABIForCalls;
247   Options.NoZerosInBSS = DontPlaceZerosInBSS;
248   Options.GuaranteedTailCallOpt = EnableGuaranteedTailCallOpt;
249   Options.DisableTailCalls = DisableTailCalls;
250   Options.StackAlignmentOverride = OverrideStackAlignment;
251   Options.TrapFuncName = TrapFuncName;
252   Options.PositionIndependentExecutable = EnablePIE;
253   Options.UseInitArray = !UseCtors;
254   Options.DataSections = DataSections;
255   Options.FunctionSections = FunctionSections;
256   Options.UniqueSectionNames = UniqueSectionNames;
257
258   Options.MCOptions = InitMCTargetOptionsFromFlags();
259   Options.JTType = JTableType;
260
261   Options.ThreadModel = TMModel;
262
263   return Options;
264 }
265
266 static inline std::string getCPUStr() {
267   // If user asked for the 'native' CPU, autodetect here. If autodection fails,
268   // this will set the CPU to an empty string which tells the target to
269   // pick a basic default.
270   if (MCPU == "native")
271     return sys::getHostCPUName();
272
273   return MCPU;
274 }
275
276 static inline std::string getFeaturesStr() {
277   SubtargetFeatures Features;
278
279   // If user asked for the 'native' CPU, we need to autodetect features.
280   // This is necessary for x86 where the CPU might not support all the
281   // features the autodetected CPU name lists in the target. For example,
282   if (MCPU == "native") {
283     StringMap<bool> HostFeatures;
284     if (sys::getHostCPUFeatures(HostFeatures))
285       for (auto &F : HostFeatures)
286         Features.AddFeature(F.first(), F.second);
287   }
288
289   for (unsigned i = 0; i != MAttrs.size(); ++i)
290     Features.AddFeature(MAttrs[i]);
291
292   return Features.getString();
293 }
294
295 static inline void overrideFunctionAttributes(StringRef CPU, StringRef Features,
296                                               Module &M) {
297   for (auto &F : M) {
298     if (!CPU.empty())
299       llvm::overrideFunctionAttribute("target-cpu", CPU, F);
300
301     if (!Features.empty())
302       llvm::overrideFunctionAttribute("target-features", Features, F);
303   }
304 }
305
306 #endif