This is an archive of the discontinued LLVM Phabricator instance.

[Dominators] Make DTU be able to delete a BB before recalculation under Eager UpdateStrategy
AbandonedPublic

Authored by NutshellySima on Jul 25 2018, 11:15 AM.

Details

Summary

Previously, when user tries to delete a BasicBlock without applying updates under Eager UpdateStrategy (typically before recalculation),

DomTreeUpdater DTU(DT, ...::Eager);
... // Decide to remove BB
DTU.deleteBB(BB); // Call DT.eraseNode(BB) and find BB is not a leaf node.
*Asserts*
DTU.recalculate(F);

When we need this code pattern to be compatible with both Eager and Lazy Strategy instances of DTU, we cannot just replace DTU.deleteBB(BB) into BB->eraseFromParent() because DTU.recalculate() under Lazy Strategy checks whether there is any pending updates/DelBB to proceed.
Under Lazy Strategy, things won't be affected because deleteBB always goes after applying updates or automatically disables DT node removal during recalculation.
Thus, a new parameter is added to bypass this removal under only Eager UpdateStrategy in this special scenario (trying to delete a BasicBlock without applying any update under Eager UpdateStrategy).

DTU.deleteBB(BB, /*DisableNodeErasing*/ true);
DTU.recalculate(F);

Diff Detail

Event Timeline

NutshellySima created this revision.Jul 25 2018, 11:15 AM
NutshellySima abandoned this revision.Aug 2 2018, 12:35 AM

It's possible to do updates related to DelBB first then call deleteBB(DelBB) then do the recalculation, which will make the DTU interface less confusing to users.

brzycki added inline comments.Aug 2 2018, 10:40 AM
include/llvm/IR/DomTreeUpdater.h
150

It would be a good idea to add the reason why you need this flag, not just what it does. The comments at the top of this ticket would be a good start to add here.

The reason it's necessary is a subtle one and may not be obvious to users of your API.