Skip to content

Commit

Permalink
[TableGen] Avoid creating a ScopeMatcher full of nullptrs.
Browse files Browse the repository at this point in the history
The call to FactorNodes will catch it and remove it, but it's easy
to catch at creation.

Remove the now unnecessary null checks from a loop in factor nodes.
  • Loading branch information
topperc committed Apr 2, 2023
1 parent 741298a commit 2be67e1
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions llvm/utils/TableGen/DAGISelMatcherOpt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,15 +209,13 @@ static void FactorNodes(std::unique_ptr<Matcher> &InputMatcherPtr) {
// Factor the subexpression.
std::unique_ptr<Matcher> Child(Scope->takeChild(i));
FactorNodes(Child);

if (Child) {
// If the child is a ScopeMatcher we can just merge its contents.
if (auto *SM = dyn_cast<ScopeMatcher>(Child.get())) {
for (unsigned j = 0, e = SM->getNumChildren(); j != e; ++j)
OptionsToMatch.push_back(SM->takeChild(j));
} else {
OptionsToMatch.push_back(Child.release());
}

// If the child is a ScopeMatcher we can just merge its contents.
if (auto *SM = dyn_cast<ScopeMatcher>(Child.get())) {
for (unsigned j = 0, e = SM->getNumChildren(); j != e; ++j)
OptionsToMatch.push_back(SM->takeChild(j));
} else {
OptionsToMatch.push_back(Child.release());
}
}

Expand Down Expand Up @@ -323,13 +321,16 @@ static void FactorNodes(std::unique_ptr<Matcher> &InputMatcherPtr) {
Matcher *Tmp = EqualMatchers[i]->takeNext();
delete EqualMatchers[i];
EqualMatchers[i] = Tmp;
assert(!Optn == !Tmp && "Expected all to be null if any are null");
}

Shared->setNext(new ScopeMatcher(std::move(EqualMatchers)));
if (EqualMatchers[0]) {
Shared->setNext(new ScopeMatcher(std::move(EqualMatchers)));

// Recursively factor the newly created node.
FactorNodes(Shared->getNextPtr());
}

// Recursively factor the newly created node.
FactorNodes(Shared->getNextPtr());

NewOptionsToMatch.push_back(Shared);
}

Expand Down

0 comments on commit 2be67e1

Please sign in to comment.