14#ifndef LLVM_CODEGEN_REMATERIALIZER_H
15#define LLVM_CODEGEN_REMATERIALIZER_H
157 assert(
DefMI &&
"defining instruction was deleted");
158 assert(
DefMI->getOperand(0).isDef() &&
"not a register def");
159 return DefMI->getOperand(0).getReg();
174 std::pair<MachineInstr *, MachineInstr *>
178 return DefMI &&
DefMI->getOpcode() != TargetOpcode::DBG_VALUE;
190 static constexpr unsigned NoReg = ~0;
195 std::pair<MachineBasicBlock::iterator, MachineBasicBlock::iterator>;
208 bool analyze(
bool SupportRollback);
211 assert(RegIdx < Regs.size() &&
"out of bounds");
218 assert(RegionIdx < Regions.size() &&
"out of bounds");
219 return Regions[RegionIdx];
226 assert(RegIdx < Regs.size() &&
"out of bounds");
227 return RegIdx >= UnrematableOprds.size();
232 return Origins[RematRegIdx - UnrematableOprds.size()];
308 DependencyReuseInfo &DRI);
320 DependencyReuseInfo &DRI);
427 bool SupportRollback =
false;
431 void addRegIfRematerializable(
unsigned VirtRegIdx,
BitVector &SeenRegs);
unsigned const MachineRegisterInfo * MRI
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
const HexagonInstrInfo * TII
Register const TargetRegisterInfo * TRI
Rematerializer::RegisterIdx RegisterIdx
Remove Loads Into Fake Uses
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Implements a dense probed hash-table based set.
MachineInstrBundleIterator< MachineInstr > iterator
Representation of each machine instruction.
MachineOperand class - Representation of each machine instruction operand.
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
Simple wrapper around std::function<void(raw_ostream&)>.
Wrapper class representing virtual and physical registers.
Printable printDependencyDAG(RegisterIdx RootIdx) const
RegisterIdx getOriginOrSelf(RegisterIdx RegIdx) const
If RegIdx is a rematerialization, returns its origin's index.
static constexpr unsigned NoReg
Error value for register indices.
Printable printID(RegisterIdx RegIdx) const
ArrayRef< Reg > getRegs() const
void rollbackRematsOf(RegisterIdx RootIdx)
Rolls back all rematerializations of original register RootIdx, transfering all their users back to i...
unsigned getNumRegs() const
RegisterIdx rematerializeToPos(RegisterIdx RootIdx, MachineBasicBlock::iterator InsertPos, DependencyReuseInfo &DRI)
Rematerializes register RootIdx before position InsertPos and returns the new register's index.
void transferUser(RegisterIdx FromRegIdx, RegisterIdx ToRegIdx, MachineInstr &UserMI)
Transfers user UserMI from register FromRegIdx to ToRegIdx, the latter of which must be a remateriali...
RegisterIdx getOriginOf(RegisterIdx RematRegIdx) const
Returns the origin index of rematerializable register RegIdx.
const Reg & getReg(RegisterIdx RegIdx) const
void updateLiveIntervals()
Recomputes all live intervals that have changed as a result of previous rematerializations/rollbacks.
RegisterIdx rematerializeToRegion(RegisterIdx RootIdx, unsigned UseRegion, DependencyReuseInfo &DRI)
Rematerializes register RootIdx just before its first user inside region UseRegion,...
std::pair< MachineBasicBlock::iterator, MachineBasicBlock::iterator > RegionBoundaries
A region's boundaries i.e.
bool analyze(bool SupportRollback)
Goes through the whole MF and identifies all rematerializable registers.
void rollback(RegisterIdx RematIdx)
Rolls back register RematIdx (which must be a rematerialization) transfering all its users back to it...
unsigned RegisterIdx
Index type for rematerializable registers.
void reviveRegIfDead(RegisterIdx RootIdx)
Revives original register RootIdx at its original position in the MIR if it was fully rematerialized ...
bool isMOIdenticalAtUses(MachineOperand &MO, ArrayRef< SlotIndex > Uses) const
Determines whether (sub-)register operand MO has the same value at all Uses as at MO.
void transferRegionUsers(RegisterIdx FromRegIdx, RegisterIdx ToRegIdx, unsigned UseRegion)
Transfers all users of register FromRegIdx in region UseRegion to ToRegIdx, the latter of which must ...
void commitRematerializations()
Deletes unused rematerialized registers that were left in the MIR to support rollback.
unsigned getNumRegions() const
Rematerializer(MachineFunction &MF, SmallVectorImpl< RegionBoundaries > &Regions, LiveIntervals &LIS)
Simply initializes some internal state, does not identify rematerialization candidates.
ArrayRef< unsigned > getUnrematableOprds(unsigned RegIdx) const
Returns operand indices corresponding to unrematerializable operands for any register RegIdx.
const RegionBoundaries & getRegion(RegisterIdx RegionIdx)
Printable printUser(const MachineInstr *MI) const
bool isRematerializedRegister(RegisterIdx RegIdx) const
Whether register RegIdx is a rematerialization of some original register.
Printable printRematReg(RegisterIdx RegIdx, bool SkipRegions=false) const
Printable printRegUsers(RegisterIdx RegIdx) const
RegisterIdx findRematInRegion(RegisterIdx RegIdx, unsigned Region, SlotIndex Before) const
Finds the closest rematerialization of register RegIdx in region Region that exists before slot Befor...
SlotIndex - An opaque wrapper around machine indexes.
Implements a dense probed hash-table based set with some number of buckets stored inline.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
TargetInstrInfo - Interface to description of machine instruction set.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
This is an optimization pass for GlobalISel generic memory operations.
When rematerializating a register (called the "root" register in this context) to a given position,...
DependencyReuseInfo & clear()
DependencyReuseInfo & reuse(RegisterIdx DepIdx)
SmallDenseMap< RegisterIdx, RegisterIdx, 4 > DependencyMap
Keys and values are rematerializable register indices.
DependencyReuseInfo & useRemat(RegisterIdx DepIdx, RegisterIdx DepRematIdx)
unsigned MOIdx
The register's machine operand index in DefMI.
Dependency(unsigned MOIdx, RegisterIdx RegIdx)
RegisterIdx RegIdx
The corresponding register's index in the rematerializer.
A rematerializable register defined by a single machine instruction.
MachineInstr * DefMI
Single MI defining the rematerializable register.
SmallVector< Dependency, 2 > Dependencies
This register's rematerializable dependencies, one per unique rematerializable register operand.
LaneBitmask Mask
The rematerializable register's lane bitmask.
std::pair< MachineInstr *, MachineInstr * > getRegionUseBounds(unsigned UseRegion, const LiveIntervals &LIS) const
Returns the first and last user of the register in region UseRegion.
bool hasUsersInDefRegion() const
bool hasUsersOutsideDefRegion() const
unsigned DefRegion
Defining region of DefMI.
SmallDenseMap< unsigned, RegionUsers, 2 > Uses
Uses of the register, mapped by region.
Register getDefReg() const
Returns the rematerializable register from its defining instruction.
SmallDenseSet< MachineInstr *, 4 > RegionUsers