BasicBlock predecessors list

Hi there,

I’m trying to get a list of predecessors of a BasicBlock. I’m using a code similar to that on here, but it appears to be more nodes been iterating that it should. Now, when I print out the llvm IR, I get something like:
[…]
while.body: ; preds = %7, %while.cond
[…]
for a code that have only a while loop. Ok, I can recognize the %while.cond block on the code, but the %7 block seems to be an extra BasicBlock (I mean, it is not directly represented in the IR) that holds only a copy of the branch instruction that ends the %while.cond block.

Here is the question: is there any way that I could discard these blocks that are not represented in the IR?

Thanks in advance,

Hi Cristianno,

I'm trying to get a list of predecessors of a BasicBlock. I'm using a code
similar to that on here
<http://llvm.org/docs/ProgrammersManual.html#iterate_preds>, but it appears to
be more nodes been iterating that it should. Now, when I print out the llvm IR,
I get something like:
[…]
while.body: ; preds = %7, %while.cond
[…]
for a code that have only a while loop. Ok, I can recognize the %while.cond
block on the code, but the %7 block seems to be an extra BasicBlock (I mean, it
is not directly represented in the IR)

what do you mean by "is not directly represented in the IR"? Do you mean that
if you dump the IR for function then it is not there? If so, probably there is
a basic block that wasn't properly added to the function (i.e. doesn't have the
function as its parent), in which case most likely you have written your own
pass and made a mistake in your basic block manipulation. If you mean that the
basic block is there but is lacking a label like "while.cond" then that is
normal: labels are entirely optional. The start of a basic block is not
defined by a label, it is defined by the end of the previous basic block, which
itself is defined by the presence of a terminator instruction.

Ciao, Duncan.

  that holds only a copy of the branch

Hello Duncan,

Thank you for the reply; I could now see what was wrong in my case: I’m cloning some instructions from the CFG to work with them, without risking to broke any blocks in the CFG. It appears that when some of these cloned instructions were branches, they still were referring to the original CFG’s basic blocks (increasing their predecessors list), even though I added them to a different function in a different module.

Thanks again,