Skip to content

Commit

Permalink
Fix size calculations
Browse files Browse the repository at this point in the history
Previously, they weren't calculating branches and LEAs correctly
  • Loading branch information
ammrat13 committed May 12, 2023
1 parent 2543c28 commit f8f7941
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
9 changes: 6 additions & 3 deletions llvm/lib/Target/LC32/LC32FrameLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,12 @@ static unsigned EstimateFunctionSize(const MachineFunction &MF,
// later, so over-estimate their size for the purposes of register
// scavenging.
if (MI.getOpcode() == LC32::BR)
ret += 16;
else if (MI.getOpcode() == LC32::C_BR_CMP_ZERO)
ret += 18;

// Otherwise, handle normally
ret += TII.getInstSizeInBytes(MI);
else
ret += TII.getInstSizeInBytes(MI);
}
}
return ret;
Expand All @@ -154,7 +156,8 @@ void LC32FrameLowering::processFunctionBeforeFrameFinalized(

// Count the number of scavenging slots we need:
// 1. if the stack frame is too large. This is an underestimate, so compensate
// 2. if branches can be out of range
// 2. if branches can be out of range. This is an overestimate, but we still
// make contingency space.
unsigned num_scav = 0;
if (!isInt<6 - 1>(MFI.estimateStackSize(MF)))
num_scav++;
Expand Down
3 changes: 3 additions & 0 deletions llvm/lib/Target/LC32/LC32InstrInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ unsigned LC32InstrInfo::getInstSizeInBytes(const MachineInstr &MI) const {
// compiler, while JSR is handled in the assembler.
if (d_op == LC32::JSR)
return this->get(LC32::P_FARJSR).getSize();
// Same for LEA
if (d_op == LC32::LEA)
return this->get(LC32::P_LOADCONSTW).getSize();

return d.getSize();
}
Expand Down

0 comments on commit f8f7941

Please sign in to comment.