Extraction of constant operands from the instruction

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Extraction of constant operands from the instruction

Prabhat Kumar Saraswat
Hi all,

 I am trying to extract the operands from an instruction, for that i am iterating over the operand list as defined by the user class.

 for (User::op_iterator O = i->op_begin() ;O != i->op_end(); ++O)
{
Value *v = *O;
llvm::cout << v->getNameStr() ;
}

However, whenever there is a constant operand like a numerical value, it does not displays any value at all, i checked using the hasName() method, for the constant operands the hasName() returns 0.
Is there anyway I can display/extract these constant values from the instruction ?

Another question:
For and example IR like below,

%tmp6 = load i32* @glob_var, align 4            ; <i32> [#uses=1]

How can i extract the name of the instruction i.e. %tmp6 

Regards
Prabhat

_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Reply | Threaded
Open this post in threaded view
|

Re: Extraction of constant operands from the instruction

Anton Korobeynikov
Hello,

> However, whenever there is a constant operand like a numerical value, it
> does not displays any value at all, i checked using the hasName() method,
> for the constant operands the hasName() returns 0.
Correct. Constant doesn't have name at all. You should check, whether
operand is a constant, cast the Value to Constant (for example, via
dyn_cast facility) and then use the Constant' methods to obtain the
exact value.

> How can i extract the name of the instruction i.e. %tmp6
getName() will return it.

--
WBR, Anton Korobeynikov
_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev