|
|
|||
File indexing completed on 2026-05-10 08:43:26
0001 //===- AtomicExpandUtils.h - Utilities for expanding atomic instructions --===// 0002 // 0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 0004 // See https://llvm.org/LICENSE.txt for license information. 0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 0006 // 0007 //===----------------------------------------------------------------------===// 0008 0009 #ifndef LLVM_CODEGEN_ATOMICEXPANDUTILS_H 0010 #define LLVM_CODEGEN_ATOMICEXPANDUTILS_H 0011 0012 #include "llvm/ADT/STLExtras.h" 0013 #include "llvm/IR/IRBuilder.h" 0014 #include "llvm/Support/AtomicOrdering.h" 0015 0016 namespace llvm { 0017 0018 class AtomicRMWInst; 0019 class Value; 0020 0021 /// Parameters (see the expansion example below): 0022 /// (the builder, %addr, %loaded, %new_val, ordering, 0023 /// /* OUT */ %success, /* OUT */ %new_loaded, 0024 /// %MetadataSrc) 0025 using CreateCmpXchgInstFun = function_ref<void( 0026 IRBuilderBase &, Value *, Value *, Value *, Align, AtomicOrdering, 0027 SyncScope::ID, Value *&, Value *&, Instruction *)>; 0028 0029 /// Expand an atomic RMW instruction into a loop utilizing 0030 /// cmpxchg. You'll want to make sure your target machine likes cmpxchg 0031 /// instructions in the first place and that there isn't another, better, 0032 /// transformation available (for example AArch32/AArch64 have linked loads). 0033 /// 0034 /// This is useful in passes which can't rewrite the more exotic RMW 0035 /// instructions directly into a platform specific intrinsics (because, say, 0036 /// those intrinsics don't exist). If such a pass is able to expand cmpxchg 0037 /// instructions directly however, then, with this function, it could avoid two 0038 /// extra module passes (avoiding passes by `-atomic-expand` and itself). A 0039 /// specific example would be PNaCl's `RewriteAtomics` pass. 0040 /// 0041 /// Given: atomicrmw some_op iN* %addr, iN %incr ordering 0042 /// 0043 /// The standard expansion we produce is: 0044 /// [...] 0045 /// %init_loaded = load atomic iN* %addr 0046 /// br label %loop 0047 /// loop: 0048 /// %loaded = phi iN [ %init_loaded, %entry ], [ %new_loaded, %loop ] 0049 /// %new = some_op iN %loaded, %incr 0050 /// ; This is what -atomic-expand will produce using this function on i686 0051 /// targets: 0052 /// %pair = cmpxchg iN* %addr, iN %loaded, iN %new_val 0053 /// %new_loaded = extractvalue { iN, i1 } %pair, 0 0054 /// %success = extractvalue { iN, i1 } %pair, 1 0055 /// ; End callback produced IR 0056 /// br i1 %success, label %atomicrmw.end, label %loop 0057 /// atomicrmw.end: 0058 /// [...] 0059 /// 0060 /// Returns true if the containing function was modified. 0061 bool expandAtomicRMWToCmpXchg(AtomicRMWInst *AI, CreateCmpXchgInstFun CreateCmpXchg); 0062 0063 } // end namespace llvm 0064 0065 #endif // LLVM_CODEGEN_ATOMICEXPANDUTILS_H
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|