Skip to content

Commit

Permalink
[MachineVerifier] Use the for_range loop to instead llvm::any_of
Browse files Browse the repository at this point in the history
Summary:
In the patch D78849, it uses llvm::any_of to instead of for loop to
simplify the function addRequired().
It's obvious that above code is not a NFC conversion. Because any_of
will return if any addRequired(Reg) is true immediately, but we want
every element to call addRequired(Reg).

This patch uses for_range loop to fix above any_of bug.

Reviewed By: MaskRay, nickdesaulniers

Differential Revision: https://reviews.llvm.org/D79872
  • Loading branch information
zhangkangcool committed May 15, 2020
1 parent dad2e92 commit aedb661
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions llvm/lib/CodeGen/MachineVerifier.cpp
Expand Up @@ -168,14 +168,18 @@ namespace {

// Same for a full set.
bool addRequired(const RegSet &RS) {
return llvm::any_of(
RS, [this](unsigned Reg) { return this->addRequired(Reg); });
bool Changed = false;
for (unsigned Reg : RS)
Changed |= addRequired(Reg);
return Changed;
}

// Same for a full map.
bool addRequired(const RegMap &RM) {
return llvm::any_of(
RM, [this](const auto &P) { return this->addRequired(P.first); });
bool Changed = false;
for (const auto &I : RM)
Changed |= addRequired(I.first);
return Changed;
}

// Live-out registers are either in regsLiveOut or vregsPassed.
Expand Down

0 comments on commit aedb661

Please sign in to comment.