[Mlir-commits] [mlir] [MLIR][Mem2Reg] Extract shared utilities for PromotableRegionOpInterface (PR #188514)

Théo Degioanni llvmlistbot at llvm.org
Fri Mar 27 03:20:15 PDT 2026


================
@@ -0,0 +1,49 @@
+//===- MemorySlotUtils.cpp - Utilities for MemorySlot interfaces ----------===//
+//
+// 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 file implements common utilities for implementing MemorySlot interfaces,
+// in particular PromotableRegionOpInterface.
+//
+//===----------------------------------------------------------------------===//
+
+#include "mlir/Interfaces/Utils/MemorySlotUtils.h"
+
+using namespace mlir;
+
+void mlir::memoryslot::updateTerminator(
+    Block *block, Value defaultReachingDef,
+    const DenseMap<Block *, Value> &reachingAtBlockEnd) {
+  Value blockReachingDef = reachingAtBlockEnd.lookup(block);
+  if (!blockReachingDef)
+    blockReachingDef = defaultReachingDef;
+  Operation *terminator = block->getTerminator();
+  terminator->insertOperands(terminator->getNumOperands(), {blockReachingDef});
+}
+
+Operation *mlir::memoryslot::replaceWithNewResults(RewriterBase &rewriter,
+                                                   Operation *op,
+                                                   TypeRange resultTypes) {
+  RewriterBase::InsertionGuard guard(rewriter);
+  rewriter.setInsertionPoint(op);
+  OperationState state(op->getLoc(), op->getName(), op->getOperands(),
----------------
Moxinilian wrote:

Could you test that this also clones properties correctly?
I wish we did not have to have them run through attributes, but since the existing implementation does that too I guess it's not too bad.

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


More information about the Mlir-commits mailing list