FLANG
FrontendActions.h
1//===- FrontendActions.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// Coding style: https://mlir.llvm.org/getting_started/DeveloperGuide/
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef FORTRAN_FRONTEND_FRONTENDACTIONS_H
14#define FORTRAN_FRONTEND_FRONTENDACTIONS_H
15
16#include "flang/Frontend/CodeGenOptions.h"
18#include "flang/Parser/parsing.h"
19#include "flang/Semantics/semantics.h"
20
21#include "mlir/IR/BuiltinOps.h"
22#include "mlir/IR/OwningOpRef.h"
23#include "llvm/ADT/StringRef.h"
24#include "llvm/IR/Module.h"
25#include <memory>
26
27namespace Fortran::frontend {
28
29// TODO: This is a copy from f18.cpp. It doesn't really belong here and should
30// be moved to a more suitable place in future.
32 template <typename A>
33 bool Pre(const A &) {
34 return true;
35 }
36 template <typename A>
37 void Post(const A &) {
38 ++objects;
39 bytes += sizeof(A);
40 }
41 size_t objects{0}, bytes{0};
42};
43
44//===----------------------------------------------------------------------===//
45// Custom Consumer Actions
46//===----------------------------------------------------------------------===//
47
49 void executeAction() override;
50};
51
53 void executeAction() override;
54};
55
56//===----------------------------------------------------------------------===//
57// Prescan Actions
58//===----------------------------------------------------------------------===//
60 void executeAction() override = 0;
61 bool beginSourceFileAction() override;
62};
63
65 void executeAction() override;
66};
67
69 void executeAction() override;
70};
71
73 void executeAction() override;
74};
75
77 void executeAction() override;
78};
79
80//===----------------------------------------------------------------------===//
81// PrescanAndParse Actions
82//===----------------------------------------------------------------------===//
84 void executeAction() override = 0;
85 bool beginSourceFileAction() override;
86};
87
89 void executeAction() override;
90};
91
93 void executeAction() override;
94};
95
96//===----------------------------------------------------------------------===//
97// PrescanAndSema Actions
98//
99// These actions will parse the input, run the semantic checks and execute
100// their actions provided that no parsing or semantic errors were found.
101//===----------------------------------------------------------------------===//
103
104 void executeAction() override = 0;
105 bool beginSourceFileAction() override;
106};
107
109 void executeAction() override;
110};
111
113 void executeAction() override;
114};
115
117 void executeAction() override;
118};
119
121 void executeAction() override;
122};
123
125 void executeAction() override;
126};
127
129 void executeAction() override;
130};
131
133 void executeAction() override;
134};
135
137 void executeAction() override;
138};
139
141 void executeAction() override;
142};
143
145 void executeAction() override;
146};
147
149 void executeAction() override = 0;
150
151public:
152 Fortran::parser::Parsing &getParsing();
159 std::unique_ptr<llvm::raw_pwrite_stream>
160 createOutputFile(llvm::StringRef extension);
161};
162
163//===----------------------------------------------------------------------===//
164// PrescanAndSemaDebug Actions
165//
166// These actions will parse the input, run the semantic checks and execute
167// their actions _regardless of_ whether any semantic errors have been found.
168// This can be useful when adding new languge feature and when you wish to
169// investigate compiler output (e.g. the parse tree) despite any semantic
170// errors.
171//
172// NOTE: Use with care and for development only!
173//===----------------------------------------------------------------------===//
175
176 void executeAction() override = 0;
177 bool beginSourceFileAction() override;
178};
179
181 void executeAction() override;
182};
183
184//===----------------------------------------------------------------------===//
185// CodeGen Actions
186//===----------------------------------------------------------------------===//
193enum class BackendActionTy {
194 Backend_EmitAssembly,
195 Backend_EmitObj,
196 Backend_EmitBC,
197 Backend_EmitLL,
198 Backend_EmitFIR,
199 Backend_EmitHLFIR,
200};
201
207
208 void executeAction() override;
210 bool beginSourceFileAction() override;
213 void runOptimizationPipeline(llvm::raw_pwrite_stream &os);
214
215protected:
216 CodeGenAction(BackendActionTy act) : action{act} {};
219 std::unique_ptr<mlir::MLIRContext> mlirCtx;
220 mlir::OwningOpRef<mlir::ModuleOp> mlirModule;
222
224 std::unique_ptr<llvm::LLVMContext> llvmCtx;
225 std::unique_ptr<llvm::Module> llvmModule;
226
228 void embedOffloadObjects();
229
231 void linkBuiltinBCLibs();
232
234 void lowerHLFIRToFIR();
235
238 void generateLLVMIR();
239
240 BackendActionTy action;
241
243public:
244 ~CodeGenAction() override;
245};
246
248public:
249 EmitFIRAction() : CodeGenAction(BackendActionTy::Backend_EmitFIR) {}
250};
251
253public:
254 EmitHLFIRAction() : CodeGenAction(BackendActionTy::Backend_EmitHLFIR) {}
255};
256
258public:
259 EmitLLVMAction() : CodeGenAction(BackendActionTy::Backend_EmitLL) {}
260};
261
263public:
264 EmitLLVMBitcodeAction() : CodeGenAction(BackendActionTy::Backend_EmitBC) {}
265};
266
268public:
269 EmitObjAction() : CodeGenAction(BackendActionTy::Backend_EmitObj) {}
270};
271
273public:
274 EmitAssemblyAction() : CodeGenAction(BackendActionTy::Backend_EmitAssembly) {}
275};
276
277} // namespace Fortran::frontend
278
279#endif // FORTRAN_FRONTEND_FRONTENDACTIONS_H
Definition: FrontendActions.h:206
void generateLLVMIR()
Definition: FrontendActions.cpp:836
void lowerHLFIRToFIR()
Runs pass pipeline to lower HLFIR into FIR.
Definition: FrontendActions.cpp:727
void embedOffloadObjects()
Embeds offload objects specified with -fembed-offload-object.
Definition: FrontendActions.cpp:1229
void linkBuiltinBCLibs()
Links in BC libraries spefified with -mlink-builtin-bitcode.
Definition: FrontendActions.cpp:1248
Definition: FrontendActions.h:180
Definition: FrontendActions.h:128
Definition: FrontendActions.h:124
Definition: FrontendActions.h:72
Definition: FrontendActions.h:68
Definition: FrontendActions.h:120
Definition: FrontendActions.h:76
Definition: FrontendActions.h:132
Definition: FrontendActions.h:116
Definition: FrontendActions.h:88
Definition: FrontendActions.h:112
Definition: FrontendActions.h:108
Definition: FrontendActions.h:272
Definition: FrontendActions.h:247
Definition: FrontendActions.h:252
Definition: FrontendActions.h:257
Definition: FrontendActions.h:262
Definition: FrontendActions.h:267
Abstract base class for actions which can be performed by the frontend.
Definition: FrontendAction.h:28
Definition: FrontendActions.h:136
Definition: FrontendActions.h:140
Definition: FrontendActions.h:52
Definition: FrontendActions.h:48
Definition: FrontendActions.h:144
Definition: FrontendActions.h:148
std::unique_ptr< llvm::raw_pwrite_stream > createOutputFile(llvm::StringRef extension)
Definition: FrontendActions.cpp:1485
Definition: FrontendActions.h:59
Definition: FrontendActions.h:83
Definition: FrontendActions.h:102
Definition: FrontendActions.h:174
Definition: FrontendActions.h:64
Definition: parsing.h:47
Definition: FrontendActions.h:31