[LLVMdev] problem with visitBranchInst()

Duncan Sands baldrick at free.fr
Mon Jul 9 10:03:43 PDT 2012


Hi Jun,

> my code inherits InstVisitor class, and visitBranchInst() method.
>
> however, i notice that inside the virtual method
> visitBranchInst(BranchInst &I), on the LLVM instruction like:
>
> br i1 %1, label %2, label %3

when you see numbers %1, %2 etc like this, it means that the instruction,
basic block etc doesn't have a name.  So why the numbers?  These numbers
only occur in the human readable IR and are used to identify two things as
being the same, which is needed to turn the IR into bitcode.  For example,
considering reading in the following IR, and turning it into bitcode, by
which I mean creating the corresponding CmpInst, BranchInst, i.e. the internal
objects you access and manipulate using the C++ API:

   %1 = icmp eq ...
   br i1 %1, ...

When the IR reader sees two occurrences of %1, it understands that the
operand of the branch is the result of the icmp instruction, and it
constructs the BranchInst object that way.  Without some kind of labels
this would be impossible.

Ciao, Duncan.

>
> my code doesnt return expected info. for ex, the code
>
> I.getCondition->getName().str()
>
> would return empty string. and at the same time, the code
>
> I.getSuccessor(0)->getName()
>
> would also return emtpy string.
>
> i am pretty confused, as i am expecting non-empty strings returned
> from the above functions.
> any idea on why this happens?
>
> this is on LLVM 3.0, Ubuntu 12.04.
>
> thanks so much,
> Jun
> _______________________________________________
> 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