@@ -504,24 +504,22 @@ void CMKernelArgOffset::processKernelOnOCLRT(MDNode *Node, Function *F) {
504
504
Type *ArgTy = Arg.getType ();
505
505
if (ArgTy->isPointerTy ()) {
506
506
SmallVector<Instruction *, 8 > ToErase;
507
-
508
- IGC_ASSERT_MESSAGE (Arg.hasOneUse (), " invalid surface input" );
509
- auto ArgUse = Arg.use_begin ()->getUser ();
510
- IGC_ASSERT_MESSAGE (isa<PtrToIntInst>(ArgUse),
511
- " invalid surface input usage" );
512
- ToErase.push_back (cast<Instruction>(ArgUse));
513
-
514
- for (auto ui = ArgUse->use_begin (), ue = ArgUse->use_end (); ui != ue;
515
- ++ui) {
516
- auto User = cast<Instruction>(ui->getUser ());
517
- User->replaceAllUsesWith (
518
- ConstantInt::get (User->getType (), BTI));
519
- ToErase.push_back (User);
507
+ for (Use &U : Arg.uses ()) {
508
+ auto ArgUse = U.getUser ();
509
+ IGC_ASSERT_MESSAGE (isa<PtrToIntInst>(ArgUse),
510
+ " invalid surface input usage" );
511
+
512
+ std::transform (ArgUse->user_begin (), ArgUse->user_end (),
513
+ std::back_inserter (ToErase), [BTI](User *U) {
514
+ U->replaceAllUsesWith (
515
+ ConstantInt::get (U->getType (), BTI));
516
+ return cast<Instruction>(U);
517
+ });
518
+ ToErase.push_back (cast<Instruction>(ArgUse));
520
519
}
520
+ std::for_each (ToErase.begin (), ToErase.end (),
521
+ [](Instruction *I) { I->eraseFromParent (); });
521
522
522
- for (auto i = ToErase.rbegin (), e = ToErase.rend (); i != e; ++i)
523
- (*i)->eraseFromParent ();
524
- ToErase.clear ();
525
523
} else {
526
524
auto BTIConstant = ConstantInt::get (ArgTy, BTI);
527
525
// If the number of uses for this arg more than 1 it's better to
0 commit comments