[flang-commits] [flang] [FIR] add a fir.shape_extents operation (PR #199361)
Valentin Clement バレンタイン クレメン via flang-commits
flang-commits at lists.llvm.org
Sat May 23 13:29:13 PDT 2026
================
@@ -2087,6 +2087,41 @@ def fir_ShapeOp : fir_Op<"shape", [Pure]> {
let builders = [OpBuilder<(ins "mlir::ValueRange":$extents)>];
}
+def fir_ShapeExtentsOp : fir_Op<"shape_extents", [Pure]> {
+ let summary = "unpack a `!fir.shape` into per-dimension extent SSA values";
+
+ let description = [{
+ Takes a single abstract `!fir.shape<n>` value and yields `n` integer SSA
+ results, one per dimension extent in Fortran row-to-column order. This is
+ intended for lowering when extent values are needed but the defining
+ `fir.shape` is not visible (for example when a shape is forwarded through
+ control flow as a block argument).
+
+ When the operand is the result of `fir.shape`, a canonicalization may fold
+ this operation to the original extent operands.
+
+ ```
+ %e0, %e1 = fir.shape_extents %sh : (!fir.shape<2>) -> (index, index)
+ ```
+ }];
+
+ let arguments = (ins fir_ShapeType:$shape);
+
+ let results = (outs Variadic<AnyIntegerType>:$extents);
+
+ let assemblyFormat = [{
+ $shape attr-dict `:` functional-type(operands, results)
+ }];
+
+ let hasVerifier = 1;
+
+ let hasCanonicalizer = 1;
+
+ let skipDefaultBuilders = 1;
+
+ let builders = [OpBuilder<(ins "mlir::Value":$shape)>];
----------------
clementval wrote:
Makes sense
https://github.com/llvm/llvm-project/pull/199361
More information about the flang-commits
mailing list