[LLVMdev] llvm instrinsic (memcpy/memset/memmov)and ConstantExpression with cast

Kodakara, Sreekumar V sreekumar.v.kodakara at intel.com
Fri Apr 15 09:51:31 PDT 2011


Thanks for the reply John.
>>Since memcpy takes i8* as its argument, the struct.ta* is bitcasted to i8* in the call to llvm.memcpy. For a pass that I am working 
>>on, I would like to know the original type of this pointer. >>In this example, I would like to know that the second argument is a pointer 
>>to type struct.ta, and hence the size of memory allocated to that pointer is 4 bytes. 

>You should be able to use the stripPointerCasts() method of llvm::Value * to strip off the bitcast.
This is a very useful function. Thanks for pointing this out.


>>When I dump CE->getArgument(0), I get the following. 
 >>@t1 = global %struct.ta zeroinitializer, align 4
 
>>But from here, I am not able to find the relevant class/API to extract the type of CE->getArgument(0) and hence the size of it. When I tried 
>> CE->getArgument(0)->getType(), I am getting  the type as Pointer and hence the size to be 8 bytes. 

>This is because all global variables in LLVM are pointers to the actual data in memory.  What you need to do is:

>if (GlobalVariable * GV = dyn_cast<GlobalVariable>(CE->getArgument(0)) {
>    Type * T = GV->getType()->getContainedType();
>}

I made a mistake here. It is CE->getOperand(0) instead of CE->getArgument(0). There is also one small modification to getContainedType. 
getContainedType takes an unsigned int as a parameter. I gave that to be 0 and got the correct type. Then using TargetData I was able 
to get the size of the type. With this I was able to get the desired result. 

Thanks again.

Sreekumar 





More information about the llvm-dev mailing list