[PATCH] D37575: [BasicBlock] add new function removeEdge()
Brian Rzycki via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 7 09:40:19 PDT 2017
brzycki created this revision.
Herald added a subscriber: mgorny.
First let me comment by saying I'm not sure if the community desires to go in this direction. The primary reason for uploading this patch was twofold:
1. To start a discussion about how we work with edges between blocks in an IR vs CFG manner.
2. To archive the patch should others find the idea useful in the future.
This patch adds a new function removeEdge() as a BasicBlock primitive. It does exactly what the name implies: removes an outgoing edge from BB1 into BB2. The routine asserts if no such edge exists.
This routine started as a reaction to removePredecessor(); a call that only adjust PHIs in the successor BB. Calls to removePredecessor() quietly do nothing in cases such as the following:
BB1:
br BB2
BB2:
br BB3
BB2->removePredecessor(BB1)
This is a bit surprising until one reads the documentation/source for removePredecessor().
The removeEdge() routine alters the terminator instruction of BB1. Should we call BB1->removeEdge(BB2) the resulting IR would now look like
BB1:
unreachable
BB2:
br BB3
Dominance is preserved if a DT handle is passed in: BB1->removeEdge(BB2, DT).
This new interface gives the caller the option to think more about the CFG than the underlying IR details. This has a few complications related to it:
1. The successors of BB1 will be altered by the call, making looping over successors different than of call sites using removePredecessor()
2. removeEdge() does not alter uses.
Even with these drawbacks I think this alternative interface has merit: in too many locations throughout the middle end do we see special-cased code that deals with the details of the IRs many terminator instruction types. At the very least I hope this code spurs a fruitful discussion.
Repository:
rL LLVM
https://reviews.llvm.org/D37575
Files:
llvm/include/llvm/IR/BasicBlock.h
llvm/lib/IR/BasicBlock.cpp
llvm/unittests/IR/BasicBlockRemoveEdgeTest.cpp
llvm/unittests/IR/CMakeLists.txt
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D37575.114190.patch
Type: text/x-patch
Size: 44991 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170907/782bfcd6/attachment.bin>
More information about the llvm-commits
mailing list