28 #define DEBUG_TYPE "wasm-lower-br_unless" 33 return "WebAssembly Lower br_unless";
51 "Lowers br_unless into inverted br_if",
false,
false)
54 return new WebAssemblyLowerBrUnless();
57 bool WebAssemblyLowerBrUnless::runOnMachineFunction(
MachineFunction &MF) {
59 "********** Function: " 66 for (
auto &MBB : MF) {
67 for (
auto MII = MBB.begin(); MII != MBB.end();) {
69 if (MI->
getOpcode() != WebAssembly::BR_UNLESS)
73 bool Inverted =
false;
76 if (MFI.isVRegStackified(Cond)) {
79 switch (Def->getOpcode()) {
80 using namespace WebAssembly;
81 case EQ_I32: Def->setDesc(TII.get(NE_I32)); Inverted =
true;
break;
82 case NE_I32: Def->setDesc(TII.get(EQ_I32)); Inverted =
true;
break;
83 case GT_S_I32: Def->setDesc(TII.get(LE_S_I32)); Inverted =
true;
break;
84 case GE_S_I32: Def->setDesc(TII.get(LT_S_I32)); Inverted =
true;
break;
85 case LT_S_I32: Def->setDesc(TII.get(GE_S_I32)); Inverted =
true;
break;
86 case LE_S_I32: Def->setDesc(TII.get(GT_S_I32)); Inverted =
true;
break;
87 case GT_U_I32: Def->setDesc(TII.get(LE_U_I32)); Inverted =
true;
break;
88 case GE_U_I32: Def->setDesc(TII.get(LT_U_I32)); Inverted =
true;
break;
89 case LT_U_I32: Def->setDesc(TII.get(GE_U_I32)); Inverted =
true;
break;
90 case LE_U_I32: Def->setDesc(TII.get(GT_U_I32)); Inverted =
true;
break;
91 case EQ_I64: Def->setDesc(TII.get(NE_I64)); Inverted =
true;
break;
92 case NE_I64: Def->setDesc(TII.get(EQ_I64)); Inverted =
true;
break;
93 case GT_S_I64: Def->setDesc(TII.get(LE_S_I64)); Inverted =
true;
break;
94 case GE_S_I64: Def->setDesc(TII.get(LT_S_I64)); Inverted =
true;
break;
95 case LT_S_I64: Def->setDesc(TII.get(GE_S_I64)); Inverted =
true;
break;
96 case LE_S_I64: Def->setDesc(TII.get(GT_S_I64)); Inverted =
true;
break;
97 case GT_U_I64: Def->setDesc(TII.get(LE_U_I64)); Inverted =
true;
break;
98 case GE_U_I64: Def->setDesc(TII.get(LT_U_I64)); Inverted =
true;
break;
99 case LT_U_I64: Def->setDesc(TII.get(GE_U_I64)); Inverted =
true;
break;
100 case LE_U_I64: Def->setDesc(TII.get(GT_U_I64)); Inverted =
true;
break;
101 case EQ_F32: Def->setDesc(TII.get(NE_F32)); Inverted =
true;
break;
102 case NE_F32: Def->setDesc(TII.get(EQ_F32)); Inverted =
true;
break;
103 case EQ_F64: Def->setDesc(TII.get(NE_F64)); Inverted =
true;
break;
104 case NE_F64: Def->setDesc(TII.get(EQ_F64)); Inverted =
true;
break;
107 Cond = Def->getOperand(1).getReg();
108 Def->eraseFromParent();
119 unsigned Tmp =
MRI.createVirtualRegister(&WebAssembly::I32RegClass);
122 MFI.stackifyVReg(Tmp);
FunctionPass * createWebAssemblyLowerBrUnless()
Compute iterated dominance frontiers using a linear time algorithm.
const DebugLoc & getDebugLoc() const
Returns the debug location id of this MachineInstr.
unsigned getReg() const
getReg - Returns the register number.
This file contains the entry points for global functions defined in the LLVM WebAssembly back-end...
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
const HexagonInstrInfo * TII
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
StringRef getName() const
getName - Return the name of the corresponding LLVM function.
MachineInstrBuilder BuildMI(MachineFunction &MF, const DebugLoc &DL, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
unsigned const MachineRegisterInfo * MRI
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
This file provides WebAssembly-specific target descriptions.
Represent the analysis usage information of a pass.
Ty * getInfo()
getInfo - Keep track of various per-function pieces of information for backends that would like to do...
FunctionPass class - This class is used to implement most global optimizations.
This file declares the WebAssembly-specific subclass of TargetSubtarget.
void setPreservesCFG()
This function should be called by the pass, iff they do not:
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Representation of each machine instruction.
This class is derived from MachineFunctionInfo and contains private WebAssembly-specific information ...
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
INITIALIZE_PASS(WebAssemblyLowerBrUnless, DEBUG_TYPE, "Lowers br_unless into inverted br_if", false, false) FunctionPass *llvm
This file declares WebAssembly-specific per-machine-function information.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
StringRef - Represent a constant reference to a string, i.e.
const MachineOperand & getOperand(unsigned i) const