[PATCH] [OPENMP] Codegen for 'atomic capture'.

Alexey Bataev a.bataev at hotmail.com
Thu Apr 16 02:47:39 PDT 2015


Hi rjmccall, hfinkel, fraggamuffin, ejstotzer,

Adds codegen for 'atomic capture' constructs with the following forms of expressions/statements:
```
v = x binop= expr;
v = x++;
v = ++x;
v = x--;
v = --x;
v = x = x binop expr;
v = x = expr binop x;
{v = x; x = binop= expr;}
{v = x; x++;}
{v = x; ++x;}
{v = x; x--;}
{v = x; --x;}
{x = x binop expr; v = x;}
{x = binop= expr; v = x;}
{x++; v = x;}
{++x; v = x;}
{x--; v = x;}
{--x; v = x;}
{x = x binop expr; v = x;}
{x = expr binop x; v = x;}
{x = expr binop x; v = x;}
```
If x and expr are integer and binop is associative or x is a LHS in a RHS of the assignment expression, and atomics are allowed for type of x on the target platform atomicrmw instruction is emitted.
Otherwise compare-and-swap sequence is emitted.
Update of 'v' is not required to be be atomic with respect to the read or write of the 'x'.

```
bb:
...
atomic load <x>
cont:
<expected> = phi [ <x>, label %bb ], [ <new_failed>, %cont ]
<desired> = <expected> binop <expr>
<res> = cmpxchg atomic &<x>, desired, expected
<new_failed> = <res>.field1;
br <res>field2, label %exit, label %cont
exit:
atomic store <old/new x>, <v>
...
```
If 'x' was updated with ```atomicrmw``` instruction and 'v' must be updated with the new value of 'x', an additional atomic load of 'x' is used to read the new value to be stored to 'v'. Otherwise previous value of 'x', returned by atomic instruction is used (if 'v' must be rewritten by the old value of 'x'), or newly calculated update value for 'x' is used (if 'v' must be rewritten by the new value of 'x').

http://reviews.llvm.org/D9049

Files:
  lib/CodeGen/CGStmtOpenMP.cpp
  lib/CodeGen/CodeGenFunction.h
  lib/Sema/SemaOpenMP.cpp
  test/OpenMP/atomic_capture_codegen.cpp
  test/OpenMP/atomic_codegen.cpp
  test/OpenMP/atomic_messages.cpp

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D9049.23834.patch
Type: text/x-patch
Size: 87904 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150416/bb81e821/attachment.bin>


More information about the cfe-commits mailing list