[LLVMdev] How to get the Operand type

John Criswell criswell at uiuc.edu
Fri Apr 23 07:28:49 PDT 2010


khaled hamidouche wrote:
> Hello
>
> How to get the type of an Operand ?
>
> so for example I want to get the type of the operand(0) in this 
> istruction
>
>  %arrayidx22 = getelementptr [1000 x double]* %C, i64 0, i64 %indvar67 
> ; <double*> [#uses=1]
>
> I tried    (II->getOperand(0))->getType() ) but this give me an adress 
> (I think) (some think like 0x1253.. )

The getType() method returns a pointer to an object that describes the 
type.  The object will be of class Type or one of Type's subclasses.  
This is what you want.

Type objects are unique in LLVM.  The methods for creating type objects 
ensure that only one Type object is ever created for a particular LLVM type.

This means that comparing types for equality can be done by comparing 
the Type pointers.  Code like this is guaranteed to work:

Value * V1 = ...
Value * V2 = ...

if (V1->getType() == V2->getType())
    // V1 and V2 have the same type
else
    // V1 and V2 have different types

The document at http://llvm.org/docs/ProgrammersManual.html#Type briefly 
describes this feature of the LLVM API.  It also says that there is a 
isFloatingPointTy() method of the Type class that will tell you if the 
type if a floating point type.

-- John T.




More information about the llvm-dev mailing list