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