LLVM 20.0.0git
|
This file implements a register stacking pass. More...
#include "MCTargetDesc/WebAssemblyMCTargetDesc.h"
#include "WebAssembly.h"
#include "WebAssemblyDebugValueManager.h"
#include "WebAssemblyMachineFunctionInfo.h"
#include "WebAssemblySubtarget.h"
#include "WebAssemblyUtilities.h"
#include "llvm/CodeGen/LiveIntervals.h"
#include "llvm/CodeGen/MachineBlockFrequencyInfo.h"
#include "llvm/CodeGen/MachineDominators.h"
#include "llvm/CodeGen/MachineInstrBuilder.h"
#include "llvm/CodeGen/MachineRegisterInfo.h"
#include "llvm/CodeGen/Passes.h"
#include "llvm/IR/GlobalAlias.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/raw_ostream.h"
#include <iterator>
Go to the source code of this file.
Macros | |
#define | DEBUG_TYPE "wasm-reg-stackify" |
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.
#define DEBUG_TYPE "wasm-reg-stackify" |
Definition at line 40 of file WebAssemblyRegStackify.cpp.
|
static |
Definition at line 96 of file WebAssemblyRegStackify.cpp.
References assert(), llvm::MachineOperand::CreateFPImm(), llvm::MachineOperand::CreateImm(), llvm::Function::getContext(), llvm::Type::getDoubleTy(), llvm::Type::getFloatTy(), llvm::MachineFunction::getFunction(), llvm::Constant::getNullValue(), llvm_unreachable, MI, MRI, and TII.
|
static |
Definition at line 561 of file WebAssemblyRegStackify.cpp.
Referenced by rematerializeCheapDef().
|
static |
Get the appropriate tee opcode for the given register class.
Definition at line 491 of file WebAssemblyRegStackify.cpp.
References llvm_unreachable.
Referenced by moveAndTeeForMultiUse().
|
static |
Definition at line 263 of file WebAssemblyRegStackify.cpp.
References llvm::LiveIntervals::getInstructionFromIndex(), llvm::LiveIntervals::getInstructionIndex(), llvm::LiveIntervals::getInterval(), llvm::LiveRange::getVNInfoBefore(), and MRI.
|
static |
Definition at line 281 of file WebAssemblyRegStackify.cpp.
References assert(), llvm::LiveIntervals::getInstructionIndex(), llvm::LiveIntervals::getInterval(), llvm::SlotIndex::getRegSlot(), llvm::LiveRange::getVNInfoAt(), I, MRI, and llvm::LiveRange::Query().
|
static |
Definition at line 80 of file WebAssemblyRegStackify.cpp.
References llvm::MachineOperand::CreateReg(), and MI.
Referenced by moveAndTeeForMultiUse(), moveForSingleUse(), and rematerializeCheapDef().
INITIALIZE_PASS | ( | WebAssemblyRegStackify | , |
DEBUG_TYPE | , | ||
"Reorder instructions to use the WebAssembly value stack" | , | ||
false | , | ||
false | |||
) |
Definition at line 69 of file WebAssemblyRegStackify.cpp.
|
static |
Definition at line 311 of file WebAssemblyRegStackify.cpp.
References assert(), D, llvm::MachineInstr::defs(), llvm::drop_begin(), llvm::SmallVectorBase< Size_T >::empty(), llvm::MachineBasicBlock::end(), llvm::MachineInstr::getOpcode(), llvm::MachineInstr::getParent(), I, llvm::WebAssembly::isCatch(), MBB, MRI, llvm::MachineInstr::operands(), llvm::SmallVectorTemplateBase< T, bool >::push_back(), query(), llvm::Read, and llvm::Write.
|
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 633 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, shrinkToUses(), llvm::WebAssemblyDebugValueManager::sink(), llvm::WebAssemblyFunctionInfo::stackifyVReg(), TII, and llvm::WebAssemblyDebugValueManager::updateReg().
|
static |
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.
Definition at line 521 of file WebAssemblyRegStackify.cpp.
References llvm::LiveIntervals::createAndComputeVirtRegInterval(), llvm::dbgs(), llvm::LiveIntervals::getInstructionIndex(), llvm::LiveIntervals::getInterval(), llvm::SlotIndex::getRegSlot(), llvm::LiveIntervals::handleMove(), imposeStackOrdering(), LLVM_DEBUG, MRI, llvm::LiveRange::removeSegment(), llvm::WebAssemblyDebugValueManager::sink(), llvm::WebAssemblyFunctionInfo::stackifyVReg(), and llvm::WebAssemblyDebugValueManager::updateReg().
|
static |
Test whether OneUse, a use of Reg, dominates all of Reg's other uses.
Definition at line 433 of file WebAssemblyRegStackify.cpp.
References assert(), llvm::MachineDominatorTree::dominates(), llvm::MachineInstr::getDesc(), llvm::LiveIntervals::getInstructionIndex(), llvm::LiveIntervals::getInterval(), llvm::MCInstrDesc::getNumDefs(), llvm::MachineInstr::getOperand(), llvm::MachineOperand::getParent(), llvm::MachineOperand::getReg(), llvm::LiveRange::getVNInfoBefore(), llvm::MachineOperand::isReg(), llvm::Register::isVirtual(), llvm::WebAssemblyFunctionInfo::isVRegStackified(), and MRI.
|
static |
Definition at line 164 of file WebAssemblyRegStackify.cpp.
References assert(), MI, queryCallee(), llvm::Read, and llvm::Write.
Referenced by isSafeToMove().
|
static |
Definition at line 132 of file WebAssemblyRegStackify.cpp.
References F, llvm::WebAssembly::getCalleeOp(), llvm::MachineOperand::getGlobal(), llvm::MachineOperand::isGlobal(), MI, llvm::Read, and llvm::Write.
Referenced by query().
|
static |
A trivially cloneable instruction; clone it and nest the new copy with the current instruction.
Definition at line 570 of file WebAssemblyRegStackify.cpp.
References assert(), llvm::WebAssemblyDebugValueManager::cloneSink(), llvm::LiveIntervals::createAndComputeVirtRegInterval(), llvm::dbgs(), llvm::MachineInstr::dump(), llvm::dump(), llvm::MCRegister::from(), llvm::SlotIndex::getDeadSlot(), llvm::LiveIntervals::getInstructionIndex(), llvm::LiveIntervals::getInterval(), getPrevNonDebugInst(), llvm::SlotIndex::getRegSlot(), Idx, imposeStackOrdering(), llvm::LiveIntervals::InsertMachineInstrInMaps(), IsDead, llvm::LiveRange::liveAt(), LLVM_DEBUG, MRI, llvm::WebAssemblyDebugValueManager::removeDef(), llvm::LiveIntervals::removeInterval(), llvm::LiveIntervals::RemoveMachineInstrFromMaps(), llvm::LiveIntervals::removePhysRegDefAt(), shrinkToUses(), and llvm::WebAssemblyFunctionInfo::stackifyVReg().
|
static |
Definition at line 255 of file WebAssemblyRegStackify.cpp.
References TII.
|
static |
Definition at line 512 of file WebAssemblyRegStackify.cpp.
References llvm::LiveIntervals::shrinkToUses(), and llvm::LiveIntervals::splitSeparateComponents().
Referenced by moveAndTeeForMultiUse(), and rematerializeCheapDef().