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())
85 if (&MI != &MBB.
back())
90 assert(End->getOpcode() == WebAssembly::END_FUNCTION);
96 if (FallthroughOpc != WebAssembly::FALLTHROUGH_RETURN_VOID) {
111 MI.
setDesc(TII.get(FallthroughOpc));
117 dbgs() <<
"********** Peephole **********\n"
118 <<
"********** Function: " << MF.
getName() <<
'\n';
126 auto &LibInfo = getAnalysis<TargetLibraryInfoWrapperPass>().getTLI();
127 bool Changed =
false;
131 switch (
MI.getOpcode()) {
134 case WebAssembly::CALL_I32:
135 case WebAssembly::CALL_I64: {
143 if (LibInfo.getLibFunc(
Name, Func)) {
144 const auto &Op2 =
MI.getOperand(2);
147 "wrong signature, not consuming reg");
149 unsigned OldReg = MO.
getReg();
150 unsigned NewReg = Op2.getReg();
152 if (MRI.getRegClass(NewReg) != MRI.getRegClass(OldReg))
154 "wrong signature, from/to mismatch");
162 case WebAssembly::RETURN_I32:
164 MI, MBB, MF, MFI, MRI, TII, WebAssembly::FALLTHROUGH_RETURN_I32,
165 WebAssembly::COPY_I32);
167 case WebAssembly::RETURN_I64:
169 MI, MBB, MF, MFI, MRI, TII, WebAssembly::FALLTHROUGH_RETURN_I64,
170 WebAssembly::COPY_I64);
172 case WebAssembly::RETURN_F32:
174 MI, MBB, MF, MFI, MRI, TII, WebAssembly::FALLTHROUGH_RETURN_F32,
175 WebAssembly::COPY_F32);
177 case WebAssembly::RETURN_F64:
179 MI, MBB, MF, MFI, MRI, TII, WebAssembly::FALLTHROUGH_RETURN_F64,
180 WebAssembly::COPY_F64);
182 case WebAssembly::RETURN_v16i8:
184 MI, MBB, MF, MFI, MRI, TII, WebAssembly::FALLTHROUGH_RETURN_v16i8,
185 WebAssembly::COPY_V128);
187 case WebAssembly::RETURN_v8i16:
189 MI, MBB, MF, MFI, MRI, TII, WebAssembly::FALLTHROUGH_RETURN_v8i16,
190 WebAssembly::COPY_V128);
192 case WebAssembly::RETURN_v4i32:
194 MI, MBB, MF, MFI, MRI, TII, WebAssembly::FALLTHROUGH_RETURN_v4i32,
195 WebAssembly::COPY_V128);
197 case WebAssembly::RETURN_v4f32:
199 MI, MBB, MF, MFI, MRI, TII, WebAssembly::FALLTHROUGH_RETURN_v4f32,
200 WebAssembly::COPY_V128);
202 case WebAssembly::RETURN_VOID:
204 MI, MBB, MF, MFI, MRI, TII, WebAssembly::FALLTHROUGH_RETURN_VOID,
205 WebAssembly::INSTRUCTION_LIST_END);
const Triple & getTargetTriple() const
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
const MachineOperand & getOperand(unsigned i) const
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.
bool isSymbol() const
isSymbol - Tests if this is a MO_ExternalSymbol operand.
static const unsigned End
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 ...
bool isOSBinFormatELF() const
Tests whether the OS uses the ELF binary format.
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.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
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.