30#define DEBUG_TYPE "wasm-peephole"
35 return "WebAssembly late peephole optimizer";
53char WebAssemblyPeepholeLegacy::ID = 0;
55 "WebAssembly peephole optimizations",
false,
false)
58 return new WebAssemblyPeepholeLegacy();
66 if (OldReg == NewReg) {
68 Register NewReg =
MRI.createVirtualRegister(
MRI.getRegClass(OldReg));
86 assert(
End->getOpcode() == WebAssembly::END_FUNCTION);
91 for (
auto &MO :
MI.explicit_operands()) {
96 unsigned CopyLocalOpc;
99 Register NewReg =
MRI.createVirtualRegister(RegClass);
107 MI.setDesc(
TII.get(WebAssembly::FALLTHROUGH_RETURN));
114 dbgs() <<
"********** Peephole **********\n"
115 <<
"********** Function: " << MF.
getName() <<
'\n';
124 RTLIB::LibcallImpl MemcpyImpl = LibcallLowering.
getLibcallImpl(RTLIB::MEMCPY);
125 RTLIB::LibcallImpl MemmoveImpl =
127 RTLIB::LibcallImpl MemsetImpl = LibcallLowering.
getLibcallImpl(RTLIB::MEMSET);
140 switch (
MI.getOpcode()) {
143 case WebAssembly::CALL: {
147 if (Name == MemcpyName || Name == MemmoveName || Name == MemsetName) {
149 const auto &Op2 =
MI.getOperand(2);
152 "wrong signature, not consuming reg");
157 if (
MRI.getRegClass(NewReg) !=
MRI.getRegClass(OldReg))
159 "wrong signature, from/to mismatch");
167 case WebAssembly::RETURN:
168 if (
Subtarget.getCLOpts().fallthrough_return_opt)
176bool WebAssemblyPeepholeLegacy::runOnMachineFunction(
MachineFunction &MF) {
177 TargetLibraryInfo &LibInfo =
178 getAnalysis<TargetLibraryInfoWrapperPass>().getTLI(MF.
getFunction());
181 const LibcallLoweringInfo &LibcallLowering =
182 getAnalysis<LibcallLoweringInfoWrapper>().getLibcallLowering(
184 return peephole(MF, LibInfo, LibcallLowering);
201 return peephole(MF, LibInfo, LibcallLowering)
const AArch64Subtarget & Subtarget
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
const AArch64InstrInfo & TII
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
MachineRegisterInfo & MRI
This file provides WebAssembly-specific target descriptions.
This file declares WebAssembly-specific per-machine-function information.
static bool peephole(MachineFunction &MF, TargetLibraryInfo &LibInfo, const LibcallLoweringInfo &LibcallLowering)
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)
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.
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
Represent the analysis usage information of a pass.
AnalysisUsage & addRequired()
LLVM_ABI void setPreservesCFG()
This function should be called by the pass, iff they do not:
Represents analyses that only rely on functions' control flow.
FunctionPass class - This class is used to implement most global optimizations.
Module * getParent()
Get the module that this global value is contained inside of...
Tracks which library functions to use for a particular subtarget or function.
RTLIB::LibcallImpl getLibcallImpl(RTLIB::Libcall Call) const
Return the lowering's selection of implementation call for Call.
MachineInstrBundleIterator< MachineInstr > iterator
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.
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, RegState Flags={}, 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)
LLVM_ABI 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,...
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
PreservedAnalyses & preserveSet()
Mark an analysis set as preserved.
Wrapper class representing virtual and physical registers.
Represent a constant reference to a string, i.e.
Analysis pass providing the TargetLibraryInfo.
Provides information about what library functions are available for the current target.
LibFunc getLibFunc(StringRef funcName) const
Searches for a particular function name.
This class is derived from MachineFunctionInfo and contains private WebAssembly-specific information ...
void stackifyVReg(MachineRegisterInfo &MRI, Register VReg)
bool isVRegStackified(Register VReg) const
PreservedAnalyses run(MachineFunction &MF, MachineFunctionAnalysisManager &MFAM)
Pass manager infrastructure for declaring and invalidating analyses.
unsigned getCopyOpcodeForRegClass(const TargetRegisterClass *RC)
Returns the appropriate copy opcode for the given register class.
This is an optimization pass for GlobalISel generic memory operations.
OuterAnalysisManagerProxy< ModuleAnalysisManager, MachineFunction > ModuleAnalysisManagerMachineFunctionProxy
Provide the ModuleAnalysisManager to Function proxy.
MachineInstrBuilder BuildMI(MachineFunction &MF, const MIMetadata &MIMD, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
AnalysisManager< MachineFunction > MachineFunctionAnalysisManager
LLVM_ABI PreservedAnalyses getMachineFunctionPassPreservedAnalyses()
Returns the minimum set of Analyses that all machine function passes must preserve.
LLVM_ABI const LibcallLoweringInfo & getLibcallLowering(const ModuleLibcallLoweringInfo &ModuleInfo, const TargetSubtargetInfo &Subtarget)
Resolve the LibcallLoweringInfo for Subtarget from the module-level ModuleInfo, applying the subtarge...
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
FunctionPass * createWebAssemblyPeepholeLegacyPass()
@ End
Run the machine verifier once, at the end of the pipeline.
MCRegisterClass TargetRegisterClass
static StringRef getLibcallImplName(RTLIB::LibcallImpl CallImpl)
Get the libcall routine name for the specified libcall implementation.