[LLVMdev] [LLVMDev] How to use memcpy with getOrInsertFunction()

Prem Anand prem.iamme at gmail.com
Mon Aug 3 19:34:35 PDT 2015


A)
In LLVM, why are memcpy (and other memory related functions) treated
specially? i.e why do they have this intrinsic notion.
The IR generated is like the following, while the normal functions differ.

call void @llvm.memcpy.p0i8.p0i8.i64(....)
call void @my_function(...)

Can anyone explain me what the p0* mean in the above IR of memcpy?

B)
How to insert a call to "memcpy(A, B, 252);" before a particular basic
block. Assume A and B are integer64 array of 252 size each.
Can anyone help me figure out the parameter that needs to be placed in
'??' below

    my_memcpy = M.getOrInsertFunction("memcpy",
                                    FunctionType::getInt8PtrTy(Context),
                                    Type::getInt8PtrTy(Context),
                                    Type::getInt8PtrTy(Context),
                                    Type::getInt64Ty(Context),
                                    NULL);


        Value *my_params[] = {
            builder.CreateIntToPtr(builder.getInt64( ?? ),
Type::getInt8PtrTy(Context)),
            builder.CreateIntToPtr(builder.getInt64( ??),
Type::getInt8PtrTy(Context)),
            ConstantInt::get(Context, APInt(64, 252)),
        };
        Function *func_ptr= cast<Function>(my_memcpy);
        builder.CreateCall(func_ptr, my_params);


Hoping for a reply,
Prem Anand



More information about the llvm-dev mailing list