I find that there are some intrinsic functions in LLVM such as llvm.memcpy
, llvm.va_start
.
However I haven't got any idea why they exist and why others don't. For example, as memcpy
's prototype is inside string.h
, why other functions, like strcpy
, are not treated as intrinsic?
I noticed that the frontend may generate special intrinsic function call in some cases. For a simple case:
#include<string.h>
int foo(void){
char str[10] = "str";
return 0;
}
The llvm IR for foo
generated by clang is:
define i32 @foo() #0 {
entry:
%str = alloca [10 x i8], align 1
%0 = bitcast [10 x i8]* %str to i8*
call void @llvm.memcpy.p0i8.p0i8.i64(i8* %0, i8* getelementptr inbounds ([10 x i8]* @foo.str, i32 0, i32 0), i64 10, i32 1, i1 false)
ret i32 0
}
llvm.memcpy
is called in IR but is not in source code. But can the frontend generate LLVM IR without this intrinsic?
I also came across a document about a much earlier version of llvm language reference and found that some special functions like malloc
, free
were included in LLVM instructions(obviously they no longer exist).
So what's the insight that the llvm instruction is designed so?