the pred_begin and pred_end of BasicBlock

hi,
I'm a bit confused by the pred_begin/end of BasicBlock in CFG.h. I cann't understand what is a **use** of a BasicBlock. Also, I have no idea of when CFG would be constructed in LLVM.
Thanks.
Zhou Feng

The CFG is always implicit in LLVM. The two things that "use" BasicBlocks are branch/control flow instructions and PHI nodes.

-Chris

Sorry, still a bit confused. Say we have two basic blocks: A and B. B has a label. There is no branch/control flow instructions explicit uses B. like this:
B:
lable_of_b:
    code sequence
Is A still a predecessor of B?
Thanks.

Chris Lattner wrote:

Zhou,

I remember this issue biting me at first. It seemed logical that the
basic blocks would have an order and that there would be an implicit
branch between them, but that is not the case. In LLVM every BasicBlock
must be terminated with a terminating instruction (return, branch, etc.)

So, if your "A" never branches at the end it is invalid and will fail
the validator. A is not a predecessor of B unless you put in a "branch
to B" instruction.

You might want to read this:

http://llvm.cs.uiuc.edu/docs/LangRef.html#functionstructure

then this:

http://llvm.cs.uiuc.edu/docs/LangRef.html#terminators

then this:

http://llvm.cs.uiuc.edu/docs/ProgrammersManual.html#BasicBlock

Reid

Sorry, still a bit confused. Say we have two basic blocks: A and B. B has a label. There is no branch/control flow instructions explicit uses B. like this:
A: code sequence does not contain br/other control flow instruction
B:
lable_of_b:
  code sequence
Is A still a predecessor of B?

There is no such thing as a fall through block in LLVM. All blocks end in a "terminator" instruction. If the block is logically a fall-through, it will end with an unconditional branch to the block after it.

What are you trying to do?

-Chris

Chris Lattner wrote:

hi,
I'm a bit confused by the pred_begin/end of BasicBlock in CFG.h. I cann't understand what is a **use** of a BasicBlock. Also, I have no idea of when CFG would be constructed in LLVM.

The CFG is always implicit in LLVM. The two things that "use" BasicBlocks are branch/control flow instructions and PHI nodes.

-Chris

_______________________________________________
LLVM Developers mailing list
LLVMdev@cs.uiuc.edu http://llvm.cs.uiuc.edu
http://mail.cs.uiuc.edu/mailman/listinfo/llvmdev

-Chris