[Mlir-commits] [mlir] [MLIR] Add single definition multiple regions for mem2reg (PR #89107)
Christian Ulmann
llvmlistbot at llvm.org
Thu Apr 18 08:06:44 PDT 2024
================
@@ -297,14 +313,52 @@ LogicalResult MemorySlotPromotionAnalyzer::computeBlockingUses(
}
}
- // Because this pass currently only supports analysing the parent region of
- // the slot pointer, if a promotable memory op that needs promotion is outside
- // of this region, promotion must fail because it will be impossible to
- // provide a valid `reachingDef` for it.
- for (auto &[toPromote, _] : userToBlockingUses)
+ // The define uses web only have one definition, It is the potential case.
+ totalStores != 1 ? singleDefining.setPointer(nullptr) : (void)0;
+
+ // The single definition can not dominate all of the uses, there are some
+ // uses need default value and block arguments. But current dominate
+ // frontier algorithms only support single region, so failed.
+ auto leagelSingleDefiningMultiRegions = [this](BlockingUsesMap &userMap) {
+ if (singleDefining.getPointer() == nullptr)
+ return failure();
+
+ // The single definition dominate all the uses, we can ignore whether
+ // all of the uses and definotion in a same region.
+ for (auto &[user, _] : userMap)
+ if (!dominance.dominates(singleDefining.getPointer(), user))
+ return failure();
+ // The same region case is fail in here we can konwn, clear the bool value
+ // of `singleDefing`, otherwise we may confuse weather same region or single
+ // define multiple region. Place this above return success() because when
+ // return failure() there is not any afterwards, will clear everything
+ // prepare the next slot.
+ singleDefining.setInt(false);
+ return success();
+ };
+
+ // Because we will first check weather def-uses at same region, if this
+ // success, we will missing the opportunity clear the pointer value
+ // of`singleDefinig`, so we need to known weather this is the same region case
+ // in the code afterward. If same region check fails, this value will been
+ // clear at the single defining multiple regions case.
+ singleDefining.setInt(true);
+ // Because this pass currently only supports has only one defining operation
+ // for the , slot or analysing the parent region of the slot pointer, if a
+ // promotable memory op that needs promotion is outside of this region,
+ // promotion must fail because it will be impossible to provide a valid
+ // `reachingDef` for it.
+ for (auto &[toPromote, _] : userToBlockingUses) {
----------------
Dinistro wrote:
`llvm::make_first_range` helps with such things.
https://github.com/llvm/llvm-project/pull/89107
More information about the Mlir-commits
mailing list