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 <memory>
26#include <optional>
27#include <string>
28#include <vector>
29
30namespace Fortran::frontend {
31
35
36public:
37#define CODEGENOPT(Name, Bits, Default) unsigned Name : Bits;
38#define ENUM_CODEGENOPT(Name, Type, Bits, Default)
39#include "flang/Frontend/CodeGenOptions.def"
40
41protected:
42#define CODEGENOPT(Name, Bits, Default)
43#define ENUM_CODEGENOPT(Name, Type, Bits, Default) unsigned Name : Bits;
44#include "flang/Frontend/CodeGenOptions.def"
45};
46
49class CodeGenOptions : public CodeGenOptionsBase {
50
51public:
53 std::vector<std::string> LLVMPassPlugins;
54
56 std::string PreferVectorWidth;
57
59 std::string Reciprocals;
60
63 std::vector<std::string> OffloadObjects;
64
67 std::vector<std::string> BuiltinBCLibs;
68
70 std::optional<std::string> SaveTempsDir;
71
73 std::optional<std::string> RecordCommandLine;
74
78 std::string DwarfDebugFlags;
79
82 std::string OptRecordFile;
83
86 std::string OptRecordPasses;
87
89 std::string OptRecordFormat;
90
92 std::vector<std::string> DependentLibs;
93
94 // The RemarkKind enum class and OptRemark struct are identical to what Clang
95 // has
96 // TODO: Share with clang instead of re-implementing here
97 enum class RemarkKind {
98 RK_Missing, // Remark argument not present on the command line.
99 RK_Enabled, // Remark enabled via '-Rgroup', i.e. -Rpass, -Rpass-missed,
100 // -Rpass-analysis
101 RK_Disabled, // Remark disabled via '-Rno-group', i.e. -Rno-pass,
102 // -Rno-pass-missed, -Rno-pass-analysis.
103 RK_WithPattern, // Remark pattern specified via '-Rgroup=regexp'.
104 };
105
107 llvm::CodeObjectVersionKind CodeObjectVersion =
108 llvm::CodeObjectVersionKind::COV_None;
109
111 struct OptRemark {
112 RemarkKind Kind = RemarkKind::RK_Missing;
113 std::string Pattern;
114 std::shared_ptr<llvm::Regex> Regex;
115
117 OptRemark() = default;
118
121 bool hasValidPattern() const { return Regex != nullptr; }
122
124 bool patternMatches(llvm::StringRef string) const {
125 return hasValidPattern() && Regex->match(string);
126 }
127 };
128
129 // The OptRemark fields provided here are identical to Clang.
130
136
142
149
151 std::string CodeModel;
152
156
159 using DoConcurrentMappingKind = flangomp::DoConcurrentMappingKind;
160
164
167
170
174
177 std::string SplitDwarfFile;
178
180 std::string SplitDwarfOutput;
181
183 std::string SampleProfileFile;
184
186 bool hasProfileClangInstr() const {
187 return getProfileInstr() == llvm::driver::ProfileClangInstr;
188 }
189
191 bool hasProfileIRInstr() const {
192 return getProfileInstr() == llvm::driver::ProfileIRInstr;
193 }
194
196 bool hasProfileCSIRInstr() const {
197 return getProfileInstr() == llvm::driver::ProfileCSIRInstr;
198 }
199
200 bool hasProfileIRUse() const {
201 return getProfileUse() == llvm::driver::ProfileIRInstr ||
202 getProfileUse() == llvm::driver::ProfileCSIRInstr;
203 }
204
205 bool hasProfileCSIRUse() const {
206 return getProfileUse() == llvm::driver::ProfileCSIRInstr;
207 }
208
233
234 // Define accessors/mutators for code generation options of enumeration type.
235#define CODEGENOPT(Name, Bits, Default)
236#define ENUM_CODEGENOPT(Name, Type, Bits, Default) \
237 Type get##Name() const { return static_cast<Type>(Name); } \
238 void set##Name(Type Value) { Name = static_cast<unsigned>(Value); }
239#include "flang/Frontend/CodeGenOptions.def"
240
242};
243
244std::optional<llvm::CodeModel::Model> getCodeModel(llvm::StringRef string);
245
246} // end namespace Fortran::frontend
247
248#endif // FORTRAN_FRONTEND_CODEGENOPTIONS_H
Definition CodeGenOptions.h:34
Definition CodeGenOptions.h:49
std::string MemoryProfileUsePath
Name of the profile file to use as input for -fmemory-profile-use.
Definition CodeGenOptions.h:166
std::string PreferVectorWidth
The prefered vector width, if requested by -mprefer-vector-width.
Definition CodeGenOptions.h:56
std::string OptRecordPasses
Definition CodeGenOptions.h:86
std::vector< std::string > DependentLibs
Options to add to the linker for the object file.
Definition CodeGenOptions.h:92
std::string SplitDwarfFile
Definition CodeGenOptions.h:177
bool hasProfileClangInstr() const
Check if Clang profile instrumenation is on.
Definition CodeGenOptions.h:186
std::string SplitDwarfOutput
Output filename for the split debug info, not used in the skeleton CU.
Definition CodeGenOptions.h:180
OptRemark OptimizationRemark
Definition CodeGenOptions.h:135
llvm::CodeObjectVersionKind CodeObjectVersion
Code object version for AMDGPU.
Definition CodeGenOptions.h:107
OptRemark OptimizationRemarkAnalysis
Definition CodeGenOptions.h:148
std::string InstrProfileOutput
Definition CodeGenOptions.h:163
std::string ProfileRemappingFile
Definition CodeGenOptions.h:173
std::string Reciprocals
List of reciprocal estimate sub-options.
Definition CodeGenOptions.h:59
std::vector< std::string > LLVMPassPlugins
The paths to the pass plugins that were registered using -fpass-plugin.
Definition CodeGenOptions.h:53
std::string SampleProfileFile
Name of the profile file to use with -fprofile-sample-use.
Definition CodeGenOptions.h:183
std::string OptRecordFormat
The format used for serializing remarks (default: YAML)
Definition CodeGenOptions.h:89
std::optional< std::string > SaveTempsDir
The directory where temp files are stored if specified by -save-temps.
Definition CodeGenOptions.h:70
flangomp::DoConcurrentMappingKind DoConcurrentMappingKind
Definition CodeGenOptions.h:159
bool hasProfileCSIRInstr() const
Check if CS IR level profile instrumentation is on.
Definition CodeGenOptions.h:196
std::string CodeModel
The code model to use (-mcmodel).
Definition CodeGenOptions.h:151
std::vector< std::string > OffloadObjects
Definition CodeGenOptions.h:63
ComplexRangeKind
Controls the various implementations for complex division.
Definition CodeGenOptions.h:210
@ CX_Full
Definition CodeGenOptions.h:214
@ CX_None
No range rule is enabled.
Definition CodeGenOptions.h:228
@ CX_Basic
Definition CodeGenOptions.h:225
@ CX_Improved
Definition CodeGenOptions.h:220
std::string ProfileInstrumentUsePath
Name of the profile file to use as input for -fprofile-instr-use.
Definition CodeGenOptions.h:169
std::string DwarfDebugFlags
Definition CodeGenOptions.h:78
std::optional< std::string > RecordCommandLine
The string containing the commandline for the llvm.commandline metadata.
Definition CodeGenOptions.h:73
std::string OptRecordFile
Definition CodeGenOptions.h:82
std::vector< std::string > BuiltinBCLibs
Definition CodeGenOptions.h:67
uint64_t LargeDataThreshold
Definition CodeGenOptions.h:155
OptRemark OptimizationRemarkMissed
Definition CodeGenOptions.h:141
bool hasProfileIRInstr() const
Check if IR level profile instrumentation is on.
Definition CodeGenOptions.h:191
bool hasProfileCSIRUse() const
Check if CSIR profile use is on.
Definition CodeGenOptions.h:205
bool hasProfileIRUse() const
Check if IR level profile use is on.
Definition CodeGenOptions.h:200
Optimization remark with an optional regular expression pattern.
Definition CodeGenOptions.h:111
OptRemark()=default
By default, optimization remark is missing.
bool hasValidPattern() const
Definition CodeGenOptions.h:121
bool patternMatches(llvm::StringRef string) const
Matches the given string against the regex, if there is some.
Definition CodeGenOptions.h:124