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

186 views
Skip to first unread message

PeiLIU via llvm-dev

unread,
May 12, 2016, 6:57:26 AM5/12/16
to llvm...@lists.llvm.org
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, can I get that "71" name.

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).

Thanks a lot. Forgive I am a novice llvmer :)

Chandler Carruth via llvm-dev

unread,
May 15, 2016, 9:09:33 PM5/15/16
to PeiLIU, llvm...@lists.llvm.org
On Thu, May 12, 2016 at 4:57 AM PeiLIU via llvm-dev <llvm...@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:

-Chandler
Reply all
Reply to author
Forward
0 new messages