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