File tree 3 files changed +28
-0
lines changed
include/flang/Optimizer/HLFIR 3 files changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -1205,6 +1205,7 @@ def hlfir_ShapeOfOp : hlfir_Op<"shape_of", [Pure]> {
1205
1205
}];
1206
1206
1207
1207
let builders = [OpBuilder<(ins "mlir::Value":$expr)>];
1208
+ let hasFolder = 1;
1208
1209
}
1209
1210
1210
1211
def hlfir_GetExtentOp : hlfir_Op<"get_extent", [Pure]> {
Original file line number Diff line number Diff line change @@ -1704,6 +1704,15 @@ hlfir::ShapeOfOp::canonicalize(ShapeOfOp shapeOf,
1704
1704
return llvm::LogicalResult::success ();
1705
1705
}
1706
1706
1707
+ mlir::OpFoldResult hlfir::ShapeOfOp::fold (FoldAdaptor adaptor) {
1708
+ if (matchPattern (getExpr (), mlir::m_Op<hlfir::ElementalOp>())) {
1709
+ auto elementalOp =
1710
+ mlir::cast<hlfir::ElementalOp>(getExpr ().getDefiningOp ());
1711
+ return elementalOp.getShape ();
1712
+ }
1713
+ return {};
1714
+ }
1715
+
1707
1716
// ===----------------------------------------------------------------------===//
1708
1717
// GetExtent
1709
1718
// ===----------------------------------------------------------------------===//
Original file line number Diff line number Diff line change @@ -27,3 +27,21 @@ func.func @shapeof2(%arg0: !hlfir.expr<?x2xi32>) -> !fir.shape<2> {
27
27
// CHECK-ALL: %[[EXPR:.*]]: !hlfir.expr<?x2xi32>
28
28
// CHECK-ALL-NEXT: %[[SHAPE:.*]] = hlfir.shape_of %[[EXPR]] : (!hlfir.expr<?x2xi32>) -> !fir.shape<2>
29
29
// CHECK-ALL-NEXT: return %[[SHAPE]]
30
+
31
+ // Checks hlfir.elemental -> hlfir.shape_of folding
32
+ func.func @shapeof_fold1(%extent: index) -> !fir.shape<1> {
33
+ %shape1 = fir.shape %extent : (index) -> !fir.shape<1>
34
+ %elem = hlfir.elemental %shape1 : (!fir.shape<1>) -> !hlfir.expr<?xindex> {
35
+ hlfir.yield_element %extent : index
36
+ }
37
+ %shape2 = hlfir.shape_of %elem : (!hlfir.expr<?xindex>) -> !fir.shape<1>
38
+ return %shape2 : !fir.shape<1>
39
+ }
40
+ // CHECK-ALL-LABEL: func.func @shapeof_fold1(
41
+ // CHECK-ALL-SAME: %[[VAL_0:.*]]: index) -> !fir.shape<1> {
42
+ // CHECK-CANON-NEXT: %[[VAL_1:.*]] = fir.shape %[[VAL_0]] : (index) -> !fir.shape<1>
43
+ // CHECK-CANON-NEXT: %[[VAL_2:.*]] = hlfir.elemental %[[VAL_1]] : (!fir.shape<1>) -> !hlfir.expr<?xindex> {
44
+ // CHECK-CANON-NEXT: hlfir.yield_element %[[VAL_0]] : index
45
+ // CHECK-CANON-NEXT: }
46
+ // CHECK-CANON-NEXT: return %[[VAL_1]] : !fir.shape<1>
47
+ // CHECK-CANON-NEXT: }
You can’t perform that action at this time.
0 commit comments