LLVM 24.0.0git
NVPTXAtomicLower.cpp
Go to the documentation of this file.
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 "NVPTX.h"
15#include "llvm/IR/Function.h"
19
21using namespace llvm;
22
25 // TODO: Handle cmpxchg
26 // NOTE: AtomicRMW instructions are replaced with other instructions. This
27 // cannot be done while iterating over instructions. Load/Store instructions
28 // *can* be modified in-place.
29 bool Changed = false;
30 for (Instruction &I : instructions(F)) {
31 if (auto *RMWI = dyn_cast<AtomicRMWInst>(&I);
32 RMWI && RMWI->getPointerAddressSpace() == ADDRESS_SPACE_LOCAL) {
33 LocalRMWs.push_back(RMWI);
34 } else if (auto *LI = dyn_cast<LoadInst>(&I);
35 LI && LI->isAtomic() &&
36 LI->getPointerAddressSpace() == ADDRESS_SPACE_LOCAL) {
37 LI->setAtomic(AtomicOrdering::NotAtomic);
38 Changed = true;
39 } else if (auto *SI = dyn_cast<StoreInst>(&I);
40 SI && SI->isAtomic() &&
41 SI->getPointerAddressSpace() == ADDRESS_SPACE_LOCAL) {
42 SI->setAtomic(AtomicOrdering::NotAtomic);
43 Changed = true;
44 }
45 }
46
47 for (AtomicRMWInst *RMWI : LocalRMWs)
49 return Changed;
50}
51
52namespace {
53class NVPTXAtomicLowerLegacyPass : public FunctionPass {
54public:
55 static char ID; // Pass ID
56 NVPTXAtomicLowerLegacyPass() : FunctionPass(ID) {}
57
58 void getAnalysisUsage(AnalysisUsage &AU) const override {
59 AU.setPreservesCFG();
60 }
61
62 StringRef getPassName() const override {
63 return "NVPTX lower atomics of local memory";
64 }
65
66 bool runOnFunction(Function &F) override {
68 }
69};
70} // namespace
71
72char NVPTXAtomicLowerLegacyPass::ID = 0;
73
74INITIALIZE_PASS(NVPTXAtomicLowerLegacyPass, "nvptx-atomic-lower",
75 "Lower atomics of local memory to simple load/stores", false,
76 false)
77
79 return new NVPTXAtomicLowerLegacyPass();
80}
81
Expand Atomic instructions
static bool runOnFunction(Function &F, bool PostInlining)
#define F(x, y, z)
Definition MD5.cpp:54
#define I(x, y, z)
Definition MD5.cpp:57
static bool lowerLocalMemoryAtomics(Function &F)
FunctionAnalysisManager FAM
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
Definition PassSupport.h:56
LLVM_ABI void setPreservesCFG()
This function should be called by the pass, iff they do not:
Definition Pass.cpp:280
an instruction that atomically reads a memory location, combines it with another value,...
Represents analyses that only rely on functions' control flow.
Definition Analysis.h:73
FunctionPass class - This class is used to implement most global optimizations.
Definition Pass.h:312
PreservedAnalyses run(Function &F, FunctionAnalysisManager &FAM)
A set of analyses that are preserved following a run of a transformation pass.
Definition Analysis.h:112
static PreservedAnalyses none()
Convenience factory function for the empty preserved set.
Definition Analysis.h:115
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Definition Analysis.h:118
PreservedAnalyses & preserveSet()
Mark an analysis set as preserved.
Definition Analysis.h:151
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Changed
This is an optimization pass for GlobalISel generic memory operations.
FunctionPass * createNVPTXAtomicLowerLegacyPass()
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:643
LLVM_ABI bool lowerAtomicRMWInst(AtomicRMWInst *RMWI)
Convert the given RMWI into primitive load and stores, assuming that doing so is legal.
AnalysisManager< Function > FunctionAnalysisManager
Convenience typedef for the Function analysis manager.