Skip to content

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 1 commit into from
Apr 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion llvm/unittests/Analysis/CGSCCPassManagerTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion llvm/unittests/Analysis/LazyCallGraphTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
60 changes: 30 additions & 30 deletions llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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());
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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()) {
Expand Down Expand Up @@ -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(
Expand All @@ -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 &,
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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());

Expand Down Expand Up @@ -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());

Expand Down Expand Up @@ -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());

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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));

Expand All @@ -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);
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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());
Expand Down
2 changes: 1 addition & 1 deletion llvm/unittests/IR/ValueHandleTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion llvm/unittests/Linker/LinkModulesTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading