[llvm-commits] [llvm] r121344 - in /llvm/trunk/lib/CodeGen: LiveIntervalUnion.cpp LiveIntervalUnion.h
Jakob Stoklund Olesen
stoklund at 2pi.dk
Wed Dec 8 17:06:52 PST 2010
Author: stoklund
Date: Wed Dec 8 19:06:52 2010
New Revision: 121344
URL: http://llvm.org/viewvc/llvm-project?rev=121344&view=rev
Log:
IntervalMap iterators are heavyweight, so avoid copying them around and use
references instead.
Similarly, IntervalMap::begin() is almost as expensive as find(), so use find(x)
instead of begin().advanceTo(x);
This makes RegAllocBasic run another 5% faster.
Modified:
llvm/trunk/lib/CodeGen/LiveIntervalUnion.cpp
llvm/trunk/lib/CodeGen/LiveIntervalUnion.h
Modified: llvm/trunk/lib/CodeGen/LiveIntervalUnion.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/LiveIntervalUnion.cpp?rev=121344&r1=121343&r2=121344&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/LiveIntervalUnion.cpp (original)
+++ llvm/trunk/lib/CodeGen/LiveIntervalUnion.cpp Wed Dec 8 19:06:52 2010
@@ -144,12 +144,29 @@
// Find the first intersection, and cache interference info
// (retain segment iterators into both VirtReg and LiveUnion).
-LiveIntervalUnion::InterferenceResult
+const LiveIntervalUnion::InterferenceResult &
LiveIntervalUnion::Query::firstInterference() {
- if (FirstInterference != LiveIntervalUnion::InterferenceResult()) {
+ if (CheckedFirstInterference)
return FirstInterference;
+ CheckedFirstInterference = true;
+ InterferenceResult &IR = FirstInterference;
+
+ // Quickly skip interference check for empty sets.
+ if (VirtReg->empty() || LiveUnion->empty()) {
+ IR.VirtRegI = VirtReg->end();
+ } else if (VirtReg->beginIndex() < LiveUnion->startIndex()) {
+ // VirtReg starts first, perform double binary search.
+ IR.VirtRegI = VirtReg->find(LiveUnion->startIndex());
+ if (IR.VirtRegI != VirtReg->end())
+ IR.LiveUnionI = LiveUnion->find(IR.VirtRegI->start);
+ } else {
+ // LiveUnion starts first, perform double binary search.
+ IR.LiveUnionI = LiveUnion->find(VirtReg->beginIndex());
+ if (IR.LiveUnionI.valid())
+ IR.VirtRegI = VirtReg->find(IR.LiveUnionI.start());
+ else
+ IR.VirtRegI = VirtReg->end();
}
- FirstInterference = InterferenceResult(VirtReg->begin(), LiveUnion->begin());
findIntersection(FirstInterference);
return FirstInterference;
}
Modified: llvm/trunk/lib/CodeGen/LiveIntervalUnion.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/LiveIntervalUnion.h?rev=121344&r1=121343&r2=121344&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/LiveIntervalUnion.h (original)
+++ llvm/trunk/lib/CodeGen/LiveIntervalUnion.h Wed Dec 8 19:06:52 2010
@@ -75,7 +75,9 @@
// by their starting position.
SegmentIter begin() { return Segments.begin(); }
SegmentIter end() { return Segments.end(); }
+ SegmentIter find(SlotIndex x) { return Segments.find(x); }
bool empty() { return Segments.empty(); }
+ SlotIndex startIndex() { return Segments.start(); }
// Add a live virtual register to this union and merge its segments.
void unify(LiveInterval &VirtReg);
@@ -135,6 +137,7 @@
LiveInterval *VirtReg;
InterferenceResult FirstInterference;
SmallVector<LiveInterval*,4> InterferingVRegs;
+ bool CheckedFirstInterference;
bool SeenAllInterferences;
bool SeenUnspillableVReg;
@@ -149,8 +152,8 @@
void clear() {
LiveUnion = NULL;
VirtReg = NULL;
- FirstInterference = InterferenceResult();
InterferingVRegs.clear();
+ CheckedFirstInterference = false;
SeenAllInterferences = false;
SeenUnspillableVReg = false;
}
@@ -187,7 +190,7 @@
// Get the first pair of interfering segments, or a noninterfering result.
// This initializes the firstInterference_ cache.
- InterferenceResult firstInterference();
+ const InterferenceResult &firstInterference();
// Treat the result as an iterator and advance to the next interfering pair
// of segments. Visiting each unique interfering pairs means that the same
More information about the llvm-commits
mailing list