LLVM
15.0.0git
include
llvm
CodeGen
AtomicExpandUtils.h
Go to the documentation of this file.
1
//===- AtomicExpandUtils.h - Utilities for expanding atomic instructions --===//
2
//
3
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4
// See https://llvm.org/LICENSE.txt for license information.
5
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
//
7
//===----------------------------------------------------------------------===//
8
9
#ifndef LLVM_CODEGEN_ATOMICEXPANDUTILS_H
10
#define LLVM_CODEGEN_ATOMICEXPANDUTILS_H
11
12
#include "
llvm/ADT/STLExtras.h
"
13
#include "
llvm/IR/IRBuilder.h
"
14
#include "
llvm/Support/AtomicOrdering.h
"
15
16
namespace
llvm
{
17
18
class
AtomicRMWInst;
19
class
Value
;
20
21
/// Parameters (see the expansion example below):
22
/// (the builder, %addr, %loaded, %new_val, ordering,
23
/// /* OUT */ %success, /* OUT */ %new_loaded)
24
using
CreateCmpXchgInstFun
=
25
function_ref<void(
IRBuilder<>
&,
Value
*,
Value
*,
Value
*,
Align
,
26
AtomicOrdering
,
SyncScope::ID
,
Value
*&,
Value
*&)>;
27
28
/// Expand an atomic RMW instruction into a loop utilizing
29
/// cmpxchg. You'll want to make sure your target machine likes cmpxchg
30
/// instructions in the first place and that there isn't another, better,
31
/// transformation available (for example AArch32/AArch64 have linked loads).
32
///
33
/// This is useful in passes which can't rewrite the more exotic RMW
34
/// instructions directly into a platform specific intrinsics (because, say,
35
/// those intrinsics don't exist). If such a pass is able to expand cmpxchg
36
/// instructions directly however, then, with this function, it could avoid two
37
/// extra module passes (avoiding passes by `-atomic-expand` and itself). A
38
/// specific example would be PNaCl's `RewriteAtomics` pass.
39
///
40
/// Given: atomicrmw some_op iN* %addr, iN %incr ordering
41
///
42
/// The standard expansion we produce is:
43
/// [...]
44
/// %init_loaded = load atomic iN* %addr
45
/// br label %loop
46
/// loop:
47
/// %loaded = phi iN [ %init_loaded, %entry ], [ %new_loaded, %loop ]
48
/// %new = some_op iN %loaded, %incr
49
/// ; This is what -atomic-expand will produce using this function on i686
50
/// targets:
51
/// %pair = cmpxchg iN* %addr, iN %loaded, iN %new_val
52
/// %new_loaded = extractvalue { iN, i1 } %pair, 0
53
/// %success = extractvalue { iN, i1 } %pair, 1
54
/// ; End callback produced IR
55
/// br i1 %success, label %atomicrmw.end, label %loop
56
/// atomicrmw.end:
57
/// [...]
58
///
59
/// Returns true if the containing function was modified.
60
bool
expandAtomicRMWToCmpXchg
(
AtomicRMWInst
*AI,
CreateCmpXchgInstFun
CreateCmpXchg);
61
62
}
// end namespace llvm
63
64
#endif // LLVM_CODEGEN_ATOMICEXPANDUTILS_H
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition:
AddressRanges.h:17
AtomicOrdering.h
llvm::IRBuilder<>
STLExtras.h
Align
uint64_t Align
Definition:
ELFObjHandler.cpp:81
llvm::function_ref
An efficient, type-erasing, non-owning reference to a callable.
Definition:
STLFunctionalExtras.h:36
llvm::AtomicOrdering
AtomicOrdering
Atomic ordering for LLVM's memory model.
Definition:
AtomicOrdering.h:56
llvm::SyncScope::ID
uint8_t ID
Definition:
LLVMContext.h:47
IRBuilder.h
llvm::AtomicRMWInst
an instruction that atomically reads a memory location, combines it with another value,...
Definition:
Instructions.h:727
llvm::TargetStackID::Value
Value
Definition:
TargetFrameLowering.h:27
llvm::CreateCmpXchgInstFun
function_ref< void(IRBuilder<> &, Value *, Value *, Value *, Align, AtomicOrdering, SyncScope::ID, Value *&, Value *&)> CreateCmpXchgInstFun
Parameters (see the expansion example below): (the builder, addr, loaded, new_val,...
Definition:
AtomicExpandUtils.h:26
llvm::expandAtomicRMWToCmpXchg
bool expandAtomicRMWToCmpXchg(AtomicRMWInst *AI, CreateCmpXchgInstFun CreateCmpXchg)
Expand an atomic RMW instruction into a loop utilizing cmpxchg.
Definition:
AtomicExpandPass.cpp:1513
llvm::Value
LLVM Value Representation.
Definition:
Value.h:74
Generated on Mon May 16 2022 16:06:48 for LLVM by
1.8.17