Skip to content

Commit

Permalink
Remove getNumUses() comparisons (NFC)
Browse files Browse the repository at this point in the history
getNumUses() scans the full use list. Don't use it is we only want
to check if there's zero or one uses.
  • Loading branch information
nikic committed May 2, 2020
1 parent 60e9ee1 commit b7e2358
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion llvm/include/llvm/IR/AbstractCallSite.h
Expand Up @@ -144,7 +144,7 @@ class AbstractCallSite {
// If the use is actually in a constant cast expression which itself
// has only one use, we look through the constant cast expression.
if (auto *CE = dyn_cast<ConstantExpr>(U->getUser()))
if (CE->getNumUses() == 1 && CE->isCast())
if (CE->hasOneUse() && CE->isCast())
U = &*CE->use_begin();

return (int)CB->getArgOperandNo(U) == CI.ParameterEncoding[0];
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/IR/AbstractCallSite.cpp
Expand Up @@ -64,7 +64,7 @@ AbstractCallSite::AbstractCallSite(const Use *U)
// This happens by updating the use @p U to the use of the constant
// cast expression and afterwards re-initializing CB accordingly.
if (ConstantExpr *CE = dyn_cast<ConstantExpr>(U->getUser()))
if (CE->getNumUses() == 1 && CE->isCast()) {
if (CE->hasOneUse() && CE->isCast()) {
U = &*CE->use_begin();
CB = dyn_cast<CallBase>(U->getUser());
}
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Transforms/Coroutines/CoroSplit.cpp
Expand Up @@ -584,7 +584,7 @@ void CoroCloner::replaceEntryBlock() {
// Move any allocas into Entry that weren't moved into the frame.
for (auto IT = OldEntry->begin(), End = OldEntry->end(); IT != End;) {
Instruction &I = *IT++;
if (!isa<AllocaInst>(&I) || I.getNumUses() == 0)
if (!isa<AllocaInst>(&I) || I.use_empty())
continue;

I.moveBefore(*Entry, Entry->getFirstInsertionPt());
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Transforms/IPO/Attributor.cpp
Expand Up @@ -1293,7 +1293,7 @@ static void createShallowWrapper(Function &F) {
F.setLinkage(GlobalValue::InternalLinkage);

F.replaceAllUsesWith(Wrapper);
assert(F.getNumUses() == 0 && "Uses remained after wrapper was created!");
assert(F.use_empty() && "Uses remained after wrapper was created!");

// Move the COMDAT section to the wrapper.
// TODO: Check if we need to keep it for F as well.
Expand Down
6 changes: 3 additions & 3 deletions llvm/lib/Transforms/IPO/AttributorAttributes.cpp
Expand Up @@ -897,7 +897,7 @@ ChangeStatus AAReturnedValuesImpl::manifest(Attributor &A) {

// Callback to replace the uses of CB with the constant C.
auto ReplaceCallSiteUsersWith = [&A](CallBase &CB, Constant &C) {
if (CB.getNumUses() == 0)
if (CB.use_empty())
return ChangeStatus::UNCHANGED;
if (A.changeValueAfterManifest(CB, C))
return ChangeStatus::CHANGED;
Expand Down Expand Up @@ -2267,7 +2267,7 @@ struct AANoAliasFloating final : AANoAliasImpl {
if (!CI)
break;
Value *Base = CI->getOperand(0);
if (Base->getNumUses() != 1)
if (!Base->hasOneUse())
break;
Val = Base;
} while (true);
Expand Down Expand Up @@ -2451,7 +2451,7 @@ struct AANoAliasCallSiteArgument final : AANoAliasImpl {
Instruction *UserI = cast<Instruction>(U.getUser());

// If user if curr instr and only use.
if ((UserI == getCtxI()) && (UserI->getNumUses() == 1))
if (UserI == getCtxI() && UserI->hasOneUse())
return true;

const Function *ScopeFn = VIRP.getAnchorScope();
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Transforms/Scalar/SeparateConstOffsetFromGEP.cpp
Expand Up @@ -704,7 +704,7 @@ Value *ConstantOffsetExtractor::removeConstOffset(unsigned ChainIndex) {
}

BinaryOperator *BO = cast<BinaryOperator>(UserChain[ChainIndex]);
assert(BO->getNumUses() <= 1 &&
assert((BO->use_empty() || BO->hasOneUse()) &&
"distributeExtsAndCloneChain clones each BinaryOperator in "
"UserChain, so no one should be used more than "
"once");
Expand Down

0 comments on commit b7e2358

Please sign in to comment.