Skip to content

Commit 99b5a59

Browse files
committed
[AMDGPU] Switch to MF.estimateFunctionSizeInBytes()
Both methods are equally inaccurate, we need to switch to MCExpr for better results in the future.
1 parent eb3ece0 commit 99b5a59

File tree

3 files changed

+6
-24
lines changed

3 files changed

+6
-24
lines changed

llvm/lib/Target/AMDGPU/SIInstrInfo.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8978,7 +8978,7 @@ unsigned SIInstrInfo::getInstSizeInBytes(const MachineInstr &MI) const {
89788978
return getInlineAsmLength(AsmStr, *MF->getTarget().getMCAsmInfo(), &ST);
89798979
}
89808980
default:
8981-
if (MI.isMetaInstruction())
8981+
if (MI.isMetaInstruction() || MI.isDebugInstr())
89828982
return 0;
89838983
return DescSize;
89848984
}

llvm/lib/Target/AMDGPU/SIProgramInfo.cpp

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -202,27 +202,9 @@ const MCExpr *SIProgramInfo::getPGMRSrc2(CallingConv::ID CC,
202202
return MCConstantExpr::create(0, Ctx);
203203
}
204204

205-
uint64_t SIProgramInfo::getFunctionCodeSize(const MachineFunction &MF) {
206-
if (CodeSizeInBytes.has_value())
207-
return *CodeSizeInBytes;
205+
uint64_t SIProgramInfo::getFunctionCodeSize(MachineFunction &MF) {
206+
if (!CodeSizeInBytes.has_value())
207+
CodeSizeInBytes = MF.estimateFunctionSizeInBytes();
208208

209-
const GCNSubtarget &STM = MF.getSubtarget<GCNSubtarget>();
210-
const SIInstrInfo *TII = STM.getInstrInfo();
211-
212-
uint64_t CodeSize = 0;
213-
214-
for (const MachineBasicBlock &MBB : MF) {
215-
for (const MachineInstr &MI : MBB) {
216-
// TODO: CodeSize should account for multiple functions.
217-
218-
// TODO: Should we count size of debug info?
219-
if (MI.isDebugInstr())
220-
continue;
221-
222-
CodeSize += TII->getInstSizeInBytes(MI);
223-
}
224-
}
225-
226-
CodeSizeInBytes = CodeSize;
227-
return CodeSize;
209+
return *CodeSizeInBytes;
228210
}

llvm/lib/Target/AMDGPU/SIProgramInfo.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ struct LLVM_EXTERNAL_VISIBILITY SIProgramInfo {
101101
void reset(const MachineFunction &MF);
102102

103103
// Get function code size and cache the value.
104-
uint64_t getFunctionCodeSize(const MachineFunction &MF);
104+
uint64_t getFunctionCodeSize(MachineFunction &MF);
105105

106106
/// Compute the value of the ComputePGMRsrc1 register.
107107
const MCExpr *getComputePGMRSrc1(const GCNSubtarget &ST,

0 commit comments

Comments
 (0)