25 #define DEBUG_TYPE "wasm-peephole"
28 "disable-wasm-fallthrough-return-opt",
cl::Hidden,
29 cl::desc(
"WebAssembly: Disable fallthrough-return optimizations."),
35 return "WebAssembly late peephole optimizer";
54 return new WebAssemblyPeephole();
62 if (OldReg == NewReg) {
77 unsigned FallthroughOpc,
78 unsigned CopyLocalOpc) {
81 if (&MBB != &MF.
back())
83 if (&MI != &MBB.
back())
99 MI.
setDesc(TII.get(FallthroughOpc));
105 dbgs() <<
"********** Peephole **********\n"
106 <<
"********** Function: " << MF.
getName() <<
'\n';
114 auto &LibInfo = getAnalysis<TargetLibraryInfoWrapperPass>().getTLI();
115 bool Changed =
false;
119 switch (
MI.getOpcode()) {
122 case WebAssembly::CALL_I32:
123 case WebAssembly::CALL_I64: {
131 if (LibInfo.getLibFunc(
Name, Func)) {
132 const auto &Op2 =
MI.getOperand(2);
135 "wrong signature, not consuming reg");
137 unsigned OldReg = MO.
getReg();
138 unsigned NewReg = Op2.getReg();
140 if (MRI.getRegClass(NewReg) != MRI.getRegClass(OldReg))
142 "wrong signature, from/to mismatch");
150 case WebAssembly::RETURN_I32:
152 MI, MBB, MF, MFI, MRI, TII, WebAssembly::FALLTHROUGH_RETURN_I32,
153 WebAssembly::COPY_I32);
155 case WebAssembly::RETURN_I64:
157 MI, MBB, MF, MFI, MRI, TII, WebAssembly::FALLTHROUGH_RETURN_I64,
158 WebAssembly::COPY_I64);
160 case WebAssembly::RETURN_F32:
162 MI, MBB, MF, MFI, MRI, TII, WebAssembly::FALLTHROUGH_RETURN_F32,
163 WebAssembly::COPY_F32);
165 case WebAssembly::RETURN_F64:
167 MI, MBB, MF, MFI, MRI, TII, WebAssembly::FALLTHROUGH_RETURN_F64,
168 WebAssembly::COPY_F64);
170 case WebAssembly::RETURN_v16i8:
172 MI, MBB, MF, MFI, MRI, TII, WebAssembly::FALLTHROUGH_RETURN_v16i8,
173 WebAssembly::COPY_V128);
175 case WebAssembly::RETURN_v8i16:
177 MI, MBB, MF, MFI, MRI, TII, WebAssembly::FALLTHROUGH_RETURN_v8i16,
178 WebAssembly::COPY_V128);
180 case WebAssembly::RETURN_v4i32:
182 MI, MBB, MF, MFI, MRI, TII, WebAssembly::FALLTHROUGH_RETURN_v4i32,
183 WebAssembly::COPY_V128);
185 case WebAssembly::RETURN_v4f32:
187 MI, MBB, MF, MFI, MRI, TII, WebAssembly::FALLTHROUGH_RETURN_v4f32,
188 WebAssembly::COPY_V128);
190 case WebAssembly::RETURN_VOID:
192 &MBB == &MF.back() && &
MI == &MBB.back())
193 MI.setDesc(TII.get(WebAssembly::FALLTHROUGH_RETURN_VOID));
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
unsigned createVirtualRegister(const TargetRegisterClass *RegClass)
createVirtualRegister - Create and return a new virtual register in the function with the specified r...
static cl::opt< bool > DisableWebAssemblyFallthroughReturnOpt("disable-wasm-fallthrough-return-opt", cl::Hidden, cl::desc("WebAssembly: Disable fallthrough-return optimizations."), cl::init(false))
const char * getSymbolName() const
bool isVRegStackified(unsigned VReg) const
void setIsDead(bool Val=true)
This file contains the entry points for global functions defined in the LLVM WebAssembly back-end...
AnalysisUsage & addRequired()
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
const HexagonInstrInfo * TII
const TargetRegisterClass * getRegClass(unsigned Reg) const
Return the register class of the specified virtual register.
Reg
All possible values of the reg field in the ModR/M byte.
MachineInstrBuilder BuildMI(MachineFunction &MF, const DebugLoc &DL, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
initializer< Ty > init(const Ty &Val)
unsigned const MachineRegisterInfo * MRI
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
const MachineOperand & getOperand(unsigned i) const
This file provides WebAssembly-specific target descriptions.
Represent the analysis usage information of a pass.
bool isSymbol() const
isSymbol - Tests if this is a MO_ExternalSymbol operand.
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.
void stackifyVReg(unsigned VReg)
static bool MaybeRewriteToFallthrough(MachineInstr &MI, MachineBasicBlock &MBB, const MachineFunction &MF, WebAssemblyFunctionInfo &MFI, MachineRegisterInfo &MRI, const WebAssemblyInstrInfo &TII, unsigned FallthroughOpc, unsigned CopyLocalOpc)
This file declares the WebAssembly-specific subclass of TargetSubtarget.
void setDesc(const MCInstrDesc &tid)
Replace the instruction descriptor (thus opcode) of the current instruction with a new one...
const char * getLibcallName(RTLIB::Libcall Call) const
Get the libcall routine name for the specified libcall.
MachineOperand class - Representation of each machine instruction operand.
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.
const DebugLoc & getDebugLoc() const
Returns the debug location id of this MachineInstr.
MachineRegisterInfo - Keep track of information for virtual and physical registers, including vreg register classes, use/def chains for registers, etc.
FunctionPass * createWebAssemblyPeephole()
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.
void setReg(unsigned Reg)
Change the register this operand corresponds to.
This file declares WebAssembly-specific per-machine-function information.
static bool MaybeRewriteToDrop(unsigned OldReg, unsigned NewReg, MachineOperand &MO, WebAssemblyFunctionInfo &MFI, MachineRegisterInfo &MRI)
If desirable, rewrite NewReg to a drop register.
unsigned getReg() const
getReg - Returns the register number.
const MachineBasicBlock & back() const
StringRef - Represent a constant reference to a string, i.e.
StringRef getName() const
getName - Return the name of the corresponding LLVM function.