forked from OSchip/llvm-project
[WebAssembly][NFC] Consolidate TargetRegisterClass=>COPY opcode conversion into a single helper
Previously WebAssemblyCFGStackify, WebAssemblyInstrInfo, and WebAssemblyPeephole all had equivalent logic for this. Move it into a common helper in WebAssemblyUtilities.
This commit is contained in:
parent
20962c1240
commit
beec3e8cb1
|
@ -179,3 +179,25 @@ MachineInstr *WebAssembly::findCatch(MachineBasicBlock *EHPad) {
|
|||
return &*Pos;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
unsigned WebAssembly::getCopyOpcodeForRegClass(const TargetRegisterClass *RC) {
|
||||
assert(RC != nullptr);
|
||||
switch (RC->getID()) {
|
||||
case WebAssembly::I32RegClassID:
|
||||
return WebAssembly::COPY_I32;
|
||||
case WebAssembly::I64RegClassID:
|
||||
return WebAssembly::COPY_I64;
|
||||
case WebAssembly::F32RegClassID:
|
||||
return WebAssembly::COPY_F32;
|
||||
case WebAssembly::F64RegClassID:
|
||||
return WebAssembly::COPY_F64;
|
||||
case WebAssembly::V128RegClassID:
|
||||
return WebAssembly::COPY_V128;
|
||||
case WebAssembly::FUNCREFRegClassID:
|
||||
return WebAssembly::COPY_FUNCREF;
|
||||
case WebAssembly::EXTERNREFRegClassID:
|
||||
return WebAssembly::COPY_EXTERNREF;
|
||||
default:
|
||||
llvm_unreachable("Unexpected register class");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,6 +24,7 @@ class MachineInstr;
|
|||
class MachineOperand;
|
||||
class MCContext;
|
||||
class MCSymbolWasm;
|
||||
class TargetRegisterClass;
|
||||
class WebAssemblyFunctionInfo;
|
||||
class WebAssemblySubtarget;
|
||||
|
||||
|
@ -65,6 +66,9 @@ getOrCreateFuncrefCallTableSymbol(MCContext &Ctx,
|
|||
/// instruction found or the catch is in an invalid location.
|
||||
MachineInstr *findCatch(MachineBasicBlock *EHPad);
|
||||
|
||||
/// Returns the appropriate copy opcode for the given register class.
|
||||
unsigned getCopyOpcodeForRegClass(const TargetRegisterClass *RC);
|
||||
|
||||
} // end namespace WebAssembly
|
||||
|
||||
} // end namespace llvm
|
||||
|
|
|
@ -781,25 +781,6 @@ void WebAssemblyCFGStackify::removeUnnecessaryInstrs(MachineFunction &MF) {
|
|||
}
|
||||
}
|
||||
|
||||
// Get the appropriate copy opcode for the given register class.
|
||||
static unsigned getCopyOpcode(const TargetRegisterClass *RC) {
|
||||
if (RC == &WebAssembly::I32RegClass)
|
||||
return WebAssembly::COPY_I32;
|
||||
if (RC == &WebAssembly::I64RegClass)
|
||||
return WebAssembly::COPY_I64;
|
||||
if (RC == &WebAssembly::F32RegClass)
|
||||
return WebAssembly::COPY_F32;
|
||||
if (RC == &WebAssembly::F64RegClass)
|
||||
return WebAssembly::COPY_F64;
|
||||
if (RC == &WebAssembly::V128RegClass)
|
||||
return WebAssembly::COPY_V128;
|
||||
if (RC == &WebAssembly::FUNCREFRegClass)
|
||||
return WebAssembly::COPY_FUNCREF;
|
||||
if (RC == &WebAssembly::EXTERNREFRegClass)
|
||||
return WebAssembly::COPY_EXTERNREF;
|
||||
llvm_unreachable("Unexpected register class");
|
||||
}
|
||||
|
||||
// When MBB is split into MBB and Split, we should unstackify defs in MBB that
|
||||
// have their uses in Split.
|
||||
static void unstackifyVRegsUsedInSplitBB(MachineBasicBlock &MBB,
|
||||
|
@ -851,7 +832,8 @@ static void unstackifyVRegsUsedInSplitBB(MachineBasicBlock &MBB,
|
|||
if (!MFI.isVRegStackified(TeeReg)) {
|
||||
// Now we are not using TEE anymore, so unstackify DefReg too
|
||||
MFI.unstackifyVReg(DefReg);
|
||||
unsigned CopyOpc = getCopyOpcode(MRI.getRegClass(DefReg));
|
||||
unsigned CopyOpc =
|
||||
WebAssembly::getCopyOpcodeForRegClass(MRI.getRegClass(DefReg));
|
||||
BuildMI(MBB, &MI, MI.getDebugLoc(), TII.get(CopyOpc), TeeReg)
|
||||
.addReg(DefReg);
|
||||
BuildMI(MBB, &MI, MI.getDebugLoc(), TII.get(CopyOpc), Reg).addReg(DefReg);
|
||||
|
|
|
@ -66,23 +66,7 @@ void WebAssemblyInstrInfo::copyPhysReg(MachineBasicBlock &MBB,
|
|||
? MRI.getRegClass(DestReg)
|
||||
: MRI.getTargetRegisterInfo()->getMinimalPhysRegClass(DestReg);
|
||||
|
||||
unsigned CopyOpcode;
|
||||
if (RC == &WebAssembly::I32RegClass)
|
||||
CopyOpcode = WebAssembly::COPY_I32;
|
||||
else if (RC == &WebAssembly::I64RegClass)
|
||||
CopyOpcode = WebAssembly::COPY_I64;
|
||||
else if (RC == &WebAssembly::F32RegClass)
|
||||
CopyOpcode = WebAssembly::COPY_F32;
|
||||
else if (RC == &WebAssembly::F64RegClass)
|
||||
CopyOpcode = WebAssembly::COPY_F64;
|
||||
else if (RC == &WebAssembly::V128RegClass)
|
||||
CopyOpcode = WebAssembly::COPY_V128;
|
||||
else if (RC == &WebAssembly::FUNCREFRegClass)
|
||||
CopyOpcode = WebAssembly::COPY_FUNCREF;
|
||||
else if (RC == &WebAssembly::EXTERNREFRegClass)
|
||||
CopyOpcode = WebAssembly::COPY_EXTERNREF;
|
||||
else
|
||||
llvm_unreachable("Unexpected register class");
|
||||
unsigned CopyOpcode = WebAssembly::getCopyOpcodeForRegClass(RC);
|
||||
|
||||
BuildMI(MBB, I, DL, get(CopyOpcode), DestReg)
|
||||
.addReg(SrcReg, KillSrc ? RegState::Kill : 0);
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "MCTargetDesc/WebAssemblyMCTargetDesc.h"
|
||||
#include "Utils/WebAssemblyUtilities.h"
|
||||
#include "WebAssembly.h"
|
||||
#include "WebAssemblyMachineFunctionInfo.h"
|
||||
#include "WebAssemblySubtarget.h"
|
||||
|
@ -95,31 +96,7 @@ static bool maybeRewriteToFallthrough(MachineInstr &MI, MachineBasicBlock &MBB,
|
|||
if (!MFI.isVRegStackified(Reg)) {
|
||||
unsigned CopyLocalOpc;
|
||||
const TargetRegisterClass *RegClass = MRI.getRegClass(Reg);
|
||||
switch (RegClass->getID()) {
|
||||
case WebAssembly::I32RegClassID:
|
||||
CopyLocalOpc = WebAssembly::COPY_I32;
|
||||
break;
|
||||
case WebAssembly::I64RegClassID:
|
||||
CopyLocalOpc = WebAssembly::COPY_I64;
|
||||
break;
|
||||
case WebAssembly::F32RegClassID:
|
||||
CopyLocalOpc = WebAssembly::COPY_F32;
|
||||
break;
|
||||
case WebAssembly::F64RegClassID:
|
||||
CopyLocalOpc = WebAssembly::COPY_F64;
|
||||
break;
|
||||
case WebAssembly::V128RegClassID:
|
||||
CopyLocalOpc = WebAssembly::COPY_V128;
|
||||
break;
|
||||
case WebAssembly::FUNCREFRegClassID:
|
||||
CopyLocalOpc = WebAssembly::COPY_FUNCREF;
|
||||
break;
|
||||
case WebAssembly::EXTERNREFRegClassID:
|
||||
CopyLocalOpc = WebAssembly::COPY_EXTERNREF;
|
||||
break;
|
||||
default:
|
||||
llvm_unreachable("Unexpected register class for return operand");
|
||||
}
|
||||
CopyLocalOpc = WebAssembly::getCopyOpcodeForRegClass(RegClass);
|
||||
Register NewReg = MRI.createVirtualRegister(RegClass);
|
||||
BuildMI(MBB, MI, MI.getDebugLoc(), TII.get(CopyLocalOpc), NewReg)
|
||||
.addReg(Reg);
|
||||
|
|
Loading…
Reference in New Issue