[llvm] [AMDGPU][PromoteAlloca] Whole-function alloca promotion to vector (PR #84735)
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Mon Mar 11 02:30:13 PDT 2024
================
@@ -225,6 +253,49 @@ FunctionPass *llvm::createAMDGPUPromoteAllocaToVector() {
return new AMDGPUPromoteAllocaToVector();
}
+void AMDGPUPromoteAllocaImpl::sortAllocasToPromote(
+ SmallVectorImpl<AllocaInst *> &Allocas) {
+ DenseMap<AllocaInst *, unsigned> Scores;
+
+ LLVM_DEBUG(dbgs() << "Before sorting allocas:\n"; for (auto *A
+ : Allocas) dbgs()
+ << " " << *A << "\n";);
+
+ for (auto *Alloca : Allocas) {
+ LLVM_DEBUG(dbgs() << "Scoring: " << *Alloca << "\n");
+ unsigned &Score = Scores[Alloca];
+ // Increment score by one for each user + a bonus for users within loops.
+ //
+ // Look through GEPs and bitcasts for additional users.
+ SmallVector<User *, 8> WorkList;
+ WorkList.append(Alloca->user_begin(), Alloca->user_end());
+ while (!WorkList.empty()) {
+ auto *Inst = dyn_cast<Instruction>(WorkList.pop_back_val());
+ if (!Inst)
+ continue;
+
+ if (isa<BitCastInst>(Inst) || isa<GetElementPtrInst>(Inst)) {
----------------
arsenm wrote:
The bitcast search isn't really relevant with opaque pointers
https://github.com/llvm/llvm-project/pull/84735
More information about the llvm-commits
mailing list