#ifndef LLVM_CLANG_FRONTEND_CODEGENOPTIONS_H
#define LLVM_CLANG_FRONTEND_CODEGENOPTIONS_H
+#include "clang/Basic/DebugInfoOptions.h"
+#include "clang/Basic/Sanitizers.h"
+#include "llvm/Support/Regex.h"
+#include "llvm/Target/TargetOptions.h"
+#include <map>
+#include <memory>
#include <string>
+#include <vector>
namespace clang {
+/// \brief Bitfields of CodeGenOptions, split out from CodeGenOptions to ensure
+/// that this large collection of bitfields is a trivial class type.
+class CodeGenOptionsBase {
+public:
+#define CODEGENOPT(Name, Bits, Default) unsigned Name : Bits;
+#define ENUM_CODEGENOPT(Name, Type, Bits, Default)
+#include "clang/Frontend/CodeGenOptions.def"
+
+protected:
+#define CODEGENOPT(Name, Bits, Default)
+#define ENUM_CODEGENOPT(Name, Type, Bits, Default) unsigned Name : Bits;
+#include "clang/Frontend/CodeGenOptions.def"
+};
+
/// CodeGenOptions - Track various options which control how the code
/// is optimized and passed to the backend.
-class CodeGenOptions {
+class CodeGenOptions : public CodeGenOptionsBase {
public:
enum InliningMethod {
NoInlining, // Perform no inlining whatsoever.
NormalInlining, // Use the standard function inlining pass.
+ OnlyHintInlining, // Inline only (implicitly) hinted functions.
OnlyAlwaysInlining // Only run the always inlining pass.
};
+ enum VectorLibrary {
+ NoLibrary, // Don't use any vector library.
+ Accelerate, // Use the Accelerate framework.
+ SVML // Intel short vector math library.
+ };
+
+
enum ObjCDispatchMethodKind {
Legacy = 0,
NonLegacy = 1,
Mixed = 2
};
- unsigned AsmVerbose : 1; /// -dA, -fverbose-asm.
- unsigned CXAAtExit : 1; /// Use __cxa_atexit for calling destructors.
- unsigned CXXCtorDtorAliases: 1; /// Emit complete ctors/dtors as linker
- /// aliases to base ctors when possible.
- unsigned DataSections : 1; /// Set when -fdata-sections is enabled
- unsigned DebugInfo : 1; /// Should generate debug info (-g).
- unsigned LimitDebugInfo : 1; /// Limit generated debug info to reduce size.
- unsigned DisableFPElim : 1; /// Set when -fomit-frame-pointer is enabled.
- unsigned DisableLLVMOpts : 1; /// Don't run any optimizations, for use in
- /// getting .bc files that correspond to the
- /// internal state before optimizations are
- /// done.
- unsigned DisableRedZone : 1; /// Set when -mno-red-zone is enabled.
- unsigned EmitDeclMetadata : 1; /// Emit special metadata indicating what
- /// Decl* various IR entities came from. Only
- /// useful when running CodeGen as a
- /// subroutine.
- unsigned FunctionSections : 1; /// Set when -ffunction-sections is enabled
- unsigned HiddenWeakTemplateVTables : 1; /// Emit weak vtables and RTTI for
- /// template classes with hidden visibility
- unsigned HiddenWeakVTables : 1; /// Emit weak vtables, RTTI, and thunks with
- /// hidden visibility.
- unsigned InstrumentFunctions : 1; /// Set when -finstrument-functions is
- /// enabled.
- unsigned InstrumentForProfiling : 1; /// Set when -pg is enabled
- unsigned LessPreciseFPMAD : 1; /// Enable less precise MAD instructions to be
- /// generated.
- unsigned MergeAllConstants : 1; /// Merge identical constants.
- unsigned NoCommon : 1; /// Set when -fno-common or C++ is enabled.
- unsigned NoImplicitFloat : 1; /// Set when -mno-implicit-float is enabled.
- unsigned NoInfsFPMath : 1; /// Assume FP arguments, results not +-Inf.
- unsigned NoNaNsFPMath : 1; /// Assume FP arguments, results not NaN.
- unsigned NoZeroInitializedInBSS : 1; /// -fno-zero-initialized-in-bss
- unsigned ObjCDispatchMethod : 2; /// Method of Objective-C dispatch to use.
- unsigned OmitLeafFramePointer : 1; /// Set when -momit-leaf-frame-pointer is
- /// enabled.
- unsigned OptimizationLevel : 3; /// The -O[0-4] option specified.
- unsigned OptimizeSize : 1; /// If -Os is specified.
- unsigned RelaxAll : 1; /// Relax all machine code instructions.
- unsigned RelaxedAliasing : 1; /// Set when -fno-strict-aliasing is enabled.
- unsigned SimplifyLibCalls : 1; /// Set when -fbuiltin is enabled.
- unsigned SoftFloat : 1; /// -soft-float.
- unsigned TimePasses : 1; /// Set when -ftime-report is enabled.
- unsigned UnitAtATime : 1; /// Unused. For mirroring GCC optimization
- /// selection.
- unsigned UnrollLoops : 1; /// Control whether loops are unrolled.
- unsigned UnsafeFPMath : 1; /// Allow unsafe floating point optzns.
- unsigned UnwindTables : 1; /// Emit unwind tables.
- unsigned VerifyModule : 1; /// Control whether the module should be run
- /// through the LLVM Verifier.
+ enum TLSModel {
+ GeneralDynamicTLSModel,
+ LocalDynamicTLSModel,
+ InitialExecTLSModel,
+ LocalExecTLSModel
+ };
+
+ enum FPContractModeKind {
+ FPC_Off, // Form fused FP ops only where result will not be affected.
+ FPC_On, // Form fused FP ops according to FP_CONTRACT rules.
+ FPC_Fast // Aggressively fuse FP ops (E.g. FMA).
+ };
+
+ enum StructReturnConventionKind {
+ SRCK_Default, // No special option was passed.
+ SRCK_OnStack, // Small structs on the stack (-fpcc-struct-return).
+ SRCK_InRegs // Small structs in registers (-freg-struct-return).
+ };
+
+ enum ProfileInstrKind {
+ ProfileNone, // Profile instrumentation is turned off.
+ ProfileClangInstr, // Clang instrumentation to generate execution counts
+ // to use with PGO.
+ ProfileIRInstr, // IR level PGO instrumentation in LLVM.
+ };
+
+ enum EmbedBitcodeKind {
+ Embed_Off, // No embedded bitcode.
+ Embed_All, // Embed both bitcode and commandline in the output.
+ Embed_Bitcode, // Embed just the bitcode in the output.
+ Embed_Marker // Embed a marker as a placeholder for bitcode.
+ };
/// The code model to use (-mcmodel).
std::string CodeModel;
+ /// The filename with path we use for coverage data files. The runtime
+ /// allows further manipulation with the GCOV_PREFIX and GCOV_PREFIX_STRIP
+ /// environment variables.
+ std::string CoverageDataFile;
+
+ /// The filename with path we use for coverage notes files.
+ std::string CoverageNotesFile;
+
+ /// The version string to put into coverage files.
+ char CoverageVersion[4];
+
/// Enable additional debugging information.
std::string DebugPass;
+ /// The string to embed in debug information as the current working directory.
+ std::string DebugCompilationDir;
+
/// The string to embed in the debug information for the compile unit, if
/// non-empty.
std::string DwarfDebugFlags;
+ std::map<std::string, std::string> DebugPrefixMap;
+
/// The ABI to use for passing floating point arguments.
std::string FloatABI;
+ /// The floating-point denormal mode to use.
+ std::string FPDenormalMode;
+
/// The float precision limit to use, if non-empty.
std::string LimitFloatPrecision;
- /// The kind of inlining to perform.
- InliningMethod Inlining;
+ /// The name of the bitcode file to link before optzns.
+ std::vector<std::pair<unsigned, std::string>> LinkBitcodeFiles;
/// The user provided name for the "main file", if non-empty. This is useful
/// in situations where the input file name does not match the original input
/// file, for example with -save-temps.
std::string MainFileName;
+ /// The name for the split debug info file that we'll break out. This is used
+ /// in the backend for setting the name in the skeleton cu.
+ std::string SplitDwarfFile;
+
/// The name of the relocation model to use.
std::string RelocationModel;
- /// The user specified number of registers to be used for integral arguments,
- /// or 0 if unspecified.
- unsigned NumRegisterParameters;
+ /// The thread model to use
+ std::string ThreadModel;
+
+ /// If not an empty string, trap intrinsics are lowered to calls to this
+ /// function instead of to trap instructions.
+ std::string TrapFuncName;
+
+ /// A list of command-line options to forward to the LLVM backend.
+ std::vector<std::string> BackendOptions;
+
+ /// A list of dependent libraries.
+ std::vector<std::string> DependentLibraries;
+
+ /// A list of linker options to embed in the object file.
+ std::vector<std::string> LinkerOptions;
+
+ /// Name of the profile file to use as output for -fprofile-instr-generate
+ /// and -fprofile-generate.
+ std::string InstrProfileOutput;
+
+ /// Name of the profile file to use with -fprofile-sample-use.
+ std::string SampleProfileFile;
+
+ /// Name of the profile file to use as input for -fprofile-instr-use
+ std::string ProfileInstrumentUsePath;
+
+ /// Name of the function summary index file to use for ThinLTO function
+ /// importing.
+ std::string ThinLTOIndexFile;
+
+ /// A list of file names passed with -fcuda-include-gpubinary options to
+ /// forward to CUDA runtime back-end for incorporating them into host-side
+ /// object file.
+ std::vector<std::string> CudaGpuBinaryFileNames;
+
+ /// The name of the file to which the backend should save YAML optimization
+ /// records.
+ std::string OptRecordFile;
+
+ /// Regular expression to select optimizations for which we should enable
+ /// optimization remarks. Transformation passes whose name matches this
+ /// expression (and support this feature), will emit a diagnostic
+ /// whenever they perform a transformation. This is enabled by the
+ /// -Rpass=regexp flag.
+ std::shared_ptr<llvm::Regex> OptimizationRemarkPattern;
+
+ /// Regular expression to select optimizations for which we should enable
+ /// missed optimization remarks. Transformation passes whose name matches this
+ /// expression (and support this feature), will emit a diagnostic
+ /// whenever they tried but failed to perform a transformation. This is
+ /// enabled by the -Rpass-missed=regexp flag.
+ std::shared_ptr<llvm::Regex> OptimizationRemarkMissedPattern;
+
+ /// Regular expression to select optimizations for which we should enable
+ /// optimization analyses. Transformation passes whose name matches this
+ /// expression (and support this feature), will emit a diagnostic
+ /// whenever they want to explain why they decided to apply or not apply
+ /// a given transformation. This is enabled by the -Rpass-analysis=regexp
+ /// flag.
+ std::shared_ptr<llvm::Regex> OptimizationRemarkAnalysisPattern;
+
+ /// Set of files definining the rules for the symbol rewriting.
+ std::vector<std::string> RewriteMapFiles;
+
+ /// Set of sanitizer checks that are non-fatal (i.e. execution should be
+ /// continued when possible).
+ SanitizerSet SanitizeRecover;
+
+ /// Set of sanitizer checks that trap rather than diagnose.
+ SanitizerSet SanitizeTrap;
+
+ /// List of backend command-line options for -fembed-bitcode.
+ std::vector<uint8_t> CmdArgs;
+
+ /// \brief A list of all -fno-builtin-* function names (e.g., memset).
+ std::vector<std::string> NoBuiltinFuncs;
public:
- CodeGenOptions() {
- AsmVerbose = 0;
- CXAAtExit = 1;
- CXXCtorDtorAliases = 0;
- DataSections = 0;
- DebugInfo = 0;
- LimitDebugInfo = 0;
- DisableFPElim = 0;
- DisableLLVMOpts = 0;
- DisableRedZone = 0;
- EmitDeclMetadata = 0;
- FunctionSections = 0;
- HiddenWeakTemplateVTables = 0;
- HiddenWeakVTables = 0;
- InstrumentFunctions = 0;
- InstrumentForProfiling = 0;
- LessPreciseFPMAD = 0;
- MergeAllConstants = 1;
- NoCommon = 0;
- NoImplicitFloat = 0;
- NoInfsFPMath = 0;
- NoNaNsFPMath = 0;
- NoZeroInitializedInBSS = 0;
- NumRegisterParameters = 0;
- ObjCDispatchMethod = Legacy;
- OmitLeafFramePointer = 0;
- OptimizationLevel = 0;
- OptimizeSize = 0;
- RelaxAll = 0;
- RelaxedAliasing = 0;
- SimplifyLibCalls = 1;
- SoftFloat = 0;
- TimePasses = 0;
- UnitAtATime = 1;
- UnrollLoops = 0;
- UnsafeFPMath = 0;
- UnwindTables = 0;
- VerifyModule = 1;
-
- Inlining = NoInlining;
- RelocationModel = "pic";
+ // Define accessors/mutators for code generation options of enumeration type.
+#define CODEGENOPT(Name, Bits, Default)
+#define ENUM_CODEGENOPT(Name, Type, Bits, Default) \
+ Type get##Name() const { return static_cast<Type>(Name); } \
+ void set##Name(Type Value) { Name = static_cast<unsigned>(Value); }
+#include "clang/Frontend/CodeGenOptions.def"
+
+ CodeGenOptions();
+
+ /// \brief Is this a libc/libm function that is no longer recognized as a
+ /// builtin because a -fno-builtin-* option has been specified?
+ bool isNoBuiltinFunc(const char *Name) const;
+
+ const std::vector<std::string> &getNoBuiltinFuncs() const {
+ return NoBuiltinFuncs;
+ }
+
+ /// \brief Check if Clang profile instrumenation is on.
+ bool hasProfileClangInstr() const {
+ return getProfileInstr() == ProfileClangInstr;
+ }
+
+ /// \brief Check if IR level profile instrumentation is on.
+ bool hasProfileIRInstr() const {
+ return getProfileInstr() == ProfileIRInstr;
}
- ObjCDispatchMethodKind getObjCDispatchMethod() const {
- return ObjCDispatchMethodKind(ObjCDispatchMethod);
+ /// \brief Check if Clang profile use is on.
+ bool hasProfileClangUse() const {
+ return getProfileUse() == ProfileClangInstr;
}
+
+ /// \brief Check if IR level profile use is on.
+ bool hasProfileIRUse() const {
+ return getProfileUse() == ProfileIRInstr;
+ }
+
};
} // end namespace clang