<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><br><div><div>On Dec 5, 2008, at 8:29 PM, Marc de Kruijf wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite">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 "llvm.foo" 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.<br></blockquote></div><br><div>You can use the gnu asm renaming feature to do this:</div><div><br></div><div><br></div><div>void llvmmemset(char*, char val, char len, int align) __asm__("<span class="Apple-style-span" style="font-family: -webkit-monospace; font-size: 10px; white-space: pre; "><font class="Apple-style-span" face="Helvetica" size="3"><span class="Apple-style-span" style="font-size: 12px; white-space: normal;">llvm.memset.i8</span></font><span class="Apple-style-span" style="font-family: Helvetica; font-size: 12px; white-space: normal; ">");</span></span></div><div><br></div><div>void foo(short X) {</div><div>  llvmmemset(&X, 1, 2, 1);</div><div>}</div><div><br></div><div>Except that I see that llvm-gcc is being more strict about checking parameter attrs:</div><div><br></div><div>$ llvm-gcc t.c -S -o - -emit-llvm -O3</div><div>t.c: In function ‘foo’:</div><div>t.c:4: warning: passing argument 1 of ‘llvmmemset’ from incompatible pointer type</div><div>Intrinsic has wrong parameter attributes!</div><div>void (i8*, i8, i8, i32)* @llvm.memset.i8</div><div>Broken module found, compilation aborted!</div><div>t.c:3: internal compiler error: Abort trap</div><div><br></div><div>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.</div><div><br></div><div>-Chris</div></body></html>