[LLVMdev] newbie question for type comparison

John Criswell criswell at cs.uiuc.edu
Mon Apr 21 12:39:31 PDT 2008


Gordon Henriksen wrote:
> On Apr 21, 2008, at 15:07, John Criswell wrote:
>
>   
>>> 1. For getting ALL struct allocation, when I use
>>>
>>>        if( (AI = dyn_cast<AllocaInst>(&*i)))
>>>          if(AI->getOperand(0)->getType()->getTypeID() ==
>>> Type::StructTyID) {
>>>
>>> to get all alloca instructions allocating a structure, it does not
>>> work. In my gdb session, I've got the following dumps:
>>>
>>>       
>> I'm not sure why the above doesn't work.  My best guess is that the
>> allocated type is not an operand (since it is not an LLVM Value) but
>> is
>> an attribute (for lack of a better word) of the alloca instruction.
>>     
>
> Correct.
>
>   
>> My suggestion is to use the getAllocatedType() method of the
>> AllocaInst
>> class.  I'm pretty sure it does what you want:
>>
>> if (AI->getAllocatedType()->getTypeID() == Type::StructTyID)
>>
>>     
>
> Better: if (isa<StructType>) or if (StructType *sT =
> dyn_cast<StructType>).
>   
Just out of curiosity, what is it better?  Does it use less virtual 
function calls?

-- John T.

> — Gordon
>
>
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>   




More information about the llvm-dev mailing list