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) {
81 if (&MBB != &MF.
back())
86 assert(End->getOpcode() == WebAssembly::END_FUNCTION);
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::EXNREFRegClassID:
115 CopyLocalOpc = WebAssembly::COPY_EXNREF;
128 MI.
setDesc(TII.get(WebAssembly::FALLTHROUGH_RETURN));
134 dbgs() <<
"********** Peephole **********\n" 135 <<
"********** Function: " << MF.
getName() <<
'\n';
144 getAnalysis<TargetLibraryInfoWrapperPass>().getTLI(MF.
getFunction());
145 bool Changed =
false;
149 switch (
MI.getOpcode()) {
152 case WebAssembly::CALL_i32:
153 case WebAssembly::CALL_i64: {
161 if (LibInfo.getLibFunc(
Name, Func)) {
162 const auto &Op2 =
MI.getOperand(2);
165 "wrong signature, not consuming reg");
170 if (MRI.getRegClass(NewReg) != MRI.getRegClass(OldReg))
172 "wrong signature, from/to mismatch");
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
This class represents lattice values for constants.
iterator_range< mop_iterator > explicit_operands()
Register createVirtualRegister(const TargetRegisterClass *RegClass, StringRef Name="")
createVirtualRegister - Create and return a new virtual register in the function with the specified r...
amdgpu Simplify well known AMD library false FunctionCallee Value const Twine & Name
const DebugLoc & getDebugLoc() const
Returns the debug location id of this MachineInstr.
FunctionPass * createWebAssemblyPeephole()
static cl::opt< bool > DisableWebAssemblyFallthroughReturnOpt("disable-wasm-fallthrough-return-opt", cl::Hidden, cl::desc("WebAssembly: Disable fallthrough-return optimizations."), cl::init(false))
void setIsDead(bool Val=true)
This file contains the entry points for global functions defined in the LLVM WebAssembly back-end...
static bool maybeRewriteToDrop(unsigned OldReg, unsigned NewReg, MachineOperand &MO, WebAssemblyFunctionInfo &MFI, MachineRegisterInfo &MRI)
If desirable, rewrite NewReg to a drop register.
const TargetRegisterClass * getRegClass(Register Reg) const
Return the register class of the specified virtual register.
AnalysisUsage & addRequired()
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
const HexagonInstrInfo * TII
const char * getSymbolName() const
unsigned getID() const
Return the register class ID number.
void setReg(Register Reg)
Change the register this operand corresponds to.
bool isVRegStackified(unsigned VReg) const
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.
initializer< Ty > init(const Ty &Val)
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.
void stackifyVReg(unsigned VReg)
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
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...
MachineOperand class - Representation of each machine instruction operand.
void setPreservesCFG()
This function should be called by the pass, iff they do not:
const Function & getFunction() const
Return the LLVM function that this machine code represents.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
static bool maybeRewriteToFallthrough(MachineInstr &MI, MachineBasicBlock &MBB, const MachineFunction &MF, WebAssemblyFunctionInfo &MFI, MachineRegisterInfo &MRI, const WebAssemblyInstrInfo &TII)
MachineRegisterInfo - Keep track of information for virtual and physical registers, including vreg register classes, use/def chains for registers, etc.
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.
This file declares WebAssembly-specific per-machine-function information.
const MachineBasicBlock & back() const
bool isSymbol() const
isSymbol - Tests if this is a MO_ExternalSymbol operand.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
StringRef - Represent a constant reference to a string, i.e.
INITIALIZE_PASS(WebAssemblyPeephole, DEBUG_TYPE, "WebAssembly peephole optimizations", false, false) FunctionPass *llvm
Register getReg() const
getReg - Returns the register number.
Wrapper class representing virtual and physical registers.
const char * getLibcallName(RTLIB::Libcall Call) const
Get the libcall routine name for the specified libcall.