[Mlir-commits] [mlir] [mlir] [memref] [transform] Add alloc_to_global op. (PR #211141)
Bhavesh M
llvmlistbot at llvm.org
Wed Aug 5 13:46:01 PDT 2026
================
@@ -125,6 +125,64 @@ void transform::ApplyResolveRankedShapedTypeResultDimsPatternsOp::
memref::populateResolveRankedShapedTypeResultDimsPatterns(patterns);
}
+//===----------------------------------------------------------------------===//
+// Alloc and alloca to global utilities
+//===----------------------------------------------------------------------===//
+
+/// Converts an allocation operation (`memref.alloca` or `memref.alloc`) to a
+/// `memref.global` operation in the nearest symbol table, and replaces the
+/// allocation with a `memref.get_global` operation. Any `memref.dealloc`
+/// operations referencing the allocation are erased.
+template <typename AllocLikeOp>
+static DiagnosedSilenceableFailure
+allocLikeToGlobal(transform::TransformRewriter &rewriter,
+ AllocLikeOp allocLikeOp, StringRef globalName,
+ memref::GlobalOp &globalOp,
+ memref::GetGlobalOp &getGlobalOp) {
+ MemRefType memrefType = allocLikeOp.getType();
+ if (!memrefType.hasStaticShape()) {
----------------
beamandala wrote:
Expanded the checks and made a helper containing them.
https://github.com/llvm/llvm-project/pull/211141
More information about the Mlir-commits
mailing list