[Mlir-commits] [mlir] [MLIR][Mem2Reg] Fix multi slot handling & move retry handling (PR #91464)
Tobias Gysi
llvmlistbot at llvm.org
Wed May 8 11:38:58 PDT 2024
================
@@ -636,20 +639,47 @@ LogicalResult mlir::tryToPromoteMemorySlots(
// lazily and cached to avoid expensive recomputation.
BlockIndexCache blockIndexCache;
- for (PromotableAllocationOpInterface allocator : allocators) {
- for (MemorySlot slot : allocator.getPromotableSlots()) {
- if (slot.ptr.use_empty())
- continue;
-
- MemorySlotPromotionAnalyzer analyzer(slot, dominance, dataLayout);
- std::optional<MemorySlotPromotionInfo> info = analyzer.computeInfo();
- if (info) {
- MemorySlotPromoter(slot, allocator, builder, dominance, dataLayout,
- std::move(*info), statistics, blockIndexCache)
- .promoteSlot();
- promotedAny = true;
+ SmallVector<PromotableAllocationOpInterface> workList(allocators.begin(),
+ allocators.end());
+
+ SmallVector<PromotableAllocationOpInterface> newWorkList;
+ newWorkList.reserve(workList.size());
+ while (true) {
+ bool changesInThisRound = false;
+ for (PromotableAllocationOpInterface allocator : workList) {
+ for (MemorySlot slot : allocator.getPromotableSlots()) {
+ if (slot.ptr.use_empty())
+ continue;
+
+ MemorySlotPromotionAnalyzer analyzer(slot, dominance, dataLayout);
+ std::optional<MemorySlotPromotionInfo> info = analyzer.computeInfo();
+ if (info) {
+ std::optional<PromotableAllocationOpInterface> newAllocator =
+ MemorySlotPromoter(slot, allocator, builder, dominance,
+ dataLayout, std::move(*info), statistics,
+ blockIndexCache)
+ .promoteSlot();
+ changesInThisRound = true;
+ // Add newly created allocators to the worklist for further
+ // processing.
+ if (newAllocator)
+ newWorkList.push_back(*newAllocator);
+
+ // Breaking is required, as a modification to an allocator might have
----------------
gysit wrote:
```suggestion
// A break is required, since promoting a slot may invalidate the remaining slots of an allocator.
```
nit: I would use promotion instead of modification here
https://github.com/llvm/llvm-project/pull/91464
More information about the Mlir-commits
mailing list