diff --git a/llvm/include/llvm/CodeGen/LivePhysRegs.h b/llvm/include/llvm/CodeGen/LivePhysRegs.h index 9574a6f0c7c00..d315e4ff6f3ab 100644 --- a/llvm/include/llvm/CodeGen/LivePhysRegs.h +++ b/llvm/include/llvm/CodeGen/LivePhysRegs.h @@ -199,14 +199,15 @@ void computeAndAddLiveIns(LivePhysRegs &LiveRegs, /// any changes were made. static inline bool recomputeLiveIns(MachineBasicBlock &MBB) { LivePhysRegs LPR; - auto oldLiveIns = MBB.getLiveIns(); + std::vector OldLiveIns; - MBB.clearLiveIns(); + MBB.clearLiveIns(OldLiveIns); computeAndAddLiveIns(LPR, MBB); MBB.sortUniqueLiveIns(); - auto newLiveIns = MBB.getLiveIns(); - return oldLiveIns != newLiveIns; + const std::vector &NewLiveIns = + MBB.getLiveIns(); + return OldLiveIns != NewLiveIns; } /// Convenience function for recomputing live-in's for a set of MBBs until the diff --git a/llvm/include/llvm/CodeGen/MachineBasicBlock.h b/llvm/include/llvm/CodeGen/MachineBasicBlock.h index dc2035fa598c4..5b6be3a96b2fb 100644 --- a/llvm/include/llvm/CodeGen/MachineBasicBlock.h +++ b/llvm/include/llvm/CodeGen/MachineBasicBlock.h @@ -441,6 +441,10 @@ class MachineBasicBlock /// Clear live in list. void clearLiveIns(); + /// Clear the live in list, and return the removed live in's in \p OldLiveIns. + /// Requires that the vector \p OldLiveIns is empty. + void clearLiveIns(std::vector &OldLiveIns); + /// Add PhysReg as live in to this block, and ensure that there is a copy of /// PhysReg to a virtual register of class RC. Return the virtual register /// that is a copy of the live in PhysReg. @@ -477,7 +481,7 @@ class MachineBasicBlock /// Remove entry from the livein set and return iterator to the next. livein_iterator removeLiveIn(livein_iterator I); - std::vector getLiveIns() const { return LiveIns; } + const std::vector &getLiveIns() const { return LiveIns; } class liveout_iterator { public: diff --git a/llvm/lib/CodeGen/MachineBasicBlock.cpp b/llvm/lib/CodeGen/MachineBasicBlock.cpp index b2114c250ac09..0bd5f09564ec0 100644 --- a/llvm/lib/CodeGen/MachineBasicBlock.cpp +++ b/llvm/lib/CodeGen/MachineBasicBlock.cpp @@ -1728,6 +1728,12 @@ void MachineBasicBlock::clearLiveIns() { LiveIns.clear(); } +void MachineBasicBlock::clearLiveIns( + std::vector &OldLiveIns) { + assert(OldLiveIns.empty() && "Vector must be empty"); + std::swap(LiveIns, OldLiveIns); +} + MachineBasicBlock::livein_iterator MachineBasicBlock::livein_begin() const { assert(getParent()->getProperties().hasProperty( MachineFunctionProperties::Property::TracksLiveness) &&