[llvm-dev] questions about temporary variables in IntermidateRepresentation(IR)

Chandler Carruth via llvm-dev llvm-dev at lists.llvm.org
Sun May 15 18:09:15 PDT 2016


On Thu, May 12, 2016 at 4:57 AM PeiLIU via llvm-dev <llvm-dev at lists.llvm.org>
wrote:

> Now, I am get the .ll file, some code just like this in the below.
>
>   %call89 = call noalias i8* @malloc(i64 %add88) #5, !dbg !374
>
>   %71 = bitcast i8* %call89 to i32*, !dbg !374
>
>   store i32* %71, i32** %buffer2, align 8, !dbg !374
>
> You can see that the first operand of store is a temporary variables %71.
>
> Q1.  the StoreInst->getOperand(0)->getName().str() return the string
> NULL(""),
>
> how does it happened,
>

Unnamed instructions get numbered automatically when writing IR.


> can I get that "71" name.
>

You can look at how the AsmPrinter computes the number, but in general
"no". You can however force name everything with a pass like the meta
renamer.


>
> Q2. I want to get the real operand that is call89 which returned by
> function call
>
> malloc. How can I get the original operand call89? I know I can get that
> from the
>
> previous instruction bitcast, I can get it from the previous instruction
> but it only work
>
> in this circumstance the bitcast instruction, if the previous instruction
> is changed, how
>
> I get the variable name in efficiency. Is there a efficiency and elegance
> way to get the
>
> origin operand avoid temporary variables like 71(just decimal numbers).
>

You can use the 'stripPointerCasts()' method on the operand's base class
(Value) to walk back through pointer casts like this:
http://llvm.org/docs/doxygen/html/classllvm_1_1Value.html#a38ea12c04523d63adda732b9c5d6da0a

-Chandler
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20160516/9bb2db75/attachment.html>


More information about the llvm-dev mailing list