MachineBasicBlock: Cleanup computeRegisterLiveness()

- Clean documentation comment
- Change the API to accept an iterator so you can actually pass
  MachineBasicBlock::end() now.
- Add more "const".

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@238288 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Matthias Braun
2015-05-27 05:12:39 +00:00
parent 299e50237a
commit f5b4273058
2 changed files with 23 additions and 24 deletions

View File

@@ -633,17 +633,18 @@ public:
///< neighborhood. ///< neighborhood.
}; };
/// computeRegisterLiveness - Return whether (physical) register \c Reg /// Return whether (physical) register \p Reg has been <def>ined and not
/// has been <def>ined and not <kill>ed as of just before \c MI. /// <kill>ed as of just before \p Before.
/// ///
/// Search is localised to a neighborhood of /// Search is localised to a neighborhood of \p Neighborhood instructions
/// \c Neighborhood instructions before (searching for defs or kills) and /// before (searching for defs or kills) and \p Neighborhood instructions
/// Neighborhood instructions after (searching just for defs) MI. /// after (searching just for defs) \p Before.
/// ///
/// \c Reg must be a physical register. /// \p Reg must be a physical register.
LivenessQueryResult computeRegisterLiveness(const TargetRegisterInfo *TRI, LivenessQueryResult computeRegisterLiveness(const TargetRegisterInfo *TRI,
unsigned Reg, MachineInstr *MI, unsigned Reg,
unsigned Neighborhood=10); const_iterator Before,
unsigned Neighborhood=10) const;
// Debugging methods. // Debugging methods.
void dump() const; void dump() const;

View File

@@ -1129,21 +1129,19 @@ getWeightIterator(MachineBasicBlock::const_succ_iterator I) const {
/// instructions after (searching just for defs) MI. /// instructions after (searching just for defs) MI.
MachineBasicBlock::LivenessQueryResult MachineBasicBlock::LivenessQueryResult
MachineBasicBlock::computeRegisterLiveness(const TargetRegisterInfo *TRI, MachineBasicBlock::computeRegisterLiveness(const TargetRegisterInfo *TRI,
unsigned Reg, MachineInstr *MI, unsigned Reg, const_iterator Before,
unsigned Neighborhood) { unsigned Neighborhood) const {
unsigned N = Neighborhood; unsigned N = Neighborhood;
MachineBasicBlock *MBB = MI->getParent();
// Start by searching backwards from MI, looking for kills, reads or defs. // Start by searching backwards from Before, looking for kills, reads or defs.
const_iterator I(Before);
MachineBasicBlock::iterator I(MI);
// If this is the first insn in the block, don't search backwards. // If this is the first insn in the block, don't search backwards.
if (I != MBB->begin()) { if (I != begin()) {
do { do {
--I; --I;
MachineOperandIteratorBase::PhysRegInfo Analysis = MachineOperandIteratorBase::PhysRegInfo Analysis =
MIOperands(I).analyzePhysReg(Reg, TRI); ConstMIOperands(I).analyzePhysReg(Reg, TRI);
if (Analysis.Defines) if (Analysis.Defines)
// Outputs happen after inputs so they take precedence if both are // Outputs happen after inputs so they take precedence if both are
@@ -1158,15 +1156,15 @@ MachineBasicBlock::computeRegisterLiveness(const TargetRegisterInfo *TRI,
// Defined or read without a previous kill - live. // Defined or read without a previous kill - live.
return Analysis.Reads ? LQR_Live : LQR_OverlappingLive; return Analysis.Reads ? LQR_Live : LQR_OverlappingLive;
} while (I != MBB->begin() && --N > 0); } while (I != begin() && --N > 0);
} }
// Did we get to the start of the block? // Did we get to the start of the block?
if (I == MBB->begin()) { if (I == begin()) {
// If so, the register's state is definitely defined by the live-in state. // If so, the register's state is definitely defined by the live-in state.
for (MCRegAliasIterator RAI(Reg, TRI, /*IncludeSelf=*/true); for (MCRegAliasIterator RAI(Reg, TRI, /*IncludeSelf=*/true);
RAI.isValid(); ++RAI) { RAI.isValid(); ++RAI) {
if (MBB->isLiveIn(*RAI)) if (isLiveIn(*RAI))
return (*RAI == Reg) ? LQR_Live : LQR_OverlappingLive; return (*RAI == Reg) ? LQR_Live : LQR_OverlappingLive;
} }
@@ -1175,13 +1173,13 @@ MachineBasicBlock::computeRegisterLiveness(const TargetRegisterInfo *TRI,
N = Neighborhood; N = Neighborhood;
// Try searching forwards from MI, looking for reads or defs. // Try searching forwards from Before, looking for reads or defs.
I = MachineBasicBlock::iterator(MI); I = const_iterator(Before);
// If this is the last insn in the block, don't search forwards. // If this is the last insn in the block, don't search forwards.
if (I != MBB->end()) { if (I != end()) {
for (++I; I != MBB->end() && N > 0; ++I, --N) { for (++I; I != end() && N > 0; ++I, --N) {
MachineOperandIteratorBase::PhysRegInfo Analysis = MachineOperandIteratorBase::PhysRegInfo Analysis =
MIOperands(I).analyzePhysReg(Reg, TRI); ConstMIOperands(I).analyzePhysReg(Reg, TRI);
if (Analysis.ReadsOverlap) if (Analysis.ReadsOverlap)
// Used, therefore must have been live. // Used, therefore must have been live.