/src/llvm-project/llvm/lib/Target/NVPTX/NVPTXAtomicLower.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | //===-- NVPTXAtomicLower.cpp - Lower atomics of local memory ----*- C++ -*-===// |
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 | | // Lower atomics of local memory to simple load/stores |
10 | | // |
11 | | //===----------------------------------------------------------------------===// |
12 | | |
13 | | #include "NVPTXAtomicLower.h" |
14 | | #include "llvm/CodeGen/StackProtector.h" |
15 | | #include "llvm/IR/Constants.h" |
16 | | #include "llvm/IR/Function.h" |
17 | | #include "llvm/IR/IRBuilder.h" |
18 | | #include "llvm/IR/InstIterator.h" |
19 | | #include "llvm/IR/Instructions.h" |
20 | | #include "llvm/Transforms/Utils/LowerAtomic.h" |
21 | | |
22 | | #include "MCTargetDesc/NVPTXBaseInfo.h" |
23 | | using namespace llvm; |
24 | | |
25 | | namespace { |
26 | | // Hoisting the alloca instructions in the non-entry blocks to the entry |
27 | | // block. |
28 | | class NVPTXAtomicLower : public FunctionPass { |
29 | | public: |
30 | | static char ID; // Pass ID |
31 | 740 | NVPTXAtomicLower() : FunctionPass(ID) {} |
32 | | |
33 | 740 | void getAnalysisUsage(AnalysisUsage &AU) const override { |
34 | 740 | AU.setPreservesCFG(); |
35 | 740 | } |
36 | | |
37 | 0 | StringRef getPassName() const override { |
38 | 0 | return "NVPTX lower atomics of local memory"; |
39 | 0 | } |
40 | | |
41 | | bool runOnFunction(Function &F) override; |
42 | | }; |
43 | | } // namespace |
44 | | |
45 | 738 | bool NVPTXAtomicLower::runOnFunction(Function &F) { |
46 | 738 | SmallVector<AtomicRMWInst *> LocalMemoryAtomics; |
47 | 738 | for (Instruction &I : instructions(F)) |
48 | 17.9k | if (AtomicRMWInst *RMWI = dyn_cast<AtomicRMWInst>(&I)) |
49 | 0 | if (RMWI->getPointerAddressSpace() == ADDRESS_SPACE_LOCAL) |
50 | 0 | LocalMemoryAtomics.push_back(RMWI); |
51 | | |
52 | 738 | bool Changed = false; |
53 | 738 | for (AtomicRMWInst *RMWI : LocalMemoryAtomics) |
54 | 0 | Changed |= lowerAtomicRMWInst(RMWI); |
55 | 738 | return Changed; |
56 | 738 | } |
57 | | |
58 | | char NVPTXAtomicLower::ID = 0; |
59 | | |
60 | | namespace llvm { |
61 | | void initializeNVPTXAtomicLowerPass(PassRegistry &); |
62 | | } |
63 | | |
64 | | INITIALIZE_PASS(NVPTXAtomicLower, "nvptx-atomic-lower", |
65 | | "Lower atomics of local memory to simple load/stores", false, |
66 | | false) |
67 | | |
68 | 740 | FunctionPass *llvm::createNVPTXAtomicLowerPass() { |
69 | 740 | return new NVPTXAtomicLower(); |
70 | 740 | } |