]> granicus.if.org Git - llvm/commitdiff
[Tablegen] Optimize isSubsetOf() in AsmMatcherEmitter.cpp. NFC
authorMarcello Maggioni <hayarms@gmail.com>
Fri, 13 Jul 2018 16:36:14 +0000 (16:36 +0000)
committerMarcello Maggioni <hayarms@gmail.com>
Fri, 13 Jul 2018 16:36:14 +0000 (16:36 +0000)
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.

Differential Revision: https://reviews.llvm.org/D49124

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@337020 91177308-0d34-0410-b5e6-96231b3b80d8

utils/TableGen/AsmMatcherEmitter.cpp

index 7318c6d109e3587ca0bf29254be8a7d11d0df997..e808661b7a51fd193bca5ea9c4cf054c82473125 100644 (file)
@@ -273,9 +273,17 @@ public:
       return true;
 
     // ... or if any of its super classes are a subset of RHS.
-    for (const ClassInfo *CI : SuperClasses)
-      if (CI->isSubsetOf(RHS))
+    SmallVector<const ClassInfo *, 16> Worklist(SuperClasses.begin(),
+                                                SuperClasses.end());
+    SmallPtrSet<const ClassInfo *, 16> Visited;
+    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;
   }