diff options
| author | Dimitry Andric <dim@FreeBSD.org> | 2025-12-06 19:56:45 +0000 |
|---|---|---|
| committer | Dimitry Andric <dim@FreeBSD.org> | 2025-12-06 20:08:43 +0000 |
| commit | 3f709e42e3be0f28a88ca3e77663a02b52c914f4 (patch) | |
| tree | 948796bf3bf7e164373caf6c31f9f128ca85fd8c /llvm/lib/Target/AMDGPU/SIProgramInfo.cpp | |
| parent | 32a711e1c447004eb1fd015925f305ed1d8426de (diff) | |
Diffstat (limited to 'llvm/lib/Target/AMDGPU/SIProgramInfo.cpp')
| -rw-r--r-- | llvm/lib/Target/AMDGPU/SIProgramInfo.cpp | 46 |
1 files changed, 45 insertions, 1 deletions
diff --git a/llvm/lib/Target/AMDGPU/SIProgramInfo.cpp b/llvm/lib/Target/AMDGPU/SIProgramInfo.cpp index 212edff09783..7093fe6405ab 100644 --- a/llvm/lib/Target/AMDGPU/SIProgramInfo.cpp +++ b/llvm/lib/Target/AMDGPU/SIProgramInfo.cpp @@ -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; @@ -37,6 +39,7 @@ void SIProgramInfo::reset(const MachineFunction &MF) { IEEEMode = 0; WgpMode = 0; MemOrdered = 0; + FwdProgress = 0; RrWgMode = 0; ScratchSize = ZeroExpr; @@ -55,7 +58,7 @@ void SIProgramInfo::reset(const MachineFunction &MF) { LdsSize = 0; EXCPEnable = 0; - ComputePGMRSrc3GFX90A = ZeroExpr; + ComputePGMRSrc3 = ZeroExpr; NumVGPR = ZeroExpr; NumArchVGPR = ZeroExpr; @@ -90,6 +93,10 @@ static uint64_t getComputePGMRSrc1Reg(const SIProgramInfo &ProgInfo, if (ST.hasIEEEMode()) Reg |= S_00B848_IEEE_MODE(ProgInfo.IEEEMode); + // TODO: in the long run we will want to enable this unconditionally. + if (ST.getTargetTriple().getOS() == Triple::OSType::AMDHSA) + Reg |= S_00B848_FWD_PROGRESS(ProgInfo.FwdProgress); + if (ST.hasRrWGMode()) Reg |= S_00B848_RR_WG_MODE(ProgInfo.RrWgMode); @@ -199,3 +206,40 @@ const MCExpr *SIProgramInfo::getPGMRSrc2(CallingConv::ID CC, return MCConstantExpr::create(0, Ctx); } + +uint64_t SIProgramInfo::getFunctionCodeSize(const MachineFunction &MF, + bool IsLowerBound) { + if (!IsLowerBound && 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) { + // The amount of padding to align code can be both underestimated and + // overestimated. In case of inline asm used getInstSizeInBytes() will + // return a maximum size of a single instruction, where the real size may + // differ. At this point CodeSize may be already off. + if (!IsLowerBound) + CodeSize = alignTo(CodeSize, MBB.getAlignment()); + + for (const MachineInstr &MI : MBB) { + // TODO: CodeSize should account for multiple functions. + + if (MI.isMetaInstruction()) + continue; + + // We cannot properly estimate inline asm size. It can be as small as zero + // if that is just a comment. + if (IsLowerBound && MI.isInlineAsm()) + continue; + + CodeSize += TII->getInstSizeInBytes(MI); + } + } + + CodeSizeInBytes = CodeSize; + return CodeSize; +} |
