[LLVMdev] llvm instrinsic (memcpy/memset/memmov)and ConstantExpression with cast
John Criswell
criswell at illinois.edu
Thu Apr 14 17:18:02 PDT 2011
On 4/14/11 6:34 PM, Kodakara, Sreekumar V wrote:
>
> Hi All,
>
> I have a question on ConstantExpressions and llvm intrinsic
> memcpy/memset/memmove. I am using llvm-2.8 release. In one of the C
> programs that I am compiling using clang frontend, the call to memcpy
> instrinsic looks like the following
>
> call void @llvm.memcpy.p0i8.p0i8.i64(i8* %tmp2, i8* bitcast
> (%struct.ta* @tret to i8*), i64 4, i32 4, i1 false), !dbg !19
>
> The second argument to memcpy is of type "struct ta" and global
> variable "tret" is defined as follows in the code.
>
> struct ta {
>
> int a;
>
> };
>
> struct ta tret;
>
> 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.
> I understand that the second argument to memcpy intrinsic namely i8*
> bitcast (%struct.ta* @t1 to i8*) is a ConstantExpression (CE). 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 would like to get the type as StructTy and size to be 4 bytes. I
> searched through the llvm code
>
> Any help is appreciated.
>
-- John T.
> Thanks
>
> Sreekumar
>
>
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20110414/8e0abe43/attachment.html>
More information about the llvm-dev
mailing list