[flang-commits] [flang] [FIR] add a fir.shape_extents operation (PR #199361)

via flang-commits flang-commits at lists.llvm.org
Tue Jun 2 01:44:00 PDT 2026


================
@@ -316,6 +323,36 @@ void FIRToMemRef::populateShape(SmallVectorImpl<Value> &vec,
   vec.append(shape.getExtents().begin(), shape.getExtents().end());
 }
 
+bool FIRToMemRef::materializeShapeExtents(
+    Value shapeVal, PatternRewriter &rewriter, Location loc,
+    SmallVectorImpl<Value> &shapeVec) const {
+  if (!shapeVal)
+    return false;
+
+  while (auto convertOp = shapeVal.getDefiningOp<fir::ConvertOp>())
+    shapeVal = convertOp.getOperand();
+
+  if (auto shapeOp = shapeVal.getDefiningOp<fir::ShapeOp>()) {
+    shapeVec.append(shapeOp.getExtents().begin(), shapeOp.getExtents().end());
+    return true;
+  }
+
+  if (auto extentsOp = shapeVal.getDefiningOp<fir::ShapeExtentsOp>()) {
+    shapeVec.append(extentsOp.getExtents().begin(),
+                    extentsOp.getExtents().end());
+    return true;
+  }
+
+  if (mlir::isa<fir::ShapeType>(shapeVal.getType())) {
----------------
jeanPerier wrote:

I think the operation should also be usable of fir.shape_shift (we should probably get rid of fir.shape_shift and have operation that cares about lower bounds take a separate fir.shift instead, but that is a bigger change).

https://github.com/llvm/llvm-project/pull/199361


More information about the flang-commits mailing list