[LLVMdev] Why is BasicBlock's copy constructor private?

Tobias Grosser grosser at fim.uni-passau.de
Thu Mar 25 17:40:25 PDT 2010


On 03/26/10 01:04, Trevor Harmon wrote:
> Hi,
>
> LLVM provides basic graph traversal for its CFGs, but I need
> additional operations, such as iterating over the edges. I thought I
> would solve this problem using the Boost graph library. It should be
> relatively simple to walk an LLVM CFG and add the BasicBlock objects
> to a Boost graph declared as:

Hi Trevor,

I am not 100% sure why you should not copy a BasicBlock, however I 
believe two times the same BasicBlock does not make any sense in a CFG. 
There would be inconsistencies as e.g if a BB A is the successor of B 
there are two equal basic blocks A and A' after copying A, but only one 
(A) can be the real successor. The other one (A') is not referenced, but 
still references B as the predecessor of A'.
So for me the reason is that BasicBlocks are not independent and can 
just be copied. They are connected to their environment and cannot be 
exactly the same. Even the statements in the basicblock always have to 
be different, as every register in LLVM can only be written once per 
function.


To copy a BasicBlock in LLVM you should probably create a new one and 
copy the statements into the new BasicBlock. This obviously does not 
work for boost.

Some basic functionality for graph traversal is already in LLVM (as you 
mentioned) like iterating over edges, children or doing stuff like 
depthfirstsearch or post order search.
What kind of graph algorithm would you like to execute that is not 
available in LLVM?

Tobi





More information about the llvm-dev mailing list