[llvm] c44d528 - [StackColoring] Declare BitVector outside the loop (#95688)
via llvm-commits
llvm-commits at lists.llvm.org
Sun Jun 16 00:27:25 PDT 2024
Author: Kazu Hirata
Date: 2024-06-16T00:27:22-07:00
New Revision: c44d52823b4fe8f3aa98fc034f9fcc69b98ef6a0
URL: https://github.com/llvm/llvm-project/commit/c44d52823b4fe8f3aa98fc034f9fcc69b98ef6a0
DIFF: https://github.com/llvm/llvm-project/commit/c44d52823b4fe8f3aa98fc034f9fcc69b98ef6a0.diff
LOG: [StackColoring] Declare BitVector outside the loop (#95688)
The StackColoring pass creates two instances of BitVector per basic
block until the fixed point is reached. Each instance may involve a
heap allocation depending on its size.
This patch declares them outside the loop, saving 1.40% of heap
allocations during the compilation of CGBuiltin.cpp.ii, a preprocessed
version of CGBuiltin.cpp.
Added:
Modified:
llvm/lib/CodeGen/StackColoring.cpp
Removed:
################################################################################
diff --git a/llvm/lib/CodeGen/StackColoring.cpp b/llvm/lib/CodeGen/StackColoring.cpp
index 37f7aa9290054..36414e742c327 100644
--- a/llvm/lib/CodeGen/StackColoring.cpp
+++ b/llvm/lib/CodeGen/StackColoring.cpp
@@ -773,6 +773,10 @@ unsigned StackColoring::collectMarkers(unsigned NumSlot) {
void StackColoring::calculateLocalLiveness() {
unsigned NumIters = 0;
bool changed = true;
+ // Create BitVector outside the loop and reuse them to avoid repeated heap
+ // allocations.
+ BitVector LocalLiveIn;
+ BitVector LocalLiveOut;
while (changed) {
changed = false;
++NumIters;
@@ -784,7 +788,7 @@ void StackColoring::calculateLocalLiveness() {
BlockLifetimeInfo &BlockInfo = BI->second;
// Compute LiveIn by unioning together the LiveOut sets of all preds.
- BitVector LocalLiveIn;
+ LocalLiveIn.clear();
for (MachineBasicBlock *Pred : BB->predecessors()) {
LivenessMap::const_iterator I = BlockLiveness.find(Pred);
// PR37130: transformations prior to stack coloring can
@@ -801,7 +805,7 @@ void StackColoring::calculateLocalLiveness() {
// because we already handle the case where the BEGIN comes
// before the END when collecting the markers (and building the
// BEGIN/END vectors).
- BitVector LocalLiveOut = LocalLiveIn;
+ LocalLiveOut = LocalLiveIn;
LocalLiveOut.reset(BlockInfo.End);
LocalLiveOut |= BlockInfo.Begin;
More information about the llvm-commits
mailing list