[Mlir-commits] [mlir] [PDL] Avoid repeated hash lookups (NFC) (PR #108927)

Kazu Hirata llvmlistbot at llvm.org
Mon Sep 16 21:27:57 PDT 2024


https://github.com/kazutakahirata created https://github.com/llvm/llvm-project/pull/108927

None

>From c72953239fb29b6fa6aae844fa4938fe3f76abdb Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Mon, 16 Sep 2024 06:51:08 -0700
Subject: [PATCH] [PDL] Avoid repeated hash lookups (NFC)

---
 mlir/lib/Dialect/PDL/IR/PDL.cpp | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/mlir/lib/Dialect/PDL/IR/PDL.cpp b/mlir/lib/Dialect/PDL/IR/PDL.cpp
index 428b19f4c74af8..9d7c36520874d3 100644
--- a/mlir/lib/Dialect/PDL/IR/PDL.cpp
+++ b/mlir/lib/Dialect/PDL/IR/PDL.cpp
@@ -65,13 +65,10 @@ static void visit(Operation *op, DenseSet<Operation *> &visited) {
   if (!isa<PatternOp>(op->getParentOp()) || isa<RewriteOp>(op))
     return;
 
-  // Ignore if already visited.
-  if (visited.contains(op))
+  // Ignore if already visited.  Otherwise, mark as visited.
+  if (!visited.insert(op).second)
     return;
 
-  // Mark as visited.
-  visited.insert(op);
-
   // Traverse the operands / parent.
   TypeSwitch<Operation *>(op)
       .Case<OperationOp>([&visited](auto operation) {



More information about the Mlir-commits mailing list