1 //===-- CommandFlags.h - Command Line Flags Interface -----------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
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
14 //===----------------------------------------------------------------------===//
16 #ifndef LLVM_CODEGEN_COMMANDFLAGS_H
17 #define LLVM_CODEGEN_COMMANDFLAGS_H
19 #include "llvm/MC/MCTargetOptionsCommandFlags.h"
20 #include "llvm//MC/SubtargetFeature.h"
21 #include "llvm/Support/CodeGen.h"
22 #include "llvm/Support/CommandLine.h"
23 #include "llvm/Support/Host.h"
24 #include "llvm/Target/TargetMachine.h"
25 #include "llvm/Target/TargetOptions.h"
30 MArch("march", cl::desc("Architecture to generate code for (see --version)"));
34 cl::desc("Target a specific cpu type (-mcpu=help for details)"),
35 cl::value_desc("cpu-name"),
41 cl::desc("Target specific attributes (-mattr=help for details)"),
42 cl::value_desc("a1,+a2,-a3,..."));
45 RelocModel("relocation-model",
46 cl::desc("Choose relocation model"),
47 cl::init(Reloc::Default),
49 clEnumValN(Reloc::Default, "default",
50 "Target default relocation model"),
51 clEnumValN(Reloc::Static, "static",
52 "Non-relocatable code"),
53 clEnumValN(Reloc::PIC_, "pic",
54 "Fully relocatable, position independent code"),
55 clEnumValN(Reloc::DynamicNoPIC, "dynamic-no-pic",
56 "Relocatable external references, non-relocatable code"),
59 cl::opt<ThreadModel::Model>
60 TMModel("thread-model",
61 cl::desc("Choose threading model"),
62 cl::init(ThreadModel::POSIX),
63 cl::values(clEnumValN(ThreadModel::POSIX, "posix",
64 "POSIX thread model"),
65 clEnumValN(ThreadModel::Single, "single",
66 "Single thread model"),
69 cl::opt<llvm::CodeModel::Model>
71 cl::desc("Choose code model"),
72 cl::init(CodeModel::Default),
73 cl::values(clEnumValN(CodeModel::Default, "default",
74 "Target default code model"),
75 clEnumValN(CodeModel::Small, "small",
77 clEnumValN(CodeModel::Kernel, "kernel",
79 clEnumValN(CodeModel::Medium, "medium",
81 clEnumValN(CodeModel::Large, "large",
85 cl::opt<TargetMachine::CodeGenFileType>
86 FileType("filetype", cl::init(TargetMachine::CGFT_AssemblyFile),
87 cl::desc("Choose a file type (not all types are supported by all targets):"),
89 clEnumValN(TargetMachine::CGFT_AssemblyFile, "asm",
90 "Emit an assembly ('.s') file"),
91 clEnumValN(TargetMachine::CGFT_ObjectFile, "obj",
92 "Emit a native object ('.o') file"),
93 clEnumValN(TargetMachine::CGFT_Null, "null",
94 "Emit nothing, for performance testing"),
98 EnableFPMAD("enable-fp-mad",
99 cl::desc("Enable less precise MAD instructions to be generated"),
103 DisableFPElim("disable-fp-elim",
104 cl::desc("Disable frame pointer elimination optimization"),
108 EnableUnsafeFPMath("enable-unsafe-fp-math",
109 cl::desc("Enable optimizations that may decrease FP precision"),
113 EnableNoInfsFPMath("enable-no-infs-fp-math",
114 cl::desc("Enable FP math optimizations that assume no +-Infs"),
118 EnableNoNaNsFPMath("enable-no-nans-fp-math",
119 cl::desc("Enable FP math optimizations that assume no NaNs"),
123 EnableHonorSignDependentRoundingFPMath("enable-sign-dependent-rounding-fp-math",
125 cl::desc("Force codegen to assume rounding mode can change dynamically"),
129 GenerateSoftFloatCalls("soft-float",
130 cl::desc("Generate software floating point library calls"),
133 cl::opt<llvm::FloatABI::ABIType>
134 FloatABIForCalls("float-abi",
135 cl::desc("Choose float ABI type"),
136 cl::init(FloatABI::Default),
138 clEnumValN(FloatABI::Default, "default",
139 "Target default float ABI type"),
140 clEnumValN(FloatABI::Soft, "soft",
141 "Soft float ABI (implied by -soft-float)"),
142 clEnumValN(FloatABI::Hard, "hard",
143 "Hard float ABI (uses FP registers)"),
146 cl::opt<llvm::FPOpFusion::FPOpFusionMode>
147 FuseFPOps("fp-contract",
148 cl::desc("Enable aggressive formation of fused FP ops"),
149 cl::init(FPOpFusion::Standard),
151 clEnumValN(FPOpFusion::Fast, "fast",
152 "Fuse FP ops whenever profitable"),
153 clEnumValN(FPOpFusion::Standard, "on",
154 "Only fuse 'blessed' FP ops."),
155 clEnumValN(FPOpFusion::Strict, "off",
156 "Only fuse FP ops when the result won't be effected."),
160 DontPlaceZerosInBSS("nozero-initialized-in-bss",
161 cl::desc("Don't place zero-initialized symbols into bss section"),
165 EnableGuaranteedTailCallOpt("tailcallopt",
166 cl::desc("Turn fastcc calls into tail calls by (potentially) changing ABI."),
170 DisableTailCalls("disable-tail-calls",
171 cl::desc("Never emit tail calls"),
175 OverrideStackAlignment("stack-alignment",
176 cl::desc("Override default stack alignment"),
180 TrapFuncName("trap-func", cl::Hidden,
181 cl::desc("Emit a call to trap function rather than a trap instruction"),
185 EnablePIE("enable-pie",
186 cl::desc("Assume the creation of a position independent executable."),
190 UseCtors("use-ctors",
191 cl::desc("Use .ctors instead of .init_array."),
194 cl::opt<std::string> StopAfter("stop-after",
195 cl::desc("Stop compilation after a specific pass"),
196 cl::value_desc("pass-name"),
198 cl::opt<std::string> StartAfter("start-after",
199 cl::desc("Resume compilation after a specific pass"),
200 cl::value_desc("pass-name"),
203 cl::opt<bool> DataSections("data-sections",
204 cl::desc("Emit data into separate sections"),
208 FunctionSections("function-sections",
209 cl::desc("Emit functions into separate sections"),
212 cl::opt<bool> UniqueSectionNames("unique-section-names",
213 cl::desc("Give unique names to every section"),
216 cl::opt<llvm::JumpTable::JumpTableType>
217 JTableType("jump-table-type",
218 cl::desc("Choose the type of Jump-Instruction Table for jumptable."),
219 cl::init(JumpTable::Single),
221 clEnumValN(JumpTable::Single, "single",
222 "Create a single table for all jumptable functions"),
223 clEnumValN(JumpTable::Arity, "arity",
224 "Create one table per number of parameters."),
225 clEnumValN(JumpTable::Simplified, "simplified",
226 "Create one table per simplified function type."),
227 clEnumValN(JumpTable::Full, "full",
228 "Create one table per unique function type."),
231 // Common utility function tightly tied to the options listed here. Initializes
232 // a TargetOptions object with CodeGen flags and returns it.
233 static inline TargetOptions InitTargetOptionsFromCodeGenFlags() {
234 TargetOptions Options;
235 Options.LessPreciseFPMADOption = EnableFPMAD;
236 Options.NoFramePointerElim = DisableFPElim;
237 Options.AllowFPOpFusion = FuseFPOps;
238 Options.UnsafeFPMath = EnableUnsafeFPMath;
239 Options.NoInfsFPMath = EnableNoInfsFPMath;
240 Options.NoNaNsFPMath = EnableNoNaNsFPMath;
241 Options.HonorSignDependentRoundingFPMathOption =
242 EnableHonorSignDependentRoundingFPMath;
243 Options.UseSoftFloat = GenerateSoftFloatCalls;
244 if (FloatABIForCalls != FloatABI::Default)
245 Options.FloatABIType = FloatABIForCalls;
246 Options.NoZerosInBSS = DontPlaceZerosInBSS;
247 Options.GuaranteedTailCallOpt = EnableGuaranteedTailCallOpt;
248 Options.DisableTailCalls = DisableTailCalls;
249 Options.StackAlignmentOverride = OverrideStackAlignment;
250 Options.TrapFuncName = TrapFuncName;
251 Options.PositionIndependentExecutable = EnablePIE;
252 Options.UseInitArray = !UseCtors;
253 Options.DataSections = DataSections;
254 Options.FunctionSections = FunctionSections;
255 Options.UniqueSectionNames = UniqueSectionNames;
257 Options.MCOptions = InitMCTargetOptionsFromFlags();
258 Options.JTType = JTableType;
260 Options.ThreadModel = TMModel;
265 static inline std::string getCPUStr() {
266 // If user asked for the 'native' CPU, autodetect here. If autodection fails,
267 // this will set the CPU to an empty string which tells the target to
268 // pick a basic default.
269 if (MCPU == "native")
270 return sys::getHostCPUName();
275 static inline std::string getFeaturesStr() {
276 SubtargetFeatures Features;
278 // If user asked for the 'native' CPU, we need to autodetect features.
279 // This is necessary for x86 where the CPU might not support all the
280 // features the autodetected CPU name lists in the target. For example,
281 if (MCPU == "native") {
282 StringMap<bool> HostFeatures;
283 if (sys::getHostCPUFeatures(HostFeatures))
284 for (auto &F : HostFeatures)
285 Features.AddFeature(F.first(), F.second);
288 for (unsigned i = 0; i != MAttrs.size(); ++i)
289 Features.AddFeature(MAttrs[i]);
291 return Features.getString();