-
Notifications
You must be signed in to change notification settings - Fork 14.3k
unittests: Avoid using getNumUses #136352
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@llvm/pr-subscribers-llvm-ir @llvm/pr-subscribers-flang-openmp Author: Matt Arsenault (arsenm) ChangesFull diff: https://github.com/llvm/llvm-project/pull/136352.diff 5 Files Affected:
diff --git a/llvm/unittests/Analysis/CGSCCPassManagerTest.cpp b/llvm/unittests/Analysis/CGSCCPassManagerTest.cpp
index cf649776c04fd..17240a1c73bce 100644
--- a/llvm/unittests/Analysis/CGSCCPassManagerTest.cpp
+++ b/llvm/unittests/Analysis/CGSCCPassManagerTest.cpp
@@ -1641,7 +1641,7 @@ TEST_F(CGSCCPassManagerTest, TestUpdateCGAndAnalysisManagerForPasses8) {
CGU.initialize(CG, C, AM, UR);
ASSERT_NO_FATAL_FAILURE(CGU.replaceFunctionWith(*FnF, *FnewF));
ASSERT_TRUE(FnF->isDeclaration());
- ASSERT_EQ(FnF->getNumUses(), 0U);
+ ASSERT_TRUE(FnF->use_empty());
}));
ModulePassManager MPM;
diff --git a/llvm/unittests/Analysis/LazyCallGraphTest.cpp b/llvm/unittests/Analysis/LazyCallGraphTest.cpp
index 49677d7301f88..4a4ff3242c4c4 100644
--- a/llvm/unittests/Analysis/LazyCallGraphTest.cpp
+++ b/llvm/unittests/Analysis/LazyCallGraphTest.cpp
@@ -1155,7 +1155,7 @@ TEST(LazyCallGraphTest, InlineAndDeleteFunction) {
ASSERT_EQ(&D2F, D1Call->getCalledFunction());
C1Call->setCalledFunction(&D3.getFunction());
D1Call->setCalledFunction(&D3.getFunction());
- ASSERT_EQ(0u, D2F.getNumUses());
+ ASSERT_TRUE(D2F.use_empty());
// Insert new edges first.
CRC.insertTrivialCallEdge(C1, D3);
diff --git a/llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp b/llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
index 5dd018006ec37..8300c311da604 100644
--- a/llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
+++ b/llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
@@ -325,7 +325,7 @@ static Value *findStoredValueInAggregateAt(LLVMContext &Ctx, Value *Aggregate,
}
EXPECT_NE(GEPAtIdx, nullptr);
- EXPECT_EQ(GEPAtIdx->getNumUses(), 1U);
+ EXPECT_TRUE(GEPAtIdx->hasOneUse());
// Find the value stored to the aggregate.
StoreInst *StoreToAgg = dyn_cast<StoreInst>(*GEPAtIdx->user_begin());
@@ -443,7 +443,7 @@ TEST_F(OpenMPIRBuilderTest, CreateCancel) {
EXPECT_EQ(Cancel->getCalledFunction()->getName(), "__kmpc_cancel");
EXPECT_FALSE(Cancel->getCalledFunction()->doesNotAccessMemory());
EXPECT_FALSE(Cancel->getCalledFunction()->doesNotFreeMemory());
- EXPECT_EQ(Cancel->getNumUses(), 1U);
+ EXPECT_TRUE(Cancel->hasOneUse());
Instruction *CancelBBTI = Cancel->getParent()->getTerminator();
EXPECT_EQ(CancelBBTI->getNumSuccessors(), 2U);
EXPECT_EQ(CancelBBTI->getSuccessor(0), NewIP.getBlock());
@@ -460,7 +460,7 @@ TEST_F(OpenMPIRBuilderTest, CreateCancel) {
EXPECT_EQ(Barrier->getCalledFunction()->getName(), "__kmpc_cancel_barrier");
EXPECT_FALSE(Barrier->getCalledFunction()->doesNotAccessMemory());
EXPECT_FALSE(Barrier->getCalledFunction()->doesNotFreeMemory());
- EXPECT_EQ(Barrier->getNumUses(), 0U);
+ EXPECT_TRUE(Barrier->use_empty());
EXPECT_EQ(CancelBBTI->getSuccessor(1)->getTerminator()->getNumSuccessors(),
1U);
EXPECT_EQ(CancelBBTI->getSuccessor(1)->getTerminator()->getSuccessor(0), CBB);
@@ -516,7 +516,7 @@ TEST_F(OpenMPIRBuilderTest, CreateCancelIfCond) {
EXPECT_EQ(Cancel->getCalledFunction()->getName(), "__kmpc_cancel");
EXPECT_FALSE(Cancel->getCalledFunction()->doesNotAccessMemory());
EXPECT_FALSE(Cancel->getCalledFunction()->doesNotFreeMemory());
- EXPECT_EQ(Cancel->getNumUses(), 1U);
+ EXPECT_TRUE(Cancel->hasOneUse());
Instruction *CancelBBTI = Cancel->getParent()->getTerminator();
EXPECT_EQ(CancelBBTI->getNumSuccessors(), 2U);
EXPECT_EQ(CancelBBTI->getSuccessor(0)->size(), 1U);
@@ -535,7 +535,7 @@ TEST_F(OpenMPIRBuilderTest, CreateCancelIfCond) {
EXPECT_EQ(Barrier->getCalledFunction()->getName(), "__kmpc_cancel_barrier");
EXPECT_FALSE(Barrier->getCalledFunction()->doesNotAccessMemory());
EXPECT_FALSE(Barrier->getCalledFunction()->doesNotFreeMemory());
- EXPECT_EQ(Barrier->getNumUses(), 0U);
+ EXPECT_TRUE(Barrier->use_empty());
EXPECT_EQ(CancelBBTI->getSuccessor(1)->getTerminator()->getNumSuccessors(),
1U);
EXPECT_EQ(CancelBBTI->getSuccessor(1)->getTerminator()->getSuccessor(0), CBB);
@@ -586,7 +586,7 @@ TEST_F(OpenMPIRBuilderTest, CreateCancelBarrier) {
EXPECT_EQ(Barrier->getCalledFunction()->getName(), "__kmpc_cancel_barrier");
EXPECT_FALSE(Barrier->getCalledFunction()->doesNotAccessMemory());
EXPECT_FALSE(Barrier->getCalledFunction()->doesNotFreeMemory());
- EXPECT_EQ(Barrier->getNumUses(), 1U);
+ EXPECT_TRUE(Barrier->hasOneUse());
Instruction *BarrierBBTI = Barrier->getParent()->getTerminator();
EXPECT_EQ(BarrierBBTI->getNumSuccessors(), 2U);
EXPECT_EQ(BarrierBBTI->getSuccessor(0), NewIP.getBlock());
@@ -741,7 +741,7 @@ TEST_F(OpenMPIRBuilderTest, ParallelSimpleGPU) {
EXPECT_EQ(OutlinedFn->getArg(2)->getType(),
PointerType::get(M->getContext(), 0));
EXPECT_EQ(&OutlinedFn->getEntryBlock(), PrivAI->getParent());
- EXPECT_EQ(OutlinedFn->getNumUses(), 1U);
+ EXPECT_TRUE(OutlinedFn->hasOneUse());
User *Usr = OutlinedFn->user_back();
ASSERT_TRUE(isa<CallInst>(Usr));
CallInst *Parallel51CI = dyn_cast<CallInst>(Usr);
@@ -849,7 +849,7 @@ TEST_F(OpenMPIRBuilderTest, ParallelSimple) {
EXPECT_EQ(OutlinedFn->arg_size(), 3U);
EXPECT_EQ(&OutlinedFn->getEntryBlock(), PrivAI->getParent());
- EXPECT_EQ(OutlinedFn->getNumUses(), 1U);
+ EXPECT_TRUE(OutlinedFn->hasOneUse());
User *Usr = OutlinedFn->user_back();
ASSERT_TRUE(isa<CallInst>(Usr));
CallInst *ForkCI = dyn_cast<CallInst>(Usr);
@@ -952,7 +952,7 @@ TEST_F(OpenMPIRBuilderTest, ParallelNested) {
EXPECT_TRUE(OutlinedFn.hasInternalLinkage());
EXPECT_EQ(OutlinedFn.arg_size(), 2U);
- EXPECT_EQ(OutlinedFn.getNumUses(), 1U);
+ EXPECT_TRUE(OutlinedFn.hasOneUse());
User *Usr = OutlinedFn.user_back();
ASSERT_TRUE(isa<CallInst>(Usr));
CallInst *ForkCI = dyn_cast<CallInst>(Usr);
@@ -1071,7 +1071,7 @@ TEST_F(OpenMPIRBuilderTest, ParallelNested2Inner) {
NumAllocas += isa<AllocaInst>(I);
EXPECT_EQ(NumAllocas, 1U);
- EXPECT_EQ(OutlinedFn.getNumUses(), 1U);
+ EXPECT_TRUE(OutlinedFn.hasOneUse());
User *Usr = OutlinedFn.user_back();
ASSERT_TRUE(isa<CallInst>(Usr));
CallInst *ForkCI = dyn_cast<CallInst>(Usr);
@@ -1178,7 +1178,7 @@ TEST_F(OpenMPIRBuilderTest, ParallelIfCond) {
EXPECT_EQ(OutlinedFn->arg_size(), 3U);
EXPECT_EQ(&OutlinedFn->getEntryBlock(), PrivAI->getParent());
- ASSERT_EQ(OutlinedFn->getNumUses(), 1U);
+ ASSERT_TRUE(OutlinedFn->hasOneUse());
CallInst *ForkCI = nullptr;
for (User *Usr : OutlinedFn->users()) {
@@ -1229,9 +1229,9 @@ TEST_F(OpenMPIRBuilderTest, ParallelCancelBarrier) {
BFn = M->getFunction("__kmpc_barrier");
ASSERT_NE(CBFn, nullptr);
ASSERT_EQ(BFn, nullptr);
- ASSERT_EQ(CBFn->getNumUses(), 1U);
+ ASSERT_TRUE(CBFn->hasOneUse());
ASSERT_TRUE(isa<CallInst>(CBFn->user_back()));
- ASSERT_EQ(CBFn->user_back()->getNumUses(), 1U);
+ ASSERT_TRUE(CBFn->user_back()->hasOneUse());
CheckedBarrier = cast<CallInst>(CBFn->user_back());
ASSERT_EXPECTED_INIT(
@@ -1242,20 +1242,20 @@ TEST_F(OpenMPIRBuilderTest, ParallelCancelBarrier) {
BFn = M->getFunction("__kmpc_barrier");
ASSERT_NE(CBFn, nullptr);
ASSERT_NE(BFn, nullptr);
- ASSERT_EQ(CBFn->getNumUses(), 1U);
- ASSERT_EQ(BFn->getNumUses(), 1U);
+ ASSERT_TRUE(CBFn->hasOneUse());
+ ASSERT_TRUE(BFn->hasOneUse());
ASSERT_TRUE(isa<CallInst>(BFn->user_back()));
- ASSERT_EQ(BFn->user_back()->getNumUses(), 0U);
+ ASSERT_TRUE(BFn->user_back()->use_empty());
ASSERT_EXPECTED_INIT(OpenMPIRBuilder::InsertPointTy, BarrierIP3,
OMPBuilder.createBarrier(Builder.saveIP(),
OMPD_parallel, false, false));
Builder.restoreIP(BarrierIP3);
- ASSERT_EQ(CBFn->getNumUses(), 2U);
- ASSERT_EQ(BFn->getNumUses(), 1U);
+ ASSERT_TRUE(CBFn->hasNUses(2));
+ ASSERT_TRUE(BFn->hasOneUse());
ASSERT_TRUE(CBFn->user_back() != CheckedBarrier);
ASSERT_TRUE(isa<CallInst>(CBFn->user_back()));
- ASSERT_EQ(CBFn->user_back()->getNumUses(), 0U);
+ ASSERT_TRUE(CBFn->user_back()->use_empty());
};
auto PrivCB = [&](InsertPointTy, InsertPointTy, Value &V, Value &,
@@ -1289,7 +1289,7 @@ TEST_F(OpenMPIRBuilderTest, ParallelCancelBarrier) {
EXPECT_EQ(NumBodiesGenerated, 1U);
EXPECT_EQ(NumPrivatizedVars, 0U);
EXPECT_EQ(NumFinalizationPoints, 2U);
- EXPECT_EQ(FakeDestructor->getNumUses(), 2U);
+ EXPECT_TRUE(FakeDestructor->hasNUses(2));
Builder.restoreIP(AfterIP);
Builder.CreateRetVoid();
@@ -3988,7 +3988,7 @@ TEST_F(OpenMPIRBuilderTest, OMPAtomicUpdate) {
EXPECT_EQ(Phi->getIncomingBlock(0), EntryBB);
EXPECT_EQ(Phi->getIncomingBlock(1), ContBB);
- EXPECT_EQ(Sub->getNumUses(), 1U);
+ EXPECT_TRUE(Sub->hasOneUse());
StoreInst *St = dyn_cast<StoreInst>(Sub->user_back());
AllocaInst *UpdateTemp = dyn_cast<AllocaInst>(St->getPointerOperand());
@@ -4058,7 +4058,7 @@ TEST_F(OpenMPIRBuilderTest, OMPAtomicUpdateFloat) {
EXPECT_EQ(Phi->getIncomingBlock(0), EntryBB);
EXPECT_EQ(Phi->getIncomingBlock(1), ContBB);
- EXPECT_EQ(Sub->getNumUses(), 1U);
+ EXPECT_TRUE(Sub->hasOneUse());
StoreInst *St = dyn_cast<StoreInst>(Sub->user_back());
AllocaInst *UpdateTemp = dyn_cast<AllocaInst>(St->getPointerOperand());
@@ -4127,7 +4127,7 @@ TEST_F(OpenMPIRBuilderTest, OMPAtomicUpdateIntr) {
EXPECT_EQ(Phi->getIncomingBlock(0), EntryBB);
EXPECT_EQ(Phi->getIncomingBlock(1), ContBB);
- EXPECT_EQ(Sub->getNumUses(), 1U);
+ EXPECT_TRUE(Sub->hasOneUse());
StoreInst *St = dyn_cast<StoreInst>(Sub->user_back());
AllocaInst *UpdateTemp = dyn_cast<AllocaInst>(St->getPointerOperand());
@@ -4942,7 +4942,7 @@ TEST_F(OpenMPIRBuilderTest, CreateTeamsWithIfConditionAndNumTeams) {
Value *ThreadLimitArg = PushNumTeamsCallInst->getArgOperand(4);
// Get the boolean conversion of if expression
- ASSERT_EQ(IfExpr->getNumUses(), 1U);
+ ASSERT_TRUE(IfExpr->hasOneUse());
User *IfExprInst = IfExpr->user_back();
ICmpInst *IfExprCmpInst = dyn_cast<ICmpInst>(IfExprInst);
ASSERT_NE(IfExprCmpInst, nullptr);
@@ -5272,7 +5272,7 @@ TEST_F(OpenMPIRBuilderTest, CreateReductions) {
// Find the GEP instructions preceding stores to the local array.
Value *FirstArrayElemPtr = nullptr;
Value *SecondArrayElemPtr = nullptr;
- EXPECT_EQ(LocalArray->getNumUses(), 3u);
+ EXPECT_TRUE(LocalArray->hasNUses(3));
ASSERT_TRUE(
findGEPZeroOne(LocalArray, FirstArrayElemPtr, SecondArrayElemPtr));
@@ -5292,7 +5292,7 @@ TEST_F(OpenMPIRBuilderTest, CreateReductions) {
// Check that the result of the runtime reduction call is used for further
// dispatch.
- ASSERT_EQ(SwitchArg->getNumUses(), 1u);
+ ASSERT_TRUE(SwitchArg->hasOneUse());
SwitchInst *Switch = dyn_cast<SwitchInst>(*SwitchArg->user_begin());
ASSERT_NE(Switch, nullptr);
EXPECT_EQ(Switch->getNumSuccessors(), 3u);
@@ -6296,7 +6296,7 @@ TEST_F(OpenMPIRBuilderTest, TargetRegion) {
// Check num_teams and num_threads kernel arguments (use number 5 starting
// from the end and counting the call to __tgt_target_kernel as the first use)
Value *KernelArgs = Call->getArgOperand(Call->arg_size() - 1);
- EXPECT_TRUE(KernelArgs->getNumUses() >= 4);
+ EXPECT_TRUE(KernelArgs->hasNUsesOrMore(4));
Value *NumTeamsGetElemPtr = *std::next(KernelArgs->user_begin(), 3);
EXPECT_TRUE(isa<GetElementPtrInst>(NumTeamsGetElemPtr));
Value *NumTeamsStore = NumTeamsGetElemPtr->getUniqueUndroppableUser();
@@ -6622,7 +6622,7 @@ TEST_F(OpenMPIRBuilderTest, TargetRegionSPMD) {
// Check the trip count kernel argument (use number 5 starting from the end
// and counting the call to __tgt_target_kernel as the first use)
Value *KernelArgs = Call->getArgOperand(Call->arg_size() - 1);
- EXPECT_TRUE(KernelArgs->getNumUses() >= 6);
+ EXPECT_TRUE(KernelArgs->hasNUsesOrMore(6));
Value *TripCountGetElemPtr = *std::next(KernelArgs->user_begin(), 5);
EXPECT_TRUE(isa<GetElementPtrInst>(TripCountGetElemPtr));
Value *TripCountStore = TripCountGetElemPtr->getUniqueUndroppableUser();
@@ -7024,7 +7024,7 @@ TEST_F(OpenMPIRBuilderTest, CreateTask) {
// Verify that the data argument is used only once, and that too in the load
// instruction that is then used for accessing shared data.
Value *DataPtr = OutlinedFn->getArg(1);
- EXPECT_EQ(DataPtr->getNumUses(), 1U);
+ EXPECT_TRUE(DataPtr->hasOneUse());
EXPECT_TRUE(isa<LoadInst>(DataPtr->uses().begin()->getUser()));
Value *Data = DataPtr->uses().begin()->getUser();
EXPECT_TRUE(all_of(Data->uses(), [](Use &U) {
@@ -7501,7 +7501,7 @@ TEST_F(OpenMPIRBuilderTest, CreateTaskgroupWithTasks) {
Function *TaskAllocFn =
OMPBuilder.getOrCreateRuntimeFunctionPtr(OMPRTL___kmpc_omp_task_alloc);
- ASSERT_EQ(TaskAllocFn->getNumUses(), 2u);
+ ASSERT_TRUE(TaskAllocFn->hasNUses(2));
CallInst *FirstTaskAllocCall =
dyn_cast_or_null<CallInst>(*TaskAllocFn->users().begin());
diff --git a/llvm/unittests/IR/ValueHandleTest.cpp b/llvm/unittests/IR/ValueHandleTest.cpp
index e11c545520d5a..0d4d0e220b561 100644
--- a/llvm/unittests/IR/ValueHandleTest.cpp
+++ b/llvm/unittests/IR/ValueHandleTest.cpp
@@ -329,7 +329,7 @@ TEST_F(ValueHandle, CallbackVH_DeletionCanRAUW) {
}
void allUsesReplacedWith(Value *new_value) override {
ASSERT_TRUE(nullptr != getValPtr());
- EXPECT_EQ(1U, getValPtr()->getNumUses());
+ EXPECT_TRUE(getValPtr()->hasOneUse());
EXPECT_EQ(nullptr, AURWArgument);
AURWArgument = new_value;
}
diff --git a/llvm/unittests/Linker/LinkModulesTest.cpp b/llvm/unittests/Linker/LinkModulesTest.cpp
index 758e859e32fbd..c98cdc2b24f79 100644
--- a/llvm/unittests/Linker/LinkModulesTest.cpp
+++ b/llvm/unittests/Linker/LinkModulesTest.cpp
@@ -358,7 +358,7 @@ TEST_F(LinkModuleTest, RemangleIntrinsics) {
// types, so they must be uniquified by linker. Check that they use the same
// intrinsic definition.
Function *F = Foo->getFunction("llvm.ssa.copy.s_struct.rtx_defs");
- ASSERT_EQ(F->getNumUses(), (unsigned)2);
+ ASSERT_TRUE(F->hasNUses(2));
}
} // end anonymous namespace
|
nikic
approved these changes
Apr 18, 2025
IanWood1
pushed a commit
to IanWood1/llvm-project
that referenced
this pull request
May 6, 2025
IanWood1
pushed a commit
to IanWood1/llvm-project
that referenced
this pull request
May 6, 2025
IanWood1
pushed a commit
to IanWood1/llvm-project
that referenced
this pull request
May 6, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
clang:openmp
OpenMP related changes to Clang
flang:openmp
llvm:analysis
Includes value tracking, cost tables and constant folding
llvm:ir
LTO
Link time optimization (regular/full LTO or ThinLTO)
test-suite
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
No description provided.