[llvm] [AMDGPU] Debug dump for AMDGPU resource usage (PR #122952)
Janek van Oirschot via llvm-commits
llvm-commits at lists.llvm.org
Tue Jan 14 11:12:52 PST 2025
https://github.com/JanekvO created https://github.com/llvm/llvm-project/pull/122952
None
>From e385c227f9ce565fa8e39fe793f8d4b5ac3a205f Mon Sep 17 00:00:00 2001
From: Janek van Oirschot <Janek.vanOirschot at amd.com>
Date: Tue, 14 Jan 2025 17:56:59 +0000
Subject: [PATCH] [AMDGPU] Debug dump for resource usage
---
.../Target/AMDGPU/AMDGPUMCResourceInfo.cpp | 40 ++++++++++++++++++-
1 file changed, 39 insertions(+), 1 deletion(-)
diff --git a/llvm/lib/Target/AMDGPU/AMDGPUMCResourceInfo.cpp b/llvm/lib/Target/AMDGPU/AMDGPUMCResourceInfo.cpp
index 9511b6bb7de062..67cf9044ee37ce 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUMCResourceInfo.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUMCResourceInfo.cpp
@@ -19,6 +19,8 @@
#include "llvm/MC/MCSymbol.h"
#include "llvm/Target/TargetMachine.h"
+#define DEBUG_TYPE "amdgpu-mc-resource-usage"
+
using namespace llvm;
MCSymbol *MCResourceInfo::getSymbol(StringRef FuncName, ResourceInfoKind RIK,
@@ -101,6 +103,8 @@ void MCResourceInfo::assignResourceInfoExpr(
MCConstantExpr::create(LocalValue, OutContext);
const MCExpr *SymVal = LocalConstExpr;
MCSymbol *Sym = getSymbol(FnSym->getName(), RIK, OutContext);
+ LLVM_DEBUG(dbgs() << "MCResUse: " << Sym->getName() << ": Adding "
+ << LocalValue << " as function local usage\n");
if (!Callees.empty()) {
SmallVector<const MCExpr *, 8> ArgExprs;
SmallPtrSet<const Function *, 8> Seen;
@@ -119,8 +123,13 @@ void MCResourceInfo::assignResourceInfoExpr(
if (!CalleeValSym->isVariable() ||
!CalleeValSym->getVariableValue(/*isUsed=*/false)
->isSymbolUsedInExpression(Sym)) {
+ LLVM_DEBUG(dbgs() << "MCResUse: " << Sym->getName() << ": Adding "
+ << CalleeValSym->getName() << " as callee\n");
ArgExprs.push_back(MCSymbolRefExpr::create(CalleeValSym, OutContext));
} else {
+ LLVM_DEBUG(
+ dbgs() << "MCResUse: " << Sym->getName()
+ << ": Recursion found, falling back to module maximum\n");
// In case of recursion: make sure to use conservative register counts
// (i.e., specifically for VGPR/SGPR/AGPR).
switch (RIK) {
@@ -165,6 +174,20 @@ void MCResourceInfo::gatherResourceInfo(
const TargetMachine &TM = MF.getTarget();
MCSymbol *FnSym = TM.getSymbol(&MF.getFunction());
+ LLVM_DEBUG(dbgs() << "MCResUse: Gathering resource information for "
+ << FnSym->getName() << "\n");
+ // clang-format off
+ LLVM_DEBUG(
+ if (!FRI.Callees.empty()) {
+ dbgs() << "MCResUse: Callees:\n";
+ for (const Function *Callee : FRI.Callees) {
+ MCSymbol *CalleeFnSym = TM.getSymbol(&Callee->getFunction());
+ dbgs() << "MCResUse: " << CalleeFnSym->getName() << "\n";
+ }
+ }
+ );
+ // clang-format on
+
auto SetMaxReg = [&](MCSymbol *MaxSym, int32_t numRegs,
ResourceInfoKind RIK) {
if (!FRI.HasIndirectCall) {
@@ -176,9 +199,12 @@ void MCResourceInfo::gatherResourceInfo(
const MCExpr *MaxWithLocal = AMDGPUMCExpr::createMax(
{MCConstantExpr::create(numRegs, OutContext), SymRef}, OutContext);
LocalNumSym->setVariableValue(MaxWithLocal);
+ LLVM_DEBUG(dbgs() << "MCResUse: " << LocalNumSym->getName()
+ << ": Indirect callee within, using module maximum\n");
}
};
+ LLVM_DEBUG(dbgs() << "MCResUse: " << FnSym->getName() << "\n");
SetMaxReg(MaxVGPRSym, FRI.NumVGPR, RIK_NumVGPR);
SetMaxReg(MaxAGPRSym, FRI.NumAGPR, RIK_NumAGPR);
SetMaxReg(MaxSGPRSym, FRI.NumExplicitSGPR, RIK_NumSGPR);
@@ -188,9 +214,13 @@ void MCResourceInfo::gatherResourceInfo(
// + max(FRI.Callees, FRI.CalleeSegmentSize)
SmallVector<const MCExpr *, 8> ArgExprs;
MCSymbol *Sym = getSymbol(FnSym->getName(), RIK_PrivateSegSize, OutContext);
- if (FRI.CalleeSegmentSize)
+ if (FRI.CalleeSegmentSize) {
+ LLVM_DEBUG(dbgs() << "MCResUse: " << Sym->getName() << ": Adding "
+ << FRI.CalleeSegmentSize
+ << " for indirect/recursive callees within\n");
ArgExprs.push_back(
MCConstantExpr::create(FRI.CalleeSegmentSize, OutContext));
+ }
SmallPtrSet<const Function *, 8> Seen;
Seen.insert(&MF.getFunction());
@@ -207,12 +237,17 @@ void MCResourceInfo::gatherResourceInfo(
if (!CalleeValSym->isVariable() ||
!CalleeValSym->getVariableValue(/*isUsed=*/false)
->isSymbolUsedInExpression(Sym)) {
+ LLVM_DEBUG(dbgs() << "MCResUse: " << Sym->getName() << ": Adding "
+ << CalleeValSym->getName() << " as callee\n");
ArgExprs.push_back(MCSymbolRefExpr::create(CalleeValSym, OutContext));
}
}
}
const MCExpr *localConstExpr =
MCConstantExpr::create(FRI.PrivateSegmentSize, OutContext);
+ LLVM_DEBUG(dbgs() << "MCResUse: " << Sym->getName() << ": Adding "
+ << FRI.PrivateSegmentSize
+ << " as function local usage\n");
if (!ArgExprs.empty()) {
const AMDGPUMCExpr *transitiveExpr =
AMDGPUMCExpr::createMax(ArgExprs, OutContext);
@@ -224,6 +259,9 @@ void MCResourceInfo::gatherResourceInfo(
auto SetToLocal = [&](int64_t LocalValue, ResourceInfoKind RIK) {
MCSymbol *Sym = getSymbol(FnSym->getName(), RIK, OutContext);
+ LLVM_DEBUG(
+ dbgs() << "MCResUse: " << Sym->getName() << ": Adding " << LocalValue
+ << ", no further propagation as indirect callee found within\n");
Sym->setVariableValue(MCConstantExpr::create(LocalValue, OutContext));
};
More information about the llvm-commits
mailing list