Thanks to visit codestin.com
Credit goes to llvm.org

LLVM 22.0.0git
WebAssemblyRegStackify.cpp File Reference

This file implements a register stacking pass. More...

Go to the source code of this file.

Macros

#define DEBUG_TYPE   "wasm-reg-stackify"

Functions

 INITIALIZE_PASS (WebAssemblyRegStackify, DEBUG_TYPE, "Reorder instructions to use the WebAssembly value stack", false, false) FunctionPass *llvm
static void imposeStackOrdering (MachineInstr *MI)
static void convertImplicitDefToConstZero (MachineInstr *MI, MachineRegisterInfo &MRI, const TargetInstrInfo *TII, MachineFunction &MF)
static void queryCallee (const MachineInstr &MI, bool &Read, bool &Write, bool &Effects, bool &StackPointer)
static void query (const MachineInstr &MI, bool &Read, bool &Write, bool &Effects, bool &StackPointer)
static bool shouldRematerialize (const MachineInstr &Def, const WebAssemblyInstrInfo *TII)
static MachineInstrgetVRegDef (unsigned Reg, const MachineInstr *Insert, const MachineRegisterInfo &MRI, const LiveIntervals *LIS)
static bool hasSingleUse (unsigned Reg, MachineRegisterInfo &MRI, WebAssemblyFunctionInfo &MFI, bool Optimize, MachineInstr *Def, LiveIntervals *LIS)
static bool isSafeToMove (const MachineOperand *Def, const MachineOperand *Use, const MachineInstr *Insert, const WebAssemblyFunctionInfo &MFI, const MachineRegisterInfo &MRI, bool Optimize)
static bool oneUseDominatesOtherUses (unsigned Reg, const MachineOperand &OneUse, const MachineBasicBlock &MBB, const MachineRegisterInfo &MRI, const MachineDominatorTree &MDT, LiveIntervals &LIS, WebAssemblyFunctionInfo &MFI)
 Test whether OneUse, a use of Reg, dominates all of Reg's other uses.
static unsigned getTeeOpcode (const TargetRegisterClass *RC)
 Get the appropriate tee opcode for the given register class.
static void shrinkToUses (LiveInterval &LI, LiveIntervals &LIS)
static MachineInstrmoveForSingleUse (unsigned Reg, MachineOperand &Op, MachineInstr *Def, MachineBasicBlock &MBB, MachineInstr *Insert, LiveIntervals *LIS, WebAssemblyFunctionInfo &MFI, MachineRegisterInfo &MRI)
 A single-use def in the same block with no intervening memory or register dependencies; move the def down and nest it with the current instruction.
static MachineInstrgetPrevNonDebugInst (MachineInstr *MI)
static MachineInstrrematerializeCheapDef (unsigned Reg, MachineOperand &Op, MachineInstr &Def, MachineBasicBlock::instr_iterator Insert, LiveIntervals &LIS, WebAssemblyFunctionInfo &MFI, MachineRegisterInfo &MRI, const WebAssemblyInstrInfo *TII)
 A trivially cloneable instruction; clone it and nest the new copy with the current instruction.
static MachineInstrmoveAndTeeForMultiUse (unsigned Reg, MachineOperand &Op, MachineInstr *Def, MachineBasicBlock &MBB, MachineInstr *Insert, LiveIntervals &LIS, WebAssemblyFunctionInfo &MFI, MachineRegisterInfo &MRI, const WebAssemblyInstrInfo *TII)
 A multiple-use def in the same block with no intervening memory or register dependencies; move the def down, nest it with the current instruction, and insert a tee to satisfy the rest of the uses.

Detailed Description

This file implements a register stacking pass.

This pass reorders instructions to put register uses and defs in an order such that they form single-use expression trees. Registers fitting this form are then marked as "stackified", meaning references to them are replaced by "push" and "pop" from the value stack.

This is primarily a code size optimization, since temporary values on the value stack don't need to be named.

Definition in file WebAssemblyRegStackify.cpp.

Macro Definition Documentation

◆ DEBUG_TYPE

#define DEBUG_TYPE   "wasm-reg-stackify"

Definition at line 40 of file WebAssemblyRegStackify.cpp.

Function Documentation

◆ convertImplicitDefToConstZero()

◆ getPrevNonDebugInst()

MachineInstr * getPrevNonDebugInst ( MachineInstr * MI)
static

Definition at line 592 of file WebAssemblyRegStackify.cpp.

References I, and MI.

Referenced by rematerializeCheapDef().

◆ getTeeOpcode()

unsigned getTeeOpcode ( const TargetRegisterClass * RC)
static

Get the appropriate tee opcode for the given register class.

Definition at line 520 of file WebAssemblyRegStackify.cpp.

References llvm_unreachable.

Referenced by moveAndTeeForMultiUse().

◆ getVRegDef()

◆ hasSingleUse()

◆ imposeStackOrdering()

void imposeStackOrdering ( MachineInstr * MI)
static

◆ INITIALIZE_PASS()

INITIALIZE_PASS ( WebAssemblyRegStackify ,
DEBUG_TYPE ,
"Reorder instructions to use the WebAssembly value stack" ,
false ,
false  )

Definition at line 75 of file WebAssemblyRegStackify.cpp.

References llvm::createWebAssemblyRegStackify(), and DEBUG_TYPE.

◆ isSafeToMove()

◆ moveAndTeeForMultiUse()

MachineInstr * moveAndTeeForMultiUse ( unsigned Reg,
MachineOperand & Op,
MachineInstr * Def,
MachineBasicBlock & MBB,
MachineInstr * Insert,
LiveIntervals & LIS,
WebAssemblyFunctionInfo & MFI,
MachineRegisterInfo & MRI,
const WebAssemblyInstrInfo * TII )
static

A multiple-use def in the same block with no intervening memory or register dependencies; move the def down, nest it with the current instruction, and insert a tee to satisfy the rest of the uses.

As an illustration, rewrite this:

Reg = INST ... // Def INST ..., Reg, ... // Insert INST ..., Reg, ... INST ..., Reg, ...

to this:

DefReg = INST ... // Def (to become the new Insert) TeeReg, Reg = TEE_... DefReg INST ..., TeeReg, ... // Insert INST ..., Reg, ... INST ..., Reg, ...

with DefReg and TeeReg stackified. This eliminates a local.get from the resulting code.

Definition at line 665 of file WebAssemblyRegStackify.cpp.

References llvm::MachineInstrBuilder::addReg(), llvm::BuildMI(), llvm::WebAssemblyDebugValueManager::cloneSink(), llvm::LiveIntervals::createAndComputeVirtRegInterval(), llvm::dbgs(), llvm::VNInfo::def, llvm::RegState::Define, llvm::MachineInstr::dump(), llvm::LiveRange::FindSegmentContaining(), llvm::LiveIntervals::getInstructionIndex(), llvm::LiveIntervals::getInterval(), llvm::SlotIndex::getRegSlot(), getTeeOpcode(), llvm::getUndefRegState(), llvm::LiveRange::getVNInfoAt(), llvm::LiveIntervals::handleMove(), I, imposeStackOrdering(), llvm::LiveIntervals::InsertMachineInstrInMaps(), llvm::MachineOperand::isDead(), LLVM_DEBUG, MBB, MRI, Reg, shrinkToUses(), llvm::WebAssemblyDebugValueManager::sink(), llvm::WebAssemblyFunctionInfo::stackifyVReg(), TII, and llvm::WebAssemblyDebugValueManager::updateReg().

◆ moveForSingleUse()

◆ oneUseDominatesOtherUses()

◆ query()

void query ( const MachineInstr & MI,
bool & Read,
bool & Write,
bool & Effects,
bool & StackPointer )
static

Definition at line 169 of file WebAssemblyRegStackify.cpp.

References assert(), MI, queryCallee(), llvm::Read, and llvm::Write.

Referenced by isSafeToMove().

◆ queryCallee()

void queryCallee ( const MachineInstr & MI,
bool & Read,
bool & Write,
bool & Effects,
bool & StackPointer )
static

◆ rematerializeCheapDef()

◆ shouldRematerialize()

bool shouldRematerialize ( const MachineInstr & Def,
const WebAssemblyInstrInfo * TII )
static

Definition at line 261 of file WebAssemblyRegStackify.cpp.

References TII.

◆ shrinkToUses()