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";
52char WebAssemblyPeephole::ID = 0;
54 "WebAssembly peephole optimizations",
false,
false)
57 return new WebAssemblyPeephole();
65 if (OldReg == NewReg) {
67 Register NewReg =
MRI.createVirtualRegister(
MRI.getRegClass(OldReg));
87 assert(
End->getOpcode() == WebAssembly::END_FUNCTION);
92 for (
auto &MO :
MI.explicit_operands()) {
97 unsigned CopyLocalOpc;
100 Register NewReg =
MRI.createVirtualRegister(RegClass);
108 MI.setDesc(
TII.get(WebAssembly::FALLTHROUGH_RETURN));
114 dbgs() <<
"********** Peephole **********\n"
115 <<
"********** Function: " << MF.
getName() <<
'\n';
124 getAnalysis<TargetLibraryInfoWrapperPass>().getTLI(MF.
getFunction());
125 bool Changed =
false;
129 switch (
MI.getOpcode()) {
132 case WebAssembly::CALL: {
140 if (LibInfo.getLibFunc(
Name, Func)) {
141 const auto &Op2 =
MI.getOperand(2);
144 "wrong signature, not consuming reg");
149 if (
MRI.getRegClass(NewReg) !=
MRI.getRegClass(OldReg))
151 "wrong signature, from/to mismatch");
159 case WebAssembly::RETURN:
unsigned const MachineRegisterInfo * MRI
const HexagonInstrInfo * TII
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file provides WebAssembly-specific target descriptions.
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.
static bool maybeRewriteToFallthrough(MachineInstr &MI, MachineBasicBlock &MBB, const MachineFunction &MF, WebAssemblyFunctionInfo &MFI, MachineRegisterInfo &MRI, const WebAssemblyInstrInfo &TII)
static cl::opt< bool > DisableWebAssemblyFallthroughReturnOpt("disable-wasm-fallthrough-return-opt", cl::Hidden, cl::desc("WebAssembly: Disable fallthrough-return optimizations."), cl::init(false))
This file declares the WebAssembly-specific subclass of TargetSubtarget.
This file contains the declaration of the WebAssembly-specific utility functions.
This file contains the entry points for global functions defined in the LLVM WebAssembly back-end.
Represent the analysis usage information of a pass.
AnalysisUsage & addRequired()
void setPreservesCFG()
This function should be called by the pass, iff they do not:
FunctionPass class - This class is used to implement most global optimizations.
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
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.
Function & getFunction()
Return the LLVM function that this machine code represents.
const MachineBasicBlock & back() const
Ty * getInfo()
getInfo - Keep track of various per-function pieces of information for backends that would like to do...
const MachineInstrBuilder & addReg(Register RegNo, unsigned flags=0, unsigned SubReg=0) const
Add a new virtual register operand.
Representation of each machine instruction.
MachineOperand class - Representation of each machine instruction operand.
void setIsDead(bool Val=true)
void setReg(Register Reg)
Change the register this operand corresponds to.
bool isSymbol() const
isSymbol - Tests if this is a MO_ExternalSymbol operand.
const char * getSymbolName() const
Register getReg() const
getReg - Returns the register number.
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
virtual StringRef getPassName() const
getPassName - Return a nice clean name for a pass.
Wrapper class representing virtual and physical registers.
StringRef - Represent a constant reference to a string, i.e.
const char * getLibcallName(RTLIB::Libcall Call) const
Get the libcall routine name for the specified libcall.
This class is derived from MachineFunctionInfo and contains private WebAssembly-specific information ...
bool isVRegStackified(unsigned VReg) const
void stackifyVReg(MachineRegisterInfo &MRI, unsigned VReg)
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
unsigned getCopyOpcodeForRegClass(const TargetRegisterClass *RC)
Returns the appropriate copy opcode for the given register class.
initializer< Ty > init(const Ty &Val)
NodeAddr< FuncNode * > Func
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.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
FunctionPass * createWebAssemblyPeephole()