Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[AMDGPU] Move into SIProgramInfo and cache getFunctionCodeSize. NFCI. #127111

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 3 additions & 23 deletions llvm/lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -748,7 +748,7 @@ bool AMDGPUAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
RI.getSymbol(CurrentFnSym->getName(), RIK::RIK_PrivateSegSize,
OutContext, IsLocal)
->getVariableValue(),
getFunctionCodeSize(MF), MFI);
CurrentProgramInfo.getFunctionCodeSize(MF), MFI);
return false;
}

Expand All @@ -757,7 +757,8 @@ bool AMDGPUAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
CurrentProgramInfo.NumArchVGPR,
STM.hasMAIInsts() ? CurrentProgramInfo.NumAccVGPR : nullptr,
CurrentProgramInfo.NumVGPR, CurrentProgramInfo.NumSGPR,
CurrentProgramInfo.ScratchSize, getFunctionCodeSize(MF), MFI);
CurrentProgramInfo.ScratchSize,
CurrentProgramInfo.getFunctionCodeSize(MF), MFI);

OutStreamer->emitRawComment(
" FloatMode: " + Twine(CurrentProgramInfo.FloatMode), false);
Expand Down Expand Up @@ -893,27 +894,6 @@ void AMDGPUAsmPrinter::initializeTargetID(const Module &M) {
}
}

uint64_t AMDGPUAsmPrinter::getFunctionCodeSize(const MachineFunction &MF) const {
const GCNSubtarget &STM = MF.getSubtarget<GCNSubtarget>();
const SIInstrInfo *TII = STM.getInstrInfo();

uint64_t CodeSize = 0;

for (const MachineBasicBlock &MBB : MF) {
for (const MachineInstr &MI : MBB) {
// TODO: CodeSize should account for multiple functions.

// TODO: Should we count size of debug info?
if (MI.isDebugInstr())
continue;

CodeSize += TII->getInstSizeInBytes(MI);
}
}

return CodeSize;
}

// AccumOffset computed for the MCExpr equivalent of:
// alignTo(std::max(1, NumVGPR), 4) / 4 - 1;
static const MCExpr *computeAccumOffset(const MCExpr *NumVGPR, MCContext &Ctx) {
Expand Down
2 changes: 0 additions & 2 deletions llvm/lib/Target/AMDGPU/AMDGPUAsmPrinter.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ class AMDGPUAsmPrinter final : public AsmPrinter {

MCCodeEmitter *DumpCodeInstEmitter = nullptr;

uint64_t getFunctionCodeSize(const MachineFunction &MF) const;

void getSIProgramInfo(SIProgramInfo &Out, const MachineFunction &MF);
void getAmdKernelCode(AMDGPU::AMDGPUMCKernelCodeT &Out,
const SIProgramInfo &KernelInfo,
Expand Down
27 changes: 27 additions & 0 deletions llvm/lib/Target/AMDGPU/SIProgramInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ void SIProgramInfo::reset(const MachineFunction &MF) {

const MCExpr *ZeroExpr = MCConstantExpr::create(0, Ctx);

CodeSizeInBytes.reset();

VGPRBlocks = ZeroExpr;
SGPRBlocks = ZeroExpr;
Priority = 0;
Expand Down Expand Up @@ -199,3 +201,28 @@ const MCExpr *SIProgramInfo::getPGMRSrc2(CallingConv::ID CC,

return MCConstantExpr::create(0, Ctx);
}

uint64_t SIProgramInfo::getFunctionCodeSize(const MachineFunction &MF) {
if (CodeSizeInBytes.has_value())
return *CodeSizeInBytes;

const GCNSubtarget &STM = MF.getSubtarget<GCNSubtarget>();
const SIInstrInfo *TII = STM.getInstrInfo();

uint64_t CodeSize = 0;

for (const MachineBasicBlock &MBB : MF) {
for (const MachineInstr &MI : MBB) {
// TODO: CodeSize should account for multiple functions.

// TODO: Should we count size of debug info?
if (MI.isDebugInstr())
continue;

CodeSize += TII->getInstSizeInBytes(MI);
}
}

CodeSizeInBytes = CodeSize;
return CodeSize;
}
6 changes: 6 additions & 0 deletions llvm/lib/Target/AMDGPU/SIProgramInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "llvm/IR/CallingConv.h"
#include "llvm/Support/Compiler.h"
#include <cstdint>
#include <optional>

namespace llvm {

Expand All @@ -29,6 +30,8 @@ class MachineFunction;

/// Track resource usage for kernels / entry functions.
struct LLVM_EXTERNAL_VISIBILITY SIProgramInfo {
std::optional<uint64_t> CodeSizeInBytes;

// Fields set in PGM_RSRC1 pm4 packet.
const MCExpr *VGPRBlocks = nullptr;
const MCExpr *SGPRBlocks = nullptr;
Expand Down Expand Up @@ -97,6 +100,9 @@ struct LLVM_EXTERNAL_VISIBILITY SIProgramInfo {
// non-MCExpr members.
void reset(const MachineFunction &MF);

// Get function code size and cache the value.
uint64_t getFunctionCodeSize(const MachineFunction &MF);

/// Compute the value of the ComputePGMRsrc1 register.
const MCExpr *getComputePGMRSrc1(const GCNSubtarget &ST,
MCContext &Ctx) const;
Expand Down