FLANG
VectorSubscripts.h
Go to the documentation of this file.
1//===-- VectorSubscripts.h -- vector subscripts tools -----------*- 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//===----------------------------------------------------------------------===//
17//===----------------------------------------------------------------------===//
18
19#ifndef FORTRAN_LOWER_VECTORSUBSCRIPTS_H
20#define FORTRAN_LOWER_VECTORSUBSCRIPTS_H
21
22#include "flang/Optimizer/Builder/BoxValue.h"
23
24namespace fir {
25class FirOpBuilder;
26}
27
28namespace Fortran {
29
30namespace evaluate {
31template <typename>
32class Expr;
33struct SomeType;
34} // namespace evaluate
35
36namespace lower {
37
38class AbstractConverter;
39class StatementContext;
40
57public:
60 using ElementalGenerator = std::function<void(const fir::ExtendedValue &)>;
61 using ElementalGeneratorWithBoolReturn =
62 std::function<mlir::Value(const fir::ExtendedValue &)>;
64 LoweredVectorSubscript(fir::ExtendedValue &&vector, mlir::Value size)
65 : vector{std::move(vector)}, size{size} {}
66 fir::ExtendedValue vector;
67 // Vector size, guaranteed to be of indexType.
68 mlir::Value size;
69 };
71 // Triplets value, guaranteed to be of indexType.
72 mlir::Value lb;
73 mlir::Value ub;
74 mlir::Value stride;
75 };
76 using LoweredSubscript =
77 std::variant<mlir::Value, LoweredTriplet, LoweredVectorSubscript>;
80 fir::ExtendedValue &&loweredBase,
82 llvm::SmallVector<mlir::Value> &&componentPath,
83 MaybeSubstring substringBounds, mlir::Type elementType)
84 : loweredBase{std::move(loweredBase)}, loweredSubscripts{std::move(
85 loweredSubscripts)},
86 componentPath{std::move(componentPath)},
87 substringBounds{substringBounds}, elementType{elementType} {};
88
91 void loopOverElements(fir::FirOpBuilder &builder, mlir::Location loc,
92 const ElementalGenerator &elementalGenerator);
93
99 mlir::Value loopOverElementsWhile(
100 fir::FirOpBuilder &builder, mlir::Location loc,
101 const ElementalGeneratorWithBoolReturn &elementalGenerator,
102 mlir::Value initialCondition);
103
105 mlir::Type getElementType() { return elementType; }
106
107private:
109 template <typename LoopType, typename Generator>
110 mlir::Value loopOverElementsBase(fir::FirOpBuilder &builder,
111 mlir::Location loc,
112 const Generator &elementalGenerator,
113 mlir::Value initialCondition);
115 mlir::Value createSlice(fir::FirOpBuilder &builder, mlir::Location loc);
116
118 fir::ExtendedValue getElementAt(fir::FirOpBuilder &builder,
119 mlir::Location loc, mlir::Value shape,
120 mlir::Value slice,
121 mlir::ValueRange inductionVariables);
122
126 genLoopBounds(fir::FirOpBuilder &builder, mlir::Location loc);
127
129 fir::ExtendedValue loweredBase;
134 llvm::SmallVector<mlir::Value> componentPath;
137 MaybeSubstring substringBounds;
139 mlir::Type elementType;
140};
141
146VectorSubscriptBox genVectorSubscriptBox(
147 mlir::Location loc, Fortran::lower::AbstractConverter &converter,
150
151} // namespace lower
152} // namespace Fortran
153
154#endif // FORTRAN_LOWER_VECTORSUBSCRIPTS_H
Definition: common.h:213
Definition: AbstractConverter.h:82
Definition: StatementContext.h:46
Definition: VectorSubscripts.h:56
void loopOverElements(fir::FirOpBuilder &builder, mlir::Location loc, const ElementalGenerator &elementalGenerator)
Definition: VectorSubscripts.cpp:306
std::function< void(const fir::ExtendedValue &)> ElementalGenerator
Definition: VectorSubscripts.h:60
mlir::Type getElementType()
Return the type of the elements of the array section.
Definition: VectorSubscripts.h:105
mlir::Value loopOverElementsWhile(fir::FirOpBuilder &builder, mlir::Location loc, const ElementalGeneratorWithBoolReturn &elementalGenerator, mlir::Value initialCondition)
Definition: VectorSubscripts.cpp:314
Definition: BoxValue.h:478
Definition: FIRBuilder.h:55
VectorSubscriptBox genVectorSubscriptBox(mlir::Location loc, Fortran::lower::AbstractConverter &converter, Fortran::lower::StatementContext &stmtCtx, const Fortran::evaluate::Expr< Fortran::evaluate::SomeType > &expr)
Definition: VectorSubscripts.cpp:250
Definition: bit-population-count.h:20
Definition: AbstractConverter.h:31