[flang-commits] [flang] [flang] Lowering FIR memory ops to MemRef dialect (PR #173507)
Valentin Clement バレンタイン クレメン via flang-commits
flang-commits at lists.llvm.org
Sat Dec 27 18:20:43 PST 2025
================
@@ -0,0 +1,1156 @@
+//===-- FIRToMemRef.cpp - Convert FIR loads and stores to MemRef ---------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// This pass lowers FIR dialect memory operations to the MemRef dialect.
+// In particular it:
+//
+// - Rewrites `fir.alloca` to `memref.alloca`.
+//
+// - Rewrites `fir.load` / `fir.store` to `memref.load` / `memref.store`.
+//
+// - Allows FIR and MemRef to coexist by introducing `fir.convert` at
+// memory-use sites. Memory operations (`memref.load`, `memref.store`,
+// `memref.reinterpret_cast`, etc.) see MemRef-typed values, while the
+// original FIR-typed values remain available for non-memory uses. For
+// example:
+//
+// %fir_ref = ... : !fir.ref<!fir.array<...>>
+// %memref = fir.convert %fir_ref
+// : !fir.ref<!fir.array<...>> -> memref<...>
+// %val = memref.load %memref[...] : memref<...>
+// fir.call @callee(%fir_ref) : (!fir.ref<!fir.array<...>>) -> ()
+//
+// Here the MemRef-typed value is used for `memref.load`, while the
+// original FIR-typed value is preserved for `fir.call`.
+//
+// - Computes shapes, strides, and indices as needed for slices and shifts
+// and emits `memref.reinterpret_cast` when dynamic layout is required
+// (TODO: use memref.cast instead).
+//
+//===----------------------------------------------------------------------===//
+
+#include "flang/Optimizer/Transforms/FIRToMemRefTypeConverter.h"
+#include "flang/Optimizer/Transforms/Passes.h"
+
----------------
clementval wrote:
I don't see empty lines in other flang files between group of headers.
https://github.com/llvm/llvm-project/pull/173507
More information about the flang-commits
mailing list