[llvm] d0c51f7 - [LiveIns] Improve recomputeLiveIns() (#88951)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 17 13:07:39 PDT 2024
Author: Kai Nacke
Date: 2024-04-17T16:07:35-04:00
New Revision: d0c51f7d5496015ce410cc758a7caf976ffaaec7
URL: https://github.com/llvm/llvm-project/commit/d0c51f7d5496015ce410cc758a7caf976ffaaec7
DIFF: https://github.com/llvm/llvm-project/commit/d0c51f7d5496015ce410cc758a7caf976ffaaec7.diff
LOG: [LiveIns] Improve recomputeLiveIns() (#88951)
Some small changes to recomputeLiveIns() to improve performance:
- Instead of copying the list of old live-ins, and then clearing
them, a new method swaps the list for an empty one.
- getLiveIns() now returns a constant reference to the list
As result, the list-data is never copied. Depending on the
implementation
details of the vector container, it can also save calls to allocate
and deallocate memory.
I see a small improvement on CTMark with these changes.
---------
Co-authored-by: Nikita Popov <github at npopov.com>
Added:
Modified:
llvm/include/llvm/CodeGen/LivePhysRegs.h
llvm/include/llvm/CodeGen/MachineBasicBlock.h
llvm/lib/CodeGen/MachineBasicBlock.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/CodeGen/LivePhysRegs.h b/llvm/include/llvm/CodeGen/LivePhysRegs.h
index 9574a6f0c7c005..d315e4ff6f3abe 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<MachineBasicBlock::RegisterMaskPair> OldLiveIns;
- MBB.clearLiveIns();
+ MBB.clearLiveIns(OldLiveIns);
computeAndAddLiveIns(LPR, MBB);
MBB.sortUniqueLiveIns();
- auto newLiveIns = MBB.getLiveIns();
- return oldLiveIns != newLiveIns;
+ const std::vector<MachineBasicBlock::RegisterMaskPair> &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 dc2035fa598c46..5b6be3a96b2fb3 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<RegisterMaskPair> &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<RegisterMaskPair> getLiveIns() const { return LiveIns; }
+ const std::vector<RegisterMaskPair> &getLiveIns() const { return LiveIns; }
class liveout_iterator {
public:
diff --git a/llvm/lib/CodeGen/MachineBasicBlock.cpp b/llvm/lib/CodeGen/MachineBasicBlock.cpp
index b2114c250ac09d..0bd5f09564ec0c 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<RegisterMaskPair> &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) &&
More information about the llvm-commits
mailing list