26#define DEBUG_TYPE "wasm-fix-br-table-defaults"
32 return "WebAssembly Fix br_table Defaults";
42char WebAssemblyFixBrTableDefaults::ID = 0;
57 assert(
MI.getDesc().getOpcode() == WebAssembly::BR_TABLE_I64 &&
58 "64-bit br_table pseudo instruction expected");
62 if (ExtMI->getOpcode() == WebAssembly::I64_EXTEND_U_I32) {
65 assert(
MI.getOperand(0).getReg() == ExtDefReg);
66 MI.getOperand(0).setReg(ExtMI->getOperand(1).getReg());
69 ExtMI->eraseFromParent();
76 WST.getInstrInfo()->get(WebAssembly::I32_WRAP_I64), Reg32)
78 MI.getOperand(0).setReg(Reg32);
83 MI.setDesc(WST.getInstrInfo()->get(WebAssembly::BR_TABLE_I32));
104 assert(Analyzed &&
"Could not analyze jump header branches");
117 "Expected jump or fallthrough to br_table block");
118 assert(
Cond.size() == 2 &&
Cond[1].isReg() &&
"Unexpected condition info");
128 assert(RangeCheck !=
nullptr);
129 if (RangeCheck->getOpcode() != WebAssembly::GT_U_I32)
133 MI.removeOperand(
MI.getNumExplicitOperands() - 1);
143 HeaderMBB->removeSuccessor(
MBB);
145 if (HeaderMBB->isSuccessor(Succ))
146 HeaderMBB->removeSuccessor(Succ);
147 HeaderMBB->transferSuccessorsAndUpdatePHIs(
MBB);
155bool WebAssemblyFixBrTableDefaults::runOnMachineFunction(
MachineFunction &MF) {
156 LLVM_DEBUG(
dbgs() <<
"********** Fixing br_table Default Targets **********\n"
157 "********** Function: "
160 bool Changed =
false;
165 while (!MBBSet.
empty()) {
168 for (
auto &
MI : *
MBB) {
170 fixBrTableIndex(
MI,
MBB, MF);
172 if (
Fixed !=
nullptr) {
193 "Removes range checks and sets br_table default targets",
false,
197 return new WebAssemblyFixBrTableDefaults();
unsigned const MachineRegisterInfo * MRI
SmallVector< MachineOperand, 4 > Cond
const HexagonInstrInfo * TII
static unsigned getReg(const MCDisassembler *D, unsigned RC, unsigned RegNo)
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
const SmallVectorImpl< MachineOperand > MachineBasicBlock * TBB
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file provides WebAssembly-specific target descriptions.
This file contains the entry points for global functions defined in the LLVM WebAssembly back-end.
FunctionPass class - This class is used to implement most global optimizations.
unsigned removeBranch(MachineBasicBlock &MBB, int *BytesRemoved=nullptr) const override
Remove the branching code at the end of the specific MBB.
bool analyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB, MachineBasicBlock *&FBB, SmallVectorImpl< MachineOperand > &Cond, bool AllowModify) const override
Analyze the branching code at the end of MBB, returning true if it cannot be understood (e....
unsigned pred_size() const
pred_iterator pred_begin()
iterator_range< succ_iterator > successors()
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
virtual bool runOnMachineFunction(MachineFunction &MF)=0
runOnMachineFunction - This method must be overloaded to perform the desired machine code transformat...
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
StringRef getName() const
getName - Return the name of the corresponding LLVM function.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
void RenumberBlocks(MachineBasicBlock *MBBFrom=nullptr)
RenumberBlocks - This discards all of the MachineBasicBlock numbers and recomputes them.
void erase(iterator MBBI)
const MachineInstrBuilder & addReg(Register RegNo, unsigned flags=0, unsigned SubReg=0) const
Add a new virtual register operand.
Representation of each machine instruction.
const MachineOperand & getOperand(unsigned i) const
Register getReg() const
getReg - Returns the register number.
static MachineOperand CreateMBB(MachineBasicBlock *MBB, unsigned TargetFlags=0)
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
MachineInstr * getVRegDef(Register Reg) const
getVRegDef - Return the machine instr that defines the specified virtual register or null if none is ...
bool use_nodbg_empty(Register RegNo) const
use_nodbg_empty - Return true if there are no non-Debug instructions using the specified register.
Register createVirtualRegister(const TargetRegisterClass *RegClass, StringRef Name="")
createVirtualRegister - Create and return a new virtual register in the function with the specified r...
virtual StringRef getPassName() const
getPassName - Return a nice clean name for a pass.
Wrapper class representing virtual and physical registers.
bool erase(PtrType Ptr)
erase - If the set contains the specified pointer, remove it and return true, otherwise return false.
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringRef - Represent a constant reference to a string, i.e.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
bool isBrTable(const MachineInstr &MI)
This is an optimization pass for GlobalISel generic memory operations.
MachineInstrBuilder BuildMI(MachineFunction &MF, const MIMetadata &MIMD, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
FunctionPass * createWebAssemblyFixBrTableDefaults()
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.