mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2025-03-07 11:59:09 +00:00
[WebAssembly] Fix RegNumbering for the stack pointer
Previously it failed to add NumArgRegs to the offset and so clobbered an already-used register. Now just start the numbering after the arg regs and don't duplicate the add. Test coverage for this coming shortly with the implementation of byval. llvm-svn: 258597
This commit is contained in:
parent
548cef831b
commit
0558165991
@ -74,6 +74,8 @@ bool WebAssemblyRegNumbering::runOnMachineFunction(MachineFunction &MF) {
|
||||
case WebAssembly::ARGUMENT_I64:
|
||||
case WebAssembly::ARGUMENT_F32:
|
||||
case WebAssembly::ARGUMENT_F64:
|
||||
DEBUG(dbgs() << "Arg VReg " << MI.getOperand(0).getReg() << " -> WAReg "
|
||||
<< MI.getOperand(1).getImm() << "\n");
|
||||
MFI.setWAReg(MI.getOperand(0).getReg(), MI.getOperand(1).getImm());
|
||||
break;
|
||||
default:
|
||||
@ -84,26 +86,32 @@ bool WebAssemblyRegNumbering::runOnMachineFunction(MachineFunction &MF) {
|
||||
// Then assign regular WebAssembly registers for all remaining used
|
||||
// virtual registers. TODO: Consider sorting the registers by frequency of
|
||||
// use, to maximize usage of small immediate fields.
|
||||
unsigned NumArgRegs = MFI.getParams().size();
|
||||
unsigned NumVRegs = MF.getRegInfo().getNumVirtRegs();
|
||||
unsigned NumStackRegs = 0;
|
||||
unsigned CurReg = 0;
|
||||
// Start the numbering for locals after the arg regs
|
||||
unsigned CurReg = MFI.getParams().size();
|
||||
for (unsigned VRegIdx = 0; VRegIdx < NumVRegs; ++VRegIdx) {
|
||||
unsigned VReg = TargetRegisterInfo::index2VirtReg(VRegIdx);
|
||||
// Handle stackified registers.
|
||||
if (MFI.isVRegStackified(VReg)) {
|
||||
DEBUG(dbgs() << "VReg " << VReg << " -> WAReg "
|
||||
<< (INT32_MIN | NumStackRegs) << "\n");
|
||||
MFI.setWAReg(VReg, INT32_MIN | NumStackRegs++);
|
||||
continue;
|
||||
}
|
||||
// Skip unused registers.
|
||||
if (MRI.use_empty(VReg))
|
||||
continue;
|
||||
if (MFI.getWAReg(VReg) == WebAssemblyFunctionInfo::UnusedReg)
|
||||
MFI.setWAReg(VReg, NumArgRegs + CurReg++);
|
||||
if (MFI.getWAReg(VReg) == WebAssemblyFunctionInfo::UnusedReg) {
|
||||
DEBUG(dbgs() << "VReg " << VReg << " -> WAReg " << CurReg << "\n");
|
||||
MFI.setWAReg(VReg, CurReg++);
|
||||
}
|
||||
}
|
||||
// Allocate locals for used physical registers
|
||||
if (FrameInfo.getStackSize() > 0)
|
||||
if (FrameInfo.getStackSize() > 0) {
|
||||
DEBUG(dbgs() << "PReg SP " << CurReg << "\n");
|
||||
MFI.addPReg(WebAssembly::SP32, CurReg++);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user