[llvm] b7e2358 - Remove getNumUses() comparisons (NFC)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Sat May 2 02:05:49 PDT 2020
Author: Nikita Popov
Date: 2020-05-02T11:05:19+02:00
New Revision: b7e2358220f26ee82e0e958f2d691d2f00341a0a
URL: https://github.com/llvm/llvm-project/commit/b7e2358220f26ee82e0e958f2d691d2f00341a0a
DIFF: https://github.com/llvm/llvm-project/commit/b7e2358220f26ee82e0e958f2d691d2f00341a0a.diff
LOG: Remove getNumUses() comparisons (NFC)
getNumUses() scans the full use list. Don't use it is we only want
to check if there's zero or one uses.
Added:
Modified:
llvm/include/llvm/IR/AbstractCallSite.h
llvm/lib/IR/AbstractCallSite.cpp
llvm/lib/Transforms/Coroutines/CoroSplit.cpp
llvm/lib/Transforms/IPO/Attributor.cpp
llvm/lib/Transforms/IPO/AttributorAttributes.cpp
llvm/lib/Transforms/Scalar/SeparateConstOffsetFromGEP.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/IR/AbstractCallSite.h b/llvm/include/llvm/IR/AbstractCallSite.h
index 559da8578510..c78afc729d43 100644
--- a/llvm/include/llvm/IR/AbstractCallSite.h
+++ b/llvm/include/llvm/IR/AbstractCallSite.h
@@ -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];
diff --git a/llvm/lib/IR/AbstractCallSite.cpp b/llvm/lib/IR/AbstractCallSite.cpp
index 1f7371607b88..6504e566ba4b 100644
--- a/llvm/lib/IR/AbstractCallSite.cpp
+++ b/llvm/lib/IR/AbstractCallSite.cpp
@@ -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());
}
diff --git a/llvm/lib/Transforms/Coroutines/CoroSplit.cpp b/llvm/lib/Transforms/Coroutines/CoroSplit.cpp
index 7d719fd084cb..1e0bdc168e5b 100644
--- a/llvm/lib/Transforms/Coroutines/CoroSplit.cpp
+++ b/llvm/lib/Transforms/Coroutines/CoroSplit.cpp
@@ -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());
diff --git a/llvm/lib/Transforms/IPO/Attributor.cpp b/llvm/lib/Transforms/IPO/Attributor.cpp
index aafeb6ebd92c..04fc4108d8d6 100644
--- a/llvm/lib/Transforms/IPO/Attributor.cpp
+++ b/llvm/lib/Transforms/IPO/Attributor.cpp
@@ -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.
diff --git a/llvm/lib/Transforms/IPO/AttributorAttributes.cpp b/llvm/lib/Transforms/IPO/AttributorAttributes.cpp
index aeb1029ed002..eff08bd3f48e 100644
--- a/llvm/lib/Transforms/IPO/AttributorAttributes.cpp
+++ b/llvm/lib/Transforms/IPO/AttributorAttributes.cpp
@@ -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;
@@ -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);
@@ -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();
diff --git a/llvm/lib/Transforms/Scalar/SeparateConstOffsetFromGEP.cpp b/llvm/lib/Transforms/Scalar/SeparateConstOffsetFromGEP.cpp
index 0d375bb3a6eb..f1d2e3c1ecfa 100644
--- a/llvm/lib/Transforms/Scalar/SeparateConstOffsetFromGEP.cpp
+++ b/llvm/lib/Transforms/Scalar/SeparateConstOffsetFromGEP.cpp
@@ -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");
More information about the llvm-commits
mailing list