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 "llvm/Frontend/Debug/Options.h"
19#include "llvm/Frontend/Driver/CodeGenOptions.h"
20#include "llvm/Support/CodeGen.h"
21#include "llvm/Support/Regex.h"
22#include "llvm/Target/TargetOptions.h"
23#include "llvm/Transforms/Instrumentation/AddressSanitizerOptions.h"
24#include <map>
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
50
51public:
53 std::vector<std::string> LLVMPassPlugins;
54
57 std::vector<std::string> OffloadObjects;
58
61 std::vector<std::string> BuiltinBCLibs;
62
64 std::optional<std::string> SaveTempsDir;
65
67 std::optional<std::string> RecordCommandLine;
68
71 std::string OptRecordFile;
72
75 std::string OptRecordPasses;
76
78 std::string OptRecordFormat;
79
81 std::vector<std::string> DependentLibs;
82
83 // The RemarkKind enum class and OptRemark struct are identical to what Clang
84 // has
85 // TODO: Share with clang instead of re-implementing here
86 enum class RemarkKind {
87 RK_Missing, // Remark argument not present on the command line.
88 RK_Enabled, // Remark enabled via '-Rgroup', i.e. -Rpass, -Rpass-missed,
89 // -Rpass-analysis
90 RK_Disabled, // Remark disabled via '-Rno-group', i.e. -Rno-pass,
91 // -Rno-pass-missed, -Rno-pass-analysis.
92 RK_WithPattern, // Remark pattern specified via '-Rgroup=regexp'.
93 };
94
96 llvm::CodeObjectVersionKind CodeObjectVersion =
97 llvm::CodeObjectVersionKind::COV_5;
98
100 struct OptRemark {
101 RemarkKind Kind = RemarkKind::RK_Missing;
102 std::string Pattern;
103 std::shared_ptr<llvm::Regex> Regex;
104
106 OptRemark() = default;
107
110 bool hasValidPattern() const { return Regex != nullptr; }
111
113 bool patternMatches(llvm::StringRef string) const {
114 return hasValidPattern() && Regex->match(string);
115 }
116 };
117
118 // The OptRemark fields provided here are identical to Clang.
119
125
131
138
140 std::string CodeModel;
141
145
146 // Define accessors/mutators for code generation options of enumeration type.
147#define CODEGENOPT(Name, Bits, Default)
148#define ENUM_CODEGENOPT(Name, Type, Bits, Default) \
149 Type get##Name() const { return static_cast<Type>(Name); } \
150 void set##Name(Type Value) { Name = static_cast<unsigned>(Value); }
151#include "flang/Frontend/CodeGenOptions.def"
152
154};
155
156std::optional<llvm::CodeModel::Model> getCodeModel(llvm::StringRef string);
157
158} // end namespace Fortran::frontend
159
160#endif // FORTRAN_FRONTEND_CODEGENOPTIONS_H
Definition: CodeGenOptions.h:34
Definition: CodeGenOptions.h:49
std::string OptRecordPasses
Definition: CodeGenOptions.h:75
std::vector< std::string > DependentLibs
Options to add to the linker for the object file.
Definition: CodeGenOptions.h:81
OptRemark OptimizationRemark
Definition: CodeGenOptions.h:124
llvm::CodeObjectVersionKind CodeObjectVersion
Code object version for AMDGPU.
Definition: CodeGenOptions.h:96
OptRemark OptimizationRemarkAnalysis
Definition: CodeGenOptions.h:137
std::vector< std::string > LLVMPassPlugins
The paths to the pass plugins that were registered using -fpass-plugin.
Definition: CodeGenOptions.h:53
std::string OptRecordFormat
The format used for serializing remarks (default: YAML)
Definition: CodeGenOptions.h:78
std::optional< std::string > SaveTempsDir
The directory where temp files are stored if specified by -save-temps.
Definition: CodeGenOptions.h:64
std::string CodeModel
The code model to use (-mcmodel).
Definition: CodeGenOptions.h:140
std::vector< std::string > OffloadObjects
Definition: CodeGenOptions.h:57
std::optional< std::string > RecordCommandLine
The string containing the commandline for the llvm.commandline metadata.
Definition: CodeGenOptions.h:67
std::string OptRecordFile
Definition: CodeGenOptions.h:71
std::vector< std::string > BuiltinBCLibs
Definition: CodeGenOptions.h:61
uint64_t LargeDataThreshold
Definition: CodeGenOptions.h:144
OptRemark OptimizationRemarkMissed
Definition: CodeGenOptions.h:130
Optimization remark with an optional regular expression pattern.
Definition: CodeGenOptions.h:100
OptRemark()=default
By default, optimization remark is missing.
bool hasValidPattern() const
Definition: CodeGenOptions.h:110
bool patternMatches(llvm::StringRef string) const
Matches the given string against the regex, if there is some.
Definition: CodeGenOptions.h:113