LLVM 22.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 "NVPTXAtomicLower.h"
14#include "NVPTX.h"
16#include "llvm/IR/Function.h"
20
22using namespace llvm;
23
24namespace {
25// Hoisting the alloca instructions in the non-entry blocks to the entry
26// block.
27class NVPTXAtomicLower : public FunctionPass {
28public:
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
44bool NVPTXAtomicLower::runOnFunction(Function &F) {
45 SmallVector<AtomicRMWInst *> LocalMemoryAtomics;
46 for (Instruction &I : instructions(F))
47 if (AtomicRMWInst *RMWI = dyn_cast<AtomicRMWInst>(&I))
48 if (RMWI->getPointerAddressSpace() == ADDRESS_SPACE_LOCAL)
49 LocalMemoryAtomics.push_back(RMWI);
50
51 bool Changed = false;
52 for (AtomicRMWInst *RMWI : LocalMemoryAtomics)
54 return Changed;
55}
56
57char NVPTXAtomicLower::ID = 0;
58
59INITIALIZE_PASS(NVPTXAtomicLower, "nvptx-atomic-lower",
60 "Lower atomics of local memory to simple load/stores", false,
61 false)
62
64 return new NVPTXAtomicLower();
65}
Expand Atomic instructions
static bool runOnFunction(Function &F, bool PostInlining)
#define F(x, y, z)
Definition MD5.cpp:55
#define I(x, y, z)
Definition MD5.cpp:58
#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:270
FunctionPass class - This class is used to implement most global optimizations.
Definition Pass.h:314
void push_back(const T &Elt)
Changed
This is an optimization pass for GlobalISel generic memory operations.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:649
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
FunctionPass * createNVPTXAtomicLowerPass()
bool lowerAtomicRMWInst(AtomicRMWInst *RMWI)
Convert the given RMWI into primitive load and stores, assuming that doing so is legal.