FLANG

AbstractConverter.h
1 //===-- Lower/AbstractConverter.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 #ifndef FORTRAN_LOWER_ABSTRACTCONVERTER_H
10 #define FORTRAN_LOWER_ABSTRACTCONVERTER_H
11
12 #include "flang/Common/Fortran.h"
13 #include "mlir/IR/Module.h"
14
15 namespace Fortran {
16 namespace common {
17 template <typename>
18 class Reference;
19 }
20 namespace evaluate {
21 struct DataRef;
22 template <typename>
23 class Expr;
24 class FoldingContext;
25 struct SomeType;
26 } // namespace evaluate
27
28 namespace parser {
29 class CharBlock;
30 }
31 namespace semantics {
32 class Symbol;
33 }
34
35 namespace lower {
36 namespace pft {
37 struct Variable;
38 }
39
40 using SomeExpr = Fortran::evaluate::Expr<Fortran::evaluate::SomeType>;
41 using SymbolRef = Fortran::common::Reference<const Fortran::semantics::Symbol>;
42 class FirOpBuilder;
43
44 //===----------------------------------------------------------------------===//
45 // AbstractConverter interface
46 //===----------------------------------------------------------------------===//
47
51 class AbstractConverter {
52 public:
53 //===--------------------------------------------------------------------===//
54 // Symbols
55 //===--------------------------------------------------------------------===//
56
58 virtual mlir::Value getSymbolAddress(SymbolRef sym) = 0;
59
60 //===--------------------------------------------------------------------===//
61 // Expressions
62 //===--------------------------------------------------------------------===//
63
65 virtual mlir::Value genExprAddr(const SomeExpr &,
66 mlir::Location *loc = nullptr) = 0;
68 mlir::Value genExprAddr(const SomeExpr *someExpr, mlir::Location loc) {
69 return genExprAddr(*someExpr, &loc);
70 }
71
73 virtual mlir::Value genExprValue(const SomeExpr &,
74 mlir::Location *loc = nullptr) = 0;
76 mlir::Value genExprValue(const SomeExpr *someExpr, mlir::Location loc) {
77 return genExprValue(*someExpr, &loc);
78 }
79
82 virtual Fortran::evaluate::FoldingContext &getFoldingContext() = 0;
83
84 //===--------------------------------------------------------------------===//
85 // Types
86 //===--------------------------------------------------------------------===//
87
89 virtual mlir::Type genType(const Fortran::evaluate::DataRef &) = 0;
91 virtual mlir::Type genType(const SomeExpr &) = 0;
93 virtual mlir::Type genType(SymbolRef) = 0;
95 virtual mlir::Type genType(Fortran::common::TypeCategory tc) = 0;
97 virtual mlir::Type genType(Fortran::common::TypeCategory tc, int kind) = 0;
99 virtual mlir::Type genType(const pft::Variable &) = 0;
100
101 //===--------------------------------------------------------------------===//
102 // Locations
103 //===--------------------------------------------------------------------===//
104
106 virtual mlir::Location getCurrentLocation() = 0;
108 virtual mlir::Location genLocation() = 0;
110 virtual mlir::Location genLocation(const Fortran::parser::CharBlock &) = 0;
111
112 //===--------------------------------------------------------------------===//
113 // FIR/MLIR
114 //===--------------------------------------------------------------------===//
115
117 virtual Fortran::lower::FirOpBuilder &getFirOpBuilder() = 0;
119 virtual mlir::ModuleOp &getModuleOp() = 0;
121 virtual mlir::MLIRContext &getMLIRContext() = 0;
123 virtual std::string mangleName(const Fortran::semantics::Symbol &) = 0;
126 virtual std::string uniqueCGIdent(llvm::StringRef prefix,
127 llvm::StringRef name) = 0;
128
129 virtual ~AbstractConverter() = default;
130 };
131
132 } // namespace lower
133 } // namespace Fortran
134
135 #endif // FORTRAN_LOWER_ABSTRACTCONVERTER_H
Fortran::lower::AbstractConverter::uniqueCGIdent
virtual std::string uniqueCGIdent(llvm::StringRef prefix, llvm::StringRef name)=0
Fortran::lower::AbstractConverter::getSymbolAddress
virtual mlir::Value getSymbolAddress(SymbolRef sym)=0
Get the mlir instance of a symbol.
Fortran::lower::AbstractConverter::genExprAddr
virtual mlir::Value genExprAddr(const SomeExpr &, mlir::Location *loc=nullptr)=0
Generate the address of the location holding the expression, someExpr.
Fortran::semantics::Symbol
Definition: symbol.h:479
Fortran::lower::AbstractConverter::genType
virtual mlir::Type genType(const Fortran::evaluate::DataRef &)=0
Generate the type of a DataRef.
Fortran::lower::AbstractConverter::getModuleOp
virtual mlir::ModuleOp & getModuleOp()=0
Get the ModuleOp.
Fortran::lower::AbstractConverter::genExprValue
virtual mlir::Value genExprValue(const SomeExpr &, mlir::Location *loc=nullptr)=0
Generate the computations of the expression to produce a value.
Fortran::lower::AbstractConverter
Definition: AbstractConverter.h:51
Fortran::evaluate::DataRef
Definition: variable.h:286
Fortran::evaluate::FoldingContext
Definition: common.h:209
Fortran::lower::pft::Variable
Definition: PFTBuilder.h:362
Fortran::lower::AbstractConverter::getMLIRContext
virtual mlir::MLIRContext & getMLIRContext()=0
Get the MLIRContext.
Fortran::lower::AbstractConverter::genLocation
virtual mlir::Location genLocation()=0
Generate a dummy location.
Fortran::lower::AbstractConverter::getFirOpBuilder
virtual Fortran::lower::FirOpBuilder & getFirOpBuilder()=0
Get the OpBuilder.
Fortran::lower::AbstractConverter::mangleName
virtual std::string mangleName(const Fortran::semantics::Symbol &)=0
Unique a symbol.
Fortran::common::Reference
Definition: reference.h:18
Fortran::lower::AbstractConverter::genExprAddr
mlir::Value genExprAddr(const SomeExpr *someExpr, mlir::Location loc)
Generate the address of the location holding the expression, someExpr.
Definition: AbstractConverter.h:68
Fortran::lower::AbstractConverter::genExprValue
mlir::Value genExprValue(const SomeExpr *someExpr, mlir::Location loc)
Generate the computations of the expression, someExpr, to produce a value.
Definition: AbstractConverter.h:76
Fortran::lower::AbstractConverter::getCurrentLocation
virtual mlir::Location getCurrentLocation()=0
Get the converter's current location.
Fortran::parser::CharBlock
Definition: char-block.h:28
Fortran::lower::AbstractConverter::getFoldingContext
virtual Fortran::evaluate::FoldingContext & getFoldingContext()=0
Fortran::evaluate::Expr< Fortran::evaluate::SomeType >
Fortran::lower::FirOpBuilder
Definition: FIRBuilder.h:39