[LLVMdev] Detecting mutex locks (and unlocks)

Edward Lee eslee3 at uiuc.edu
Wed Sep 24 21:58:43 PDT 2008


Is there a "standard" way to check for a lock acquire and release for
a transformation pass?

Assuming the locks aren't inline asm, so llvm-gcc can compile
__sync_lock_test_and_set builtin to llvm.atomic.swap, one could
potentially look for IntrinsicInst with the appropriate IntrinsicID.
But there's many ways to acquire a lock just using the atomic builtins
[1] -- not to mention how a lock implements a blocking acquire.

The lock release could use __sync_lock_release, which is converted
into a regular function call of appropriate size, or the lock could
just do a plain write of an i8 0 assuming a byte size memory location.
I did a quick search and noticed some code using
__sync_lock_test_and_set(&lock, 0) to exchange in a 0.

[1] http://gcc.gnu.org/onlinedocs/gcc-4.1.0/gcc/Atomic-Builtins.html

Ed



More information about the llvm-dev mailing list