mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-24 11:42:57 +01:00
e43a24e432
Summary: This is useful for PNaCl's `RewriteAtomics` pass. NaCl intrinsics don't exist for some of the more exotic RMW instructions, so by refactoring this function into its own, `RewriteAtomics` can share code rewriting those atomics with `AtomicExpand` while additionally saving a few cycles by generating the `cmpxchg` NaCl-specific intrinsic with the callback. Without this patch, `RewriteAtomics` would require two extra passes over functions, by first requiring use of the full `AtomicExpand` pass to just expand the leftover exotic RMWs and then running itself again to expand resulting `cmpxchg`s. NFC Reviewers: jfb Subscribers: jfb, llvm-commits Differential Revision: http://reviews.llvm.org/D11422 llvm-svn: 243880
58 lines
2.3 KiB
C++
58 lines
2.3 KiB
C++
//===-- AtomicExpandUtils.h - Utilities for expanding atomic instructions -===//
|
|
//
|
|
// The LLVM Compiler Infrastructure
|
|
//
|
|
// This file is distributed under the University of Illinois Open Source
|
|
// License. See LICENSE.TXT for details.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "llvm/ADT/STLExtras.h"
|
|
#include "llvm/IR/IRBuilder.h"
|
|
|
|
namespace llvm {
|
|
class Value;
|
|
class AtomicRMWInst;
|
|
|
|
|
|
/// Parameters (see the expansion example below):
|
|
/// (the builder, %addr, %loaded, %new_val, ordering,
|
|
/// /* OUT */ %success, /* OUT */ %new_loaded)
|
|
typedef function_ref<void(IRBuilder<> &, Value *, Value *, Value *,
|
|
AtomicOrdering, Value *&, Value *&)> CreateCmpXchgInstFun;
|
|
|
|
/// \brief Expand an atomic RMW instruction into a loop utilizing
|
|
/// cmpxchg. You'll want to make sure your target machine likes cmpxchg
|
|
/// instructions in the first place and that there isn't another, better,
|
|
/// transformation available (for example AArch32/AArch64 have linked loads).
|
|
///
|
|
/// This is useful in passes which can't rewrite the more exotic RMW
|
|
/// instructions directly into a platform specific intrinsics (because, say,
|
|
/// those intrinsics don't exist). If such a pass is able to expand cmpxchg
|
|
/// instructions directly however, then, with this function, it could avoid two
|
|
/// extra module passes (avoiding passes by `-atomic-expand` and itself). A
|
|
/// specific example would be PNaCl's `RewriteAtomics` pass.
|
|
///
|
|
/// Given: atomicrmw some_op iN* %addr, iN %incr ordering
|
|
///
|
|
/// The standard expansion we produce is:
|
|
/// [...]
|
|
/// %init_loaded = load atomic iN* %addr
|
|
/// br label %loop
|
|
/// loop:
|
|
/// %loaded = phi iN [ %init_loaded, %entry ], [ %new_loaded, %loop ]
|
|
/// %new = some_op iN %loaded, %incr
|
|
/// ; This is what -atomic-expand will produce using this function on i686 targets:
|
|
/// %pair = cmpxchg iN* %addr, iN %loaded, iN %new_val
|
|
/// %new_loaded = extractvalue { iN, i1 } %pair, 0
|
|
/// %success = extractvalue { iN, i1 } %pair, 1
|
|
/// ; End callback produced IR
|
|
/// br i1 %success, label %atomicrmw.end, label %loop
|
|
/// atomicrmw.end:
|
|
/// [...]
|
|
///
|
|
/// Returns true if the containing function was modified.
|
|
bool
|
|
expandAtomicRMWToCmpXchg(AtomicRMWInst *AI, CreateCmpXchgInstFun Factory);
|
|
}
|