Warning: This file is not a C or C++ file. It does not have highlighting.
1 | //===-- Lower/ConvertExprToHLFIR.h -- lowering of expressions ----*- 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 | /// Implements the conversion from Fortran::evaluate::Expr trees to HLFIR. |
14 | /// |
15 | //===----------------------------------------------------------------------===// |
16 | |
17 | #ifndef FORTRAN_LOWER_CONVERTEXPRTOHLFIR_H |
18 | #define FORTRAN_LOWER_CONVERTEXPRTOHLFIR_H |
19 | |
20 | #include "flang/Lower/StatementContext.h" |
21 | #include "flang/Lower/Support/Utils.h" |
22 | #include "flang/Optimizer/Builder/FIRBuilder.h" |
23 | #include "flang/Optimizer/Builder/HLFIRTools.h" |
24 | #include "flang/Optimizer/Dialect/FIRDialect.h" |
25 | |
26 | namespace mlir { |
27 | class Location; |
28 | } // namespace mlir |
29 | |
30 | namespace hlfir { |
31 | class ElementalAddrOp; |
32 | } |
33 | |
34 | namespace Fortran::lower { |
35 | |
36 | class AbstractConverter; |
37 | class SymMap; |
38 | |
39 | hlfir::EntityWithAttributes |
40 | convertExprToHLFIR(mlir::Location loc, Fortran::lower::AbstractConverter &, |
41 | const Fortran::lower::SomeExpr &, Fortran::lower::SymMap &, |
42 | Fortran::lower::StatementContext &); |
43 | |
44 | inline fir::ExtendedValue |
45 | translateToExtendedValue(mlir::Location loc, fir::FirOpBuilder &builder, |
46 | hlfir::Entity entity, |
47 | Fortran::lower::StatementContext &context) { |
48 | auto [exv, exvCleanup] = |
49 | hlfir::translateToExtendedValue(loc, builder, entity); |
50 | if (exvCleanup) |
51 | context.attachCleanup(*exvCleanup); |
52 | return exv; |
53 | } |
54 | |
55 | /// Lower an evaluate::Expr object to a fir.box, and a procedure designator to a |
56 | /// fir.boxproc<> |
57 | fir::ExtendedValue convertExprToBox(mlir::Location loc, |
58 | Fortran::lower::AbstractConverter &, |
59 | const Fortran::lower::SomeExpr &, |
60 | Fortran::lower::SymMap &, |
61 | Fortran::lower::StatementContext &); |
62 | fir::ExtendedValue convertToBox(mlir::Location loc, |
63 | Fortran::lower::AbstractConverter &, |
64 | hlfir::Entity entity, |
65 | Fortran::lower::StatementContext &, |
66 | mlir::Type fortranType); |
67 | |
68 | /// Lower an evaluate::Expr to fir::ExtendedValue address. |
69 | /// The address may be a raw fir.ref<T>, or a fir.box<T>/fir.class<T>, or a |
70 | /// fir.boxproc<>. Pointers and allocatable are dereferenced. |
71 | /// - If the expression is a procedure designator, it is lowered to fir.boxproc |
72 | /// (with an extra length for character function procedure designators). |
73 | /// - If expression is not a variable, or is a designator with vector |
74 | /// subscripts, a temporary is created to hold the expression value and |
75 | /// is returned as: |
76 | /// - a fir.class<T> if the expression is polymorphic. |
77 | /// - otherwise, a fir.box<T> if it is a derived type with length |
78 | /// parameters (not yet implemented). |
79 | /// - otherwise, a fir.ref<T> |
80 | /// - If the expression is a variable that is not a designator with |
81 | /// vector subscripts, it is lowered without creating a temporary and |
82 | /// is returned as: |
83 | /// - a fir.class<T> if the variable is polymorphic. |
84 | /// - otherwise, a fir.box<T> if it is a derived type with length |
85 | /// parameters (not yet implemented), or if it is not a simply |
86 | /// contiguous. |
87 | /// - otherwise, a fir.ref<T> |
88 | /// |
89 | /// Beware that this is different from the previous createSomeExtendedAddress |
90 | /// that had a non-trivial behaviour and would create contiguous temporary for |
91 | /// array sections `x(:, :)`, but not for `x` even if x is not simply |
92 | /// contiguous. |
93 | fir::ExtendedValue convertExprToAddress(mlir::Location loc, |
94 | Fortran::lower::AbstractConverter &, |
95 | const Fortran::lower::SomeExpr &, |
96 | Fortran::lower::SymMap &, |
97 | Fortran::lower::StatementContext &); |
98 | fir::ExtendedValue convertToAddress(mlir::Location loc, |
99 | Fortran::lower::AbstractConverter &, |
100 | hlfir::Entity entity, |
101 | Fortran::lower::StatementContext &, |
102 | mlir::Type fortranType); |
103 | |
104 | /// Lower an evaluate::Expr to a fir::ExtendedValue value. |
105 | fir::ExtendedValue convertExprToValue(mlir::Location loc, |
106 | Fortran::lower::AbstractConverter &, |
107 | const Fortran::lower::SomeExpr &, |
108 | Fortran::lower::SymMap &, |
109 | Fortran::lower::StatementContext &); |
110 | fir::ExtendedValue convertToValue(mlir::Location loc, |
111 | Fortran::lower::AbstractConverter &, |
112 | hlfir::Entity entity, |
113 | Fortran::lower::StatementContext &); |
114 | |
115 | fir::ExtendedValue convertDataRefToValue(mlir::Location loc, |
116 | Fortran::lower::AbstractConverter &, |
117 | const Fortran::evaluate::DataRef &, |
118 | Fortran::lower::SymMap &, |
119 | Fortran::lower::StatementContext &); |
120 | |
121 | /// Lower an evaluate::Expr to a fir::MutableBoxValue value. |
122 | /// This can only be called if the Expr is a POINTER or ALLOCATABLE, |
123 | /// otherwise, this will crash. |
124 | fir::MutableBoxValue |
125 | convertExprToMutableBox(mlir::Location loc, Fortran::lower::AbstractConverter &, |
126 | const Fortran::lower::SomeExpr &, |
127 | Fortran::lower::SymMap &); |
128 | /// Lower a designator containing vector subscripts into an |
129 | /// hlfir::ElementalAddrOp that will allow looping on the elements to assign |
130 | /// them values. This only intends to cover the cases where such designator |
131 | /// appears on the left-hand side of an assignment or appears in an input IO |
132 | /// statement. These are the only contexts in Fortran where a vector subscripted |
133 | /// entity may be modified. Otherwise, there is no need to do anything special |
134 | /// about vector subscripts, they are automatically turned into array expression |
135 | /// values via an hlfir.elemental in the convertExprToXXX calls. |
136 | hlfir::ElementalAddrOp convertVectorSubscriptedExprToElementalAddr( |
137 | mlir::Location loc, Fortran::lower::AbstractConverter &, |
138 | const Fortran::lower::SomeExpr &, Fortran::lower::SymMap &, |
139 | Fortran::lower::StatementContext &); |
140 | |
141 | } // namespace Fortran::lower |
142 | |
143 | #endif // FORTRAN_LOWER_CONVERTEXPRTOHLFIR_H |
144 |
Warning: This file is not a C or C++ file. It does not have highlighting.