[llvm] 4ab66e4 - [TableGen] Combine FactorNodes and FactorScope. NFC
Craig Topper via llvm-commits
llvm-commits at lists.llvm.org
Sun Feb 15 00:21:40 PST 2026
Author: Craig Topper
Date: 2026-02-15T00:18:16-08:00
New Revision: 4ab66e444bab26b2f018f9408282eaa8b958d785
URL: https://github.com/llvm/llvm-project/commit/4ab66e444bab26b2f018f9408282eaa8b958d785
DIFF: https://github.com/llvm/llvm-project/commit/4ab66e444bab26b2f018f9408282eaa8b958d785.diff
LOG: [TableGen] Combine FactorNodes and FactorScope. NFC
These were separated in 31db7afacf4dae051fcd0da22e440813663b61f3
due to the complexity of the rebindable unique_ptr. With the
switch to MatcherList, the code is not as complicated.
Added:
Modified:
llvm/utils/TableGen/DAGISelMatcherOpt.cpp
Removed:
################################################################################
diff --git a/llvm/utils/TableGen/DAGISelMatcherOpt.cpp b/llvm/utils/TableGen/DAGISelMatcherOpt.cpp
index 553242f7143d7..8a88d3df7b1d0 100644
--- a/llvm/utils/TableGen/DAGISelMatcherOpt.cpp
+++ b/llvm/utils/TableGen/DAGISelMatcherOpt.cpp
@@ -337,8 +337,6 @@ static bool canMoveToFront(const MatcherList &ML,
llvm_unreachable("M not part of list?");
}
-static void FactorNodes(MatcherList &ML);
-
/// Turn matches like this:
/// Scope
/// OPC_CheckType i32
@@ -351,10 +349,23 @@ static void FactorNodes(MatcherList &ML);
/// ABC
/// XYZ
///
-/// \p ML is a list that ends with a ScopeMatcher. \p Prev is the iterator
-/// before the ScopeMatcher in \p ML.
-static void FactorScope(MatcherList &ML, MatcherList::iterator Prev) {
- ScopeMatcher *Scope = cast<ScopeMatcher>(*std::next(Prev));
+/// \p ML is a list that ends with a ScopeMatcher.
+static void FactorNodes(MatcherList &ML) {
+ auto Prev = ML.before_begin();
+ auto Curr = std::next(Prev);
+
+ ScopeMatcher *Scope = nullptr;
+
+ while (true) {
+ if (Curr == ML.end())
+ return;
+
+ if ((Scope = dyn_cast<ScopeMatcher>(*Curr)))
+ break;
+
+ Prev = Curr;
+ ++Curr;
+ }
SmallVectorImpl<MatcherList> &OptionsToMatch = Scope->getChildren();
@@ -491,7 +502,7 @@ static void FactorScope(MatcherList &ML, MatcherList::iterator Prev) {
new ScopeMatcher(std::move(EqualMatchers)));
// Recursively factor the newly created node.
- FactorScope(Shared, Shared.begin());
+ FactorNodes(Shared);
}
// Put the new Matcher where we started in OptionsToMatch.
@@ -615,7 +626,7 @@ static void FactorScope(MatcherList &ML, MatcherList::iterator Prev) {
// Make sure we recursively factor any scopes we may have created.
for (auto &M : Cases) {
if (isa<ScopeMatcher>(M.second.front())) {
- FactorScope(M.second, M.second.before_begin());
+ FactorNodes(M.second);
assert(!M.second.empty() && "empty matcher list");
}
}
@@ -632,20 +643,6 @@ static void FactorScope(MatcherList &ML, MatcherList::iterator Prev) {
}
}
-/// Search a ScopeMatcher to factor with FactorScope.
-static void FactorNodes(MatcherList &ML) {
- auto P = ML.before_begin();
- auto I = std::next(P);
-
- while (I != ML.end()) {
- if (isa<ScopeMatcher>(*I))
- return FactorScope(ML, P);
-
- P = I;
- ++I;
- }
-}
-
void llvm::OptimizeMatcher(MatcherList &ML, const CodeGenDAGPatterns &CGP) {
ContractNodes(ML, CGP);
FactorNodes(ML);
More information about the llvm-commits
mailing list