27#define DEBUG_TYPE "wasm-fix-br-table-defaults"
33 return "WebAssembly Fix br_table Defaults";
43char WebAssemblyFixBrTableDefaults::ID = 0;
58 assert(
MI.getDesc().getOpcode() == WebAssembly::BR_TABLE_I64 &&
59 "64-bit br_table pseudo instruction expected");
63 if (ExtMI->getOpcode() == WebAssembly::I64_EXTEND_U_I32) {
66 assert(
MI.getOperand(0).getReg() == ExtDefReg);
67 MI.getOperand(0).setReg(ExtMI->getOperand(1).getReg());
70 ExtMI->eraseFromParent();
77 WST.getInstrInfo()->get(WebAssembly::I32_WRAP_I64), Reg32)
79 MI.getOperand(0).setReg(Reg32);
84 MI.setDesc(WST.getInstrInfo()->get(WebAssembly::BR_TABLE_I32));
105 assert(Analyzed &&
"Could not analyze jump header branches");
118 "Expected jump or fallthrough to br_table block");
119 assert(
Cond.size() == 2 &&
Cond[1].isReg() &&
"Unexpected condition info");
129 assert(RangeCheck !=
nullptr);
130 if (RangeCheck->getOpcode() != WebAssembly::GT_U_I32)
134 MI.removeOperand(
MI.getNumExplicitOperands() - 1);
144 HeaderMBB->removeSuccessor(
MBB);
146 if (HeaderMBB->isSuccessor(Succ))
147 HeaderMBB->removeSuccessor(Succ);
148 HeaderMBB->transferSuccessorsAndUpdatePHIs(
MBB);
156bool WebAssemblyFixBrTableDefaults::runOnMachineFunction(
MachineFunction &MF) {
157 LLVM_DEBUG(
dbgs() <<
"********** Fixing br_table Default Targets **********\n"
158 "********** Function: "
161 bool Changed =
false;
168 while (!MBBSet.
empty()) {
171 for (
auto &
MI : *
MBB) {
173 fixBrTableIndex(
MI,
MBB, MF);
175 if (
Fixed !=
nullptr) {
196 "Removes range checks and sets br_table default targets",
false,
200 return new WebAssemblyFixBrTableDefaults();
unsigned const MachineRegisterInfo * MRI
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
const SmallVectorImpl< MachineOperand > & Cond
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file provides WebAssembly-specific target descriptions.
This file declares the WebAssembly-specific subclass of TargetSubtarget.
This file contains the entry points for global functions defined in the LLVM WebAssembly back-end.
Implements a dense probed hash-table based set.
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.
A vector that has set insertion semantics.
bool remove(const value_type &X)
Remove an item from the set vector.
bool empty() const
Determine if the SetVector is empty or not.
iterator begin()
Get an iterator to the beginning of the SetVector.
bool insert(const value_type &X)
Insert a new element into the SetVector.
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(unsigned Opc)
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.