summaryrefslogtreecommitdiffstats
path: root/flang/lib/Optimizer/HLFIR/IR/HLFIROps.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'flang/lib/Optimizer/HLFIR/IR/HLFIROps.cpp')
-rw-r--r--flang/lib/Optimizer/HLFIR/IR/HLFIROps.cpp50
1 files changed, 27 insertions, 23 deletions
diff --git a/flang/lib/Optimizer/HLFIR/IR/HLFIROps.cpp b/flang/lib/Optimizer/HLFIR/IR/HLFIROps.cpp
index 3568fe202caf..8bad4e445082 100644
--- a/flang/lib/Optimizer/HLFIR/IR/HLFIROps.cpp
+++ b/flang/lib/Optimizer/HLFIR/IR/HLFIROps.cpp
@@ -1406,33 +1406,45 @@ void hlfir::AsExprOp::getEffects(
// ElementalOp
//===----------------------------------------------------------------------===//
-void hlfir::ElementalOp::build(mlir::OpBuilder &builder,
- mlir::OperationState &odsState,
- mlir::Type resultType, mlir::Value shape,
- mlir::Value mold, mlir::ValueRange typeparams,
- bool isUnordered) {
+/// Common builder for ElementalOp and ElementalAddrOp to add the arguments and
+/// create the elemental body. Result and clean-up body must be handled in
+/// specific builders.
+template <typename Op>
+static void buildElemental(mlir::OpBuilder &builder,
+ mlir::OperationState &odsState, mlir::Value shape,
+ mlir::Value mold, mlir::ValueRange typeparams,
+ bool isUnordered) {
odsState.addOperands(shape);
if (mold)
odsState.addOperands(mold);
odsState.addOperands(typeparams);
- odsState.addTypes(resultType);
odsState.addAttribute(
- getOperandSegmentSizesAttrName(odsState.name),
+ Op::getOperandSegmentSizesAttrName(odsState.name),
builder.getDenseI32ArrayAttr({/*shape=*/1, (mold ? 1 : 0),
static_cast<int32_t>(typeparams.size())}));
if (isUnordered)
- odsState.addAttribute(getUnorderedAttrName(odsState.name),
+ odsState.addAttribute(Op::getUnorderedAttrName(odsState.name),
isUnordered ? builder.getUnitAttr() : nullptr);
mlir::Region *bodyRegion = odsState.addRegion();
bodyRegion->push_back(new mlir::Block{});
- if (auto exprType = resultType.dyn_cast<hlfir::ExprType>()) {
- unsigned dim = exprType.getRank();
+ if (auto shapeType = shape.getType().dyn_cast<fir::ShapeType>()) {
+ unsigned dim = shapeType.getRank();
mlir::Type indexType = builder.getIndexType();
for (unsigned d = 0; d < dim; ++d)
bodyRegion->front().addArgument(indexType, odsState.location);
}
}
+void hlfir::ElementalOp::build(mlir::OpBuilder &builder,
+ mlir::OperationState &odsState,
+ mlir::Type resultType, mlir::Value shape,
+ mlir::Value mold, mlir::ValueRange typeparams,
+ bool isUnordered) {
+ odsState.addTypes(resultType);
+ buildElemental<hlfir::ElementalOp>(builder, odsState, shape, mold, typeparams,
+ isUnordered);
+}
+
mlir::Value hlfir::ElementalOp::getElementEntity() {
return mlir::cast<hlfir::YieldElementOp>(getBody()->back()).getElementValue();
}
@@ -1681,19 +1693,11 @@ static void printYieldOpCleanup(mlir::OpAsmPrinter &p, YieldOp yieldOp,
void hlfir::ElementalAddrOp::build(mlir::OpBuilder &builder,
mlir::OperationState &odsState,
- mlir::Value shape, bool isUnordered) {
- odsState.addOperands(shape);
- if (isUnordered)
- odsState.addAttribute(getUnorderedAttrName(odsState.name),
- isUnordered ? builder.getUnitAttr() : nullptr);
- mlir::Region *bodyRegion = odsState.addRegion();
- bodyRegion->push_back(new mlir::Block{});
- if (auto shapeType = shape.getType().dyn_cast<fir::ShapeType>()) {
- unsigned dim = shapeType.getRank();
- mlir::Type indexType = builder.getIndexType();
- for (unsigned d = 0; d < dim; ++d)
- bodyRegion->front().addArgument(indexType, odsState.location);
- }
+ mlir::Value shape, mlir::Value mold,
+ mlir::ValueRange typeparams,
+ bool isUnordered) {
+ buildElemental<hlfir::ElementalAddrOp>(builder, odsState, shape, mold,
+ typeparams, isUnordered);
// Push cleanUp region.
odsState.addRegion();
}