[LLVMdev] problem with visitBranchInst()
Nick Lewycky
nicholas at mxc.ca
Mon Jul 9 02:08:31 PDT 2012
Jun Koi wrote:
> hi,
>
> 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
>
> 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?
Value names are optional, and your instructions don't have any. Thus,
getName() returns the empty string.
The "%1" etc., is being written from the AsmWriter because it needs some
way to refer to the instruction when it's used, so it just numbers
anonymous instructions as it goes. %1 is the second (presumably there
was a %0 earlier). If the instruction was actually named '1' then the
instruction would have been written 'br i1 %"1" ...'
There is no way to recreate the %number except by counting from the top
as the AsmWriter does. Of course, you should never need to do this. If
you want to operate on IR that has names (for instance, they make
debugging your pass easier), run the instruction naming pass (opt
-instnamer) over your IR first.
Finally, this topic was discussed at length on this list a few days ago.
Please check the list archives before posting. See the thread starting here:
http://lists.cs.uiuc.edu/pipermail/llvmdev/2012-July/051489.html
Nick
More information about the llvm-dev
mailing list