forked from OSchip/llvm-project
[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 llvm-svn: 337020
This commit is contained in:
parent
9cad502555
commit
218b6a2a2a
|
@ -273,9 +273,17 @@ public:
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
// ... or if any of its super classes are a subset of RHS.
|
// ... or if any of its super classes are a subset of RHS.
|
||||||
for (const ClassInfo *CI : SuperClasses)
|
SmallVector<const ClassInfo *, 16> Worklist(SuperClasses.begin(),
|
||||||
if (CI->isSubsetOf(RHS))
|
SuperClasses.end());
|
||||||
|
SmallPtrSet<const ClassInfo *, 16> Visited;
|
||||||
|
while (!Worklist.empty()) {
|
||||||
|
auto *CI = Worklist.pop_back_val();
|
||||||
|
if (CI == &RHS)
|
||||||
return true;
|
return true;
|
||||||
|
for (auto *Super : CI->SuperClasses)
|
||||||
|
if (Visited.insert(Super).second)
|
||||||
|
Worklist.push_back(Super);
|
||||||
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue