LLVM  5.0.0
Macros | Functions
WebAssemblyRegStackify.cpp File Reference

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

#include "MCTargetDesc/WebAssemblyMCTargetDesc.h"
#include "WebAssembly.h"
#include "WebAssemblyMachineFunctionInfo.h"
#include "WebAssemblySubtarget.h"
#include "WebAssemblyUtilities.h"
#include "llvm/Analysis/AliasAnalysis.h"
#include "llvm/CodeGen/LiveIntervalAnalysis.h"
#include "llvm/CodeGen/MachineBlockFrequencyInfo.h"
#include "llvm/CodeGen/MachineDominators.h"
#include "llvm/CodeGen/MachineInstrBuilder.h"
#include "llvm/CodeGen/MachineModuleInfoImpls.h"
#include "llvm/CodeGen/MachineRegisterInfo.h"
#include "llvm/CodeGen/Passes.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/raw_ostream.h"
Include dependency graph for WebAssemblyRegStackify.cpp:

Go to the source code of this file.

Macros

#define DEBUG_TYPE   "wasm-reg-stackify"
 

Functions

static void ImposeStackOrdering (MachineInstr *MI)
 
static void ConvertImplicitDefToConstZero (MachineInstr *MI, MachineRegisterInfo &MRI, const TargetInstrInfo *TII, MachineFunction &MF)
 
static void QueryCallee (const MachineInstr &MI, unsigned CalleeOpNo, bool &Read, bool &Write, bool &Effects, bool &StackPointer)
 
static void Query (const MachineInstr &MI, AliasAnalysis &AA, bool &Read, bool &Write, bool &Effects, bool &StackPointer)
 
static bool ShouldRematerialize (const MachineInstr &Def, AliasAnalysis &AA, const WebAssemblyInstrInfo *TII)
 
static MachineInstr * GetVRegDef (unsigned Reg, const MachineInstr *Insert, const MachineRegisterInfo &MRI, const LiveIntervals &LIS)
 
static bool HasOneUse (unsigned Reg, MachineInstr *Def, MachineRegisterInfo &MRI, MachineDominatorTree &MDT, LiveIntervals &LIS)
 
static bool IsSafeToMove (const MachineInstr *Def, const MachineInstr *Insert, AliasAnalysis &AA, const MachineRegisterInfo &MRI)
 
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. More...
 
static unsigned GetTeeOpcode (const TargetRegisterClass *RC)
 Get the appropriate tee opcode for the given register class. More...
 
static void ShrinkToUses (LiveInterval &LI, LiveIntervals &LIS)
 
static MachineInstr * MoveForSingleUse (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. More...
 
static MachineInstr * RematerializeCheapDef (unsigned Reg, MachineOperand &Op, MachineInstr &Def, MachineBasicBlock &MBB, MachineBasicBlock::instr_iterator Insert, LiveIntervals &LIS, WebAssemblyFunctionInfo &MFI, MachineRegisterInfo &MRI, const WebAssemblyInstrInfo *TII, const WebAssemblyRegisterInfo *TRI)
 A trivially cloneable instruction; clone it and nest the new copy with the current instruction. More...
 
static MachineInstr * MoveAndTeeForMultiUse (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. More...
 

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

#define DEBUG_TYPE   "wasm-reg-stackify"

Definition at line 40 of file WebAssemblyRegStackify.cpp.

Function Documentation

static void ConvertImplicitDefToConstZero ( MachineInstr *  MI,
MachineRegisterInfo &  MRI,
const TargetInstrInfo *  TII,
MachineFunction &  MF 
)
static
static unsigned GetTeeOpcode ( const TargetRegisterClass *  RC)
static

Get the appropriate tee opcode for the given register class.

Definition at line 442 of file WebAssemblyRegStackify.cpp.

References llvm_unreachable().

Referenced by MoveAndTeeForMultiUse().

static MachineInstr* GetVRegDef ( unsigned  Reg,
const MachineInstr *  Insert,
const MachineRegisterInfo &  MRI,
const LiveIntervals &  LIS 
)
static
static bool HasOneUse ( unsigned  Reg,
MachineInstr *  Def,
MachineRegisterInfo &  MRI,
MachineDominatorTree &  MDT,
LiveIntervals &  LIS 
)
static
static void ImposeStackOrdering ( MachineInstr *  MI)
static
static bool IsSafeToMove ( const MachineInstr *  Def,
const MachineInstr *  Insert,
AliasAnalysis &  AA,
const MachineRegisterInfo &  MRI 
)
static
static 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 get_local from the resulting code.

Definition at line 568 of file WebAssemblyRegStackify.cpp.

References llvm::MachineInstrBuilder::addReg(), llvm::BuildMI(), llvm::LiveIntervals::createAndComputeVirtRegInterval(), llvm::MachineRegisterInfo::createVirtualRegister(), llvm::dbgs(), DEBUG, llvm::tgtok::Def, llvm::VNInfo::def, llvm::RegState::Define, llvm::MachineInstr::dump(), llvm::LiveRange::FindSegmentContaining(), llvm::MachineInstr::getDebugLoc(), llvm::LiveIntervals::getInstructionIndex(), llvm::LiveIntervals::getInterval(), llvm::MachineInstr::getOperand(), llvm::MachineRegisterInfo::getRegClass(), llvm::SlotIndex::getRegSlot(), GetTeeOpcode(), llvm::getUndefRegState(), llvm::LiveRange::getVNInfoAt(), llvm::LiveIntervals::handleMove(), I, ImposeStackOrdering(), llvm::LiveIntervals::InsertMachineInstrInMaps(), llvm::MachineOperand::isDead(), llvm::MachineOperand::setReg(), ShrinkToUses(), llvm::MachineBasicBlock::splice(), and llvm::WebAssemblyFunctionInfo::stackifyVReg().

static MachineInstr* MoveForSingleUse ( unsigned  Reg,
MachineOperand &  Op,
MachineInstr *  Def,
MachineBasicBlock &  MBB,
MachineInstr *  Insert,
LiveIntervals &  LIS,
WebAssemblyFunctionInfo &  MFI,
MachineRegisterInfo &  MRI 
)
static
static bool OneUseDominatesOtherUses ( unsigned  Reg,
const MachineOperand &  OneUse,
const MachineBasicBlock &  MBB,
const MachineRegisterInfo &  MRI,
const MachineDominatorTree &  MDT,
LiveIntervals &  LIS,
WebAssemblyFunctionInfo &  MFI 
)
static
static void Query ( const MachineInstr &  MI,
AliasAnalysis &  AA,
bool &  Read,
bool &  Write,
bool &  Effects,
bool &  StackPointer 
)
static
static void QueryCallee ( const MachineInstr &  MI,
unsigned  CalleeOpNo,
bool &  Read,
bool &  Write,
bool &  Effects,
bool &  StackPointer 
)
static
static MachineInstr* RematerializeCheapDef ( unsigned  Reg,
MachineOperand &  Op,
MachineInstr &  Def,
MachineBasicBlock &  MBB,
MachineBasicBlock::instr_iterator  Insert,
LiveIntervals &  LIS,
WebAssemblyFunctionInfo &  MFI,
MachineRegisterInfo &  MRI,
const WebAssemblyInstrInfo *  TII,
const WebAssemblyRegisterInfo *  TRI 
)
static
static bool ShouldRematerialize ( const MachineInstr &  Def,
AliasAnalysis &  AA,
const WebAssemblyInstrInfo *  TII 
)
static
static void ShrinkToUses ( LiveInterval &  LI,
LiveIntervals &  LIS 
)
static