[flang-commits] [flang] [flang] Promote scalar slots reached through fir.convert and fir.declare (PR #219314)
Vijay Kandiah via flang-commits
flang-commits at lists.llvm.org
Mon Aug 31 08:54:46 PDT 2026
================
@@ -2135,6 +2136,131 @@ llvm::LogicalResult fir::ConvertOp::verify() {
<< getValue().getType() << " / " << getType();
}
+/// Pointee of a reference to a simple scalar, or null. Both fir.ref and rank-0
+/// memref qualify, since the storage of a scalar is cast between those forms.
+static mlir::Type getScalarSlotPointeeType(mlir::Type type) {
+ mlir::Type eleTy;
+ if (auto refTy = mlir::dyn_cast<fir::ReferenceType>(type)) {
+ eleTy = refTy.getEleTy();
+ } else if (auto memrefTy = mlir::dyn_cast<mlir::MemRefType>(type)) {
+ // A rank, layout or memory space lets the cast reinterpret the storage.
+ if (memrefTy.getRank() != 0 || !memrefTy.getLayout().isIdentity() ||
+ memrefTy.getMemorySpace())
+ return {};
+ eleTy = memrefTy.getElementType();
+ } else {
+ return {};
+ }
+ if (!mlir::isa<mlir::IntegerType, mlir::FloatType, mlir::ComplexType,
+ fir::LogicalType>(eleTy))
+ return {};
+ return eleTy;
+}
+
+/// The value a cast or declare aliases, or null if `value` is not one of those.
+static mlir::Value getAliasedSlotPointer(mlir::Value value) {
+ mlir::Operation *def = value.getDefiningOp();
+ if (auto convert = mlir::dyn_cast_or_null<fir::ConvertOp>(def))
----------------
VijayKandiah wrote:
Done! Both checks now go through `fir::FortranObjectViewOpInterface` with a `getViewOffset(result) == 0` requirement. `fir.volatile_cast` is included and keeps the storage in memory as it does not have either of the promotable interfaces
https://github.com/llvm/llvm-project/pull/219314
More information about the flang-commits
mailing list