Skip to content

Commit

Permalink
WebAssembly: Don't store MachineFunction in MachineFunctionInfo
Browse files Browse the repository at this point in the history
Soon it will be disallowed to depend on MachineFunction state in the
constructor. This was only being used to get the MachineRegisterInfo
for an assert, which I'm not sure is necessarily worth it. I would
think any missing defs would be caught by the verifier later instead.
  • Loading branch information
arsenm committed Jun 24, 2020
1 parent 457db40 commit c5d2400
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 21 deletions.
6 changes: 3 additions & 3 deletions llvm/lib/Target/WebAssembly/WebAssemblyExplicitLocals.cpp
Expand Up @@ -266,7 +266,7 @@ bool WebAssemblyExplicitLocals::runOnMachineFunction(MachineFunction &MF) {
BuildMI(MBB, &MI, MI.getDebugLoc(), TII->get(Opc), NewReg)
.addImm(LocalId);
MI.getOperand(2).setReg(NewReg);
MFI.stackifyVReg(NewReg);
MFI.stackifyVReg(MRI, NewReg);
}

// Replace the TEE with a LOCAL_TEE.
Expand Down Expand Up @@ -316,7 +316,7 @@ bool WebAssemblyExplicitLocals::runOnMachineFunction(MachineFunction &MF) {
// yet.
Def.setReg(NewReg);
Def.setIsDead(false);
MFI.stackifyVReg(NewReg);
MFI.stackifyVReg(MRI, NewReg);
Changed = true;
}
}
Expand Down Expand Up @@ -368,7 +368,7 @@ bool WebAssemblyExplicitLocals::runOnMachineFunction(MachineFunction &MF) {
BuildMI(MBB, InsertPt, MI.getDebugLoc(), TII->get(Opc), NewReg)
.addImm(LocalId);
MO.setReg(NewReg);
MFI.stackifyVReg(NewReg);
MFI.stackifyVReg(MRI, NewReg);
Changed = true;
}

Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Target/WebAssembly/WebAssemblyLowerBrUnless.cpp
Expand Up @@ -191,7 +191,7 @@ bool WebAssemblyLowerBrUnless::runOnMachineFunction(MachineFunction &MF) {
Register Tmp = MRI.createVirtualRegister(&WebAssembly::I32RegClass);
BuildMI(MBB, MI, MI->getDebugLoc(), TII.get(WebAssembly::EQZ_I32), Tmp)
.addReg(Cond);
MFI.stackifyVReg(Tmp);
MFI.stackifyVReg(MRI, Tmp);
Cond = Tmp;
Inverted = true;
}
Expand Down
Expand Up @@ -21,10 +21,10 @@ using namespace llvm;

WebAssemblyFunctionInfo::~WebAssemblyFunctionInfo() = default; // anchor.

void WebAssemblyFunctionInfo::initWARegs() {
void WebAssemblyFunctionInfo::initWARegs(MachineRegisterInfo &MRI) {
assert(WARegs.empty());
unsigned Reg = UnusedReg;
WARegs.resize(MF.getRegInfo().getNumVirtRegs(), Reg);
WARegs.resize(MRI.getNumVirtRegs(), Reg);
}

void llvm::computeLegalValueVTs(const Function &F, const TargetMachine &TM,
Expand Down
10 changes: 4 additions & 6 deletions llvm/lib/Target/WebAssembly/WebAssemblyMachineFunctionInfo.h
Expand Up @@ -30,8 +30,6 @@ struct WebAssemblyFunctionInfo;
/// This class is derived from MachineFunctionInfo and contains private
/// WebAssembly-specific information for each MachineFunction.
class WebAssemblyFunctionInfo final : public MachineFunctionInfo {
MachineFunction &MF;

std::vector<MVT> Params;
std::vector<MVT> Results;
std::vector<MVT> Locals;
Expand Down Expand Up @@ -66,7 +64,7 @@ class WebAssemblyFunctionInfo final : public MachineFunctionInfo {
bool CFGStackified = false;

public:
explicit WebAssemblyFunctionInfo(MachineFunction &MF) : MF(MF) {}
explicit WebAssemblyFunctionInfo(MachineFunction &MF) {}
~WebAssemblyFunctionInfo() override;
void initializeBaseYamlFields(const yaml::WebAssemblyFunctionInfo &YamlMFI);

Expand Down Expand Up @@ -113,8 +111,8 @@ class WebAssemblyFunctionInfo final : public MachineFunctionInfo {

static const unsigned UnusedReg = -1u;

void stackifyVReg(unsigned VReg) {
assert(MF.getRegInfo().getUniqueVRegDef(VReg));
void stackifyVReg(MachineRegisterInfo &MRI, unsigned VReg) {
assert(MRI.getUniqueVRegDef(VReg));
auto I = Register::virtReg2Index(VReg);
if (I >= VRegStackified.size())
VRegStackified.resize(I + 1);
Expand All @@ -132,7 +130,7 @@ class WebAssemblyFunctionInfo final : public MachineFunctionInfo {
return VRegStackified.test(I);
}

void initWARegs();
void initWARegs(MachineRegisterInfo &MRI);
void setWAReg(unsigned VReg, unsigned WAReg) {
assert(WAReg != UnusedReg);
auto I = Register::virtReg2Index(VReg);
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/Target/WebAssembly/WebAssemblyPeephole.cpp
Expand Up @@ -66,7 +66,7 @@ static bool maybeRewriteToDrop(unsigned OldReg, unsigned NewReg,
Register NewReg = MRI.createVirtualRegister(MRI.getRegClass(OldReg));
MO.setReg(NewReg);
MO.setIsDead();
MFI.stackifyVReg(NewReg);
MFI.stackifyVReg(MRI, NewReg);
}
return Changed;
}
Expand Down Expand Up @@ -121,7 +121,7 @@ static bool maybeRewriteToFallthrough(MachineInstr &MI, MachineBasicBlock &MBB,
BuildMI(MBB, MI, MI.getDebugLoc(), TII.get(CopyLocalOpc), NewReg)
.addReg(Reg);
MO.setReg(NewReg);
MFI.stackifyVReg(NewReg);
MFI.stackifyVReg(MRI, NewReg);
}
}

Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Target/WebAssembly/WebAssemblyRegNumbering.cpp
Expand Up @@ -66,7 +66,7 @@ bool WebAssemblyRegNumbering::runOnMachineFunction(MachineFunction &MF) {
WebAssemblyFunctionInfo &MFI = *MF.getInfo<WebAssemblyFunctionInfo>();
MachineRegisterInfo &MRI = MF.getRegInfo();

MFI.initWARegs();
MFI.initWARegs(MRI);

// WebAssembly argument registers are in the same index space as local
// variables. Assign the numbers for them first.
Expand Down
12 changes: 6 additions & 6 deletions llvm/lib/Target/WebAssembly/WebAssemblyRegStackify.cpp
Expand Up @@ -530,7 +530,7 @@ static MachineInstr *moveForSingleUse(unsigned Reg, MachineOperand &Op,
if (MRI.hasOneDef(Reg) && MRI.hasOneUse(Reg)) {
// No one else is using this register for anything so we can just stackify
// it in place.
MFI.stackifyVReg(Reg);
MFI.stackifyVReg(MRI, Reg);
} else {
// The register may have unrelated uses or defs; create a new register for
// just our one def and use so that we can stackify it.
Expand All @@ -547,7 +547,7 @@ static MachineInstr *moveForSingleUse(unsigned Reg, MachineOperand &Op,
LIS.getInstructionIndex(*Op.getParent()).getRegSlot(),
/*RemoveDeadValNo=*/true);

MFI.stackifyVReg(NewReg);
MFI.stackifyVReg(MRI, NewReg);

DefDIs.updateReg(NewReg);

Expand Down Expand Up @@ -576,7 +576,7 @@ static MachineInstr *rematerializeCheapDef(
MachineInstr *Clone = &*std::prev(Insert);
LIS.InsertMachineInstrInMaps(*Clone);
LIS.createAndComputeVirtRegInterval(NewReg);
MFI.stackifyVReg(NewReg);
MFI.stackifyVReg(MRI, NewReg);
imposeStackOrdering(Clone);

LLVM_DEBUG(dbgs() << " - Cloned to "; Clone->dump());
Expand Down Expand Up @@ -667,8 +667,8 @@ static MachineInstr *moveAndTeeForMultiUse(
// Finish stackifying the new regs.
LIS.createAndComputeVirtRegInterval(TeeReg);
LIS.createAndComputeVirtRegInterval(DefReg);
MFI.stackifyVReg(DefReg);
MFI.stackifyVReg(TeeReg);
MFI.stackifyVReg(MRI, DefReg);
MFI.stackifyVReg(MRI, TeeReg);
imposeStackOrdering(Def);
imposeStackOrdering(Tee);

Expand Down Expand Up @@ -934,7 +934,7 @@ bool WebAssemblyRegStackify::runOnMachineFunction(MachineFunction &MF) {
// TODO: This single-use restriction could be relaxed by using tees
if (DefReg != UseReg || !MRI.hasOneUse(DefReg))
break;
MFI.stackifyVReg(DefReg);
MFI.stackifyVReg(MRI, DefReg);
++SubsequentDef;
++SubsequentUse;
}
Expand Down

0 comments on commit c5d2400

Please sign in to comment.