1//===--- CodeGenOptions.h ---------------------------------------*- 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 defines the CodeGenOptions interface.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_CLANG_FRONTEND_CODEGENOPTIONS_H
15#define LLVM_CLANG_FRONTEND_CODEGENOPTIONS_H
16
17#include <string>
18#include <vector>
19#include "llvm/Support/Regex.h"
20
21namespace clang {
22
23/// \brief Bitfields of CodeGenOptions, split out from CodeGenOptions to ensure
24/// that this large collection of bitfields is a trivial class type.
25class CodeGenOptionsBase {
26public:
27#define CODEGENOPT(Name, Bits, Default) unsigned Name : Bits;
28#define ENUM_CODEGENOPT(Name, Type, Bits, Default)
29#include "clang/Frontend/CodeGenOptions.def"
30
31protected:
32#define CODEGENOPT(Name, Bits, Default)
33#define ENUM_CODEGENOPT(Name, Type, Bits, Default) unsigned Name : Bits;
34#include "clang/Frontend/CodeGenOptions.def"
35};
36
37/// CodeGenOptions - Track various options which control how the code
38/// is optimized and passed to the backend.
39class CodeGenOptions : public CodeGenOptionsBase {
40public:
41  enum InliningMethod {
42    NoInlining,         // Perform no inlining whatsoever.
43    NormalInlining,     // Use the standard function inlining pass.
44    OnlyAlwaysInlining  // Only run the always inlining pass.
45  };
46
47  enum ObjCDispatchMethodKind {
48    Legacy = 0,
49    NonLegacy = 1,
50    Mixed = 2
51  };
52
53  enum DebugInfoKind {
54    NoDebugInfo,          /// Don't generate debug info.
55
56    LocTrackingOnly,      /// Emit location information but do not generate
57                          /// debug info in the output. This is useful in
58                          /// cases where the backend wants to track source
59                          /// locations for instructions without actually
60                          /// emitting debug info for them (e.g., when -Rpass
61                          /// is used).
62
63    DebugLineTablesOnly,  /// Emit only debug info necessary for generating
64                          /// line number tables (-gline-tables-only).
65
66    LimitedDebugInfo,     /// Limit generated debug info to reduce size
67                          /// (-fno-standalone-debug). This emits
68                          /// forward decls for types that could be
69                          /// replaced with forward decls in the source
70                          /// code. For dynamic C++ classes type info
71                          /// is only emitted int the module that
72                          /// contains the classe's vtable.
73
74    FullDebugInfo         /// Generate complete debug info.
75  };
76
77  enum TLSModel {
78    GeneralDynamicTLSModel,
79    LocalDynamicTLSModel,
80    InitialExecTLSModel,
81    LocalExecTLSModel
82  };
83
84  enum FPContractModeKind {
85    FPC_Off,        // Form fused FP ops only where result will not be affected.
86    FPC_On,         // Form fused FP ops according to FP_CONTRACT rules.
87    FPC_Fast        // Aggressively fuse FP ops (E.g. FMA).
88  };
89
90  enum StructReturnConventionKind {
91    SRCK_Default,  // No special option was passed.
92    SRCK_OnStack,  // Small structs on the stack (-fpcc-struct-return).
93    SRCK_InRegs    // Small structs in registers (-freg-struct-return).
94  };
95
96  /// The code model to use (-mcmodel).
97  std::string CodeModel;
98
99  /// The filename with path we use for coverage files. The extension will be
100  /// replaced.
101  std::string CoverageFile;
102
103  /// The version string to put into coverage files.
104  char CoverageVersion[4];
105
106  /// Enable additional debugging information.
107  std::string DebugPass;
108
109  /// The string to embed in debug information as the current working directory.
110  std::string DebugCompilationDir;
111
112  /// The string to embed in the debug information for the compile unit, if
113  /// non-empty.
114  std::string DwarfDebugFlags;
115
116  /// The ABI to use for passing floating point arguments.
117  std::string FloatABI;
118
119  /// The float precision limit to use, if non-empty.
120  std::string LimitFloatPrecision;
121
122  /// The name of the bitcode file to link before optzns.
123  std::string LinkBitcodeFile;
124
125  /// The user provided name for the "main file", if non-empty. This is useful
126  /// in situations where the input file name does not match the original input
127  /// file, for example with -save-temps.
128  std::string MainFileName;
129
130  /// The name for the split debug info file that we'll break out. This is used
131  /// in the backend for setting the name in the skeleton cu.
132  std::string SplitDwarfFile;
133
134  /// The name of the relocation model to use.
135  std::string RelocationModel;
136
137  /// Path to blacklist file for sanitizers.
138  std::string SanitizerBlacklistFile;
139
140  /// If not an empty string, trap intrinsics are lowered to calls to this
141  /// function instead of to trap instructions.
142  std::string TrapFuncName;
143
144  /// A list of command-line options to forward to the LLVM backend.
145  std::vector<std::string> BackendOptions;
146
147  /// A list of dependent libraries.
148  std::vector<std::string> DependentLibraries;
149
150  /// Name of the profile file to use with -fprofile-sample-use.
151  std::string SampleProfileFile;
152
153  /// Name of the profile file to use as input for -fprofile-instr-use
154  std::string InstrProfileInput;
155
156  /// Regular expression to select optimizations for which we should enable
157  /// optimization remarks. Transformation passes whose name matches this
158  /// expression (and support this feature), will emit a diagnostic
159  /// whenever they perform a transformation. This is enabled by the
160  /// -Rpass=regexp flag.
161  std::shared_ptr<llvm::Regex> OptimizationRemarkPattern;
162
163  /// Regular expression to select optimizations for which we should enable
164  /// missed optimization remarks. Transformation passes whose name matches this
165  /// expression (and support this feature), will emit a diagnostic
166  /// whenever they tried but failed to perform a transformation. This is
167  /// enabled by the -Rpass-missed=regexp flag.
168  std::shared_ptr<llvm::Regex> OptimizationRemarkMissedPattern;
169
170  /// Regular expression to select optimizations for which we should enable
171  /// optimization analyses. Transformation passes whose name matches this
172  /// expression (and support this feature), will emit a diagnostic
173  /// whenever they want to explain why they decided to apply or not apply
174  /// a given transformation. This is enabled by the -Rpass-analysis=regexp
175  /// flag.
176  std::shared_ptr<llvm::Regex> OptimizationRemarkAnalysisPattern;
177
178public:
179  // Define accessors/mutators for code generation options of enumeration type.
180#define CODEGENOPT(Name, Bits, Default)
181#define ENUM_CODEGENOPT(Name, Type, Bits, Default) \
182  Type get##Name() const { return static_cast<Type>(Name); } \
183  void set##Name(Type Value) { Name = static_cast<unsigned>(Value); }
184#include "clang/Frontend/CodeGenOptions.def"
185
186  CodeGenOptions() {
187#define CODEGENOPT(Name, Bits, Default) Name = Default;
188#define ENUM_CODEGENOPT(Name, Type, Bits, Default) \
189  set##Name(Default);
190#include "clang/Frontend/CodeGenOptions.def"
191
192    RelocationModel = "pic";
193    memcpy(CoverageVersion, "402*", 4);
194  }
195};
196
197}  // end namespace clang
198
199#endif
200