// Assume "Call" is already defined as a CallInst Call->eraseFromParent(); // Remove and delete the call instruction
// Assume "BB" is a basic block std::vectorThis code loops over every instruction in a basic block and removes any call instructions. The calls are stored in a vector so that they can all be deleted at once at the end of the loop. This function is part of the LLVM core libraries.CallsToRemove; for (auto& Inst : BB) { if (auto* Call = dyn_cast (&Inst)) { CallsToRemove.push_back(Call); } } for (auto* Call : CallsToRemove) { Call->eraseFromParent(); // Remove and delete the call instruction }