aboutsummaryrefslogtreecommitdiff
path: root/lib/CodeGen/LiveIntervalAnalysis.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2004-07-19 14:40:29 +0000
committerChris Lattner <sabre@nondot.org>2004-07-19 14:40:29 +0000
commitcc0d156f7bca0811aade0a95b0e7419176383c90 (patch)
treedc7b1efc807e7b63ee1809eca6cda7710b15ed5a /lib/CodeGen/LiveIntervalAnalysis.cpp
parent1c5c0444f1326b58cf05015651f36f2b04ca322d (diff)
When joining intervals, join intervals in deeply nested loops first. This
is a simple change, but seems to improve code a little. For example, on 256.bzip2, we went from 75.0s -> 73.33s (2% speedup). git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@15004 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/LiveIntervalAnalysis.cpp')
-rw-r--r--lib/CodeGen/LiveIntervalAnalysis.cpp38
1 files changed, 34 insertions, 4 deletions
diff --git a/lib/CodeGen/LiveIntervalAnalysis.cpp b/lib/CodeGen/LiveIntervalAnalysis.cpp
index 475bb6e1d9..ebf9dcd2dd 100644
--- a/lib/CodeGen/LiveIntervalAnalysis.cpp
+++ b/lib/CodeGen/LiveIntervalAnalysis.cpp
@@ -109,7 +109,6 @@ bool LiveIntervals::runOnMachineFunction(MachineFunction &fn) {
// join intervals if requested
if (EnableJoining) joinIntervals();
- //DEBUG(mf_->viewCFG());
numIntervalsAfter += intervals_.size();
@@ -581,13 +580,44 @@ void LiveIntervals::joinIntervalsInMachineBB(MachineBasicBlock *MBB) {
}
}
-void LiveIntervals::joinIntervals()
-{
- DEBUG(std::cerr << "********** JOINING INTERVALS ***********\n");
+namespace {
+ // DepthMBBCompare - Comparison predicate that sort first based on the loop
+ // depth of the basic block (the unsigned), and then on the MBB number.
+ struct DepthMBBCompare {
+ typedef std::pair<unsigned, MachineBasicBlock*> DepthMBBPair;
+ bool operator()(const DepthMBBPair &LHS, const DepthMBBPair &RHS) const {
+ if (LHS.first > RHS.first) return true; // Deeper loops first
+ return LHS.first == RHS.first &&
+ LHS.second->getNumber() < RHS.second->getNumber();
+ }
+ };
+}
+
+void LiveIntervals::joinIntervals() {
+ DEBUG(std::cerr << "********** JOINING INTERVALS ***********\n");
+ const LoopInfo &LI = getAnalysis<LoopInfo>();
+ if (LI.begin() == LI.end()) {
+ // If there are no loops in the function, join intervals in function order.
for (MachineFunction::iterator I = mf_->begin(), E = mf_->end();
I != E; ++I)
joinIntervalsInMachineBB(I);
+ } else {
+ // Otherwise, join intervals in inner loops before other intervals.
+ // Unfortunately we can't just iterate over loop hierarchy here because
+ // there may be more MBB's than BB's. Collect MBB's for sorting.
+ std::vector<std::pair<unsigned, MachineBasicBlock*> > MBBs;
+ for (MachineFunction::iterator I = mf_->begin(), E = mf_->end();
+ I != E; ++I)
+ MBBs.push_back(std::make_pair(LI.getLoopDepth(I->getBasicBlock()), I));
+
+ // Sort by loop depth.
+ std::sort(MBBs.begin(), MBBs.end(), DepthMBBCompare());
+
+ // Finally, join intervals in loop nest order.
+ for (unsigned i = 0, e = MBBs.size(); i != e; ++i)
+ joinIntervalsInMachineBB(MBBs[i].second);
+ }
}
bool LiveIntervals::overlapsAliases(const LiveInterval& lhs,