aboutsummaryrefslogtreecommitdiff
path: root/contrib/llvm-project/llvm/lib/Target/AMDGPU/Utils/AMDGPUMemoryUtils.cpp
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2023-04-14 21:41:27 +0000
committerDimitry Andric <dim@FreeBSD.org>2023-06-22 18:20:56 +0000
commitbdd1243df58e60e85101c09001d9812a789b6bc4 (patch)
treea1ce621c7301dd47ba2ddc3b8eaa63b441389481 /contrib/llvm-project/llvm/lib/Target/AMDGPU/Utils/AMDGPUMemoryUtils.cpp
parent781624ca2d054430052c828ba8d2c2eaf2d733e7 (diff)
parente3b557809604d036af6e00c60f012c2025b59a5e (diff)
Diffstat (limited to 'contrib/llvm-project/llvm/lib/Target/AMDGPU/Utils/AMDGPUMemoryUtils.cpp')
-rw-r--r--contrib/llvm-project/llvm/lib/Target/AMDGPU/Utils/AMDGPUMemoryUtils.cpp82
1 files changed, 30 insertions, 52 deletions
diff --git a/contrib/llvm-project/llvm/lib/Target/AMDGPU/Utils/AMDGPUMemoryUtils.cpp b/contrib/llvm-project/llvm/lib/Target/AMDGPU/Utils/AMDGPUMemoryUtils.cpp
index 83d7cbdb183c..b1418253fd13 100644
--- a/contrib/llvm-project/llvm/lib/Target/AMDGPU/Utils/AMDGPUMemoryUtils.cpp
+++ b/contrib/llvm-project/llvm/lib/Target/AMDGPU/Utils/AMDGPUMemoryUtils.cpp
@@ -9,7 +9,6 @@
#include "AMDGPUMemoryUtils.h"
#include "AMDGPU.h"
#include "AMDGPUBaseInfo.h"
-#include "llvm/ADT/SetVector.h"
#include "llvm/ADT/SmallSet.h"
#include "llvm/Analysis/AliasAnalysis.h"
#include "llvm/Analysis/MemorySSA.h"
@@ -32,35 +31,6 @@ Align getAlign(DataLayout const &DL, const GlobalVariable *GV) {
GV->getValueType());
}
-static void collectFunctionUses(User *U, const Function *F,
- SetVector<Instruction *> &InstUsers) {
- SmallVector<User *> Stack{U};
-
- while (!Stack.empty()) {
- U = Stack.pop_back_val();
-
- if (auto *I = dyn_cast<Instruction>(U)) {
- if (I->getFunction() == F)
- InstUsers.insert(I);
- continue;
- }
-
- if (!isa<ConstantExpr>(U))
- continue;
-
- append_range(Stack, U->users());
- }
-}
-
-void replaceConstantUsesInFunction(ConstantExpr *C, const Function *F) {
- SetVector<Instruction *> InstUsers;
-
- collectFunctionUses(C, F, InstUsers);
- for (Instruction *I : InstUsers) {
- convertConstantExprsToInstructions(I, C);
- }
-}
-
static bool shouldLowerLDSToStruct(const GlobalVariable &GV,
const Function *F) {
// We are not interested in kernel LDS lowering for module LDS itself.
@@ -105,29 +75,36 @@ static bool shouldLowerLDSToStruct(const GlobalVariable &GV,
return Ret;
}
-std::vector<GlobalVariable *> findVariablesToLower(Module &M,
- const Function *F) {
+bool isLDSVariableToLower(const GlobalVariable &GV) {
+ if (GV.getType()->getPointerAddressSpace() != AMDGPUAS::LOCAL_ADDRESS) {
+ return false;
+ }
+ if (!GV.hasInitializer()) {
+ // addrspace(3) without initializer implies cuda/hip extern __shared__
+ // the semantics for such a variable appears to be that all extern
+ // __shared__ variables alias one another, in which case this transform
+ // is not required
+ return false;
+ }
+ if (!isa<UndefValue>(GV.getInitializer())) {
+ // Initializers are unimplemented for LDS address space.
+ // Leave such variables in place for consistent error reporting.
+ return false;
+ }
+ if (GV.isConstant()) {
+ // A constant undef variable can't be written to, and any load is
+ // undef, so it should be eliminated by the optimizer. It could be
+ // dropped by the back end if not. This pass skips over it.
+ return false;
+ }
+ return true;
+}
+
+std::vector<GlobalVariable *> findLDSVariablesToLower(Module &M,
+ const Function *F) {
std::vector<llvm::GlobalVariable *> LocalVars;
for (auto &GV : M.globals()) {
- if (GV.getType()->getPointerAddressSpace() != AMDGPUAS::LOCAL_ADDRESS) {
- continue;
- }
- if (!GV.hasInitializer()) {
- // addrspace(3) without initializer implies cuda/hip extern __shared__
- // the semantics for such a variable appears to be that all extern
- // __shared__ variables alias one another, in which case this transform
- // is not required
- continue;
- }
- if (!isa<UndefValue>(GV.getInitializer())) {
- // Initializers are unimplemented for LDS address space.
- // Leave such variables in place for consistent error reporting.
- continue;
- }
- if (GV.isConstant()) {
- // A constant undef variable can't be written to, and any load is
- // undef, so it should be eliminated by the optimizer. It could be
- // dropped by the back end if not. This pass skips over it.
+ if (!isLDSVariableToLower(GV)) {
continue;
}
if (!shouldLowerLDSToStruct(GV, F)) {
@@ -149,6 +126,7 @@ bool isReallyAClobber(const Value *Ptr, MemoryDef *Def, AAResults *AA) {
case Intrinsic::amdgcn_s_barrier:
case Intrinsic::amdgcn_wave_barrier:
case Intrinsic::amdgcn_sched_barrier:
+ case Intrinsic::amdgcn_sched_group_barrier:
return false;
default:
break;
@@ -207,7 +185,7 @@ bool isClobberedInFunction(const LoadInst *Load, MemorySSA *MSSA,
}
const MemoryPhi *Phi = cast<MemoryPhi>(MA);
- for (auto &Use : Phi->incoming_values())
+ for (const auto &Use : Phi->incoming_values())
WorkList.push_back(cast<MemoryAccess>(&Use));
}