66 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8//9// Lower atomics of local memory to simple load/stores10//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"22using namespace llvm;23 24namespace {25// Hoisting the alloca instructions in the non-entry blocks to the entry26// block.27class NVPTXAtomicLower : public FunctionPass {28public:29 static char ID; // Pass ID30 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} // namespace43 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)53 Changed |= lowerAtomicRMWInst(RMWI);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 63FunctionPass *llvm::createNVPTXAtomicLowerPass() {64 return new NVPTXAtomicLower();65}66