Hi,
I got a solution to use intrinsics without the need of builtin functions from:
[http://wiki.llvm.org/HowTo:_Call_LLVM_intrinsics_from_C_code](http://wiki.llvm.org/HowTo:_Call_LLVM_intrinsics_from_C_code)
Do you know if this approach is still valid ?
The example is the following:
extern "C" int llvm_cas(volatile int*, int, int) asm("llvm.atomic.cmp.swap.i32");
int foo(volatile int* add, int from, int to) {
return llvm_cas(add, from, to);
}
And the expected llvm output is:
define i32 @_Z3fooPViii(i32* %add, i32 %from, i32 %to) {
entry:
%0 = tail call i32 @llvm.atomic.cmp.swap.i32(i32* %add, i32 %from, i32 %to); <i32> [#uses=1]
ret i32 %0
}
declare i32 @llvm.atomic.cmp.swap.i32(i32*, i32, i32)
However, when I compile the same code, it generates the following call:
%call = tail call i32 @"\01llvm.atomic.cmp.swap.i32"(i32* %add, i32 %from, i32 %to) nounwind optsize
which looks to me a regular call and not a direct call to the intrinsic.
Thank you,
Damien
Hi,
I got a solution to use intrinsics without the need of builtin functions from:
http://wiki.llvm.org/HowTo:_Call_LLVM_intrinsics_from_C_code
...
However, when I compile the same code, it generates the following call:
%call = tail call i32 @"\01llvm.atomic.cmp.swap.i32"(i32* %add, i32
%from, i32 %to) nounwind optsizewhich looks to me a regular call and not a direct call to the intrinsic.
Hi Damien,
I had the same problem a while back, please see if the attached patches work
for you (apply against clang trunk).
(In the end I decided on a different solution to my problem, which
is why I never sent these patches for approval.)
Thanks,
0001-Do-not-use-IR-marker-for-LLVM-intrinsics.patch (1.18 KB)
0002-If-this-is-an-intrinsic-function-set-the-function-s-.patch (1.17 KB)
Thank you for the patch. Though I finally decided to go for builtins (this seems to be a cleaner solution).
My worry is that I don’t know how standard, compiler dependant is the following declaration:
extern int llvm_cas(volatile int*, int, int) asm("llvm.atomic.cmp.swap.i32");
Do you have any idea of the pros/cons of using either builtins or the previous declaration ?
Thank you Peter !
Damien
Thank you for the patch. Though I finally decided to go for builtins (this seems to be a cleaner solution).
My worry is that I don't know how standard, compiler dependant is the following declaration:
extern int llvm_cas(volatile int*, int, int) asm("llvm.atomic.cmp.swap.i32");
That's about as compiler dependent as you can get.
Do you have any idea of the pros/cons of using either builtins or the previous declaration ?
Use documented APIs if at all possible.
-eric