Create MCTargetOptions.
[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/MC/MCTargetOptionsCommandFlags.h"
20 #include "llvm/Support/CodeGen.h"
21 #include "llvm/Support/CommandLine.h"
22 #include "llvm/Target/TargetMachine.h"
23 #include "llvm/Target/TargetOptions.h"
24 #include <string>
25 using namespace llvm;
26
27 cl::opt<std::string>
28 MArch("march", cl::desc("Architecture to generate code for (see --version)"));
29
30 cl::opt<std::string>
31 MCPU("mcpu",
32      cl::desc("Target a specific cpu type (-mcpu=help for details)"),
33      cl::value_desc("cpu-name"),
34      cl::init(""));
35
36 cl::list<std::string>
37 MAttrs("mattr",
38        cl::CommaSeparated,
39        cl::desc("Target specific attributes (-mattr=help for details)"),
40        cl::value_desc("a1,+a2,-a3,..."));
41
42 cl::opt<Reloc::Model>
43 RelocModel("relocation-model",
44            cl::desc("Choose relocation model"),
45            cl::init(Reloc::Default),
46            cl::values(
47               clEnumValN(Reloc::Default, "default",
48                       "Target default relocation model"),
49               clEnumValN(Reloc::Static, "static",
50                       "Non-relocatable code"),
51               clEnumValN(Reloc::PIC_, "pic",
52                       "Fully relocatable, position independent code"),
53               clEnumValN(Reloc::DynamicNoPIC, "dynamic-no-pic",
54                       "Relocatable external references, non-relocatable code"),
55               clEnumValEnd));
56
57 cl::opt<llvm::CodeModel::Model>
58 CMModel("code-model",
59         cl::desc("Choose code model"),
60         cl::init(CodeModel::Default),
61         cl::values(clEnumValN(CodeModel::Default, "default",
62                               "Target default code model"),
63                    clEnumValN(CodeModel::Small, "small",
64                               "Small code model"),
65                    clEnumValN(CodeModel::Kernel, "kernel",
66                               "Kernel code model"),
67                    clEnumValN(CodeModel::Medium, "medium",
68                               "Medium code model"),
69                    clEnumValN(CodeModel::Large, "large",
70                               "Large code model"),
71                    clEnumValEnd));
72
73 cl::opt<bool>
74 RelaxAll("mc-relax-all",
75          cl::desc("When used with filetype=obj, "
76                   "relax all fixups in the emitted object file"));
77
78 cl::opt<TargetMachine::CodeGenFileType>
79 FileType("filetype", cl::init(TargetMachine::CGFT_AssemblyFile),
80   cl::desc("Choose a file type (not all types are supported by all targets):"),
81   cl::values(
82              clEnumValN(TargetMachine::CGFT_AssemblyFile, "asm",
83                         "Emit an assembly ('.s') file"),
84              clEnumValN(TargetMachine::CGFT_ObjectFile, "obj",
85                         "Emit a native object ('.o') file"),
86              clEnumValN(TargetMachine::CGFT_Null, "null",
87                         "Emit nothing, for performance testing"),
88              clEnumValEnd));
89
90 cl::opt<bool> DisableCFI("disable-cfi", cl::Hidden,
91                          cl::desc("Do not use .cfi_* directives"));
92
93 cl::opt<bool> EnableDwarfDirectory("enable-dwarf-directory", cl::Hidden,
94                   cl::desc("Use .file directives with an explicit directory."));
95
96 cl::opt<bool>
97 DisableRedZone("disable-red-zone",
98                cl::desc("Do not emit code that uses the red zone."),
99                cl::init(false));
100
101 cl::opt<bool>
102 EnableFPMAD("enable-fp-mad",
103             cl::desc("Enable less precise MAD instructions to be generated"),
104             cl::init(false));
105
106 cl::opt<bool>
107 DisableFPElim("disable-fp-elim",
108               cl::desc("Disable frame pointer elimination optimization"),
109               cl::init(false));
110
111 cl::opt<bool>
112 EnableUnsafeFPMath("enable-unsafe-fp-math",
113                 cl::desc("Enable optimizations that may decrease FP precision"),
114                 cl::init(false));
115
116 cl::opt<bool>
117 EnableNoInfsFPMath("enable-no-infs-fp-math",
118                 cl::desc("Enable FP math optimizations that assume no +-Infs"),
119                 cl::init(false));
120
121 cl::opt<bool>
122 EnableNoNaNsFPMath("enable-no-nans-fp-math",
123                    cl::desc("Enable FP math optimizations that assume no NaNs"),
124                    cl::init(false));
125
126 cl::opt<bool>
127 EnableHonorSignDependentRoundingFPMath("enable-sign-dependent-rounding-fp-math",
128       cl::Hidden,
129       cl::desc("Force codegen to assume rounding mode can change dynamically"),
130       cl::init(false));
131
132 cl::opt<bool>
133 GenerateSoftFloatCalls("soft-float",
134                     cl::desc("Generate software floating point library calls"),
135                     cl::init(false));
136
137 cl::opt<llvm::FloatABI::ABIType>
138 FloatABIForCalls("float-abi",
139                  cl::desc("Choose float ABI type"),
140                  cl::init(FloatABI::Default),
141                  cl::values(
142                      clEnumValN(FloatABI::Default, "default",
143                                 "Target default float ABI type"),
144                      clEnumValN(FloatABI::Soft, "soft",
145                                 "Soft float ABI (implied by -soft-float)"),
146                      clEnumValN(FloatABI::Hard, "hard",
147                                 "Hard float ABI (uses FP registers)"),
148                      clEnumValEnd));
149
150 cl::opt<llvm::FPOpFusion::FPOpFusionMode>
151 FuseFPOps("fp-contract",
152           cl::desc("Enable aggressive formation of fused FP ops"),
153           cl::init(FPOpFusion::Standard),
154           cl::values(
155               clEnumValN(FPOpFusion::Fast, "fast",
156                          "Fuse FP ops whenever profitable"),
157               clEnumValN(FPOpFusion::Standard, "on",
158                          "Only fuse 'blessed' FP ops."),
159               clEnumValN(FPOpFusion::Strict, "off",
160                          "Only fuse FP ops when the result won't be effected."),
161               clEnumValEnd));
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 UseInitArray("use-init-array",
195              cl::desc("Use .init_array instead of .ctors."),
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 // Common utility function tightly tied to the options listed here. Initializes
208 // a TargetOptions object with CodeGen flags and returns it.
209 static inline TargetOptions InitTargetOptionsFromCodeGenFlags() {
210   TargetOptions Options;
211   Options.LessPreciseFPMADOption = EnableFPMAD;
212   Options.NoFramePointerElim = DisableFPElim;
213   Options.AllowFPOpFusion = FuseFPOps;
214   Options.UnsafeFPMath = EnableUnsafeFPMath;
215   Options.NoInfsFPMath = EnableNoInfsFPMath;
216   Options.NoNaNsFPMath = EnableNoNaNsFPMath;
217   Options.HonorSignDependentRoundingFPMathOption =
218       EnableHonorSignDependentRoundingFPMath;
219   Options.UseSoftFloat = GenerateSoftFloatCalls;
220   if (FloatABIForCalls != FloatABI::Default)
221     Options.FloatABIType = FloatABIForCalls;
222   Options.NoZerosInBSS = DontPlaceZerosInBSS;
223   Options.GuaranteedTailCallOpt = EnableGuaranteedTailCallOpt;
224   Options.DisableTailCalls = DisableTailCalls;
225   Options.StackAlignmentOverride = OverrideStackAlignment;
226   Options.TrapFuncName = TrapFuncName;
227   Options.PositionIndependentExecutable = EnablePIE;
228   Options.UseInitArray = UseInitArray;
229
230   Options.MCOptions = InitMCTargetOptionsFromFlags();
231
232   return Options;
233 }
234
235 #endif