LLVM  4.0.0
AtomicExpandUtils.h
Go to the documentation of this file.
1 //===-- AtomicExpandUtils.h - Utilities for expanding atomic instructions -===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #include "llvm/ADT/STLExtras.h"
11 #include "llvm/IR/IRBuilder.h"
12 
13 namespace llvm {
14 class Value;
16 
17 
18 /// Parameters (see the expansion example below):
19 /// (the builder, %addr, %loaded, %new_val, ordering,
20 /// /* OUT */ %success, /* OUT */ %new_loaded)
23 
24 /// \brief Expand an atomic RMW instruction into a loop utilizing
25 /// cmpxchg. You'll want to make sure your target machine likes cmpxchg
26 /// instructions in the first place and that there isn't another, better,
27 /// transformation available (for example AArch32/AArch64 have linked loads).
28 ///
29 /// This is useful in passes which can't rewrite the more exotic RMW
30 /// instructions directly into a platform specific intrinsics (because, say,
31 /// those intrinsics don't exist). If such a pass is able to expand cmpxchg
32 /// instructions directly however, then, with this function, it could avoid two
33 /// extra module passes (avoiding passes by `-atomic-expand` and itself). A
34 /// specific example would be PNaCl's `RewriteAtomics` pass.
35 ///
36 /// Given: atomicrmw some_op iN* %addr, iN %incr ordering
37 ///
38 /// The standard expansion we produce is:
39 /// [...]
40 /// %init_loaded = load atomic iN* %addr
41 /// br label %loop
42 /// loop:
43 /// %loaded = phi iN [ %init_loaded, %entry ], [ %new_loaded, %loop ]
44 /// %new = some_op iN %loaded, %incr
45 /// ; This is what -atomic-expand will produce using this function on i686 targets:
46 /// %pair = cmpxchg iN* %addr, iN %loaded, iN %new_val
47 /// %new_loaded = extractvalue { iN, i1 } %pair, 0
48 /// %success = extractvalue { iN, i1 } %pair, 1
49 /// ; End callback produced IR
50 /// br i1 %success, label %atomicrmw.end, label %loop
51 /// atomicrmw.end:
52 /// [...]
53 ///
54 /// Returns true if the containing function was modified.
55 bool
57 }
An efficient, type-erasing, non-owning reference to a callable.
Definition: STLExtras.h:83
an instruction that atomically reads a memory location, combines it with another value, and then stores the result back.
Definition: Instructions.h:669
AtomicOrdering
Atomic ordering for LLVM's memory model.
new_loaded *typedef function_ref< void(IRBuilder<> &, Value *, Value *, Value *, AtomicOrdering, Value *&, Value *&)> CreateCmpXchgInstFun
LLVM Value Representation.
Definition: Value.h:71
bool expandAtomicRMWToCmpXchg(AtomicRMWInst *AI, CreateCmpXchgInstFun Factory)
Expand an atomic RMW instruction into a loop utilizing cmpxchg.