LLVM  13.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"
18 #include "llvm/IR/InstIterator.h"
19 #include "llvm/IR/Instructions.h"
21 
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  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 
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 
58 char NVPTXAtomicLower::ID = 0;
59 
60 namespace llvm {
62 }
63 
64 INITIALIZE_PASS(NVPTXAtomicLower, "nvptx-atomic-lower",
65  "Lower atomics of local memory to simple load/stores", false,
66  false)
67 
69  return new NVPTXAtomicLower();
70 }
StackProtector.h
llvm
Definition: AllocatorList.h:23
InstIterator.h
llvm::Function
Definition: Function.h:61
LowerAtomic.h
llvm::SmallVector
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1167
llvm::ADDRESS_SPACE_LOCAL
@ ADDRESS_SPACE_LOCAL
Definition: NVPTXBaseInfo.h:26
llvm::initializeNVPTXAtomicLowerPass
void initializeNVPTXAtomicLowerPass(PassRegistry &)
F
#define F(x, y, z)
Definition: MD5.cpp:56
Constants.h
llvm::AnalysisUsage
Represent the analysis usage information of a pass.
Definition: PassAnalysisSupport.h:47
NVPTXAtomicLower.h
INITIALIZE_PASS
INITIALIZE_PASS(NVPTXAtomicLower, "nvptx-atomic-lower", "Lower atomics of local memory to simple load/stores", false, false) FunctionPass *llvm
Definition: NVPTXAtomicLower.cpp:64
llvm::Instruction
Definition: Instruction.h:45
llvm::PassRegistry
PassRegistry - This class manages the registration and intitialization of the pass subsystem as appli...
Definition: PassRegistry.h:38
llvm::instructions
inst_range instructions(Function *F)
Definition: InstIterator.h:133
NVPTXBaseInfo.h
I
#define I(x, y, z)
Definition: MD5.cpp:59
llvm::createNVPTXAtomicLowerPass
FunctionPass * createNVPTXAtomicLowerPass()
llvm::lowerAtomicRMWInst
bool lowerAtomicRMWInst(AtomicRMWInst *RMWI)
Convert the given RMWI into primitive load and stores, assuming that doing so is legal.
Definition: LowerAtomic.cpp:43
IRBuilder.h
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
llvm::AnalysisUsage::setPreservesCFG
void setPreservesCFG()
This function should be called by the pass, iff they do not:
Definition: Pass.cpp:253
llvm::AtomicRMWInst
an instruction that atomically reads a memory location, combines it with another value,...
Definition: Instructions.h:728
runOnFunction
static bool runOnFunction(Function &F, bool PostInlining)
Definition: EntryExitInstrumenter.cpp:69
Function.h
Instructions.h
llvm::FunctionPass
FunctionPass class - This class is used to implement most global optimizations.
Definition: Pass.h:298
llvm::Intrinsic::ID
unsigned ID
Definition: TargetTransformInfo.h:38