Hi,
My pass scans call instructions for standard C library calls. For some
libc functions, however, LLVM uses intrinsics instead. For example, I
see that my memcpy calls are replaced by the llvm.memcpy.* intrinsics.
This is not a problem because I can simply look for llvm.memcpy calls
when scanning for memcpy calls.
The problem arises when LLVM implicitly inserts llvm.memcpy intrinsics
into my bitcode files when it thinks they are needed. In this case, I
do not see a single memcpy call in my source file but its IR does have
them. How do I make a distinction between a real C library call and an
intrinsic?
Btw, for this memcpy case, I should be able to take advantage of this fact:
LLVM Language Reference Manual — LLVM 16.0.0git documentation "Note that,
unlike the standard libc function, the llvm.memcpy.* intrinsics do not
return a value..."
However, I'm looking for a general solution for all libc intrinsics
listed at LLVM Language Reference Manual — LLVM 16.0.0git documentation.
Thanks!
-JS
correction: Actually, I won't even be able to take advantage of the
following fact because all memcpy calls (either libc or intrinsics)
will appear as intrinsic calls anyway.
LLVM Language Reference Manual — LLVM 16.0.0git documentation "Note that,
unlike the standard libc function, the llvm.memcpy.* intrinsics do not
return a value...
Hi,
My LLVM pass scans call instructions for standard C library calls. For
some libc functions, however, clang uses intrinsics instead. For
example, I see that my memcpy calls are replaced by the llvm.memcpy.*
intrinsics. This is not a problem because I can simply look for
llvm.memcpy calls when scanning for memcpy calls.
The problem arises when clang implicitly uses llvm.memcpy intrinsics
when it thinks they are needed. In this case, I do not see a single
memcpy call in my source file but its IR does have them. How do I make
a distinction between a real C library call and an intrinsic?
For example,
memcpy(buffer, "aa", 1); // clang uses llvm.memcpy for this statement
char* buffer = {"xxx", "yyy"}; // clang also uses llvm.memcpy for
this statement
Thanks!
-JS
James,
Can you explain in more detail what you're trying to do?
-Hal
You can use -fno-builtin to instruct Clang not to treat standard C library functions as having known, built-in semantics.
Hi Hal,
I'm trying to find how many libc calls exist in a bitcode file. Since
some libc calls appear as LLVM intrinsics, I can't find those. I've
found from other source that -fno-builtin works like a charm. Hope
this will help other people looking for a solution.
Thanks,
James.
Hi Richard,
it worked like a charm!
Thanks!!! Very much appreciated.
James