This is an archive of the discontinued LLVM Phabricator instance.

[OPENMP] Codegen for 'atomic update' construct.
ClosedPublic

Authored by ABataev on Mar 23 2015, 3:48 AM.

Details

Summary

Adds atomic update codegen for the following forms of expressions:

x binop= expr;
x++;
++x;
x--;
--x;
x = x binop expr;
x = expr binop 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:

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:
...

Diff Detail

Repository
rL LLVM

Event Timeline

ABataev updated this revision to Diff 22451.Mar 23 2015, 3:48 AM
ABataev retitled this revision from to [OPENMP] Codegen for 'atomic update' construct..
ABataev updated this object.
ABataev edited the test plan for this revision. (Show Details)
ABataev updated this object.
ABataev updated this object.
ABataev added a subscriber: Unknown Object (MLST).
rjmccall edited edge metadata.Mar 27 2015, 9:46 AM

Mostly looks great. One small tweak.

lib/CodeGen/CGStmtOpenMP.cpp
1109 ↗(On Diff #22451)

I would split this out as a helper function that returns an Optional<llvm::AtomicRMWInst::BinOp>.

John, thanks for the review!

lib/CodeGen/CGStmtOpenMP.cpp
1109 ↗(On Diff #22451)

Agree, moved to static getCompatibleAtomicRMWBinOp().

This revision was automatically updated to reflect the committed changes.