[llvm] r337020 - [Tablegen] Optimize isSubsetOf() in AsmMatcherEmitter.cpp. NFC
Marcello Maggioni via llvm-commits
llvm-commits at lists.llvm.org
Fri Jul 13 09:36:14 PDT 2018
Author: mggm
Date: Fri Jul 13 09:36:14 2018
New Revision: 337020
URL: http://llvm.org/viewvc/llvm-project?rev=337020&view=rev
Log:
[Tablegen] Optimize isSubsetOf() in AsmMatcherEmitter.cpp. NFC
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
Modified:
llvm/trunk/utils/TableGen/AsmMatcherEmitter.cpp
Modified: llvm/trunk/utils/TableGen/AsmMatcherEmitter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/AsmMatcherEmitter.cpp?rev=337020&r1=337019&r2=337020&view=diff
==============================================================================
--- llvm/trunk/utils/TableGen/AsmMatcherEmitter.cpp (original)
+++ llvm/trunk/utils/TableGen/AsmMatcherEmitter.cpp Fri Jul 13 09:36:14 2018
@@ -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;
}
More information about the llvm-commits
mailing list