[LLVMdev] BasicBlock predecessors list

Duncan Sands baldrick at free.fr
Tue Apr 3 23:37:00 PDT 2012


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
> 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,
>
> --
> Cristianno Martins
> PhD Student of Computer Science
> University of Campinas
> cmartins at ic.unicamp.br
>
>
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev




More information about the llvm-dev mailing list