Go to the documentation of this file.
24 #define DEBUG_TYPE "wasm-peephole"
27 "disable-wasm-fallthrough-return-opt",
cl::Hidden,
28 cl::desc(
"WebAssembly: Disable fallthrough-return optimizations."),
34 return "WebAssembly late peephole optimizer";
53 "WebAssembly peephole optimizations",
false,
false)
56 return new WebAssemblyPeephole();
64 if (OldReg == NewReg) {
86 assert(End->getOpcode() == WebAssembly::END_FUNCTION);
91 for (
auto &MO :
MI.explicit_operands()) {
96 unsigned CopyLocalOpc;
98 switch (RegClass->
getID()) {
99 case WebAssembly::I32RegClassID:
100 CopyLocalOpc = WebAssembly::COPY_I32;
102 case WebAssembly::I64RegClassID:
103 CopyLocalOpc = WebAssembly::COPY_I64;
105 case WebAssembly::F32RegClassID:
106 CopyLocalOpc = WebAssembly::COPY_F32;
108 case WebAssembly::F64RegClassID:
109 CopyLocalOpc = WebAssembly::COPY_F64;
111 case WebAssembly::V128RegClassID:
112 CopyLocalOpc = WebAssembly::COPY_V128;
114 case WebAssembly::FUNCREFRegClassID:
115 CopyLocalOpc = WebAssembly::COPY_FUNCREF;
117 case WebAssembly::EXTERNREFRegClassID:
118 CopyLocalOpc = WebAssembly::COPY_EXTERNREF;
131 MI.setDesc(
TII.get(WebAssembly::FALLTHROUGH_RETURN));
137 dbgs() <<
"********** Peephole **********\n"
138 <<
"********** Function: " << MF.
getName() <<
'\n';
147 getAnalysis<TargetLibraryInfoWrapperPass>().getTLI(MF.
getFunction());
148 bool Changed =
false;
152 switch (
MI.getOpcode()) {
163 if (LibInfo.getLibFunc(
Name, Func)) {
164 const auto &Op2 =
MI.getOperand(2);
167 "wrong signature, not consuming reg");
174 "wrong signature, from/to mismatch");
unsigned getID() const
Return the register class ID number.
Register createVirtualRegister(const TargetRegisterClass *RegClass, StringRef Name="")
createVirtualRegister - Create and return a new virtual register in the function with the specified r...
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
const MachineBasicBlock & back() const
const char * getLibcallName(RTLIB::Libcall Call) const
Get the libcall routine name for the specified libcall.
bool isSymbol() const
isSymbol - Tests if this is a MO_ExternalSymbol operand.
static cl::opt< bool > DisableWebAssemblyFallthroughReturnOpt("disable-wasm-fallthrough-return-opt", cl::Hidden, cl::desc("WebAssembly: Disable fallthrough-return optimizations."), cl::init(false))
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
static bool maybeRewriteToDrop(unsigned OldReg, unsigned NewReg, MachineOperand &MO, WebAssemblyFunctionInfo &MFI, MachineRegisterInfo &MRI)
If desirable, rewrite NewReg to a drop register.
Ty * getInfo()
getInfo - Keep track of various per-function pieces of information for backends that would like to do...
Represent the analysis usage information of a pass.
const HexagonInstrInfo * TII
MachineOperand class - Representation of each machine instruction operand.
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
const TargetRegisterClass * getRegClass(Register Reg) const
Return the register class of the specified virtual register.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
void stackifyVReg(MachineRegisterInfo &MRI, unsigned VReg)
void setIsDead(bool Val=true)
Representation of each machine instruction.
initializer< Ty > init(const Ty &Val)
bool isVRegStackified(unsigned VReg) const
StringRef getName() const
getName - Return the name of the corresponding LLVM function.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This class is derived from MachineFunctionInfo and contains private WebAssembly-specific information ...
const MachineInstrBuilder & addReg(Register RegNo, unsigned flags=0, unsigned SubReg=0) const
Add a new virtual register operand.
Register getReg() const
getReg - Returns the register number.
INITIALIZE_PASS(WebAssemblyPeephole, DEBUG_TYPE, "WebAssembly peephole optimizations", false, false) FunctionPass *llvm
static bool maybeRewriteToFallthrough(MachineInstr &MI, MachineBasicBlock &MBB, const MachineFunction &MF, WebAssemblyFunctionInfo &MFI, MachineRegisterInfo &MRI, const WebAssemblyInstrInfo &TII)
void setPreservesCFG()
This function should be called by the pass, iff they do not:
StringRef - Represent a constant reference to a string, i.e.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
unsigned const MachineRegisterInfo * MRI
Wrapper class representing virtual and physical registers.
Function & getFunction()
Return the LLVM function that this machine code represents.
const char * getSymbolName() const
MachineInstrBuilder BuildMI(MachineFunction &MF, const DebugLoc &DL, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
void setReg(Register Reg)
Change the register this operand corresponds to.
FunctionPass class - This class is used to implement most global optimizations.
AnalysisUsage & addRequired()
FunctionPass * createWebAssemblyPeephole()