F van der Meeren
2010-Sep-07 18:30 UTC
[LLVMdev] Intrinsic prototype has incorrect number of arguments!
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 ; <i64> [#uses=1]
%7 = add i64 %6, 25 ; <i64> [#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 ; <i32> [#uses=1]
%mallocsize = mul i32 %10, ptrtoint (i64* getelementptr (i64* null, i32 1) to
i32) ; <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 ?
On 07 Sep 2010, at 19:55, Eric Christopher wrote:
>
> On Sep 7, 2010, at 8:03 AM, F van der Meeren wrote:
>
>> Hello,
>>
>> I have a question, what is wrong with the following code?
>>
>> declare void @llvm.memcpy.p0i64.p0i64.i8(i64*, i64*, i8, i32, i1)
nounwind
>>
>> ...
>>
>> call void @llvm.memcpy.p0i64.p0i64.i8(i64* %19, i64* %21, i8 %17, i32
0, i1 false)
>>
>> ...
>>
>>
>> According to the compiler this is the error, but I seem to miss where
exactly my fault is.
>>
>> Intrinsic prototype has incorrect number of arguments!
>> void (i64*, i64*, i8, i32, i1)* @llvm.memcpy.p0i64.p0i64.i8
>>
>
> Something is wonky in the error message since it's the right number of
arguments... in general. I don't know that your prototype is correct.
What's the corresponding code?
>
> Can you send the module on and whatever you did to construct it?
>
> -eric
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://lists.llvm.org/pipermail/llvm-dev/attachments/20100907/8e65c2e4/attachment.html>
Eric Christopher
2010-Sep-07 18:37 UTC
[LLVMdev] Intrinsic prototype has incorrect number of arguments!
On Sep 7, 2010, at 11:30 AM, F van der Meeren wrote:> > > Any ideas on what I am doing wrong here ? >Why not just use something like: const Type *ArgPtr = Type::getInt8PtrTy(Context); const Type *IntPtr = getTargetData().getIntPtrType(Context); and then: const Type *ArgTypes[3] = {ArgPtr, ArgPtr, IntPtr }; Intrinsic::getDeclaration(TheModule, Intrinsic::memcpy, ArgTypes, 3) to get the type of memcpy? Trying to declare it that way is likely confusing to the system. -eric
F van der Meeren
2010-Sep-07 19:25 UTC
[LLVMdev] Intrinsic prototype has incorrect number of arguments!
That won't work when you are trying to limit yourself to C and only C. Is there an LLVM-C alternative? Filip On 07 Sep 2010, at 20:37, Eric Christopher wrote:> > On Sep 7, 2010, at 11:30 AM, F van der Meeren wrote: > >> >> >> Any ideas on what I am doing wrong here ? >> > > > Why not just use something like: > > const Type *ArgPtr = Type::getInt8PtrTy(Context); > const Type *IntPtr = getTargetData().getIntPtrType(Context); > > and then: > > const Type *ArgTypes[3] = {ArgPtr, ArgPtr, IntPtr }; > Intrinsic::getDeclaration(TheModule, Intrinsic::memcpy, ArgTypes, 3) > > to get the type of memcpy? Trying to declare it that way is likely confusing to the system. > > -eric
Reasonably Related Threads
- [LLVMdev] Intrinsic prototype has incorrect number of arguments!
- [LLVMdev] Intrinsic prototype has incorrect number of arguments!
- [PATCH] strlen -> strnlen optimization
- [LLVMdev] dragonegg svn still broken
- [LLVMdev] automatically generating intrinsic declarations