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 "WebAssembly peephole optimizations",
false,
false)
57 return new WebAssemblyPeephole();
65 if (OldReg == NewReg) {
80 unsigned FallthroughOpc,
81 unsigned CopyLocalOpc) {
84 if (&MBB != &MF.
back())
89 assert(End->getOpcode() == WebAssembly::END_FUNCTION);
94 if (FallthroughOpc != WebAssembly::FALLTHROUGH_RETURN_VOID) {
109 MI.
setDesc(TII.get(FallthroughOpc));
115 dbgs() <<
"********** Peephole **********\n" 116 <<
"********** Function: " << MF.
getName() <<
'\n';
124 auto &LibInfo = getAnalysis<TargetLibraryInfoWrapperPass>().getTLI();
125 bool Changed =
false;
129 switch (
MI.getOpcode()) {
132 case WebAssembly::CALL_I32:
133 case WebAssembly::CALL_I64: {
141 if (LibInfo.getLibFunc(
Name, Func)) {
142 const auto &Op2 =
MI.getOperand(2);
145 "wrong signature, not consuming reg");
147 unsigned OldReg = MO.
getReg();
148 unsigned NewReg = Op2.getReg();
150 if (MRI.getRegClass(NewReg) != MRI.getRegClass(OldReg))
152 "wrong signature, from/to mismatch");
160 case WebAssembly::RETURN_I32:
162 MI, MBB, MF, MFI, MRI, TII, WebAssembly::FALLTHROUGH_RETURN_I32,
163 WebAssembly::COPY_I32);
165 case WebAssembly::RETURN_I64:
167 MI, MBB, MF, MFI, MRI, TII, WebAssembly::FALLTHROUGH_RETURN_I64,
168 WebAssembly::COPY_I64);
170 case WebAssembly::RETURN_F32:
172 MI, MBB, MF, MFI, MRI, TII, WebAssembly::FALLTHROUGH_RETURN_F32,
173 WebAssembly::COPY_F32);
175 case WebAssembly::RETURN_F64:
177 MI, MBB, MF, MFI, MRI, TII, WebAssembly::FALLTHROUGH_RETURN_F64,
178 WebAssembly::COPY_F64);
180 case WebAssembly::RETURN_v16i8:
182 MI, MBB, MF, MFI, MRI, TII, WebAssembly::FALLTHROUGH_RETURN_v16i8,
183 WebAssembly::COPY_V128);
185 case WebAssembly::RETURN_v8i16:
187 MI, MBB, MF, MFI, MRI, TII, WebAssembly::FALLTHROUGH_RETURN_v8i16,
188 WebAssembly::COPY_V128);
190 case WebAssembly::RETURN_v4i32:
192 MI, MBB, MF, MFI, MRI, TII, WebAssembly::FALLTHROUGH_RETURN_v4i32,
193 WebAssembly::COPY_V128);
195 case WebAssembly::RETURN_v2i64:
197 MI, MBB, MF, MFI, MRI, TII, WebAssembly::FALLTHROUGH_RETURN_v2i64,
198 WebAssembly::COPY_V128);
200 case WebAssembly::RETURN_v4f32:
202 MI, MBB, MF, MFI, MRI, TII, WebAssembly::FALLTHROUGH_RETURN_v4f32,
203 WebAssembly::COPY_V128);
205 case WebAssembly::RETURN_v2f64:
207 MI, MBB, MF, MFI, MRI, TII, WebAssembly::FALLTHROUGH_RETURN_v2f64,
208 WebAssembly::COPY_V128);
210 case WebAssembly::RETURN_VOID:
212 MI, MBB, MF, MFI, MRI, TII, WebAssembly::FALLTHROUGH_RETURN_VOID,
213 WebAssembly::INSTRUCTION_LIST_END);
const TargetRegisterClass * getRegClass(unsigned Reg) const
Return the register class of the specified virtual register.
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.
const DebugLoc & getDebugLoc() const
Returns the debug location id of this MachineInstr.
FunctionPass * createWebAssemblyPeephole()
unsigned getReg() const
getReg - Returns the register number.
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...
AnalysisUsage & addRequired()
amdgpu Simplify well known AMD library false Value Value const Twine & Name
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
const HexagonInstrInfo * TII
const char * getSymbolName() const
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)
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...
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.
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.
void setReg(unsigned Reg)
Change the register this operand corresponds to.
This file declares WebAssembly-specific per-machine-function information.
const MachineBasicBlock & back() const
static bool MaybeRewriteToDrop(unsigned OldReg, unsigned NewReg, MachineOperand &MO, WebAssemblyFunctionInfo &MFI, MachineRegisterInfo &MRI)
If desirable, rewrite NewReg to a drop register.
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
const MachineOperand & getOperand(unsigned i) const
unsigned createVirtualRegister(const TargetRegisterClass *RegClass, StringRef Name="")
createVirtualRegister - Create and return a new virtual register in the function with the specified r...
const char * getLibcallName(RTLIB::Libcall Call) const
Get the libcall routine name for the specified libcall.