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/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"
31 MArch("march", cl::desc("Architecture to generate code for (see --version)"));
35 cl::desc("Target a specific cpu type (-mcpu=help for details)"),
36 cl::value_desc("cpu-name"),
42 cl::desc("Target specific attributes (-mattr=help for details)"),
43 cl::value_desc("a1,+a2,-a3,..."));
46 RelocModel("relocation-model",
47 cl::desc("Choose relocation model"),
48 cl::init(Reloc::Default),
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"),
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"),
70 cl::opt<llvm::CodeModel::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",
78 clEnumValN(CodeModel::Kernel, "kernel",
80 clEnumValN(CodeModel::Medium, "medium",
82 clEnumValN(CodeModel::Large, "large",
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):"),
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"),
99 EnableFPMAD("enable-fp-mad",
100 cl::desc("Enable less precise MAD instructions to be generated"),
104 DisableFPElim("disable-fp-elim",
105 cl::desc("Disable frame pointer elimination optimization"),
109 EnableUnsafeFPMath("enable-unsafe-fp-math",
110 cl::desc("Enable optimizations that may decrease FP precision"),
114 EnableNoInfsFPMath("enable-no-infs-fp-math",
115 cl::desc("Enable FP math optimizations that assume no +-Infs"),
119 EnableNoNaNsFPMath("enable-no-nans-fp-math",
120 cl::desc("Enable FP math optimizations that assume no NaNs"),
124 EnableHonorSignDependentRoundingFPMath("enable-sign-dependent-rounding-fp-math",
126 cl::desc("Force codegen to assume rounding mode can change dynamically"),
129 cl::opt<llvm::FloatABI::ABIType>
130 FloatABIForCalls("float-abi",
131 cl::desc("Choose float ABI type"),
132 cl::init(FloatABI::Default),
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)"),
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),
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."),
156 DontPlaceZerosInBSS("nozero-initialized-in-bss",
157 cl::desc("Don't place zero-initialized symbols into bss section"),
161 EnableGuaranteedTailCallOpt("tailcallopt",
162 cl::desc("Turn fastcc calls into tail calls by (potentially) changing ABI."),
166 DisableTailCalls("disable-tail-calls",
167 cl::desc("Never emit tail calls"),
171 OverrideStackAlignment("stack-alignment",
172 cl::desc("Override default stack alignment"),
176 TrapFuncName("trap-func", cl::Hidden,
177 cl::desc("Emit a call to trap function rather than a trap instruction"),
181 EnablePIE("enable-pie",
182 cl::desc("Assume the creation of a position independent executable."),
186 UseCtors("use-ctors",
187 cl::desc("Use .ctors instead of .init_array."),
190 cl::opt<std::string> StopAfter("stop-after",
191 cl::desc("Stop compilation after a specific pass"),
192 cl::value_desc("pass-name"),
194 cl::opt<std::string> StartAfter("start-after",
195 cl::desc("Resume compilation after a specific pass"),
196 cl::value_desc("pass-name"),
199 cl::opt<bool> DataSections("data-sections",
200 cl::desc("Emit data into separate sections"),
204 FunctionSections("function-sections",
205 cl::desc("Emit functions into separate sections"),
208 cl::opt<bool> UniqueSectionNames("unique-section-names",
209 cl::desc("Give unique names to every section"),
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),
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."),
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.NoFramePointerElimOverride = DisableFPElim.getNumOccurrences() > 0;
234 Options.AllowFPOpFusion = FuseFPOps;
235 Options.UnsafeFPMath = EnableUnsafeFPMath;
236 Options.NoInfsFPMath = EnableNoInfsFPMath;
237 Options.NoNaNsFPMath = EnableNoNaNsFPMath;
238 Options.HonorSignDependentRoundingFPMathOption =
239 EnableHonorSignDependentRoundingFPMath;
240 if (FloatABIForCalls != FloatABI::Default)
241 Options.FloatABIType = FloatABIForCalls;
242 Options.NoZerosInBSS = DontPlaceZerosInBSS;
243 Options.GuaranteedTailCallOpt = EnableGuaranteedTailCallOpt;
244 Options.DisableTailCalls = DisableTailCalls;
245 Options.StackAlignmentOverride = OverrideStackAlignment;
246 Options.TrapFuncName = TrapFuncName;
247 Options.PositionIndependentExecutable = EnablePIE;
248 Options.UseInitArray = !UseCtors;
249 Options.DataSections = DataSections;
250 Options.FunctionSections = FunctionSections;
251 Options.UniqueSectionNames = UniqueSectionNames;
253 Options.MCOptions = InitMCTargetOptionsFromFlags();
254 Options.JTType = JTableType;
256 Options.ThreadModel = TMModel;
261 static inline std::string getCPUStr() {
262 // If user asked for the 'native' CPU, autodetect here. If autodection fails,
263 // this will set the CPU to an empty string which tells the target to
264 // pick a basic default.
265 if (MCPU == "native")
266 return sys::getHostCPUName();
271 static inline std::string getFeaturesStr() {
272 SubtargetFeatures Features;
274 // If user asked for the 'native' CPU, we need to autodetect features.
275 // This is necessary for x86 where the CPU might not support all the
276 // features the autodetected CPU name lists in the target. For example,
277 // not all Sandybridge processors support AVX.
278 if (MCPU == "native") {
279 StringMap<bool> HostFeatures;
280 if (sys::getHostCPUFeatures(HostFeatures))
281 for (auto &F : HostFeatures)
282 Features.AddFeature(F.first(), F.second);
285 for (unsigned i = 0; i != MAttrs.size(); ++i)
286 Features.AddFeature(MAttrs[i]);
288 return Features.getString();