[PATCH] D49124: [Tablegen] Optimize isSubsetOf() in AsmMatcherEmitter.cpp

Marcello Maggioni via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 9 19:56:40 PDT 2018


kariddi created this revision.
kariddi added reviewers: dblaikie, craig.topper, ddunbar.
Herald added a subscriber: llvm-commits.

isSubsetOf() could be very slow if the hierarchy of the RegisterClasses of the target is very complicated.

This is mainly caused by the fact that isSubset() is called multiple times over the same SuperClass of a register class if this ends up being the super class of a register class from multiple paths.


Repository:
  rL LLVM

https://reviews.llvm.org/D49124

Files:
  utils/TableGen/AsmMatcherEmitter.cpp


Index: utils/TableGen/AsmMatcherEmitter.cpp
===================================================================
--- utils/TableGen/AsmMatcherEmitter.cpp
+++ utils/TableGen/AsmMatcherEmitter.cpp
@@ -272,10 +272,18 @@
     if (this == &RHS)
       return true;
 
+    SmallVector<const ClassInfo *, 16> Worklist(SuperClasses.begin(),
+                                                SuperClasses.end());
+    SmallPtrSet<const ClassInfo *, 16> Visited;
     // ... or if any of its super classes are a subset of RHS.
-    for (const ClassInfo *CI : SuperClasses)
-      if (CI->isSubsetOf(RHS))
+    while (!Worklist.empty()) {
+      auto *CI = Worklist.pop_back_val();
+      if (CI == &RHS)
         return true;
+      for (auto *Super : CI->SuperClasses)
+        if (Visited.insert(Super).second)
+          Worklist.push_back(Super);
+    }
 
     return false;
   }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D49124.154759.patch
Type: text/x-patch
Size: 872 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180710/05e69a7b/attachment.bin>


More information about the llvm-commits mailing list