FLANG
CodeGenOptions.h
1//===--- CodeGenOptions.h ---------------------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file defines the CodeGenOptions interface, which holds the
10// configuration for LLVM's middle-end and back-end. It controls LLVM's code
11// generation into assembly or machine code.
12//
13//===----------------------------------------------------------------------===//
14
15#ifndef FORTRAN_FRONTEND_CODEGENOPTIONS_H
16#define FORTRAN_FRONTEND_CODEGENOPTIONS_H
17
18#include "flang/Optimizer/OpenMP/Utils.h"
20#include "llvm/Frontend/Debug/Options.h"
21#include "llvm/Frontend/Driver/CodeGenOptions.h"
22#include "llvm/Support/CodeGen.h"
23#include "llvm/Support/Regex.h"
24#include "llvm/Target/TargetOptions.h"
25#include "llvm/Transforms/Instrumentation/AddressSanitizerOptions.h"
26#include <map>
27#include <memory>
28#include <optional>
29#include <string>
30#include <vector>
31
32namespace Fortran::frontend {
33
37
38public:
39#define CODEGENOPT(Name, Bits, Default) unsigned Name : Bits;
40#define ENUM_CODEGENOPT(Name, Type, Bits, Default)
41#include "flang/Frontend/CodeGenOptions.def"
42
43protected:
44#define CODEGENOPT(Name, Bits, Default)
45#define ENUM_CODEGENOPT(Name, Type, Bits, Default) unsigned Name : Bits;
46#include "flang/Frontend/CodeGenOptions.def"
47};
48
51class CodeGenOptions : public CodeGenOptionsBase {
52
53public:
55 std::vector<std::string> LLVMPassPlugins;
56
58 std::string PreferVectorWidth;
59
61 std::string Reciprocals;
62
65 std::vector<std::string> OffloadObjects;
66
69 std::vector<std::string> BuiltinBCLibs;
70
72 std::optional<std::string> SaveTempsDir;
73
75 std::optional<std::string> RecordCommandLine;
76
80 std::string DwarfDebugFlags;
81
84 std::string OptRecordFile;
85
88 std::string OptRecordPasses;
89
91 std::string OptRecordFormat;
92
94 std::vector<std::string> DependentLibs;
95
96 // The RemarkKind enum class and OptRemark struct are identical to what Clang
97 // has
98 // TODO: Share with clang instead of re-implementing here
99 enum class RemarkKind {
100 RK_Missing, // Remark argument not present on the command line.
101 RK_Enabled, // Remark enabled via '-Rgroup', i.e. -Rpass, -Rpass-missed,
102 // -Rpass-analysis
103 RK_Disabled, // Remark disabled via '-Rno-group', i.e. -Rno-pass,
104 // -Rno-pass-missed, -Rno-pass-analysis.
105 RK_WithPattern, // Remark pattern specified via '-Rgroup=regexp'.
106 };
107
109 llvm::CodeObjectVersionKind CodeObjectVersion =
110 llvm::CodeObjectVersionKind::COV_None;
111
113 struct OptRemark {
114 RemarkKind Kind = RemarkKind::RK_Missing;
115 std::string Pattern;
116 std::shared_ptr<llvm::Regex> Regex;
117
119 OptRemark() = default;
120
123 bool hasValidPattern() const { return Regex != nullptr; }
124
126 bool patternMatches(llvm::StringRef string) const {
127 return hasValidPattern() && Regex->match(string);
128 }
129 };
130
131 // The OptRemark fields provided here are identical to Clang.
132
138
144
151
153 std::string CodeModel;
154
158
161 using DoConcurrentMappingKind = flangomp::DoConcurrentMappingKind;
162
166
169
172
176
179 std::string SplitDwarfFile;
180
182 std::string SplitDwarfOutput;
183
185 bool hasProfileClangInstr() const {
186 return getProfileInstr() == llvm::driver::ProfileClangInstr;
187 }
188
190 bool hasProfileIRInstr() const {
191 return getProfileInstr() == llvm::driver::ProfileIRInstr;
192 }
193
195 bool hasProfileCSIRInstr() const {
196 return getProfileInstr() == llvm::driver::ProfileCSIRInstr;
197 }
198
199 bool hasProfileIRUse() const {
200 return getProfileUse() == llvm::driver::ProfileIRInstr ||
201 getProfileUse() == llvm::driver::ProfileCSIRInstr;
202 }
203
204 bool hasProfileCSIRUse() const {
205 return getProfileUse() == llvm::driver::ProfileCSIRInstr;
206 }
207
232
233 // Define accessors/mutators for code generation options of enumeration type.
234#define CODEGENOPT(Name, Bits, Default)
235#define ENUM_CODEGENOPT(Name, Type, Bits, Default) \
236 Type get##Name() const { return static_cast<Type>(Name); } \
237 void set##Name(Type Value) { Name = static_cast<unsigned>(Value); }
238#include "flang/Frontend/CodeGenOptions.def"
239
241};
242
243std::optional<llvm::CodeModel::Model> getCodeModel(llvm::StringRef string);
244
245} // end namespace Fortran::frontend
246
247#endif // FORTRAN_FRONTEND_CODEGENOPTIONS_H
Definition CodeGenOptions.h:36
Definition CodeGenOptions.h:51
std::string MemoryProfileUsePath
Name of the profile file to use as input for -fmemory-profile-use.
Definition CodeGenOptions.h:168
std::string PreferVectorWidth
The prefered vector width, if requested by -mprefer-vector-width.
Definition CodeGenOptions.h:58
std::string OptRecordPasses
Definition CodeGenOptions.h:88
std::vector< std::string > DependentLibs
Options to add to the linker for the object file.
Definition CodeGenOptions.h:94
std::string SplitDwarfFile
Definition CodeGenOptions.h:179
bool hasProfileClangInstr() const
Check if Clang profile instrumenation is on.
Definition CodeGenOptions.h:185
std::string SplitDwarfOutput
Output filename for the split debug info, not used in the skeleton CU.
Definition CodeGenOptions.h:182
OptRemark OptimizationRemark
Definition CodeGenOptions.h:137
llvm::CodeObjectVersionKind CodeObjectVersion
Code object version for AMDGPU.
Definition CodeGenOptions.h:109
OptRemark OptimizationRemarkAnalysis
Definition CodeGenOptions.h:150
std::string InstrProfileOutput
Definition CodeGenOptions.h:165
std::string ProfileRemappingFile
Definition CodeGenOptions.h:175
std::string Reciprocals
List of reciprocal estimate sub-options.
Definition CodeGenOptions.h:61
std::vector< std::string > LLVMPassPlugins
The paths to the pass plugins that were registered using -fpass-plugin.
Definition CodeGenOptions.h:55
std::string OptRecordFormat
The format used for serializing remarks (default: YAML)
Definition CodeGenOptions.h:91
std::optional< std::string > SaveTempsDir
The directory where temp files are stored if specified by -save-temps.
Definition CodeGenOptions.h:72
flangomp::DoConcurrentMappingKind DoConcurrentMappingKind
Definition CodeGenOptions.h:161
bool hasProfileCSIRInstr() const
Check if CS IR level profile instrumentation is on.
Definition CodeGenOptions.h:195
std::string CodeModel
The code model to use (-mcmodel).
Definition CodeGenOptions.h:153
std::vector< std::string > OffloadObjects
Definition CodeGenOptions.h:65
ComplexRangeKind
Controls the various implementations for complex division.
Definition CodeGenOptions.h:209
@ CX_Full
Definition CodeGenOptions.h:213
@ CX_None
No range rule is enabled.
Definition CodeGenOptions.h:227
@ CX_Basic
Definition CodeGenOptions.h:224
@ CX_Improved
Definition CodeGenOptions.h:219
std::string ProfileInstrumentUsePath
Name of the profile file to use as input for -fprofile-instr-use.
Definition CodeGenOptions.h:171
std::string DwarfDebugFlags
Definition CodeGenOptions.h:80
std::optional< std::string > RecordCommandLine
The string containing the commandline for the llvm.commandline metadata.
Definition CodeGenOptions.h:75
std::string OptRecordFile
Definition CodeGenOptions.h:84
std::vector< std::string > BuiltinBCLibs
Definition CodeGenOptions.h:69
uint64_t LargeDataThreshold
Definition CodeGenOptions.h:157
OptRemark OptimizationRemarkMissed
Definition CodeGenOptions.h:143
bool hasProfileIRInstr() const
Check if IR level profile instrumentation is on.
Definition CodeGenOptions.h:190
bool hasProfileCSIRUse() const
Check if CSIR profile use is on.
Definition CodeGenOptions.h:204
bool hasProfileIRUse() const
Check if IR level profile use is on.
Definition CodeGenOptions.h:199
Optimization remark with an optional regular expression pattern.
Definition CodeGenOptions.h:113
OptRemark()=default
By default, optimization remark is missing.
bool hasValidPattern() const
Definition CodeGenOptions.h:123
bool patternMatches(llvm::StringRef string) const
Matches the given string against the regex, if there is some.
Definition CodeGenOptions.h:126