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"
19#include "llvm/Frontend/Debug/Options.h"
20#include "llvm/Frontend/Driver/CodeGenOptions.h"
21#include "llvm/Support/CodeGen.h"
22#include "llvm/Support/Regex.h"
23#include "llvm/Target/TargetOptions.h"
24#include "llvm/Transforms/Instrumentation/AddressSanitizerOptions.h"
25#include <map>
26#include <memory>
27#include <optional>
28#include <string>
29#include <vector>
30
31namespace Fortran::frontend {
32
36
37public:
38#define CODEGENOPT(Name, Bits, Default) unsigned Name : Bits;
39#define ENUM_CODEGENOPT(Name, Type, Bits, Default)
40#include "flang/Frontend/CodeGenOptions.def"
41
42protected:
43#define CODEGENOPT(Name, Bits, Default)
44#define ENUM_CODEGENOPT(Name, Type, Bits, Default) unsigned Name : Bits;
45#include "flang/Frontend/CodeGenOptions.def"
46};
47
50class CodeGenOptions : public CodeGenOptionsBase {
51
52public:
54 std::vector<std::string> LLVMPassPlugins;
55
57 std::string PreferVectorWidth;
58
60 std::string Reciprocals;
61
64 std::vector<std::string> OffloadObjects;
65
68 std::vector<std::string> BuiltinBCLibs;
69
71 std::optional<std::string> SaveTempsDir;
72
74 std::optional<std::string> RecordCommandLine;
75
79 std::string DwarfDebugFlags;
80
83 std::string OptRecordFile;
84
87 std::string OptRecordPasses;
88
90 std::string OptRecordFormat;
91
93 std::vector<std::string> DependentLibs;
94
95 // The RemarkKind enum class and OptRemark struct are identical to what Clang
96 // has
97 // TODO: Share with clang instead of re-implementing here
98 enum class RemarkKind {
99 RK_Missing, // Remark argument not present on the command line.
100 RK_Enabled, // Remark enabled via '-Rgroup', i.e. -Rpass, -Rpass-missed,
101 // -Rpass-analysis
102 RK_Disabled, // Remark disabled via '-Rno-group', i.e. -Rno-pass,
103 // -Rno-pass-missed, -Rno-pass-analysis.
104 RK_WithPattern, // Remark pattern specified via '-Rgroup=regexp'.
105 };
106
108 llvm::CodeObjectVersionKind CodeObjectVersion =
109 llvm::CodeObjectVersionKind::COV_None;
110
112 struct OptRemark {
113 RemarkKind Kind = RemarkKind::RK_Missing;
114 std::string Pattern;
115 std::shared_ptr<llvm::Regex> Regex;
116
118 OptRemark() = default;
119
122 bool hasValidPattern() const { return Regex != nullptr; }
123
125 bool patternMatches(llvm::StringRef string) const {
126 return hasValidPattern() && Regex->match(string);
127 }
128 };
129
130 // The OptRemark fields provided here are identical to Clang.
131
137
143
150
152 std::string CodeModel;
153
157
160 using DoConcurrentMappingKind = flangomp::DoConcurrentMappingKind;
161
165
168
171
175
178 std::string SplitDwarfFile;
179
181 std::string SplitDwarfOutput;
182
184 bool hasProfileClangInstr() const {
185 return getProfileInstr() == llvm::driver::ProfileClangInstr;
186 }
187
189 bool hasProfileIRInstr() const {
190 return getProfileInstr() == llvm::driver::ProfileIRInstr;
191 }
192
194 bool hasProfileCSIRInstr() const {
195 return getProfileInstr() == llvm::driver::ProfileCSIRInstr;
196 }
197
198 bool hasProfileIRUse() const {
199 return getProfileUse() == llvm::driver::ProfileIRInstr ||
200 getProfileUse() == llvm::driver::ProfileCSIRInstr;
201 }
202
203 bool hasProfileCSIRUse() const {
204 return getProfileUse() == llvm::driver::ProfileCSIRInstr;
205 }
206
231
232 // Define accessors/mutators for code generation options of enumeration type.
233#define CODEGENOPT(Name, Bits, Default)
234#define ENUM_CODEGENOPT(Name, Type, Bits, Default) \
235 Type get##Name() const { return static_cast<Type>(Name); } \
236 void set##Name(Type Value) { Name = static_cast<unsigned>(Value); }
237#include "flang/Frontend/CodeGenOptions.def"
238
240};
241
242std::optional<llvm::CodeModel::Model> getCodeModel(llvm::StringRef string);
243
244} // end namespace Fortran::frontend
245
246#endif // FORTRAN_FRONTEND_CODEGENOPTIONS_H
Definition CodeGenOptions.h:35
Definition CodeGenOptions.h:50
std::string MemoryProfileUsePath
Name of the profile file to use as input for -fmemory-profile-use.
Definition CodeGenOptions.h:167
std::string PreferVectorWidth
The prefered vector width, if requested by -mprefer-vector-width.
Definition CodeGenOptions.h:57
std::string OptRecordPasses
Definition CodeGenOptions.h:87
std::vector< std::string > DependentLibs
Options to add to the linker for the object file.
Definition CodeGenOptions.h:93
std::string SplitDwarfFile
Definition CodeGenOptions.h:178
bool hasProfileClangInstr() const
Check if Clang profile instrumenation is on.
Definition CodeGenOptions.h:184
std::string SplitDwarfOutput
Output filename for the split debug info, not used in the skeleton CU.
Definition CodeGenOptions.h:181
OptRemark OptimizationRemark
Definition CodeGenOptions.h:136
llvm::CodeObjectVersionKind CodeObjectVersion
Code object version for AMDGPU.
Definition CodeGenOptions.h:108
OptRemark OptimizationRemarkAnalysis
Definition CodeGenOptions.h:149
std::string InstrProfileOutput
Definition CodeGenOptions.h:164
std::string ProfileRemappingFile
Definition CodeGenOptions.h:174
std::string Reciprocals
List of reciprocal estimate sub-options.
Definition CodeGenOptions.h:60
std::vector< std::string > LLVMPassPlugins
The paths to the pass plugins that were registered using -fpass-plugin.
Definition CodeGenOptions.h:54
std::string OptRecordFormat
The format used for serializing remarks (default: YAML)
Definition CodeGenOptions.h:90
std::optional< std::string > SaveTempsDir
The directory where temp files are stored if specified by -save-temps.
Definition CodeGenOptions.h:71
flangomp::DoConcurrentMappingKind DoConcurrentMappingKind
Definition CodeGenOptions.h:160
bool hasProfileCSIRInstr() const
Check if CS IR level profile instrumentation is on.
Definition CodeGenOptions.h:194
std::string CodeModel
The code model to use (-mcmodel).
Definition CodeGenOptions.h:152
std::vector< std::string > OffloadObjects
Definition CodeGenOptions.h:64
ComplexRangeKind
Controls the various implementations for complex division.
Definition CodeGenOptions.h:208
@ CX_Full
Definition CodeGenOptions.h:212
@ CX_None
No range rule is enabled.
Definition CodeGenOptions.h:226
@ CX_Basic
Definition CodeGenOptions.h:223
@ CX_Improved
Definition CodeGenOptions.h:218
std::string ProfileInstrumentUsePath
Name of the profile file to use as input for -fprofile-instr-use.
Definition CodeGenOptions.h:170
std::string DwarfDebugFlags
Definition CodeGenOptions.h:79
std::optional< std::string > RecordCommandLine
The string containing the commandline for the llvm.commandline metadata.
Definition CodeGenOptions.h:74
std::string OptRecordFile
Definition CodeGenOptions.h:83
std::vector< std::string > BuiltinBCLibs
Definition CodeGenOptions.h:68
uint64_t LargeDataThreshold
Definition CodeGenOptions.h:156
OptRemark OptimizationRemarkMissed
Definition CodeGenOptions.h:142
bool hasProfileIRInstr() const
Check if IR level profile instrumentation is on.
Definition CodeGenOptions.h:189
bool hasProfileCSIRUse() const
Check if CSIR profile use is on.
Definition CodeGenOptions.h:203
bool hasProfileIRUse() const
Check if IR level profile use is on.
Definition CodeGenOptions.h:198
Optimization remark with an optional regular expression pattern.
Definition CodeGenOptions.h:112
OptRemark()=default
By default, optimization remark is missing.
bool hasValidPattern() const
Definition CodeGenOptions.h:122
bool patternMatches(llvm::StringRef string) const
Matches the given string against the regex, if there is some.
Definition CodeGenOptions.h:125