I have created the function prototype with the following code:
const uintmax_t methodNameSize = 1024;
const char methodNameTemplate = “llvm.memcpy.p0i%llu.p0i%llu.i%llu”;
char methodName[methodNameSize];
// Create the methodName.
memset(methodName, 0, methodNameSize);
sprintf(methodName, methodNameTemplate,
dstSize,
srcSize,
lengthSize);
// Search for the function or create it.
if((function = LLVMGetNamedFunction(module, methodName)) == NULL) {
LLVMTypeRef paramTypes = {
dstType,
srcType,
lengthType,
LLVMInt32TypeInContext(context),
LLVMInt1TypeInContext(context),
};
functionType = LLVMFunctionType(LLVMVoidTypeInContext(context),
paramTypes, numberOfArguments, false);
function = LLVMAddFunction(module, methodName, functionType);
LLVMRemoveAttribute(LLVMGetParam(function, 0), LLVMNoCaptureAttribute);
LLVMRemoveAttribute(LLVMGetParam(function, 1), LLVMNoCaptureAttribute);
}
And then invoked it with this:
LLVMValueRef args = {
sourcePtr,
destinationPtr,
lengthInteger,
LLVMConstInt(LLVMInt32TypeInContext(context), 0, true),
LLVMConstInt(LLVMInt1TypeInContext(context), (unsigned long long)false, true),
};
LLVMBuildCall(builder, function, args, numberOfArguments, “”);
Then you end up with the following prototype:
declare void @llvm.memcpy.p0i64.p0i64.i64(i64*, i64*, i64, i32, i1) nounwind
and this code will invoke the copy:
reallocBlock: ; preds = %entry
%5 = getelementptr inbounds %0* %0, i32 0, i32 2 ; <i64*> [#uses=1]
%6 = load i64* %5 ; [#uses=1]
%7 = add i64 %6, 25 ; [#uses=2]
%8 = getelementptr inbounds %0* %0, i32 0, i32 0 ; <i64**> [#uses=1]
%9 = load i64** %8 ; <i64*> [#uses=1]
%10 = trunc i64 %7 to i32 ; [#uses=1]
%mallocsize = mul i32 %10, ptrtoint (i64* getelementptr (i64* null, i32 1) to i32) ; [#uses=1]
%malloccall = tail call i8* @malloc(i32 %mallocsize) ; <i8*> [#uses=1]
%11 = bitcast i8* %malloccall to i64* ; <i64*> [#uses=1]
call void @llvm.memcpy.p0i64.p0i64.i64(i64* %9, i64* %11, i64 %7, i32 0, i1 false)
br label %exit
Any ideas on what I am doing wrong here ?