LLVM 20.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"
15#include "llvm/IR/Constants.h"
16#include "llvm/IR/Function.h"
17#include "llvm/IR/IRBuilder.h"
21
23using namespace llvm;
24
25namespace {
26// Hoisting the alloca instructions in the non-entry blocks to the entry
27// block.
28class NVPTXAtomicLower : public FunctionPass {
29public:
30 static char ID; // Pass ID
31 NVPTXAtomicLower() : FunctionPass(ID) {}
32
33 void getAnalysisUsage(AnalysisUsage &AU) const override {
34 AU.setPreservesCFG();
35 }
36
37 StringRef getPassName() const override {
38 return "NVPTX lower atomics of local memory";
39 }
40
41 bool runOnFunction(Function &F) override;
42};
43} // namespace
44
45bool NVPTXAtomicLower::runOnFunction(Function &F) {
46 SmallVector<AtomicRMWInst *> LocalMemoryAtomics;
47 for (Instruction &I : instructions(F))
48 if (AtomicRMWInst *RMWI = dyn_cast<AtomicRMWInst>(&I))
49 if (RMWI->getPointerAddressSpace() == ADDRESS_SPACE_LOCAL)
50 LocalMemoryAtomics.push_back(RMWI);
51
52 bool Changed = false;
53 for (AtomicRMWInst *RMWI : LocalMemoryAtomics)
54 Changed |= lowerAtomicRMWInst(RMWI);
55 return Changed;
56}
57
58char NVPTXAtomicLower::ID = 0;
59
60namespace llvm {
62}
63
64INITIALIZE_PASS(NVPTXAtomicLower, "nvptx-atomic-lower",
65 "Lower atomics of local memory to simple load/stores", false,
66 false)
67
69 return new NVPTXAtomicLower();
70}
Expand Atomic instructions
This file contains the declarations for the subclasses of Constant, which represent the different fla...
#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:38
Represent the analysis usage information of a pass.
void setPreservesCFG()
This function should be called by the pass, iff they do not:
Definition: Pass.cpp:256
an instruction that atomically reads a memory location, combines it with another value,...
Definition: Instructions.h:696
FunctionPass class - This class is used to implement most global optimizations.
Definition: Pass.h:310
virtual bool runOnFunction(Function &F)=0
runOnFunction - Virtual method overriden by subclasses to do the per-function processing of the pass.
PassRegistry - This class manages the registration and intitialization of the pass subsystem as appli...
Definition: PassRegistry.h:37
virtual void getAnalysisUsage(AnalysisUsage &) const
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
Definition: Pass.cpp:98
virtual StringRef getPassName() const
getPassName - Return a nice clean name for a pass.
Definition: Pass.cpp:81
void push_back(const T &Elt)
Definition: SmallVector.h:427
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1210
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Definition: CallingConv.h:24
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
@ ADDRESS_SPACE_LOCAL
Definition: NVPTXBaseInfo.h:26
FunctionPass * createNVPTXAtomicLowerPass()
bool lowerAtomicRMWInst(AtomicRMWInst *RMWI)
Convert the given RMWI into primitive load and stores, assuming that doing so is legal.
void initializeNVPTXAtomicLowerPass(PassRegistry &)