Skip to content

Commit

Permalink
Parse atomic operations introduced in LLVM 9+
Browse files Browse the repository at this point in the history
This adapts `llvm-pretty-bc-parser` to new atomic operations introduced in LLVM
9 and later:

* This bumps the `llvm-pretty` submodule to incorporate the changes from
  GaloisInc/llvm-pretty#138 and
  GaloisInc/llvm-pretty#140.
* This updates the parsing code in `Data.LLVM.BitCode.IR.Function` to account
  for atomic `fadd`, `fsub`, `fmax`, `fmin`, `uinc_wrap`, and `udec_wrap`
  operations.
* This ensures that all atomic operations have a corresponding `disasm-test`
  test case.
  • Loading branch information
RyanGlScott committed Jul 25, 2024
1 parent 1cfe6e8 commit 84821be
Show file tree
Hide file tree
Showing 12 changed files with 71 additions and 5 deletions.
5 changes: 5 additions & 0 deletions disasm-test/tests/atomicrmw-faddsub.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
define void @atomicrmw(float* %a, float %f) {
%b11 = atomicrmw fadd float* %a, float %f acquire
%b12 = atomicrmw fsub float* %a, float %f acquire
ret void
}
4 changes: 4 additions & 0 deletions disasm-test/tests/atomicrmw-faddsub.pre-llvm9.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
SKIP_TEST

This test case requires the use of atomic `fadd` and `fsub` operations, which
are only available in LLVM 9 or later.
5 changes: 5 additions & 0 deletions disasm-test/tests/atomicrmw-fmaxmin.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
define void @atomicrmw(float* %a, float %f) {
%b13 = atomicrmw fmax float* %a, float %f acquire
%b14 = atomicrmw fmin float* %a, float %f acquire
ret void
}
4 changes: 4 additions & 0 deletions disasm-test/tests/atomicrmw-fmaxmin.pre-llvm15.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
SKIP_TEST

This test case requires the use of atomic `fmax` and `fmin` operations, which
are only available in LLVM 15 or later.
5 changes: 5 additions & 0 deletions disasm-test/tests/atomicrmw-uincdecwrap.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
define void @atomicrmw(i32* %a, i32 %i) {
%b15 = atomicrmw uinc_wrap i32* %a, i32 %i acquire
%b16 = atomicrmw udec_wrap i32* %a, i32 %i acquire
ret void
}
4 changes: 4 additions & 0 deletions disasm-test/tests/atomicrmw-uincdecwrap.pre-llvm16.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
SKIP_TEST

This test case requires the use of atomic `uinc_wrap` and `udec_wrap`
operations, which are only available in LLVM 16 or later.
12 changes: 11 additions & 1 deletion disasm-test/tests/atomicrmw.ll
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
define void @atomicrmw(i32* %a, i32 %i) {
%b = atomicrmw add i32* %a, i32 %i acquire
%b0 = atomicrmw xchg i32* %a, i32 %i acquire
%b1 = atomicrmw add i32* %a, i32 %i acquire
%b2 = atomicrmw sub i32* %a, i32 %i acquire
%b3 = atomicrmw and i32* %a, i32 %i acquire
%b4 = atomicrmw nand i32* %a, i32 %i acquire
%b5 = atomicrmw or i32* %a, i32 %i acquire
%b6 = atomicrmw xor i32* %a, i32 %i acquire
%b7 = atomicrmw max i32* %a, i32 %i acquire
%b8 = atomicrmw min i32* %a, i32 %i acquire
%b9 = atomicrmw umax i32* %a, i32 %i acquire
%b10 = atomicrmw umin i32* %a, i32 %i acquire
ret void
}
5 changes: 5 additions & 0 deletions disasm-test/tests/opaque-atomicrmw-uincdecwrap.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
define void @atomicrmw(ptr %a, i32 %i) {
%b15 = atomicrmw uinc_wrap ptr %a, i32 %i acquire
%b16 = atomicrmw udec_wrap ptr %a, i32 %i acquire
ret void
}
4 changes: 4 additions & 0 deletions disasm-test/tests/opaque-atomicrmw-uincdecwrap.pre-llvm16.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
SKIP_TEST

This test case requires the use of atomic `uinc_wrap` and `udec_wrap`
operations, which are only available in LLVM 16 or later.
18 changes: 16 additions & 2 deletions disasm-test/tests/opaque-atomicrmw.ll
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
define void @atomicrmw(ptr %a, i32 %i) {
%b = atomicrmw add ptr %a, i32 %i acquire
define void @atomicrmw(ptr %a1, i32 %i, ptr %a2, float %f) {
%b0 = atomicrmw xchg ptr %a1, i32 %i acquire
%b1 = atomicrmw add ptr %a1, i32 %i acquire
%b2 = atomicrmw sub ptr %a1, i32 %i acquire
%b3 = atomicrmw and ptr %a1, i32 %i acquire
%b4 = atomicrmw nand ptr %a1, i32 %i acquire
%b5 = atomicrmw or ptr %a1, i32 %i acquire
%b6 = atomicrmw xor ptr %a1, i32 %i acquire
%b7 = atomicrmw max ptr %a1, i32 %i acquire
%b8 = atomicrmw min ptr %a1, i32 %i acquire
%b9 = atomicrmw umax ptr %a1, i32 %i acquire
%b10 = atomicrmw umin ptr %a1, i32 %i acquire
%b11 = atomicrmw fadd ptr %a2, float %f acquire
%b12 = atomicrmw fsub ptr %a2, float %f acquire
%b13 = atomicrmw fmax ptr %a2, float %f acquire
%b14 = atomicrmw fmin ptr %a2, float %f acquire
ret void
}
2 changes: 1 addition & 1 deletion llvm-pretty
8 changes: 7 additions & 1 deletion src/Data/LLVM/BitCode/IR/Function.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1431,7 +1431,7 @@ getDecodedOrdering 6 = return (Just SeqCst)
getDecodedOrdering i = Assert.unknownEntity "atomic ordering" i


-- https://github.com/llvm-mirror/llvm/blob/release_60/include/llvm/Bitcode/LLVMBitCodes.h#L377
-- https://github.com/llvm/llvm-project/blob/e24dc34aa085b9e8d3ea58cc5f59f80bc4c7cdb4/llvm/include/llvm/Bitcode/LLVMBitCodes.h#L468-L489
getDecodedAtomicRWOp :: Integer -> Parse AtomicRWOp
getDecodedAtomicRWOp 0 = pure AtomicXchg
getDecodedAtomicRWOp 1 = pure AtomicAdd
Expand All @@ -1444,6 +1444,12 @@ getDecodedAtomicRWOp 7 = pure AtomicMax
getDecodedAtomicRWOp 8 = pure AtomicMin
getDecodedAtomicRWOp 9 = pure AtomicUMax
getDecodedAtomicRWOp 10 = pure AtomicUMin
getDecodedAtomicRWOp 11 = pure AtomicFAdd
getDecodedAtomicRWOp 12 = pure AtomicFSub
getDecodedAtomicRWOp 13 = pure AtomicFMax
getDecodedAtomicRWOp 14 = pure AtomicFMin
getDecodedAtomicRWOp 15 = pure AtomicUIncWrap
getDecodedAtomicRWOp 16 = pure AtomicUDecWrap
getDecodedAtomicRWOp v = Assert.unknownEntity "atomic RWOp" v

{-
Expand Down

0 comments on commit 84821be

Please sign in to comment.