CodeGenOptions.h revision 561d62280aecff3168097086425a7da0442d0de4
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
20namespace clang {
21
22/// CodeGenOptions - Track various options which control how the code
23/// is optimized and passed to the backend.
24class CodeGenOptions {
25public:
26  enum InliningMethod {
27    NoInlining,         // Perform no inlining whatsoever.
28    NormalInlining,     // Use the standard function inlining pass.
29    OnlyAlwaysInlining  // Only run the always inlining pass.
30  };
31
32  enum ObjCDispatchMethodKind {
33    Legacy = 0,
34    NonLegacy = 1,
35    Mixed = 2
36  };
37
38  unsigned AsmVerbose        : 1; /// -dA, -fverbose-asm.
39  unsigned ObjCAutoRefCountExceptions : 1; /// Whether ARC should be EH-safe.
40  unsigned CUDAIsDevice      : 1; /// Set when compiling for CUDA device.
41  unsigned CXAAtExit         : 1; /// Use __cxa_atexit for calling destructors.
42  unsigned CXXCtorDtorAliases: 1; /// Emit complete ctors/dtors as linker
43                                  /// aliases to base ctors when possible.
44  unsigned DataSections      : 1; /// Set when -fdata-sections is enabled
45  unsigned DebugInfo         : 1; /// Should generate debug info (-g).
46  unsigned LimitDebugInfo    : 1; /// Limit generated debug info to reduce size.
47  unsigned DisableFPElim     : 1; /// Set when -fomit-frame-pointer is enabled.
48  unsigned DisableLLVMOpts   : 1; /// Don't run any optimizations, for use in
49                                  /// getting .bc files that correspond to the
50                                  /// internal state before optimizations are
51                                  /// done.
52  unsigned DisableRedZone    : 1; /// Set when -mno-red-zone is enabled.
53  unsigned DisableTailCalls  : 1; /// Do not emit tail calls.
54  unsigned EmitDeclMetadata  : 1; /// Emit special metadata indicating what
55                                  /// Decl* various IR entities came from.  Only
56                                  /// useful when running CodeGen as a
57                                  /// subroutine.
58  unsigned EmitGcovArcs      : 1; /// Emit coverage data files, aka. GCDA.
59  unsigned EmitGcovNotes     : 1; /// Emit coverage "notes" files, aka GCNO.
60  unsigned ForbidGuardVariables : 1; /// Issue errors if C++ guard variables
61                                  /// are required
62  unsigned FunctionSections  : 1; /// Set when -ffunction-sections is enabled
63  unsigned HiddenWeakTemplateVTables : 1; /// Emit weak vtables and RTTI for
64                                  /// template classes with hidden visibility
65  unsigned HiddenWeakVTables : 1; /// Emit weak vtables, RTTI, and thunks with
66                                  /// hidden visibility.
67  unsigned InstrumentFunctions : 1; /// Set when -finstrument-functions is
68                                    /// enabled.
69  unsigned InstrumentForProfiling : 1; /// Set when -pg is enabled
70  unsigned LessPreciseFPMAD  : 1; /// Enable less precise MAD instructions to be
71                                  /// generated.
72  unsigned MergeAllConstants : 1; /// Merge identical constants.
73  unsigned NoCommon          : 1; /// Set when -fno-common or C++ is enabled.
74  unsigned NoDwarf2CFIAsm    : 1; /// Set when -fno-dwarf2-cfi-asm is enabled.
75  unsigned NoDwarfDirectoryAsm : 1; /// Set when -fno-dwarf-directory-asm is
76                                    /// enabled.
77  unsigned NoExecStack       : 1; /// Set when -Wa,--noexecstack is enabled.
78  unsigned NoGlobalMerge     : 1; /// Set when -mno-global-merge is enabled.
79  unsigned NoImplicitFloat   : 1; /// Set when -mno-implicit-float is enabled.
80  unsigned NoInfsFPMath      : 1; /// Assume FP arguments, results not +-Inf.
81  unsigned NoInline          : 1; /// Set when -fno-inline is enabled. Disables
82                                  /// use of the inline keyword.
83  unsigned NoNaNsFPMath      : 1; /// Assume FP arguments, results not NaN.
84  unsigned NoZeroInitializedInBSS : 1; /// -fno-zero-initialized-in-bss
85  unsigned ObjCDispatchMethod : 2; /// Method of Objective-C dispatch to use.
86  unsigned ObjCRuntimeHasARC : 1; /// The target runtime supports ARC natively
87  unsigned ObjCRuntimeHasTerminate : 1; /// The ObjC runtime has objc_terminate
88  unsigned OmitLeafFramePointer : 1; /// Set when -momit-leaf-frame-pointer is
89                                     /// enabled.
90  unsigned OptimizationLevel : 3; /// The -O[0-4] option specified.
91  unsigned OptimizeSize      : 2; /// If -Os (==1) or -Oz (==2) is specified.
92  unsigned RelaxAll          : 1; /// Relax all machine code instructions.
93  unsigned RelaxedAliasing   : 1; /// Set when -fno-strict-aliasing is enabled.
94  unsigned SaveTempLabels    : 1; /// Save temporary labels.
95  unsigned SimplifyLibCalls  : 1; /// Set when -fbuiltin is enabled.
96  unsigned SoftFloat         : 1; /// -soft-float.
97  unsigned StrictEnums       : 1; /// Optimize based on strict enum definition.
98  unsigned TimePasses        : 1; /// Set when -ftime-report is enabled.
99  unsigned UnitAtATime       : 1; /// Unused. For mirroring GCC optimization
100                                  /// selection.
101  unsigned UnrollLoops       : 1; /// Control whether loops are unrolled.
102  unsigned UnsafeFPMath      : 1; /// Allow unsafe floating point optzns.
103  unsigned UnwindTables      : 1; /// Emit unwind tables.
104
105  /// Attempt to use register sized accesses to bit-fields in structures, when
106  /// possible.
107  unsigned UseRegisterSizedBitfieldAccess : 1;
108
109  unsigned VerifyModule      : 1; /// Control whether the module should be run
110                                  /// through the LLVM Verifier.
111
112  unsigned StackRealignment  : 1; /// Control whether to permit stack
113                                  /// realignment.
114  unsigned StackAlignment;        /// Overrides default stack alignment,
115                                  /// if not 0.
116
117  /// The code model to use (-mcmodel).
118  std::string CodeModel;
119
120  /// The filename with path we use for coverage files. The extension will be
121  /// replaced.
122  std::string CoverageFile;
123
124  /// Enable additional debugging information.
125  std::string DebugPass;
126
127  /// The string to embed in debug information as the current working directory.
128  std::string DebugCompilationDir;
129
130  /// The string to embed in the debug information for the compile unit, if
131  /// non-empty.
132  std::string DwarfDebugFlags;
133
134  /// The ABI to use for passing floating point arguments.
135  std::string FloatABI;
136
137  /// The float precision limit to use, if non-empty.
138  std::string LimitFloatPrecision;
139
140  /// The name of the bitcode file to link before optzns.
141  std::string LinkBitcodeFile;
142
143  /// The kind of inlining to perform.
144  InliningMethod Inlining;
145
146  /// The user provided name for the "main file", if non-empty. This is useful
147  /// in situations where the input file name does not match the original input
148  /// file, for example with -save-temps.
149  std::string MainFileName;
150
151  /// The name of the relocation model to use.
152  std::string RelocationModel;
153
154  /// If not an empty string, trap intrinsics are lowered to calls to this
155  /// function instead of to trap instructions.
156  std::string TrapFuncName;
157
158  /// A list of command-line options to forward to the LLVM backend.
159  std::vector<std::string> BackendOptions;
160
161  /// The user specified number of registers to be used for integral arguments,
162  /// or 0 if unspecified.
163  unsigned NumRegisterParameters;
164
165public:
166  CodeGenOptions() {
167    AsmVerbose = 0;
168    CUDAIsDevice = 0;
169    CXAAtExit = 1;
170    CXXCtorDtorAliases = 0;
171    DataSections = 0;
172    DebugInfo = 0;
173    LimitDebugInfo = 0;
174    DisableFPElim = 0;
175    DisableLLVMOpts = 0;
176    DisableRedZone = 0;
177    DisableTailCalls = 0;
178    EmitDeclMetadata = 0;
179    EmitGcovArcs = 0;
180    EmitGcovNotes = 0;
181    ForbidGuardVariables = 0;
182    FunctionSections = 0;
183    HiddenWeakTemplateVTables = 0;
184    HiddenWeakVTables = 0;
185    InstrumentFunctions = 0;
186    InstrumentForProfiling = 0;
187    LessPreciseFPMAD = 0;
188    MergeAllConstants = 1;
189    NoCommon = 0;
190    NoDwarf2CFIAsm = 0;
191    NoImplicitFloat = 0;
192    NoInfsFPMath = 0;
193    NoInline = 0;
194    NoNaNsFPMath = 0;
195    NoZeroInitializedInBSS = 0;
196    NumRegisterParameters = 0;
197    ObjCAutoRefCountExceptions = 0;
198    ObjCDispatchMethod = Legacy;
199    ObjCRuntimeHasARC = 0;
200    ObjCRuntimeHasTerminate = 0;
201    OmitLeafFramePointer = 0;
202    OptimizationLevel = 0;
203    OptimizeSize = 0;
204    RelaxAll = 0;
205    RelaxedAliasing = 0;
206    SaveTempLabels = 0;
207    SimplifyLibCalls = 1;
208    SoftFloat = 0;
209    StrictEnums = 0;
210    TimePasses = 0;
211    UnitAtATime = 1;
212    UnrollLoops = 0;
213    UnsafeFPMath = 0;
214    UnwindTables = 0;
215    UseRegisterSizedBitfieldAccess = 0;
216    VerifyModule = 1;
217    StackRealignment = 0;
218    StackAlignment = 0;
219
220    Inlining = NoInlining;
221    RelocationModel = "pic";
222  }
223
224  ObjCDispatchMethodKind getObjCDispatchMethod() const {
225    return ObjCDispatchMethodKind(ObjCDispatchMethod);
226  }
227};
228
229}  // end namespace clang
230
231#endif
232