summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Trick <atrick@apple.com>2013-12-11 03:40:15 +0000
committerAndrew Trick <atrick@apple.com>2013-12-11 03:40:15 +0000
commit2e3f799f014c978486b9569237d97d6cdd1b8937 (patch)
treed555eb228147158b850d2c5d4b34a946923b9bb9
parentd194a4ae67ed47d128a08ebca2448e154c1367ea (diff)
downloadllvm-2e3f799f014c978486b9569237d97d6cdd1b8937.tar.gz
llvm-2e3f799f014c978486b9569237d97d6cdd1b8937.tar.bz2
llvm-2e3f799f014c978486b9569237d97d6cdd1b8937.tar.xz
Add TargetRegisterInfo::reverseLocalAssignment hook.
This hook reverses the order of assignment for local live ranges. This will generally allocate shorter local live ranges first. For targets with many registers, this could reduce regalloc compile time by a large factor. It should still achieve optimal coloring; however, it can change register eviction decisions. It is disabled by default for two reasons: (1) Top-down allocation is simpler and easier to debug for targets that don't benefit from reversing the order. (2) Bottom-up allocation could result in poor evicition decisions on some targets affecting the performance of compiled code. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@197001 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/llvm/Target/TargetRegisterInfo.h11
-rw-r--r--lib/CodeGen/RegAllocGreedy.cpp9
2 files changed, 19 insertions, 1 deletions
diff --git a/include/llvm/Target/TargetRegisterInfo.h b/include/llvm/Target/TargetRegisterInfo.h
index 958bea6f2b..5f50e402b9 100644
--- a/include/llvm/Target/TargetRegisterInfo.h
+++ b/include/llvm/Target/TargetRegisterInfo.h
@@ -672,6 +672,17 @@ public:
// Do nothing.
}
+ /// Allow the target to reverse allocation order of local live ranges. This
+ /// will generally allocate shorter local live ranges first. For targets with
+ /// many registers, this could reduce regalloc compile time by a large
+ /// factor. It should still achieve optimal coloring; however, it can change
+ /// register eviction decisions. It is disabled by default for two reasons:
+ /// (1) Top-down allocation is simpler and easier to debug for targets that
+ /// don't benefit from reversing the order.
+ /// (2) Bottom-up allocation could result in poor evicition decisions on some
+ /// targets affecting the performance of compiled code.
+ virtual bool reverseLocalAssignment() const { return false; }
+
/// requiresRegisterScavenging - returns true if the target requires (and can
/// make use of) the register scavenger.
virtual bool requiresRegisterScavenging(const MachineFunction &MF) const {
diff --git a/lib/CodeGen/RegAllocGreedy.cpp b/lib/CodeGen/RegAllocGreedy.cpp
index 7ddc4d5ad8..7d97993106 100644
--- a/lib/CodeGen/RegAllocGreedy.cpp
+++ b/lib/CodeGen/RegAllocGreedy.cpp
@@ -423,7 +423,14 @@ void RAGreedy::enqueue(LiveInterval *LI) {
// Allocate original local ranges in linear instruction order. Since they
// are singly defined, this produces optimal coloring in the absence of
// global interference and other constraints.
- Prio = LI->beginIndex().getInstrDistance(Indexes->getLastIndex());
+ if (!TRI->reverseLocalAssignment())
+ Prio = LI->beginIndex().getInstrDistance(Indexes->getLastIndex());
+ else {
+ // Allocating bottom up may allow many short LRGs to be assigned first
+ // to one of the cheap registers. This could be much faster for very
+ // large blocks on targets with many physical registers.
+ Prio = Indexes->getZeroIndex().getInstrDistance(LI->beginIndex());
+ }
}
else {
// Allocate global and split ranges in long->short order. Long ranges that