This patch is the first in a series of patches related to the RFC - A new dominator tree updater for LLVM.
This patch introduces the DomTreeUpdater class, which provides a cleaner API to perform updates on available dominator trees (none, only DomTree, only PostDomTree, both) using different update strategies (eagerly or lazily) to simplify the updating process.
—Prior to the patch—
- The current API is quite fragmented and different functions using these APIs need to write redundant code to manually deal with various kinds of update strategies which makes code hard to maintain.
- Directly calling update functions of DominatorTree updates the data structure eagerly while DeferredDominance does updates lazily.
- DeferredDominance class cannot be used when a PostDominatorTree also needs to be updated.
- Functions receiving DT/DDT need to branch a lot which is currently necessary.
- Functions using both DomTree and PostDomTree need to call the update function separately on both trees.
- People need to construct an additional DeferredDominance class to use functions only receiving DDT.
- We need to manually decide whether to erase a BasicBlock from the dominator tree when one is removed from the CFG.
- When using lazy updating methods, the BasicBlock waiting to delete will be deleted in an unforeseeable time after being removed from the Function so the user cannot do further actions on it.
- When we have both trees (DomTree and PostDomTree), we can try using the update information of one of them to prune updates of another to accelerate the updating process.
—After the patch—
- The abilities of the DeferredDominance are subsumed by the new updater class. And the API user can use an enum to specify which update strategy to use.
- The new updater class can update all the data structures it holds when the user calls the update function.
- The new updater class will first check whether these BasicBlocks still act as a node in the holding trees then call delete to prevent further manual checks.
- The updater class has a callbackDeleteBB function which accepts a callable to let users do additional operations on the BasicBlock before deletion.