Hello,
As an experiment, I'm simply trying to add a trivial intrinsic to LLVM, but
I'm having trouble, which suggests that I'm overlooking the obvious ;)
Platform is GCC-4.2.4/LLVM from SVN/x86.
First, I've read the page here about 10 times, so I'll speculate that my
reading comprehension is lacking:
http://www.llvm.org/docs/ExtendingLLVM.html
Code I've added to the bottom of the llvm/include/llvm/Intrinsics.td file:
-----------------
def int_test_intrinsic :
Intrinsic<[llvm_i32_ty],
[llvm_i32_ty],
[],
"llvm.test.intrinsic">;
-----------------
Code I've added to visitBuiltinCall in
llvm/lib/Target/CBackend/CBackend.cpp:
-----------------
case Intrinsic::test_intrinsic:
return true;
-----------------
I've not added any code to llvm/lib/Target/X86 because when I did, I
received a tablegen error. I think I'm not understanding the difference
between an intrinsic that maps directly to a single machine instruction, and
a more complex intrinsic that invokes a C function.
In particular, I tried adding:
def int_test_and_clear_bit : X86Inst;
to the end of X86.td, but that resulted in a tablegen compilation error.
Code I've added to the end of LowerIntrinsicCall in
/lib/CodeGen/IntrinsicLowering.cpp:
-----------------
case Intrinsic::test_intrinsic:
break;
-----------------
Note that the intent is to make this intrinsic a NOOP, just as an
experiment.
But alas, the following trivial test program does not work:
-----------------
#include <stdio.h>
int llvm_test_intrinsic(int) asm ("llvm.test.intrinsic");
int bar (int blah) {
return llvm_test_intrinsic (blah);
}
int main() {
int x = 3;
bar (x);
return 0;
}
-----------------
After invoking:
llvm-gcc -g test.c -o test.native
-----------------
The compiler returns:
cc1: Function.cpp:323: unsigned int llvm::Function::getIntrinsicID(bool)
const: Assertion `noAssert && "Invalid LLVM intrinsic
name"' failed.
test.c:24: internal compiler error: Aborted
Please submit a full bug report,
with preprocessed source if appropriate.
See <URL:http://developer.apple.com/bugreporter> for instructions.
-----------------
So, it's clear I'm missing something, or lots of things. Any help would
be
appreciated :) I'm sure this is easy.
Thanks and regards,
Matt