================
@@ -583,3 +624,283 @@ Region *mlir::getEnclosingRepetitiveRegion(Value value) {
LDBG() << "No enclosing repetitive region found for value";
return nullptr;
}
+
+/// Is a defined before b?
+static bool isDefinedBefore(Value a, Value b) {
+ Region *aRegion = a.getParentRegion();
+ Region *bRegion = b.getParentRegion();
+
+ if (aRegion->getParentOp()->isProperAncestor(bRegion->getParentOp())) {
+ return true;
+ }
+ if (aRegion == bRegion) {
+ Block *aBlock = a.getParentBlock();
+ Block *bBlock = b.getParentBlock();
+ if (aBlock != bBlock)
+ return false;
+ if (isa<BlockArgument>(a))
+ return true;
+ if (isa<BlockArgument>(b))
+ return false;
+ return a.getDefiningOp()->isBeforeInBlock(b.getDefiningOp());
+ }
+
+ return false;
+}
+
+namespace {
+// Try to make successor inputs dead by replacing their uses with values that
+// are not successor inputs. This pattern enables additional canonicalization
+// opportunities for RemoveDeadValues.
+struct RemoveUsesOfIdenticalValues : public RewritePattern {
+ RemoveUsesOfIdenticalValues(MLIRContext *context, StringRef name,
+ PatternBenefit benefit = 1)
+ : RewritePattern(name, benefit, context) {}
+
+ LogicalResult matchAndRewrite(Operation *op,
+ PatternRewriter &rewriter) const override {
+ auto regionBranchOp = cast<RegionBranchOpInterface>(op);
+
+ // Gather all potential successor inputs. (Other values may also be
+ // included, but we're not doing anything with them.)
+ SmallVector<Value> values;
+ llvm::append_range(values, regionBranchOp->getResults());
+ for (Region &r : op->getRegions())
+ llvm::append_range(values, r.getArguments());
+
+ bool changed = false;
+ for (Value value : values) {
+ if (value.use_empty())
+ continue;
+ DenseSet<Value> possibleValues =
----------------
Hardcode84 wrote:
Allocating `DenseSet` inside a loop is unfortunate, can we use `SmallDenseSet`?
https://github.com/llvm/llvm-project/pull/174094
_______________________________________________
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits