-
Notifications
You must be signed in to change notification settings - Fork 10.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This is an operation which returns the fir.shape for a hlfir.expr. A hlfir.expr can be defined by: - A transformational intrinsic (e.g. hlfir.matmul) - hlfir.as_expr - hlfir.elemental hlfir.elemental is easy because there is a compulsory shape operand. hlfir.as_expr is defined as operating on a variable (defined using a hlfir.declare). hlfir.declare has an optional shape argument. The transformational intrinsics do not have an associated shape. If all extents are known at compile time, the extents for the shape can be fetched from the hlfir.expr's type. For example, the result of a hlfir.matmul with arguments who's extents are known at compile time will have constant extents which can be queried from the type. In this case the hlfir.shape_of will be canonicalised to a fir.shape operation using those extents. If not all extents are known at compile time, shapes have to be read from boxes after bufferization. In the case of the transformational intrinsics, the shape read from the result box can be queried from the hlfir.declare operation for the buffer allocated to that hlfir.expr (via the hlfir.as_expr). Differential Revision: https://reviews.llvm.org/D146830
- Loading branch information
Showing
6 changed files
with
150 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Test hlfir.shape_of operation parse, verify (no errors), and unparse | ||
// RUN: fir-opt %s | fir-opt | FileCheck --check-prefix CHECK --check-prefix CHECK-ALL %s | ||
|
||
// Test canonicalization | ||
// RUN: fir-opt %s --canonicalize | FileCheck --check-prefix CHECK-CANON --check-prefix CHECK-ALL %s | ||
|
||
func.func @shapeof(%arg0: !hlfir.expr<2x2xi32>) -> !fir.shape<2> { | ||
%shape = hlfir.shape_of %arg0 : (!hlfir.expr<2x2xi32>) -> !fir.shape<2> | ||
return %shape : !fir.shape<2> | ||
} | ||
// CHECK-ALL-LABEL: func.func @shapeof | ||
// CHECK-ALL: %[[EXPR:.*]]: !hlfir.expr<2x2xi32> | ||
|
||
// CHECK-NEXT: %[[SHAPE:.*]] = hlfir.shape_of %[[EXPR]] : (!hlfir.expr<2x2xi32>) -> !fir.shape<2> | ||
|
||
// CHECK-CANON-NEXT: %[[C2:.*]] = arith.constant 2 : index | ||
// CHECK-CANON-NEXT: %[[SHAPE:.*]] = fir.shape %[[C2]], %[[C2]] : (index, index) -> !fir.shape<2> | ||
|
||
// CHECK-ALL-NEXT: return %[[SHAPE]] | ||
|
||
// no canonicalization of expressions with unknown extents | ||
func.func @shapeof2(%arg0: !hlfir.expr<?x2xi32>) -> !fir.shape<2> { | ||
%shape = hlfir.shape_of %arg0 : (!hlfir.expr<?x2xi32>) -> !fir.shape<2> | ||
return %shape : !fir.shape<2> | ||
} | ||
// CHECK-ALL-LABEL: func.func @shapeof2 | ||
// CHECK-ALL: %[[EXPR:.*]]: !hlfir.expr<?x2xi32> | ||
// CHECK-ALL-NEXT: %[[SHAPE:.*]] = hlfir.shape_of %[[EXPR]] : (!hlfir.expr<?x2xi32>) -> !fir.shape<2> | ||
// CHECK-ALL-NEXT: return %[[SHAPE]] |