]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/include/llvm/CodeGen/CommandFlags.def
Upgrade our copies of clang, llvm, lld, lldb, compiler-rt and libc++ to
[FreeBSD/FreeBSD.git] / contrib / llvm / include / llvm / CodeGen / CommandFlags.def
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 #include "llvm/ADT/StringExtras.h"
17 #include "llvm/IR/Instructions.h"
18 #include "llvm/IR/Intrinsics.h"
19 #include "llvm/IR/Module.h"
20 #include "llvm/MC/MCTargetOptionsCommandFlags.def"
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 static cl::opt<std::string>
31     MArch("march",
32           cl::desc("Architecture to generate code for (see --version)"));
33
34 static cl::opt<std::string>
35     MCPU("mcpu",
36          cl::desc("Target a specific cpu type (-mcpu=help for details)"),
37          cl::value_desc("cpu-name"), cl::init(""));
38
39 static cl::list<std::string>
40     MAttrs("mattr", cl::CommaSeparated,
41            cl::desc("Target specific attributes (-mattr=help for details)"),
42            cl::value_desc("a1,+a2,-a3,..."));
43
44 static cl::opt<Reloc::Model> RelocModel(
45     "relocation-model", cl::desc("Choose relocation model"),
46     cl::values(
47         clEnumValN(Reloc::Static, "static", "Non-relocatable code"),
48         clEnumValN(Reloc::PIC_, "pic",
49                    "Fully relocatable, position independent code"),
50         clEnumValN(Reloc::DynamicNoPIC, "dynamic-no-pic",
51                    "Relocatable external references, non-relocatable code"),
52         clEnumValN(Reloc::ROPI, "ropi",
53                    "Code and read-only data relocatable, accessed PC-relative"),
54         clEnumValN(
55             Reloc::RWPI, "rwpi",
56             "Read-write data relocatable, accessed relative to static base"),
57         clEnumValN(Reloc::ROPI_RWPI, "ropi-rwpi",
58                    "Combination of ropi and rwpi")));
59
60 LLVM_ATTRIBUTE_UNUSED static Optional<Reloc::Model> getRelocModel() {
61   if (RelocModel.getNumOccurrences()) {
62     Reloc::Model R = RelocModel;
63     return R;
64   }
65   return None;
66 }
67
68 static cl::opt<ThreadModel::Model> TMModel(
69     "thread-model", cl::desc("Choose threading model"),
70     cl::init(ThreadModel::POSIX),
71     cl::values(clEnumValN(ThreadModel::POSIX, "posix", "POSIX thread model"),
72                clEnumValN(ThreadModel::Single, "single",
73                           "Single thread model")));
74
75 static cl::opt<llvm::CodeModel::Model> CMModel(
76     "code-model", cl::desc("Choose code model"),
77     cl::values(clEnumValN(CodeModel::Small, "small", "Small code model"),
78                clEnumValN(CodeModel::Kernel, "kernel", "Kernel code model"),
79                clEnumValN(CodeModel::Medium, "medium", "Medium code model"),
80                clEnumValN(CodeModel::Large, "large", "Large code model")));
81
82 LLVM_ATTRIBUTE_UNUSED static Optional<CodeModel::Model> getCodeModel() {
83   if (CMModel.getNumOccurrences()) {
84     CodeModel::Model M = CMModel;
85     return M;
86   }
87   return None;
88 }
89
90 static cl::opt<llvm::ExceptionHandling> ExceptionModel(
91     "exception-model", cl::desc("exception model"),
92     cl::init(ExceptionHandling::None),
93     cl::values(
94         clEnumValN(ExceptionHandling::None, "default",
95                    "default exception handling model"),
96         clEnumValN(ExceptionHandling::DwarfCFI, "dwarf",
97                    "DWARF-like CFI based exception handling"),
98         clEnumValN(ExceptionHandling::SjLj, "sjlj", "SjLj exception handling"),
99         clEnumValN(ExceptionHandling::ARM, "arm", "ARM EHABI exceptions"),
100         clEnumValN(ExceptionHandling::WinEH, "wineh",
101                    "Windows exception model")));
102
103 static cl::opt<TargetMachine::CodeGenFileType> FileType(
104     "filetype", cl::init(TargetMachine::CGFT_AssemblyFile),
105     cl::desc(
106         "Choose a file type (not all types are supported by all targets):"),
107     cl::values(clEnumValN(TargetMachine::CGFT_AssemblyFile, "asm",
108                           "Emit an assembly ('.s') file"),
109                clEnumValN(TargetMachine::CGFT_ObjectFile, "obj",
110                           "Emit a native object ('.o') file"),
111                clEnumValN(TargetMachine::CGFT_Null, "null",
112                           "Emit nothing, for performance testing")));
113
114 static cl::opt<bool>
115     DisableFPElim("disable-fp-elim",
116                   cl::desc("Disable frame pointer elimination optimization"),
117                   cl::init(false));
118
119 static cl::opt<bool> EnableUnsafeFPMath(
120     "enable-unsafe-fp-math",
121     cl::desc("Enable optimizations that may decrease FP precision"),
122     cl::init(false));
123
124 static cl::opt<bool> EnableNoInfsFPMath(
125     "enable-no-infs-fp-math",
126     cl::desc("Enable FP math optimizations that assume no +-Infs"),
127     cl::init(false));
128
129 static cl::opt<bool> EnableNoNaNsFPMath(
130     "enable-no-nans-fp-math",
131     cl::desc("Enable FP math optimizations that assume no NaNs"),
132     cl::init(false));
133
134 static cl::opt<bool> EnableNoSignedZerosFPMath(
135     "enable-no-signed-zeros-fp-math",
136     cl::desc("Enable FP math optimizations that assume "
137              "the sign of 0 is insignificant"),
138     cl::init(false));
139
140 static cl::opt<bool>
141     EnableNoTrappingFPMath("enable-no-trapping-fp-math",
142                            cl::desc("Enable setting the FP exceptions build "
143                                     "attribute not to use exceptions"),
144                            cl::init(false));
145
146 static cl::opt<llvm::FPDenormal::DenormalMode> DenormalMode(
147     "denormal-fp-math",
148     cl::desc("Select which denormal numbers the code is permitted to require"),
149     cl::init(FPDenormal::IEEE),
150     cl::values(clEnumValN(FPDenormal::IEEE, "ieee",
151                           "IEEE 754 denormal numbers"),
152                clEnumValN(FPDenormal::PreserveSign, "preserve-sign",
153                           "the sign of a  flushed-to-zero number is preserved "
154                           "in the sign of 0"),
155                clEnumValN(FPDenormal::PositiveZero, "positive-zero",
156                           "denormals are flushed to positive zero")));
157
158 static cl::opt<bool> EnableHonorSignDependentRoundingFPMath(
159     "enable-sign-dependent-rounding-fp-math", cl::Hidden,
160     cl::desc("Force codegen to assume rounding mode can change dynamically"),
161     cl::init(false));
162
163 static cl::opt<llvm::FloatABI::ABIType> FloatABIForCalls(
164     "float-abi", cl::desc("Choose float ABI type"), cl::init(FloatABI::Default),
165     cl::values(clEnumValN(FloatABI::Default, "default",
166                           "Target default float ABI type"),
167                clEnumValN(FloatABI::Soft, "soft",
168                           "Soft float ABI (implied by -soft-float)"),
169                clEnumValN(FloatABI::Hard, "hard",
170                           "Hard float ABI (uses FP registers)")));
171
172 static cl::opt<llvm::FPOpFusion::FPOpFusionMode> FuseFPOps(
173     "fp-contract", cl::desc("Enable aggressive formation of fused FP ops"),
174     cl::init(FPOpFusion::Standard),
175     cl::values(
176         clEnumValN(FPOpFusion::Fast, "fast", "Fuse FP ops whenever profitable"),
177         clEnumValN(FPOpFusion::Standard, "on", "Only fuse 'blessed' FP ops."),
178         clEnumValN(FPOpFusion::Strict, "off",
179                    "Only fuse FP ops when the result won't be affected.")));
180
181 static cl::opt<bool> DontPlaceZerosInBSS(
182     "nozero-initialized-in-bss",
183     cl::desc("Don't place zero-initialized symbols into bss section"),
184     cl::init(false));
185
186 static cl::opt<bool> EnableGuaranteedTailCallOpt(
187     "tailcallopt",
188     cl::desc(
189         "Turn fastcc calls into tail calls by (potentially) changing ABI."),
190     cl::init(false));
191
192 static cl::opt<bool> DisableTailCalls("disable-tail-calls",
193                                       cl::desc("Never emit tail calls"),
194                                       cl::init(false));
195
196 static cl::opt<bool> StackSymbolOrdering("stack-symbol-ordering",
197                                          cl::desc("Order local stack symbols."),
198                                          cl::init(true));
199
200 static cl::opt<unsigned>
201     OverrideStackAlignment("stack-alignment",
202                            cl::desc("Override default stack alignment"),
203                            cl::init(0));
204
205 static cl::opt<bool>
206     StackRealign("stackrealign",
207                  cl::desc("Force align the stack to the minimum alignment"),
208                  cl::init(false));
209
210 static cl::opt<std::string> TrapFuncName(
211     "trap-func", cl::Hidden,
212     cl::desc("Emit a call to trap function rather than a trap instruction"),
213     cl::init(""));
214
215 static cl::opt<bool> UseCtors("use-ctors",
216                               cl::desc("Use .ctors instead of .init_array."),
217                               cl::init(false));
218
219 static cl::opt<bool> RelaxELFRelocations(
220     "relax-elf-relocations",
221     cl::desc("Emit GOTPCRELX/REX_GOTPCRELX instead of GOTPCREL on x86-64 ELF"),
222     cl::init(false));
223
224 static cl::opt<bool> DataSections("data-sections",
225                                   cl::desc("Emit data into separate sections"),
226                                   cl::init(false));
227
228 static cl::opt<bool>
229     FunctionSections("function-sections",
230                      cl::desc("Emit functions into separate sections"),
231                      cl::init(false));
232
233 static cl::opt<bool> EmulatedTLS("emulated-tls",
234                                  cl::desc("Use emulated TLS model"),
235                                  cl::init(false));
236
237 static cl::opt<bool>
238     UniqueSectionNames("unique-section-names",
239                        cl::desc("Give unique names to every section"),
240                        cl::init(true));
241
242 static cl::opt<llvm::EABI>
243     EABIVersion("meabi", cl::desc("Set EABI type (default depends on triple):"),
244                 cl::init(EABI::Default),
245                 cl::values(clEnumValN(EABI::Default, "default",
246                                       "Triple default EABI version"),
247                            clEnumValN(EABI::EABI4, "4", "EABI version 4"),
248                            clEnumValN(EABI::EABI5, "5", "EABI version 5"),
249                            clEnumValN(EABI::GNU, "gnu", "EABI GNU")));
250
251 static cl::opt<DebuggerKind> DebuggerTuningOpt(
252     "debugger-tune", cl::desc("Tune debug info for a particular debugger"),
253     cl::init(DebuggerKind::Default),
254     cl::values(clEnumValN(DebuggerKind::GDB, "gdb", "gdb"),
255                clEnumValN(DebuggerKind::LLDB, "lldb", "lldb"),
256                clEnumValN(DebuggerKind::SCE, "sce", "SCE targets (e.g. PS4)")));
257
258 static cl::opt<bool> EnableStackSizeSection(
259     "stack-size-section",
260     cl::desc("Emit a section containing stack size metadata"), cl::init(false));
261
262 // Common utility function tightly tied to the options listed here. Initializes
263 // a TargetOptions object with CodeGen flags and returns it.
264 static TargetOptions InitTargetOptionsFromCodeGenFlags() {
265   TargetOptions Options;
266   Options.AllowFPOpFusion = FuseFPOps;
267   Options.UnsafeFPMath = EnableUnsafeFPMath;
268   Options.NoInfsFPMath = EnableNoInfsFPMath;
269   Options.NoNaNsFPMath = EnableNoNaNsFPMath;
270   Options.NoSignedZerosFPMath = EnableNoSignedZerosFPMath;
271   Options.NoTrappingFPMath = EnableNoTrappingFPMath;
272   Options.FPDenormalMode = DenormalMode;
273   Options.HonorSignDependentRoundingFPMathOption =
274       EnableHonorSignDependentRoundingFPMath;
275   if (FloatABIForCalls != FloatABI::Default)
276     Options.FloatABIType = FloatABIForCalls;
277   Options.NoZerosInBSS = DontPlaceZerosInBSS;
278   Options.GuaranteedTailCallOpt = EnableGuaranteedTailCallOpt;
279   Options.StackAlignmentOverride = OverrideStackAlignment;
280   Options.StackSymbolOrdering = StackSymbolOrdering;
281   Options.UseInitArray = !UseCtors;
282   Options.RelaxELFRelocations = RelaxELFRelocations;
283   Options.DataSections = DataSections;
284   Options.FunctionSections = FunctionSections;
285   Options.UniqueSectionNames = UniqueSectionNames;
286   Options.EmulatedTLS = EmulatedTLS;
287   Options.ExceptionModel = ExceptionModel;
288   Options.EmitStackSizeSection = EnableStackSizeSection;
289
290   Options.MCOptions = InitMCTargetOptionsFromFlags();
291
292   Options.ThreadModel = TMModel;
293   Options.EABIVersion = EABIVersion;
294   Options.DebuggerTuning = DebuggerTuningOpt;
295
296   return Options;
297 }
298
299 LLVM_ATTRIBUTE_UNUSED static std::string getCPUStr() {
300   // If user asked for the 'native' CPU, autodetect here. If autodection fails,
301   // this will set the CPU to an empty string which tells the target to
302   // pick a basic default.
303   if (MCPU == "native")
304     return sys::getHostCPUName();
305
306   return MCPU;
307 }
308
309 LLVM_ATTRIBUTE_UNUSED static std::string getFeaturesStr() {
310   SubtargetFeatures Features;
311
312   // If user asked for the 'native' CPU, we need to autodetect features.
313   // This is necessary for x86 where the CPU might not support all the
314   // features the autodetected CPU name lists in the target. For example,
315   // not all Sandybridge processors support AVX.
316   if (MCPU == "native") {
317     StringMap<bool> HostFeatures;
318     if (sys::getHostCPUFeatures(HostFeatures))
319       for (auto &F : HostFeatures)
320         Features.AddFeature(F.first(), F.second);
321   }
322
323   for (unsigned i = 0; i != MAttrs.size(); ++i)
324     Features.AddFeature(MAttrs[i]);
325
326   return Features.getString();
327 }
328
329 /// \brief Set function attributes of functions in Module M based on CPU,
330 /// Features, and command line flags.
331 LLVM_ATTRIBUTE_UNUSED static void
332 setFunctionAttributes(StringRef CPU, StringRef Features, Module &M) {
333   for (auto &F : M) {
334     auto &Ctx = F.getContext();
335     AttributeList Attrs = F.getAttributes();
336     AttrBuilder NewAttrs;
337
338     if (!CPU.empty())
339       NewAttrs.addAttribute("target-cpu", CPU);
340     if (!Features.empty())
341       NewAttrs.addAttribute("target-features", Features);
342     if (DisableFPElim.getNumOccurrences() > 0)
343       NewAttrs.addAttribute("no-frame-pointer-elim",
344                             DisableFPElim ? "true" : "false");
345     if (DisableTailCalls.getNumOccurrences() > 0)
346       NewAttrs.addAttribute("disable-tail-calls",
347                             toStringRef(DisableTailCalls));
348     if (StackRealign)
349       NewAttrs.addAttribute("stackrealign");
350
351     if (TrapFuncName.getNumOccurrences() > 0)
352       for (auto &B : F)
353         for (auto &I : B)
354           if (auto *Call = dyn_cast<CallInst>(&I))
355             if (const auto *F = Call->getCalledFunction())
356               if (F->getIntrinsicID() == Intrinsic::debugtrap ||
357                   F->getIntrinsicID() == Intrinsic::trap)
358                 Call->addAttribute(
359                     llvm::AttributeList::FunctionIndex,
360                     Attribute::get(Ctx, "trap-func-name", TrapFuncName));
361
362     // Let NewAttrs override Attrs.
363     F.setAttributes(
364         Attrs.addAttributes(Ctx, AttributeList::FunctionIndex, NewAttrs));
365   }
366 }