LLVM  3.7.0
CommandFlags.h
Go to the documentation of this file.
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/ADT/StringExtras.h"
20 #include "llvm/IR/Instructions.h"
21 #include "llvm/IR/Intrinsics.h"
22 #include "llvm/IR/Module.h"
25 #include "llvm/Support/CodeGen.h"
27 #include "llvm/Support/Host.h"
31 #include <string>
32 using namespace llvm;
33 
35 MArch("march", cl::desc("Architecture to generate code for (see --version)"));
36 
38 MCPU("mcpu",
39  cl::desc("Target a specific cpu type (-mcpu=help for details)"),
40  cl::value_desc("cpu-name"),
41  cl::init(""));
42 
44 MAttrs("mattr",
46  cl::desc("Target specific attributes (-mattr=help for details)"),
47  cl::value_desc("a1,+a2,-a3,..."));
48 
50 RelocModel("relocation-model",
51  cl::desc("Choose relocation model"),
53  cl::values(
54  clEnumValN(Reloc::Default, "default",
55  "Target default relocation model"),
56  clEnumValN(Reloc::Static, "static",
57  "Non-relocatable code"),
58  clEnumValN(Reloc::PIC_, "pic",
59  "Fully relocatable, position independent code"),
60  clEnumValN(Reloc::DynamicNoPIC, "dynamic-no-pic",
61  "Relocatable external references, non-relocatable code"),
62  clEnumValEnd));
63 
65 TMModel("thread-model",
66  cl::desc("Choose threading model"),
69  "POSIX thread model"),
71  "Single thread model"),
72  clEnumValEnd));
73 
75 CMModel("code-model",
76  cl::desc("Choose code model"),
79  "Target default code model"),
81  "Small code model"),
82  clEnumValN(CodeModel::Kernel, "kernel",
83  "Kernel code model"),
84  clEnumValN(CodeModel::Medium, "medium",
85  "Medium code model"),
87  "Large code model"),
88  clEnumValEnd));
89 
92  cl::desc("Choose a file type (not all types are supported by all targets):"),
93  cl::values(
95  "Emit an assembly ('.s') file"),
97  "Emit a native object ('.o') file"),
99  "Emit nothing, for performance testing"),
100  clEnumValEnd));
101 
103 EnableFPMAD("enable-fp-mad",
104  cl::desc("Enable less precise MAD instructions to be generated"),
105  cl::init(false));
106 
108 DisableFPElim("disable-fp-elim",
109  cl::desc("Disable frame pointer elimination optimization"),
110  cl::init(false));
111 
113 EnableUnsafeFPMath("enable-unsafe-fp-math",
114  cl::desc("Enable optimizations that may decrease FP precision"),
115  cl::init(false));
116 
118 EnableNoInfsFPMath("enable-no-infs-fp-math",
119  cl::desc("Enable FP math optimizations that assume no +-Infs"),
120  cl::init(false));
121 
123 EnableNoNaNsFPMath("enable-no-nans-fp-math",
124  cl::desc("Enable FP math optimizations that assume no NaNs"),
125  cl::init(false));
126 
128 EnableHonorSignDependentRoundingFPMath("enable-sign-dependent-rounding-fp-math",
129  cl::Hidden,
130  cl::desc("Force codegen to assume rounding mode can change dynamically"),
131  cl::init(false));
132 
134 FloatABIForCalls("float-abi",
135  cl::desc("Choose float ABI type"),
137  cl::values(
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)"),
144  clEnumValEnd));
145 
147 FuseFPOps("fp-contract",
148  cl::desc("Enable aggressive formation of fused FP ops"),
150  cl::values(
152  "Fuse FP ops whenever profitable"),
154  "Only fuse 'blessed' FP ops."),
156  "Only fuse FP ops when the result won't be affected."),
157  clEnumValEnd));
158 
160 ReciprocalOps("recip",
162  cl::desc("Choose reciprocal operation types and parameters."),
163  cl::value_desc("all,none,default,divf,!vec-sqrtd,vec-divd:0,sqrt:9..."));
164 
166 DontPlaceZerosInBSS("nozero-initialized-in-bss",
167  cl::desc("Don't place zero-initialized symbols into bss section"),
168  cl::init(false));
169 
171 EnableGuaranteedTailCallOpt("tailcallopt",
172  cl::desc("Turn fastcc calls into tail calls by (potentially) changing ABI."),
173  cl::init(false));
174 
176 DisableTailCalls("disable-tail-calls",
177  cl::desc("Never emit tail calls"),
178  cl::init(false));
179 
181 OverrideStackAlignment("stack-alignment",
182  cl::desc("Override default stack alignment"),
183  cl::init(0));
184 
186 TrapFuncName("trap-func", cl::Hidden,
187  cl::desc("Emit a call to trap function rather than a trap instruction"),
188  cl::init(""));
189 
191 EnablePIE("enable-pie",
192  cl::desc("Assume the creation of a position independent executable."),
193  cl::init(false));
194 
196 UseCtors("use-ctors",
197  cl::desc("Use .ctors instead of .init_array."),
198  cl::init(false));
199 
200 cl::opt<std::string> StopAfter("stop-after",
201  cl::desc("Stop compilation after a specific pass"),
202  cl::value_desc("pass-name"),
203  cl::init(""));
204 cl::opt<std::string> StartAfter("start-after",
205  cl::desc("Resume compilation after a specific pass"),
206  cl::value_desc("pass-name"),
207  cl::init(""));
208 
210  RunPass("run-pass", cl::desc("Run compiler only for one specific pass"),
211  cl::value_desc("pass-name"), cl::init(""));
212 
213 cl::opt<bool> DataSections("data-sections",
214  cl::desc("Emit data into separate sections"),
215  cl::init(false));
216 
218 FunctionSections("function-sections",
219  cl::desc("Emit functions into separate sections"),
220  cl::init(false));
221 
222 cl::opt<bool> UniqueSectionNames("unique-section-names",
223  cl::desc("Give unique names to every section"),
224  cl::init(true));
225 
227 JTableType("jump-table-type",
228  cl::desc("Choose the type of Jump-Instruction Table for jumptable."),
230  cl::values(
231  clEnumValN(JumpTable::Single, "single",
232  "Create a single table for all jumptable functions"),
233  clEnumValN(JumpTable::Arity, "arity",
234  "Create one table per number of parameters."),
235  clEnumValN(JumpTable::Simplified, "simplified",
236  "Create one table per simplified function type."),
237  clEnumValN(JumpTable::Full, "full",
238  "Create one table per unique function type."),
239  clEnumValEnd));
240 
241 // Common utility function tightly tied to the options listed here. Initializes
242 // a TargetOptions object with CodeGen flags and returns it.
244  TargetOptions Options;
246  Options.AllowFPOpFusion = FuseFPOps;
254  Options.FloatABIType = FloatABIForCalls;
259  Options.UseInitArray = !UseCtors;
260  Options.DataSections = DataSections;
263 
265  Options.JTType = JTableType;
266 
267  Options.ThreadModel = TMModel;
268 
269  return Options;
270 }
271 
272 static inline std::string getCPUStr() {
273  // If user asked for the 'native' CPU, autodetect here. If autodection fails,
274  // this will set the CPU to an empty string which tells the target to
275  // pick a basic default.
276  if (MCPU == "native")
277  return sys::getHostCPUName();
278 
279  return MCPU;
280 }
281 
282 static inline std::string getFeaturesStr() {
284 
285  // If user asked for the 'native' CPU, we need to autodetect features.
286  // This is necessary for x86 where the CPU might not support all the
287  // features the autodetected CPU name lists in the target. For example,
288  // not all Sandybridge processors support AVX.
289  if (MCPU == "native") {
290  StringMap<bool> HostFeatures;
291  if (sys::getHostCPUFeatures(HostFeatures))
292  for (auto &F : HostFeatures)
293  Features.AddFeature(F.first(), F.second);
294  }
295 
296  for (unsigned i = 0; i != MAttrs.size(); ++i)
297  Features.AddFeature(MAttrs[i]);
298 
299  return Features.getString();
300 }
301 
302 /// \brief Set function attributes of functions in Module M based on CPU,
303 /// Features, and command line flags.
305  Module &M) {
306  for (auto &F : M) {
307  auto &Ctx = F.getContext();
308  AttributeSet Attrs = F.getAttributes(), NewAttrs;
309 
310  if (!CPU.empty())
311  NewAttrs = NewAttrs.addAttribute(Ctx, AttributeSet::FunctionIndex,
312  "target-cpu", CPU);
313 
314  if (!Features.empty())
315  NewAttrs = NewAttrs.addAttribute(Ctx, AttributeSet::FunctionIndex,
316  "target-features", Features);
317 
318  if (DisableFPElim.getNumOccurrences() > 0)
319  NewAttrs = NewAttrs.addAttribute(Ctx, AttributeSet::FunctionIndex,
320  "no-frame-pointer-elim",
321  DisableFPElim ? "true" : "false");
322 
323  if (DisableTailCalls.getNumOccurrences() > 0)
324  NewAttrs = NewAttrs.addAttribute(Ctx, AttributeSet::FunctionIndex,
325  "disable-tail-calls",
327 
328  if (TrapFuncName.getNumOccurrences() > 0)
329  for (auto &B : F)
330  for (auto &I : B)
331  if (auto *Call = dyn_cast<CallInst>(&I))
332  if (const auto *F = Call->getCalledFunction())
333  if (F->getIntrinsicID() == Intrinsic::debugtrap ||
334  F->getIntrinsicID() == Intrinsic::trap)
336  "trap-func-name", TrapFuncName);
337 
338  // Let NewAttrs override Attrs.
339  NewAttrs = Attrs.addAttributes(Ctx, AttributeSet::FunctionIndex, NewAttrs);
340  F.setAttributes(NewAttrs);
341  }
342 }
343 
344 #endif
ValuesClass< DataType > LLVM_END_WITH_NULL values(const char *Arg, DataType Val, const char *Desc,...)
Definition: CommandLine.h:536
cl::opt< bool > EnableNoNaNsFPMath("enable-no-nans-fp-math", cl::desc("Enable FP math optimizations that assume no NaNs"), cl::init(false))
cl::opt< bool > UniqueSectionNames("unique-section-names", cl::desc("Give unique names to every section"), cl::init(true))
MCTargetOptions MCOptions
Machine level options.
static std::string getCPUStr()
Definition: CommandFlags.h:272
A Module instance is used to store all the information related to an LLVM module. ...
Definition: Module.h:114
#define clEnumValEnd
Definition: CommandLine.h:498
unsigned DataSections
Emit data into separate sections.
cl::opt< llvm::JumpTable::JumpTableType > JTableType("jump-table-type", cl::desc("Choose the type of Jump-Instruction Table for jumptable."), cl::init(JumpTable::Single), cl::values(clEnumValN(JumpTable::Single,"single","Create a single table for all jumptable functions"), clEnumValN(JumpTable::Arity,"arity","Create one table per number of parameters."), clEnumValN(JumpTable::Simplified,"simplified","Create one table per simplified function type."), clEnumValN(JumpTable::Full,"full","Create one table per unique function type."), clEnumValEnd))
cl::opt< ThreadModel::Model > TMModel("thread-model", cl::desc("Choose threading model"), cl::init(ThreadModel::POSIX), cl::values(clEnumValN(ThreadModel::POSIX,"posix","POSIX thread model"), clEnumValN(ThreadModel::Single,"single","Single thread model"), clEnumValEnd))
const FeatureBitset Features
F(f)
ThreadModel::Model ThreadModel
ThreadModel - This flag specifies the type of threading model to assume for things like atomics...
static MCTargetOptions InitMCTargetOptionsFromFlags()
cl::opt< llvm::FPOpFusion::FPOpFusionMode > FuseFPOps("fp-contract", cl::desc("Enable aggressive formation of fused FP ops"), cl::init(FPOpFusion::Standard), cl::values(clEnumValN(FPOpFusion::Fast,"fast","Fuse FP ops whenever profitable"), clEnumValN(FPOpFusion::Standard,"on","Only fuse 'blessed' FP ops."), clEnumValN(FPOpFusion::Strict,"off","Only fuse FP ops when the result won't be affected."), clEnumValEnd))
void AddFeature(StringRef String, bool Enable=true)
Adding Features.
cl::opt< bool > EnableFPMAD("enable-fp-mad", cl::desc("Enable less precise MAD instructions to be generated"), cl::init(false))
static TargetOptions InitTargetOptionsFromCodeGenFlags()
Definition: CommandFlags.h:243
unsigned NoNaNsFPMath
NoNaNsFPMath - This flag is enabled when the -enable-no-nans-fp-math flag is specified on the command...
unsigned FunctionSections
Emit functions into separate sections.
cl::opt< bool > EnablePIE("enable-pie", cl::desc("Assume the creation of a position independent executable."), cl::init(false))
unsigned UniqueSectionNames
cl::opt< bool > DisableFPElim("disable-fp-elim", cl::desc("Disable frame pointer elimination optimization"), cl::init(false))
cl::opt< bool > DontPlaceZerosInBSS("nozero-initialized-in-bss", cl::desc("Don't place zero-initialized symbols into bss section"), cl::init(false))
initializer< Ty > init(const Ty &Val)
Definition: CommandLine.h:325
unsigned UnsafeFPMath
UnsafeFPMath - This flag is enabled when the -enable-unsafe-fp-math flag is specified on the command ...
FPOpFusion::FPOpFusionMode AllowFPOpFusion
AllowFPOpFusion - This flag is set by the -fuse-fp-ops=xxx option.
cl::opt< Reloc::Model > RelocModel("relocation-model", cl::desc("Choose relocation model"), cl::init(Reloc::Default), cl::values(clEnumValN(Reloc::Default,"default","Target default relocation model"), clEnumValN(Reloc::Static,"static","Non-relocatable code"), clEnumValN(Reloc::PIC_,"pic","Fully relocatable, position independent code"), clEnumValN(Reloc::DynamicNoPIC,"dynamic-no-pic","Relocatable external references, non-relocatable code"), clEnumValEnd))
static void setFunctionAttributes(StringRef CPU, StringRef Features, Module &M)
Set function attributes of functions in Module M based on CPU, Features, and command line flags...
Definition: CommandFlags.h:304
cl::list< std::string > MAttrs("mattr", cl::CommaSeparated, cl::desc("Target specific attributes (-mattr=help for details)"), cl::value_desc("a1,+a2,-a3,..."))
cl::opt< bool > EnableNoInfsFPMath("enable-no-infs-fp-math", cl::desc("Enable FP math optimizations that assume no +-Infs"), cl::init(false))
TargetRecip Reciprocals
This class encapsulates options for reciprocal-estimate code generation.
unsigned GuaranteedTailCallOpt
GuaranteedTailCallOpt - This flag is enabled when -tailcallopt is specified on the commandline...
unsigned NoInfsFPMath
NoInfsFPMath - This flag is enabled when the -enable-no-infs-fp-math flag is specified on the command...
unsigned NoZerosInBSS
NoZerosInBSS - By default some codegens place zero-initialized data to .bss section.
cl::opt< llvm::CodeModel::Model > CMModel("code-model", cl::desc("Choose code model"), cl::init(CodeModel::Default), cl::values(clEnumValN(CodeModel::Default,"default","Target default code model"), clEnumValN(CodeModel::Small,"small","Small code model"), clEnumValN(CodeModel::Kernel,"kernel","Kernel code model"), clEnumValN(CodeModel::Medium,"medium","Medium code model"), clEnumValN(CodeModel::Large,"large","Large code model"), clEnumValEnd))
std::string getString() const
Features string accessors.
cl::opt< llvm::FloatABI::ABIType > FloatABIForCalls("float-abi", cl::desc("Choose float ABI type"), cl::init(FloatABI::Default), cl::values(clEnumValN(FloatABI::Default,"default","Target default float ABI type"), clEnumValN(FloatABI::Soft,"soft","Soft float ABI (implied by -soft-float)"), clEnumValN(FloatABI::Hard,"hard","Hard float ABI (uses FP registers)"), clEnumValEnd))
cl::opt< bool > EnableUnsafeFPMath("enable-unsafe-fp-math", cl::desc("Enable optimizations that may decrease FP precision"), cl::init(false))
cl::opt< std::string > MCPU("mcpu", cl::desc("Target a specific cpu type (-mcpu=help for details)"), cl::value_desc("cpu-name"), cl::init(""))
cl::opt< bool > FunctionSections("function-sections", cl::desc("Emit functions into separate sections"), cl::init(false))
JumpTable::JumpTableType JTType
JTType - This flag specifies the type of jump-instruction table to create for functions that have the...
unsigned UseInitArray
UseInitArray - Use .init_array instead of .ctors for static constructors.
Module.h This file contains the declarations for the Module class.
cl::opt< std::string > MArch("march", cl::desc("Architecture to generate code for (see --version)"))
cl::opt< bool > DisableTailCalls("disable-tail-calls", cl::desc("Never emit tail calls"), cl::init(false))
unsigned StackAlignmentOverride
StackAlignmentOverride - Override default stack alignment for target.
SubtargetFeatures - Manages the enabling and disabling of subtarget specific features.
cl::opt< bool > DataSections("data-sections", cl::desc("Emit data into separate sections"), cl::init(false))
static std::string getFeaturesStr()
Definition: CommandFlags.h:282
cl::opt< unsigned > OverrideStackAlignment("stack-alignment", cl::desc("Override default stack alignment"), cl::init(0))
static StringRef toStringRef(bool B)
Construct a string ref from a boolean.
Definition: StringExtras.h:32
#define clEnumValN(ENUMVAL, FLAGNAME, DESC)
Definition: CommandLine.h:497
cl::opt< std::string > TrapFuncName("trap-func", cl::Hidden, cl::desc("Emit a call to trap function rather than a trap instruction"), cl::init(""))
cl::opt< std::string > RunPass("run-pass", cl::desc("Run compiler only for one specific pass"), cl::value_desc("pass-name"), cl::init(""))
StringRef getHostCPUName()
getHostCPUName - Get the LLVM name for the host CPU.
Definition: Host.cpp:729
unsigned PositionIndependentExecutable
PositionIndependentExecutable - This flag indicates whether the code will eventually be linked into a...
#define I(x, y, z)
Definition: MD5.cpp:54
cl::opt< std::string > StopAfter("stop-after", cl::desc("Stop compilation after a specific pass"), cl::value_desc("pass-name"), cl::init(""))
cl::opt< std::string > StartAfter("start-after", cl::desc("Resume compilation after a specific pass"), cl::value_desc("pass-name"), cl::init(""))
cl::opt< TargetMachine::CodeGenFileType > FileType("filetype", cl::init(TargetMachine::CGFT_AssemblyFile), cl::desc("Choose a file type (not all types are supported by all targets):"), cl::values(clEnumValN(TargetMachine::CGFT_AssemblyFile,"asm","Emit an assembly ('.s') file"), clEnumValN(TargetMachine::CGFT_ObjectFile,"obj","Emit a native object ('.o') file"), clEnumValN(TargetMachine::CGFT_Null,"null","Emit nothing, for performance testing"), clEnumValEnd))
cl::opt< bool > EnableHonorSignDependentRoundingFPMath("enable-sign-dependent-rounding-fp-math", cl::Hidden, cl::desc("Force codegen to assume rounding mode can change dynamically"), cl::init(false))
unsigned HonorSignDependentRoundingFPMathOption
HonorSignDependentRoundingFPMath - This returns true when the -enable-sign-dependent-rounding-fp-math...
cl::opt< bool > UseCtors("use-ctors", cl::desc("Use .ctors instead of .init_array."), cl::init(false))
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:40
cl::opt< bool > EnableGuaranteedTailCallOpt("tailcallopt", cl::desc("Turn fastcc calls into tail calls by (potentially) changing ABI."), cl::init(false))
cl::list< std::string > ReciprocalOps("recip", cl::CommaSeparated, cl::desc("Choose reciprocal operation types and parameters."), cl::value_desc("all,none,default,divf,!vec-sqrtd,vec-divd:0,sqrt:9..."))
bool getHostCPUFeatures(StringMap< bool > &Features)
getHostCPUFeatures - Get the LLVM names for the host CPU features.
Definition: Host.cpp:893
unsigned LessPreciseFPMADOption
LessPreciseFPMAD - This flag is enabled when the -enable-fp-mad is specified on the command line...
Definition: TargetOptions.h:94
AttributeSet addAttributes(LLVMContext &C, unsigned Index, AttributeSet Attrs) const
Add attributes to the attribute set at the given index.
Definition: Attributes.cpp:773
bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:110
FloatABI::ABIType FloatABIType
FloatABIType - This setting is set by -float-abi=xxx option is specfied on the command line...