Skip to content

Commit

Permalink
[WebAssembly] Fixed FrameBaseLocal not being set.
Browse files Browse the repository at this point in the history
Summary:
Fixes: https://bugs.llvm.org/show_bug.cgi?id=44920

WebAssemblyRegColoring may merge the vreg that currently represents
the FrameBase with one representing an argument.
WebAssemblyExplicitLocals picks up the corresponding local when
a vreg is first added to the Reg2Local mapping, except when it is
an argument instruction which are handled separately.

Note that this does not change that vregs representing the FrameBase
may get merged, it is not clear to me that this may have other
effects we may want to avoid?

Reviewers: dschuff

Reviewed By: dschuff

Subscribers: azakai, sbc100, hiraditya, aheejin, sunfish, llvm-commits, jgravelle-google

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D75718
  • Loading branch information
aardappel committed Mar 10, 2020
1 parent 77eec38 commit a7a3751
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions llvm/lib/Target/WebAssembly/WebAssemblyExplicitLocals.cpp
Expand Up @@ -69,21 +69,26 @@ FunctionPass *llvm::createWebAssemblyExplicitLocals() {
return new WebAssemblyExplicitLocals();
}

static void checkFrameBase(WebAssemblyFunctionInfo &MFI, unsigned Local,
unsigned Reg) {
// Mark a local for the frame base vreg.
if (MFI.isFrameBaseVirtual() && Reg == MFI.getFrameBaseVreg()) {
LLVM_DEBUG({
dbgs() << "Allocating local " << Local << "for VReg "
<< Register::virtReg2Index(Reg) << '\n';
});
MFI.setFrameBaseLocal(Local);
}
}

/// Return a local id number for the given register, assigning it a new one
/// if it doesn't yet have one.
static unsigned getLocalId(DenseMap<unsigned, unsigned> &Reg2Local,
WebAssemblyFunctionInfo &MFI, unsigned &CurLocal,
unsigned Reg) {
auto P = Reg2Local.insert(std::make_pair(Reg, CurLocal));
if (P.second) {
// Mark the local allocated for the frame base vreg.
if (MFI.isFrameBaseVirtual() && Reg == MFI.getFrameBaseVreg()) {
LLVM_DEBUG({
dbgs() << "Allocating local " << CurLocal << "for VReg "
<< Register::virtReg2Index(Reg) << '\n';
});
MFI.setFrameBaseLocal(CurLocal);
}
checkFrameBase(MFI, CurLocal, Reg);
++CurLocal;
}
return P.first->second;
Expand Down Expand Up @@ -227,7 +232,9 @@ bool WebAssemblyExplicitLocals::runOnMachineFunction(MachineFunction &MF) {
break;
Register Reg = MI.getOperand(0).getReg();
assert(!MFI.isVRegStackified(Reg));
Reg2Local[Reg] = static_cast<unsigned>(MI.getOperand(1).getImm());
auto Local = static_cast<unsigned>(MI.getOperand(1).getImm());
Reg2Local[Reg] = Local;
checkFrameBase(MFI, Local, Reg);
MI.eraseFromParent();
Changed = true;
}
Expand Down

0 comments on commit a7a3751

Please sign in to comment.