LLVM 20.0.0git
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"
15
16namespace llvm {
17
18class AtomicRMWInst;
19class Value;
20
21/// Parameters (see the expansion example below):
22/// (the builder, %addr, %loaded, %new_val, ordering,
23/// /* OUT */ %success, /* OUT */ %new_loaded,
24/// %MetadataSrc)
28
29/// Expand an atomic RMW instruction into a loop utilizing
30/// cmpxchg. You'll want to make sure your target machine likes cmpxchg
31/// instructions in the first place and that there isn't another, better,
32/// transformation available (for example AArch32/AArch64 have linked loads).
33///
34/// This is useful in passes which can't rewrite the more exotic RMW
35/// instructions directly into a platform specific intrinsics (because, say,
36/// those intrinsics don't exist). If such a pass is able to expand cmpxchg
37/// instructions directly however, then, with this function, it could avoid two
38/// extra module passes (avoiding passes by `-atomic-expand` and itself). A
39/// specific example would be PNaCl's `RewriteAtomics` pass.
40///
41/// Given: atomicrmw some_op iN* %addr, iN %incr ordering
42///
43/// The standard expansion we produce is:
44/// [...]
45/// %init_loaded = load atomic iN* %addr
46/// br label %loop
47/// loop:
48/// %loaded = phi iN [ %init_loaded, %entry ], [ %new_loaded, %loop ]
49/// %new = some_op iN %loaded, %incr
50/// ; This is what -atomic-expand will produce using this function on i686
51/// targets:
52/// %pair = cmpxchg iN* %addr, iN %loaded, iN %new_val
53/// %new_loaded = extractvalue { iN, i1 } %pair, 0
54/// %success = extractvalue { iN, i1 } %pair, 1
55/// ; End callback produced IR
56/// br i1 %success, label %atomicrmw.end, label %loop
57/// atomicrmw.end:
58/// [...]
59///
60/// Returns true if the containing function was modified.
62
63} // end namespace llvm
64
65#endif // LLVM_CODEGEN_ATOMICEXPANDUTILS_H
Atomic ordering constants.
This file contains some templates that are useful if you are working with the STL at all.
an instruction that atomically reads a memory location, combines it with another value,...
Definition: Instructions.h:704
Common base class shared among various IRBuilders.
Definition: IRBuilder.h:91
LLVM Value Representation.
Definition: Value.h:74
An efficient, type-erasing, non-owning reference to a callable.
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
AtomicOrdering
Atomic ordering for LLVM's memory model.
bool expandAtomicRMWToCmpXchg(AtomicRMWInst *AI, CreateCmpXchgInstFun CreateCmpXchg)
Expand an atomic RMW instruction into a loop utilizing cmpxchg.
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition: Alignment.h:39