Intrinsics question

Is it necessary to modify the front-end (in this case, for C) to generate new intrinsic calls for a particular target? For instance, say I wanted to allow programmers to call a function “foo” that does some target-specific magic. I want “foo” to be handled as an intrinsic by the back-end, but all intrinsics needs the “llvm.” prefix, and I can’t declare a function called “” in C. Can it be done some other way? Or do I need to hack it with inline assembly or some sort of intermediary find/replace transformation.


You can use the gnu asm renaming feature to do this:

void llvmmemset(char*, char val, char len, int align) asm(“llvm.memset.i8”);

void foo(short X) {
llvmmemset(&X, 1, 2, 1);

Except that I see that llvm-gcc is being more strict about checking parameter attrs:

$ llvm-gcc t.c -S -o - -emit-llvm -O3
t.c: In function ‘foo’:
t.c:4: warning: passing argument 1 of ‘llvmmemset’ from incompatible pointer type
Intrinsic has wrong parameter attributes!
void (i8*, i8, i8, i32)* @llvm.memset.i8
Broken module found, compilation aborted!
t.c:3: internal compiler error: Abort trap

It would probably be easy enough to make this work: after applying the asm rename, llvm-gcc could check to see if it is being renamed to an intrinsic, if so, add attrs and check the types as appropriate.