This is an archive of the discontinued LLVM Phabricator instance.

[IR][NFC] Add BasicBlock::erase(Instruction *I) for erasing a single Instruction.
AbandonedPublic

Authored by vporpo on Dec 16 2022, 11:18 AM.

Details

Reviewers
aeubanks
asbirlea

Diff Detail

Event Timeline

vporpo created this revision.Dec 16 2022, 11:18 AM
Herald added a project: Restricted Project. · View Herald TranscriptDec 16 2022, 11:18 AM
vporpo requested review of this revision.Dec 16 2022, 11:18 AM
Herald added a project: Restricted Project. · View Herald TranscriptDec 16 2022, 11:18 AM
nikic added a subscriber: nikic.Dec 16 2022, 11:25 AM

How does this differ from I->eraseFromParent()?

is this to use with Instruction::eraseFromParent? if so I think that change should also be in this patch to show why this patch exists

It is exactly the same. There is no super strong reason for having both functions.
The main reason is that the BB behaves like a list as it implements begin(), end(), size(), splice() etc. so not having an erase(I) function looks strange.
Up until now one could simply do BB->getInstList().erase(I), instead of I->eraseFromParent(), so this function is covering this case.

vporpo updated this revision to Diff 483637.Dec 16 2022, 12:21 PM

I->eraseFromParent() now calls BasicBlock::erase(BB). Also BasicBlock::erase(BB) now calls InstList.erase() directly instead of calling BasicBlock::erase(FromIt, ToIt).

The main reason is that the BB behaves like a list as it implements begin(), end(), size(), splice() etc. so not having an erase(I) function looks strange.
Up until now one could simply do BB->getInstList().erase(I), instead of I->eraseFromParent(), so this function is covering this case.

If the intention is to make it behave like a container, then the erase method should take an iterator.
But who would possibly use it if it requires a BB reference to call the method? It is kind of easier and safer to just I->eraseFromParent().
I don't mind adding this, just don't see how it can be useful.

If the intention is to make it behave like a container, then the erase method should take an iterator.
But who would possibly use it if it requires a BB reference to call the method? It is kind of easier and safer to just I->eraseFromParent().
I don't mind adding this, just don't see how it can be useful.

I agree, I think it is not very useful. I will abandon the patch.

vporpo abandoned this revision.Dec 16 2022, 12:40 PM