llvm.org GIT mirror llvm / d7eaf51
Rename CommandFlags.h -> CommandFlags.def Since this isn't a real header - it includes static functions and had external linkage variables (though this change makes them static, since that's what they should be) so can't be included more than once in a program. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@319082 91177308-0d34-0410-b5e6-96231b3b80d8 David Blaikie 1 year, 8 months ago
11 changed file(s) with 371 addition(s) and 392 deletion(s). Raw diff Collapse all Expand all
0 //===-- CommandFlags.h - Command Line Flags Interface -----------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file contains codegen-specific flags that are shared between different
10 // command line tools. The tools "llc" and "opt" both use this file to prevent
11 // flag duplication.
12 //
13 //===----------------------------------------------------------------------===//
14
15 #include "llvm/ADT/StringExtras.h"
16 #include "llvm/IR/Instructions.h"
17 #include "llvm/IR/Intrinsics.h"
18 #include "llvm/IR/Module.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"
26 #include
27 using namespace llvm;
28
29 static cl::opt
30 MArch("march",
31 cl::desc("Architecture to generate code for (see --version)"));
32
33 static cl::opt
34 MCPU("mcpu",
35 cl::desc("Target a specific cpu type (-mcpu=help for details)"),
36 cl::value_desc("cpu-name"), cl::init(""));
37
38 static cl::list
39 MAttrs("mattr", cl::CommaSeparated,
40 cl::desc("Target specific attributes (-mattr=help for details)"),
41 cl::value_desc("a1,+a2,-a3,..."));
42
43 static cl::opt RelocModel(
44 "relocation-model", cl::desc("Choose relocation model"),
45 cl::values(
46 clEnumValN(Reloc::Static, "static", "Non-relocatable code"),
47 clEnumValN(Reloc::PIC_, "pic",
48 "Fully relocatable, position independent code"),
49 clEnumValN(Reloc::DynamicNoPIC, "dynamic-no-pic",
50 "Relocatable external references, non-relocatable code"),
51 clEnumValN(Reloc::ROPI, "ropi",
52 "Code and read-only data relocatable, accessed PC-relative"),
53 clEnumValN(
54 Reloc::RWPI, "rwpi",
55 "Read-write data relocatable, accessed relative to static base"),
56 clEnumValN(Reloc::ROPI_RWPI, "ropi-rwpi",
57 "Combination of ropi and rwpi")));
58
59 LLVM_ATTRIBUTE_UNUSED static Optional getRelocModel() {
60 if (RelocModel.getNumOccurrences()) {
61 Reloc::Model R = RelocModel;
62 return R;
63 }
64 return None;
65 }
66
67 static cl::opt TMModel(
68 "thread-model", cl::desc("Choose threading model"),
69 cl::init(ThreadModel::POSIX),
70 cl::values(clEnumValN(ThreadModel::POSIX, "posix", "POSIX thread model"),
71 clEnumValN(ThreadModel::Single, "single",
72 "Single thread model")));
73
74 static cl::opt CMModel(
75 "code-model", cl::desc("Choose code model"),
76 cl::values(clEnumValN(CodeModel::Small, "small", "Small code model"),
77 clEnumValN(CodeModel::Kernel, "kernel", "Kernel code model"),
78 clEnumValN(CodeModel::Medium, "medium", "Medium code model"),
79 clEnumValN(CodeModel::Large, "large", "Large code model")));
80
81 LLVM_ATTRIBUTE_UNUSED static Optional getCodeModel() {
82 if (CMModel.getNumOccurrences()) {
83 CodeModel::Model M = CMModel;
84 return M;
85 }
86 return None;
87 }
88
89 static cl::opt ExceptionModel(
90 "exception-model", cl::desc("exception model"),
91 cl::init(ExceptionHandling::None),
92 cl::values(
93 clEnumValN(ExceptionHandling::None, "default",
94 "default exception handling model"),
95 clEnumValN(ExceptionHandling::DwarfCFI, "dwarf",
96 "DWARF-like CFI based exception handling"),
97 clEnumValN(ExceptionHandling::SjLj, "sjlj", "SjLj exception handling"),
98 clEnumValN(ExceptionHandling::ARM, "arm", "ARM EHABI exceptions"),
99 clEnumValN(ExceptionHandling::WinEH, "wineh",
100 "Windows exception model")));
101
102 static cl::opt FileType(
103 "filetype", cl::init(TargetMachine::CGFT_AssemblyFile),
104 cl::desc(
105 "Choose a file type (not all types are supported by all targets):"),
106 cl::values(clEnumValN(TargetMachine::CGFT_AssemblyFile, "asm",
107 "Emit an assembly ('.s') file"),
108 clEnumValN(TargetMachine::CGFT_ObjectFile, "obj",
109 "Emit a native object ('.o') file"),
110 clEnumValN(TargetMachine::CGFT_Null, "null",
111 "Emit nothing, for performance testing")));
112
113 static cl::opt
114 DisableFPElim("disable-fp-elim",
115 cl::desc("Disable frame pointer elimination optimization"),
116 cl::init(false));
117
118 static cl::opt EnableUnsafeFPMath(
119 "enable-unsafe-fp-math",
120 cl::desc("Enable optimizations that may decrease FP precision"),
121 cl::init(false));
122
123 static cl::opt EnableNoInfsFPMath(
124 "enable-no-infs-fp-math",
125 cl::desc("Enable FP math optimizations that assume no +-Infs"),
126 cl::init(false));
127
128 static cl::opt EnableNoNaNsFPMath(
129 "enable-no-nans-fp-math",
130 cl::desc("Enable FP math optimizations that assume no NaNs"),
131 cl::init(false));
132
133 static cl::opt EnableNoSignedZerosFPMath(
134 "enable-no-signed-zeros-fp-math",
135 cl::desc("Enable FP math optimizations that assume "
136 "the sign of 0 is insignificant"),
137 cl::init(false));
138
139 static cl::opt
140 EnableNoTrappingFPMath("enable-no-trapping-fp-math",
141 cl::desc("Enable setting the FP exceptions build "
142 "attribute not to use exceptions"),
143 cl::init(false));
144
145 static cl::opt DenormalMode(
146 "denormal-fp-math",
147 cl::desc("Select which denormal numbers the code is permitted to require"),
148 cl::init(FPDenormal::IEEE),
149 cl::values(clEnumValN(FPDenormal::IEEE, "ieee",
150 "IEEE 754 denormal numbers"),
151 clEnumValN(FPDenormal::PreserveSign, "preserve-sign",
152 "the sign of a flushed-to-zero number is preserved "
153 "in the sign of 0"),
154 clEnumValN(FPDenormal::PositiveZero, "positive-zero",
155 "denormals are flushed to positive zero")));
156
157 static cl::opt EnableHonorSignDependentRoundingFPMath(
158 "enable-sign-dependent-rounding-fp-math", cl::Hidden,
159 cl::desc("Force codegen to assume rounding mode can change dynamically"),
160 cl::init(false));
161
162 static cl::opt FloatABIForCalls(
163 "float-abi", cl::desc("Choose float ABI type"), cl::init(FloatABI::Default),
164 cl::values(clEnumValN(FloatABI::Default, "default",
165 "Target default float ABI type"),
166 clEnumValN(FloatABI::Soft, "soft",
167 "Soft float ABI (implied by -soft-float)"),
168 clEnumValN(FloatABI::Hard, "hard",
169 "Hard float ABI (uses FP registers)")));
170
171 static cl::opt FuseFPOps(
172 "fp-contract", cl::desc("Enable aggressive formation of fused FP ops"),
173 cl::init(FPOpFusion::Standard),
174 cl::values(
175 clEnumValN(FPOpFusion::Fast, "fast", "Fuse FP ops whenever profitable"),
176 clEnumValN(FPOpFusion::Standard, "on", "Only fuse 'blessed' FP ops."),
177 clEnumValN(FPOpFusion::Strict, "off",
178 "Only fuse FP ops when the result won't be affected.")));
179
180 static cl::opt DontPlaceZerosInBSS(
181 "nozero-initialized-in-bss",
182 cl::desc("Don't place zero-initialized symbols into bss section"),
183 cl::init(false));
184
185 static cl::opt EnableGuaranteedTailCallOpt(
186 "tailcallopt",
187 cl::desc(
188 "Turn fastcc calls into tail calls by (potentially) changing ABI."),
189 cl::init(false));
190
191 static cl::opt DisableTailCalls("disable-tail-calls",
192 cl::desc("Never emit tail calls"),
193 cl::init(false));
194
195 static cl::opt StackSymbolOrdering("stack-symbol-ordering",
196 cl::desc("Order local stack symbols."),
197 cl::init(true));
198
199 static cl::opt
200 OverrideStackAlignment("stack-alignment",
201 cl::desc("Override default stack alignment"),
202 cl::init(0));
203
204 static cl::opt
205 StackRealign("stackrealign",
206 cl::desc("Force align the stack to the minimum alignment"),
207 cl::init(false));
208
209 static cl::opt TrapFuncName(
210 "trap-func", cl::Hidden,
211 cl::desc("Emit a call to trap function rather than a trap instruction"),
212 cl::init(""));
213
214 static cl::opt UseCtors("use-ctors",
215 cl::desc("Use .ctors instead of .init_array."),
216 cl::init(false));
217
218 static cl::opt RelaxELFRelocations(
219 "relax-elf-relocations",
220 cl::desc("Emit GOTPCRELX/REX_GOTPCRELX instead of GOTPCREL on x86-64 ELF"),
221 cl::init(false));
222
223 static cl::opt DataSections("data-sections",
224 cl::desc("Emit data into separate sections"),
225 cl::init(false));
226
227 static cl::opt
228 FunctionSections("function-sections",
229 cl::desc("Emit functions into separate sections"),
230 cl::init(false));
231
232 static cl::opt EmulatedTLS("emulated-tls",
233 cl::desc("Use emulated TLS model"),
234 cl::init(false));
235
236 static cl::opt
237 UniqueSectionNames("unique-section-names",
238 cl::desc("Give unique names to every section"),
239 cl::init(true));
240
241 static cl::opt
242 EABIVersion("meabi", cl::desc("Set EABI type (default depends on triple):"),
243 cl::init(EABI::Default),
244 cl::values(clEnumValN(EABI::Default, "default",
245 "Triple default EABI version"),
246 clEnumValN(EABI::EABI4, "4", "EABI version 4"),
247 clEnumValN(EABI::EABI5, "5", "EABI version 5"),
248 clEnumValN(EABI::GNU, "gnu", "EABI GNU")));
249
250 static cl::opt DebuggerTuningOpt(
251 "debugger-tune", cl::desc("Tune debug info for a particular debugger"),
252 cl::init(DebuggerKind::Default),
253 cl::values(clEnumValN(DebuggerKind::GDB, "gdb", "gdb"),
254 clEnumValN(DebuggerKind::LLDB, "lldb", "lldb"),
255 clEnumValN(DebuggerKind::SCE, "sce", "SCE targets (e.g. PS4)")));
256
257 // Common utility function tightly tied to the options listed here. Initializes
258 // a TargetOptions object with CodeGen flags and returns it.
259 static TargetOptions InitTargetOptionsFromCodeGenFlags() {
260 TargetOptions Options;
261 Options.AllowFPOpFusion = FuseFPOps;
262 Options.UnsafeFPMath = EnableUnsafeFPMath;
263 Options.NoInfsFPMath = EnableNoInfsFPMath;
264 Options.NoNaNsFPMath = EnableNoNaNsFPMath;
265 Options.NoSignedZerosFPMath = EnableNoSignedZerosFPMath;
266 Options.NoTrappingFPMath = EnableNoTrappingFPMath;
267 Options.FPDenormalMode = DenormalMode;
268 Options.HonorSignDependentRoundingFPMathOption =
269 EnableHonorSignDependentRoundingFPMath;
270 if (FloatABIForCalls != FloatABI::Default)
271 Options.FloatABIType = FloatABIForCalls;
272 Options.NoZerosInBSS = DontPlaceZerosInBSS;
273 Options.GuaranteedTailCallOpt = EnableGuaranteedTailCallOpt;
274 Options.StackAlignmentOverride = OverrideStackAlignment;
275 Options.StackSymbolOrdering = StackSymbolOrdering;
276 Options.UseInitArray = !UseCtors;
277 Options.RelaxELFRelocations = RelaxELFRelocations;
278 Options.DataSections = DataSections;
279 Options.FunctionSections = FunctionSections;
280 Options.UniqueSectionNames = UniqueSectionNames;
281 Options.EmulatedTLS = EmulatedTLS;
282 Options.ExceptionModel = ExceptionModel;
283
284 Options.MCOptions = InitMCTargetOptionsFromFlags();
285
286 Options.ThreadModel = TMModel;
287 Options.EABIVersion = EABIVersion;
288 Options.DebuggerTuning = DebuggerTuningOpt;
289
290 return Options;
291 }
292
293 LLVM_ATTRIBUTE_UNUSED static std::string getCPUStr() {
294 // If user asked for the 'native' CPU, autodetect here. If autodection fails,
295 // this will set the CPU to an empty string which tells the target to
296 // pick a basic default.
297 if (MCPU == "native")
298 return sys::getHostCPUName();
299
300 return MCPU;
301 }
302
303 LLVM_ATTRIBUTE_UNUSED static std::string getFeaturesStr() {
304 SubtargetFeatures Features;
305
306 // If user asked for the 'native' CPU, we need to autodetect features.
307 // This is necessary for x86 where the CPU might not support all the
308 // features the autodetected CPU name lists in the target. For example,
309 // not all Sandybridge processors support AVX.
310 if (MCPU == "native") {
311 StringMap HostFeatures;
312 if (sys::getHostCPUFeatures(HostFeatures))
313 for (auto &F : HostFeatures)
314 Features.AddFeature(F.first(), F.second);
315 }
316
317 for (unsigned i = 0; i != MAttrs.size(); ++i)
318 Features.AddFeature(MAttrs[i]);
319
320 return Features.getString();
321 }
322
323 /// \brief Set function attributes of functions in Module M based on CPU,
324 /// Features, and command line flags.
325 LLVM_ATTRIBUTE_UNUSED static void
326 setFunctionAttributes(StringRef CPU, StringRef Features, Module &M) {
327 for (auto &F : M) {
328 auto &Ctx = F.getContext();
329 AttributeList Attrs = F.getAttributes();
330 AttrBuilder NewAttrs;
331
332 if (!CPU.empty())
333 NewAttrs.addAttribute("target-cpu", CPU);
334 if (!Features.empty())
335 NewAttrs.addAttribute("target-features", Features);
336 if (DisableFPElim.getNumOccurrences() > 0)
337 NewAttrs.addAttribute("no-frame-pointer-elim",
338 DisableFPElim ? "true" : "false");
339 if (DisableTailCalls.getNumOccurrences() > 0)
340 NewAttrs.addAttribute("disable-tail-calls",
341 toStringRef(DisableTailCalls));
342 if (StackRealign)
343 NewAttrs.addAttribute("stackrealign");
344
345 if (TrapFuncName.getNumOccurrences() > 0)
346 for (auto &B : F)
347 for (auto &I : B)
348 if (auto *Call = dyn_cast(&I))
349 if (const auto *F = Call->getCalledFunction())
350 if (F->getIntrinsicID() == Intrinsic::debugtrap ||
351 F->getIntrinsicID() == Intrinsic::trap)
352 Call->addAttribute(
353 llvm::AttributeList::FunctionIndex,
354 Attribute::get(Ctx, "trap-func-name", TrapFuncName));
355
356 // Let NewAttrs override Attrs.
357 F.setAttributes(
358 Attrs.addAttributes(Ctx, AttributeList::FunctionIndex, NewAttrs));
359 }
360 }
+0
-382
include/llvm/CodeGen/CommandFlags.h less more
None //===-- CommandFlags.h - Command Line Flags Interface -----------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file contains codegen-specific flags that are shared between different
10 // command line tools. The tools "llc" and "opt" both use this file to prevent
11 // flag duplication.
12 //
13 //===----------------------------------------------------------------------===//
14
15 #ifndef LLVM_CODEGEN_COMMANDFLAGS_H
16 #define LLVM_CODEGEN_COMMANDFLAGS_H
17
18 #include "llvm/ADT/StringExtras.h"
19 #include "llvm/IR/Instructions.h"
20 #include "llvm/IR/Intrinsics.h"
21 #include "llvm/IR/Module.h"
22 #include "llvm/MC/MCTargetOptionsCommandFlags.h"
23 #include "llvm/MC/SubtargetFeature.h"
24 #include "llvm/Support/CodeGen.h"
25 #include "llvm/Support/CommandLine.h"
26 #include "llvm/Support/Host.h"
27 #include "llvm/Target/TargetMachine.h"
28 #include "llvm/Target/TargetOptions.h"
29 #include
30 using namespace llvm;
31
32 cl::opt
33 MArch("march", cl::desc("Architecture to generate code for (see --version)"));
34
35 cl::opt
36 MCPU("mcpu",
37 cl::desc("Target a specific cpu type (-mcpu=help for details)"),
38 cl::value_desc("cpu-name"),
39 cl::init(""));
40
41 cl::list
42 MAttrs("mattr",
43 cl::CommaSeparated,
44 cl::desc("Target specific attributes (-mattr=help for details)"),
45 cl::value_desc("a1,+a2,-a3,..."));
46
47 cl::opt RelocModel(
48 "relocation-model", cl::desc("Choose relocation model"),
49 cl::values(
50 clEnumValN(Reloc::Static, "static", "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 clEnumValN(Reloc::ROPI, "ropi",
56 "Code and read-only data relocatable, accessed PC-relative"),
57 clEnumValN(Reloc::RWPI, "rwpi",
58 "Read-write data relocatable, accessed relative to static base"),
59 clEnumValN(Reloc::ROPI_RWPI, "ropi-rwpi",
60 "Combination of ropi and rwpi")));
61
62 static inline Optional getRelocModel() {
63 if (RelocModel.getNumOccurrences()) {
64 Reloc::Model R = RelocModel;
65 return R;
66 }
67 return None;
68 }
69
70 cl::opt
71 TMModel("thread-model",
72 cl::desc("Choose threading model"),
73 cl::init(ThreadModel::POSIX),
74 cl::values(clEnumValN(ThreadModel::POSIX, "posix",
75 "POSIX thread model"),
76 clEnumValN(ThreadModel::Single, "single",
77 "Single thread model")));
78
79 cl::opt CMModel(
80 "code-model", cl::desc("Choose code model"),
81 cl::values(clEnumValN(CodeModel::Small, "small", "Small code model"),
82 clEnumValN(CodeModel::Kernel, "kernel", "Kernel code model"),
83 clEnumValN(CodeModel::Medium, "medium", "Medium code model"),
84 clEnumValN(CodeModel::Large, "large", "Large code model")));
85
86 static inline Optional getCodeModel() {
87 if (CMModel.getNumOccurrences()) {
88 CodeModel::Model M = CMModel;
89 return M;
90 }
91 return None;
92 }
93
94 cl::opt
95 ExceptionModel("exception-model",
96 cl::desc("exception model"),
97 cl::init(ExceptionHandling::None),
98 cl::values(clEnumValN(ExceptionHandling::None, "default",
99 "default exception handling model"),
100 clEnumValN(ExceptionHandling::DwarfCFI, "dwarf",
101 "DWARF-like CFI based exception handling"),
102 clEnumValN(ExceptionHandling::SjLj, "sjlj",
103 "SjLj exception handling"),
104 clEnumValN(ExceptionHandling::ARM, "arm",
105 "ARM EHABI exceptions"),
106 clEnumValN(ExceptionHandling::WinEH, "wineh",
107 "Windows exception model")));
108
109 cl::opt
110 FileType("filetype", cl::init(TargetMachine::CGFT_AssemblyFile),
111 cl::desc("Choose a file type (not all types are supported by all targets):"),
112 cl::values(
113 clEnumValN(TargetMachine::CGFT_AssemblyFile, "asm",
114 "Emit an assembly ('.s') file"),
115 clEnumValN(TargetMachine::CGFT_ObjectFile, "obj",
116 "Emit a native object ('.o') file"),
117 clEnumValN(TargetMachine::CGFT_Null, "null",
118 "Emit nothing, for performance testing")));
119
120 cl::opt
121 DisableFPElim("disable-fp-elim",
122 cl::desc("Disable frame pointer elimination optimization"),
123 cl::init(false));
124
125 cl::opt
126 EnableUnsafeFPMath("enable-unsafe-fp-math",
127 cl::desc("Enable optimizations that may decrease FP precision"),
128 cl::init(false));
129
130 cl::opt
131 EnableNoInfsFPMath("enable-no-infs-fp-math",
132 cl::desc("Enable FP math optimizations that assume no +-Infs"),
133 cl::init(false));
134
135 cl::opt
136 EnableNoNaNsFPMath("enable-no-nans-fp-math",
137 cl::desc("Enable FP math optimizations that assume no NaNs"),
138 cl::init(false));
139
140 cl::opt
141 EnableNoSignedZerosFPMath("enable-no-signed-zeros-fp-math",
142 cl::desc("Enable FP math optimizations that assume "
143 "the sign of 0 is insignificant"),
144 cl::init(false));
145
146 cl::opt
147 EnableNoTrappingFPMath("enable-no-trapping-fp-math",
148 cl::desc("Enable setting the FP exceptions build "
149 "attribute not to use exceptions"),
150 cl::init(false));
151
152 cl::opt
153 DenormalMode("denormal-fp-math",
154 cl::desc("Select which denormal numbers the code is permitted to require"),
155 cl::init(FPDenormal::IEEE),
156 cl::values(
157 clEnumValN(FPDenormal::IEEE, "ieee",
158 "IEEE 754 denormal numbers"),
159 clEnumValN(FPDenormal::PreserveSign, "preserve-sign",
160 "the sign of a flushed-to-zero number is preserved "
161 "in the sign of 0"),
162 clEnumValN(FPDenormal::PositiveZero, "positive-zero",
163 "denormals are flushed to positive zero")));
164
165 cl::opt
166 EnableHonorSignDependentRoundingFPMath("enable-sign-dependent-rounding-fp-math",
167 cl::Hidden,
168 cl::desc("Force codegen to assume rounding mode can change dynamically"),
169 cl::init(false));
170
171 cl::opt
172 FloatABIForCalls("float-abi",
173 cl::desc("Choose float ABI type"),
174 cl::init(FloatABI::Default),
175 cl::values(
176 clEnumValN(FloatABI::Default, "default",
177 "Target default float ABI type"),
178 clEnumValN(FloatABI::Soft, "soft",
179 "Soft float ABI (implied by -soft-float)"),
180 clEnumValN(FloatABI::Hard, "hard",
181 "Hard float ABI (uses FP registers)")));
182
183 cl::opt
184 FuseFPOps("fp-contract",
185 cl::desc("Enable aggressive formation of fused FP ops"),
186 cl::init(FPOpFusion::Standard),
187 cl::values(
188 clEnumValN(FPOpFusion::Fast, "fast",
189 "Fuse FP ops whenever profitable"),
190 clEnumValN(FPOpFusion::Standard, "on",
191 "Only fuse 'blessed' FP ops."),
192 clEnumValN(FPOpFusion::Strict, "off",
193 "Only fuse FP ops when the result won't be affected.")));
194
195 cl::opt
196 DontPlaceZerosInBSS("nozero-initialized-in-bss",
197 cl::desc("Don't place zero-initialized symbols into bss section"),
198 cl::init(false));
199
200 cl::opt
201 EnableGuaranteedTailCallOpt("tailcallopt",
202 cl::desc("Turn fastcc calls into tail calls by (potentially) changing ABI."),
203 cl::init(false));
204
205 cl::opt
206 DisableTailCalls("disable-tail-calls",
207 cl::desc("Never emit tail calls"),
208 cl::init(false));
209
210 cl::opt
211 StackSymbolOrdering("stack-symbol-ordering",
212 cl::desc("Order local stack symbols."),
213 cl::init(true));
214
215 cl::opt
216 OverrideStackAlignment("stack-alignment",
217 cl::desc("Override default stack alignment"),
218 cl::init(0));
219
220 cl::opt
221 StackRealign("stackrealign",
222 cl::desc("Force align the stack to the minimum alignment"),
223 cl::init(false));
224
225 cl::opt
226 TrapFuncName("trap-func", cl::Hidden,
227 cl::desc("Emit a call to trap function rather than a trap instruction"),
228 cl::init(""));
229
230 cl::opt
231 UseCtors("use-ctors",
232 cl::desc("Use .ctors instead of .init_array."),
233 cl::init(false));
234
235 cl::opt RelaxELFRelocations(
236 "relax-elf-relocations",
237 cl::desc("Emit GOTPCRELX/REX_GOTPCRELX instead of GOTPCREL on x86-64 ELF"),
238 cl::init(false));
239
240 cl::opt DataSections("data-sections",
241 cl::desc("Emit data into separate sections"),
242 cl::init(false));
243
244 cl::opt
245 FunctionSections("function-sections",
246 cl::desc("Emit functions into separate sections"),
247 cl::init(false));
248
249 cl::opt EmulatedTLS("emulated-tls",
250 cl::desc("Use emulated TLS model"),
251 cl::init(false));
252
253 cl::opt UniqueSectionNames("unique-section-names",
254 cl::desc("Give unique names to every section"),
255 cl::init(true));
256
257 cl::opt EABIVersion(
258 "meabi", cl::desc("Set EABI type (default depends on triple):"),
259 cl::init(EABI::Default),
260 cl::values(clEnumValN(EABI::Default, "default",
261 "Triple default EABI version"),
262 clEnumValN(EABI::EABI4, "4", "EABI version 4"),
263 clEnumValN(EABI::EABI5, "5", "EABI version 5"),
264 clEnumValN(EABI::GNU, "gnu", "EABI GNU")));
265
266 cl::opt
267 DebuggerTuningOpt("debugger-tune",
268 cl::desc("Tune debug info for a particular debugger"),
269 cl::init(DebuggerKind::Default),
270 cl::values(
271 clEnumValN(DebuggerKind::GDB, "gdb", "gdb"),
272 clEnumValN(DebuggerKind::LLDB, "lldb", "lldb"),
273 clEnumValN(DebuggerKind::SCE, "sce",
274 "SCE targets (e.g. PS4)")));
275
276 // Common utility function tightly tied to the options listed here. Initializes
277 // a TargetOptions object with CodeGen flags and returns it.
278 static inline TargetOptions InitTargetOptionsFromCodeGenFlags() {
279 TargetOptions Options;
280 Options.AllowFPOpFusion = FuseFPOps;
281 Options.UnsafeFPMath = EnableUnsafeFPMath;
282 Options.NoInfsFPMath = EnableNoInfsFPMath;
283 Options.NoNaNsFPMath = EnableNoNaNsFPMath;
284 Options.NoSignedZerosFPMath = EnableNoSignedZerosFPMath;
285 Options.NoTrappingFPMath = EnableNoTrappingFPMath;
286 Options.FPDenormalMode = DenormalMode;
287 Options.HonorSignDependentRoundingFPMathOption =
288 EnableHonorSignDependentRoundingFPMath;
289 if (FloatABIForCalls != FloatABI::Default)
290 Options.FloatABIType = FloatABIForCalls;
291 Options.NoZerosInBSS = DontPlaceZerosInBSS;
292 Options.GuaranteedTailCallOpt = EnableGuaranteedTailCallOpt;
293 Options.StackAlignmentOverride = OverrideStackAlignment;
294 Options.StackSymbolOrdering = StackSymbolOrdering;
295 Options.UseInitArray = !UseCtors;
296 Options.RelaxELFRelocations = RelaxELFRelocations;
297 Options.DataSections = DataSections;
298 Options.FunctionSections = FunctionSections;
299 Options.UniqueSectionNames = UniqueSectionNames;
300 Options.EmulatedTLS = EmulatedTLS;
301 Options.ExceptionModel = ExceptionModel;
302
303 Options.MCOptions = InitMCTargetOptionsFromFlags();
304
305 Options.ThreadModel = TMModel;
306 Options.EABIVersion = EABIVersion;
307 Options.DebuggerTuning = DebuggerTuningOpt;
308
309 return Options;
310 }
311
312 static inline std::string getCPUStr() {
313 // If user asked for the 'native' CPU, autodetect here. If autodection fails,
314 // this will set the CPU to an empty string which tells the target to
315 // pick a basic default.
316 if (MCPU == "native")
317 return sys::getHostCPUName();
318
319 return MCPU;
320 }
321
322 static inline std::string getFeaturesStr() {
323 SubtargetFeatures Features;
324
325 // If user asked for the 'native' CPU, we need to autodetect features.
326 // This is necessary for x86 where the CPU might not support all the
327 // features the autodetected CPU name lists in the target. For example,
328 // not all Sandybridge processors support AVX.
329 if (MCPU == "native") {
330 StringMap HostFeatures;
331 if (sys::getHostCPUFeatures(HostFeatures))
332 for (auto &F : HostFeatures)
333 Features.AddFeature(F.first(), F.second);
334 }
335
336 for (unsigned i = 0; i != MAttrs.size(); ++i)
337 Features.AddFeature(MAttrs[i]);
338
339 return Features.getString();
340 }
341
342 /// \brief Set function attributes of functions in Module M based on CPU,
343 /// Features, and command line flags.
344 static inline void setFunctionAttributes(StringRef CPU, StringRef Features,
345 Module &M) {
346 for (auto &F : M) {
347 auto &Ctx = F.getContext();
348 AttributeList Attrs = F.getAttributes();
349 AttrBuilder NewAttrs;
350
351 if (!CPU.empty())
352 NewAttrs.addAttribute("target-cpu", CPU);
353 if (!Features.empty())
354 NewAttrs.addAttribute("target-features", Features);
355 if (DisableFPElim.getNumOccurrences() > 0)
356 NewAttrs.addAttribute("no-frame-pointer-elim",
357 DisableFPElim ? "true" : "false");
358 if (DisableTailCalls.getNumOccurrences() > 0)
359 NewAttrs.addAttribute("disable-tail-calls",
360 toStringRef(DisableTailCalls));
361 if (StackRealign)
362 NewAttrs.addAttribute("stackrealign");
363
364 if (TrapFuncName.getNumOccurrences() > 0)
365 for (auto &B : F)
366 for (auto &I : B)
367 if (auto *Call = dyn_cast(&I))
368 if (const auto *F = Call->getCalledFunction())
369 if (F->getIntrinsicID() == Intrinsic::debugtrap ||
370 F->getIntrinsicID() == Intrinsic::trap)
371 Call->addAttribute(
372 llvm::AttributeList::FunctionIndex,
373 Attribute::get(Ctx, "trap-func-name", TrapFuncName));
374
375 // Let NewAttrs override Attrs.
376 F.setAttributes(
377 Attrs.addAttributes(Ctx, AttributeList::FunctionIndex, NewAttrs));
378 }
379 }
380
381 #endif
1414 #include "llvm/ADT/Statistic.h"
1515 #include "llvm/Bitcode/BitcodeReader.h"
1616 #include "llvm/Bitcode/BitcodeWriter.h"
17 #include "llvm/CodeGen/CommandFlags.h"
17 #include "llvm/CodeGen/CommandFlags.def"
1818 #include "llvm/Config/config.h" // plugin-api.h requires HAVE_STDINT_H
1919 #include "llvm/IR/Constants.h"
2020 #include "llvm/IR/DiagnosticPrinter.h"
1515 #include "llvm/ADT/STLExtras.h"
1616 #include "llvm/ADT/Triple.h"
1717 #include "llvm/Analysis/TargetLibraryInfo.h"
18 #include "llvm/CodeGen/CommandFlags.h"
18 #include "llvm/CodeGen/CommandFlags.def"
1919 #include "llvm/CodeGen/LinkAllAsmWriterComponents.h"
2020 #include "llvm/CodeGen/LinkAllCodegenComponents.h"
2121 #include "llvm/CodeGen/MIRParser/MIRParser.h"
1717 #include "llvm/ADT/StringExtras.h"
1818 #include "llvm/ADT/Triple.h"
1919 #include "llvm/Bitcode/BitcodeReader.h"
20 #include "llvm/CodeGen/CommandFlags.h"
20 #include "llvm/CodeGen/CommandFlags.def"
2121 #include "llvm/CodeGen/LinkAllCodegenComponents.h"
2222 #include "llvm/ExecutionEngine/GenericValue.h"
2323 #include "llvm/ExecutionEngine/Interpreter.h"
413413
414414 builder.setOptLevel(getOptLevel());
415415
416 TargetOptions Options;
416 TargetOptions Options = InitTargetOptionsFromCodeGenFlags();
417417 if (FloatABIForCalls != FloatABI::Default)
418418 Options.FloatABIType = FloatABIForCalls;
419419
1414 #include "llvm/Analysis/TargetLibraryInfo.h"
1515 #include "llvm/Bitcode/BitcodeReader.h"
1616 #include "llvm/Bitcode/BitcodeWriter.h"
17 #include "llvm/CodeGen/CommandFlags.h"
17 #include "llvm/CodeGen/CommandFlags.def"
1818 #include "llvm/FuzzMutate/FuzzerCLI.h"
1919 #include "llvm/FuzzMutate/IRMutator.h"
2020 #include "llvm/FuzzMutate/Operations.h"
2121 #include "llvm/ADT/Twine.h"
2222 #include "llvm/Bitcode/BitcodeReader.h"
2323 #include "llvm/Bitcode/BitcodeWriter.h"
24 #include "llvm/CodeGen/CommandFlags.h"
24 #include "llvm/CodeGen/CommandFlags.def"
2525 #include "llvm/IR/DiagnosticInfo.h"
2626 #include "llvm/IR/DiagnosticPrinter.h"
2727 #include "llvm/IR/LLVMContext.h"
1616 //===----------------------------------------------------------------------===//
1717
1818 #include "llvm/Bitcode/BitcodeReader.h"
19 #include "llvm/CodeGen/CommandFlags.h"
19 #include "llvm/CodeGen/CommandFlags.def"
2020 #include "llvm/IR/DiagnosticPrinter.h"
2121 #include "llvm/LTO/Caching.h"
2222 #include "llvm/LTO/LTO.h"
1212
1313 #include "llvm/Bitcode/BitcodeReader.h"
1414 #include "llvm/Bitcode/BitcodeWriter.h"
15 #include "llvm/CodeGen/CommandFlags.h"
15 #include "llvm/CodeGen/CommandFlags.def"
1616 #include "llvm/FuzzMutate/FuzzerCLI.h"
1717 #include "llvm/FuzzMutate/IRMutator.h"
1818 #include "llvm/FuzzMutate/Operations.h"
1414 #include "llvm-c/lto.h"
1515 #include "llvm/ADT/STLExtras.h"
1616 #include "llvm/Bitcode/BitcodeReader.h"
17 #include "llvm/CodeGen/CommandFlags.h"
17 #include "llvm/CodeGen/CommandFlags.def"
1818 #include "llvm/IR/DiagnosticInfo.h"
1919 #include "llvm/IR/DiagnosticPrinter.h"
2020 #include "llvm/IR/LLVMContext.h"
2222 #include "llvm/Analysis/TargetLibraryInfo.h"
2323 #include "llvm/Analysis/TargetTransformInfo.h"
2424 #include "llvm/Bitcode/BitcodeWriterPass.h"
25 #include "llvm/CodeGen/CommandFlags.h"
25 #include "llvm/CodeGen/CommandFlags.def"
2626 #include "llvm/CodeGen/TargetPassConfig.h"
2727 #include "llvm/IR/DataLayout.h"
2828 #include "llvm/IR/DebugInfo.h"