[opaque pointer type] Allow gep_type_iterator to work with the pointee type from...
[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<llvm::FloatABI::ABIType>
130 FloatABIForCalls("float-abi",
131                  cl::desc("Choose float ABI type"),
132                  cl::init(FloatABI::Default),
133                  cl::values(
134                      clEnumValN(FloatABI::Default, "default",
135                                 "Target default float ABI type"),
136                      clEnumValN(FloatABI::Soft, "soft",
137                                 "Soft float ABI (implied by -soft-float)"),
138                      clEnumValN(FloatABI::Hard, "hard",
139                                 "Hard float ABI (uses FP registers)"),
140                      clEnumValEnd));
141
142 cl::opt<llvm::FPOpFusion::FPOpFusionMode>
143 FuseFPOps("fp-contract",
144           cl::desc("Enable aggressive formation of fused FP ops"),
145           cl::init(FPOpFusion::Standard),
146           cl::values(
147               clEnumValN(FPOpFusion::Fast, "fast",
148                          "Fuse FP ops whenever profitable"),
149               clEnumValN(FPOpFusion::Standard, "on",
150                          "Only fuse 'blessed' FP ops."),
151               clEnumValN(FPOpFusion::Strict, "off",
152                          "Only fuse FP ops when the result won't be effected."),
153               clEnumValEnd));
154
155 cl::opt<bool>
156 DontPlaceZerosInBSS("nozero-initialized-in-bss",
157               cl::desc("Don't place zero-initialized symbols into bss section"),
158               cl::init(false));
159
160 cl::opt<bool>
161 EnableGuaranteedTailCallOpt("tailcallopt",
162   cl::desc("Turn fastcc calls into tail calls by (potentially) changing ABI."),
163   cl::init(false));
164
165 cl::opt<bool>
166 DisableTailCalls("disable-tail-calls",
167                  cl::desc("Never emit tail calls"),
168                  cl::init(false));
169
170 cl::opt<unsigned>
171 OverrideStackAlignment("stack-alignment",
172                        cl::desc("Override default stack alignment"),
173                        cl::init(0));
174
175 cl::opt<std::string>
176 TrapFuncName("trap-func", cl::Hidden,
177         cl::desc("Emit a call to trap function rather than a trap instruction"),
178         cl::init(""));
179
180 cl::opt<bool>
181 EnablePIE("enable-pie",
182           cl::desc("Assume the creation of a position independent executable."),
183           cl::init(false));
184
185 cl::opt<bool>
186 UseCtors("use-ctors",
187              cl::desc("Use .ctors instead of .init_array."),
188              cl::init(false));
189
190 cl::opt<std::string> StopAfter("stop-after",
191                             cl::desc("Stop compilation after a specific pass"),
192                             cl::value_desc("pass-name"),
193                                       cl::init(""));
194 cl::opt<std::string> StartAfter("start-after",
195                           cl::desc("Resume compilation after a specific pass"),
196                           cl::value_desc("pass-name"),
197                           cl::init(""));
198
199 cl::opt<bool> DataSections("data-sections",
200                            cl::desc("Emit data into separate sections"),
201                            cl::init(false));
202
203 cl::opt<bool>
204 FunctionSections("function-sections",
205                  cl::desc("Emit functions into separate sections"),
206                  cl::init(false));
207
208 cl::opt<bool> UniqueSectionNames("unique-section-names",
209                                  cl::desc("Give unique names to every section"),
210                                  cl::init(true));
211
212 cl::opt<llvm::JumpTable::JumpTableType>
213 JTableType("jump-table-type",
214           cl::desc("Choose the type of Jump-Instruction Table for jumptable."),
215           cl::init(JumpTable::Single),
216           cl::values(
217               clEnumValN(JumpTable::Single, "single",
218                          "Create a single table for all jumptable functions"),
219               clEnumValN(JumpTable::Arity, "arity",
220                          "Create one table per number of parameters."),
221               clEnumValN(JumpTable::Simplified, "simplified",
222                          "Create one table per simplified function type."),
223               clEnumValN(JumpTable::Full, "full",
224                          "Create one table per unique function type."),
225               clEnumValEnd));
226
227 // Common utility function tightly tied to the options listed here. Initializes
228 // a TargetOptions object with CodeGen flags and returns it.
229 static inline TargetOptions InitTargetOptionsFromCodeGenFlags() {
230   TargetOptions Options;
231   Options.LessPreciseFPMADOption = EnableFPMAD;
232   Options.NoFramePointerElim = DisableFPElim;
233   Options.AllowFPOpFusion = FuseFPOps;
234   Options.UnsafeFPMath = EnableUnsafeFPMath;
235   Options.NoInfsFPMath = EnableNoInfsFPMath;
236   Options.NoNaNsFPMath = EnableNoNaNsFPMath;
237   Options.HonorSignDependentRoundingFPMathOption =
238       EnableHonorSignDependentRoundingFPMath;
239   if (FloatABIForCalls != FloatABI::Default)
240     Options.FloatABIType = FloatABIForCalls;
241   Options.NoZerosInBSS = DontPlaceZerosInBSS;
242   Options.GuaranteedTailCallOpt = EnableGuaranteedTailCallOpt;
243   Options.DisableTailCalls = DisableTailCalls;
244   Options.StackAlignmentOverride = OverrideStackAlignment;
245   Options.TrapFuncName = TrapFuncName;
246   Options.PositionIndependentExecutable = EnablePIE;
247   Options.UseInitArray = !UseCtors;
248   Options.DataSections = DataSections;
249   Options.FunctionSections = FunctionSections;
250   Options.UniqueSectionNames = UniqueSectionNames;
251
252   Options.MCOptions = InitMCTargetOptionsFromFlags();
253   Options.JTType = JTableType;
254
255   Options.ThreadModel = TMModel;
256
257   return Options;
258 }
259
260 static inline std::string getCPUStr() {
261   // If user asked for the 'native' CPU, autodetect here. If autodection fails,
262   // this will set the CPU to an empty string which tells the target to
263   // pick a basic default.
264   if (MCPU == "native")
265     return sys::getHostCPUName();
266
267   return MCPU;
268 }
269
270 static inline std::string getFeaturesStr() {
271   SubtargetFeatures Features;
272
273   // If user asked for the 'native' CPU, we need to autodetect features.
274   // This is necessary for x86 where the CPU might not support all the
275   // features the autodetected CPU name lists in the target. For example,
276   // not all Sandybridge processors support AVX.
277   if (MCPU == "native") {
278     StringMap<bool> HostFeatures;
279     if (sys::getHostCPUFeatures(HostFeatures))
280       for (auto &F : HostFeatures)
281         Features.AddFeature(F.first(), F.second);
282   }
283
284   for (unsigned i = 0; i != MAttrs.size(); ++i)
285     Features.AddFeature(MAttrs[i]);
286
287   return Features.getString();
288 }
289
290 static inline void overrideFunctionAttributes(StringRef CPU, StringRef Features,
291                                               Module &M) {
292   for (auto &F : M) {
293     if (!CPU.empty())
294       llvm::overrideFunctionAttribute("target-cpu", CPU, F);
295
296     if (!Features.empty())
297       llvm::overrideFunctionAttribute("target-features", Features, F);
298   }
299 }
300
301 #endif