Bug 943429 - IonMonkey: Make forLSRA a template parameter instead of a dynamic parameter. r=bhackett
authorDan Gohman <sunfish@google.com>
Tue, 26 Nov 2013 11:22:58 -0800
changeset 157594 f2ed1e244513e952c6a800874577263c9d6b51a0
parent 157593 ea3d28db82526fb0aec04342ab147bf1aef8eefb
child 157595 4b627d104594af5c0edfa43343cdf745b93574e2
push id25716
push userkwierso@gmail.com
push dateWed, 27 Nov 2013 01:32:11 +0000
treeherdermozilla-central@d822990ba9ee [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbhackett
bugs943429
milestone28.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 943429 - IonMonkey: Make forLSRA a template parameter instead of a dynamic parameter. r=bhackett
js/src/jit/BacktrackingAllocator.h
js/src/jit/LinearScan.h
js/src/jit/LiveRangeAllocator.cpp
js/src/jit/LiveRangeAllocator.h
--- a/js/src/jit/BacktrackingAllocator.h
+++ b/js/src/jit/BacktrackingAllocator.h
@@ -103,17 +103,18 @@ class BacktrackingVirtualRegister : publ
         return group_;
     }
 };
 
 // A sequence of code positions, for tellings BacktrackingAllocator::splitAt
 // where to split.
 typedef js::Vector<CodePosition, 4, SystemAllocPolicy> SplitPositionVector;
 
-class BacktrackingAllocator : private LiveRangeAllocator<BacktrackingVirtualRegister>
+class BacktrackingAllocator
+  : private LiveRangeAllocator<BacktrackingVirtualRegister, /* forLSRA = */ false>
 {
     // Priority queue element: either an interval or group of intervals and the
     // associated priority.
     struct QueueItem
     {
         LiveInterval *interval;
         VirtualRegisterGroup *group;
 
@@ -172,17 +173,17 @@ class BacktrackingAllocator : private Li
     mozilla::Array<PhysicalRegister, AnyRegister::Total> registers;
 
     // Ranges of code which are considered to be hot, for which good allocation
     // should be prioritized.
     AllocatedRangeSet hotcode;
 
   public:
     BacktrackingAllocator(MIRGenerator *mir, LIRGenerator *lir, LIRGraph &graph)
-      : LiveRangeAllocator<BacktrackingVirtualRegister>(mir, lir, graph, /* forLSRA = */ false)
+      : LiveRangeAllocator<BacktrackingVirtualRegister, /* forLSRA = */ false>(mir, lir, graph)
     { }
 
     bool go();
 
   private:
 
     typedef Vector<LiveInterval *, 4, SystemAllocPolicy> LiveIntervalVector;
 
--- a/js/src/jit/LinearScan.h
+++ b/js/src/jit/LinearScan.h
@@ -54,17 +54,18 @@ class LinearScanVirtualRegister : public
     CodePosition spillPosition() const {
         return spillPosition_;
     }
     void setSpillPosition(CodePosition pos) {
         spillPosition_ = pos;
     }
 };
 
-class LinearScanAllocator : private LiveRangeAllocator<LinearScanVirtualRegister>
+class LinearScanAllocator
+  : private LiveRangeAllocator<LinearScanVirtualRegister, /* forLSRA = */ true>
 {
     friend class C1Spewer;
     friend class JSONSpewer;
 
     // Work set of LiveIntervals, sorted by start() and then by priority,
     // non-monotonically descending from tail to head.
     class UnhandledQueue : public InlineList<LiveInterval>
     {
@@ -119,17 +120,17 @@ class LinearScanAllocator : private Live
     void validateAllocations();
 #else
     inline void validateIntervals() { }
     inline void validateAllocations() { }
 #endif
 
   public:
     LinearScanAllocator(MIRGenerator *mir, LIRGenerator *lir, LIRGraph &graph)
-      : LiveRangeAllocator<LinearScanVirtualRegister>(mir, lir, graph, /* forLSRA = */ true)
+      : LiveRangeAllocator<LinearScanVirtualRegister, /* forLSRA = */ true>(mir, lir, graph)
     {
     }
 
     bool go();
 };
 
 } // namespace jit
 } // namespace js
--- a/js/src/jit/LiveRangeAllocator.cpp
+++ b/js/src/jit/LiveRangeAllocator.cpp
@@ -350,18 +350,18 @@ VirtualRegister::intervalFor(CodePositio
 LiveInterval *
 VirtualRegister::getFirstInterval()
 {
     JS_ASSERT(!intervals_.empty());
     return intervals_[0];
 }
 
 // Instantiate LiveRangeAllocator for each template instance.
-template bool LiveRangeAllocator<LinearScanVirtualRegister>::buildLivenessInfo();
-template bool LiveRangeAllocator<BacktrackingVirtualRegister>::buildLivenessInfo();
+template bool LiveRangeAllocator<LinearScanVirtualRegister, true>::buildLivenessInfo();
+template bool LiveRangeAllocator<BacktrackingVirtualRegister, false>::buildLivenessInfo();
 
 #ifdef DEBUG
 static inline bool
 NextInstructionHasFixedUses(LBlock *block, LInstruction *ins)
 {
     LInstructionIterator iter(block->begin(ins));
     iter++;
     for (LInstruction::InputIterator alloc(**iter); alloc.more(); alloc.next()) {
@@ -394,19 +394,19 @@ IsInputReused(LInstruction *ins, LUse *u
     return false;
 }
 #endif
 
 /*
  * This function pre-allocates and initializes as much global state as possible
  * to avoid littering the algorithms with memory management cruft.
  */
-template <typename VREG>
+template <typename VREG, bool forLSRA>
 bool
-LiveRangeAllocator<VREG>::init()
+LiveRangeAllocator<VREG, forLSRA>::init()
 {
     if (!RegisterAllocator::init())
         return false;
 
     liveIn = mir->allocate<BitSet*>(graph.numBlockIds());
     if (!liveIn)
         return false;
 
@@ -485,19 +485,19 @@ AddRegisterToSafepoint(LSafepoint *safep
  * The algorithm operates on blocks ordered such that dominators of a block
  * are before the block itself, and such that all blocks of a loop are
  * contiguous. It proceeds backwards over the instructions in this order,
  * marking registers live at their uses, ending their live intervals at
  * definitions, and recording which registers are live at the top of every
  * block. To deal with loop backedges, variables live at the beginning of
  * a loop gain an interval covering the entire loop.
  */
-template <typename VREG>
+template <typename VREG, bool forLSRA>
 bool
-LiveRangeAllocator<VREG>::buildLivenessInfo()
+LiveRangeAllocator<VREG, forLSRA>::buildLivenessInfo()
 {
     if (!init())
         return false;
 
     Vector<MBasicBlock *, 1, SystemAllocPolicy> loopWorkList;
     BitSet *loopDone = BitSet::New(alloc(), graph.numBlockIds());
     if (!loopDone)
         return false;
--- a/js/src/jit/LiveRangeAllocator.h
+++ b/js/src/jit/LiveRangeAllocator.h
@@ -548,44 +548,41 @@ IsTraceable(VirtualRegister *reg)
         return true;
 #endif
     return false;
 }
 
 typedef InlineList<LiveInterval>::iterator IntervalIterator;
 typedef InlineList<LiveInterval>::reverse_iterator IntervalReverseIterator;
 
-template <typename VREG>
+// The forLSRA parameter indicates whether the underlying allocator is LSRA.
+// This changes the generated live ranges in various ways: inserting additional
+// fixed uses of registers, and shifting the boundaries of live ranges by small
+// amounts. This exists because different allocators handle live ranges
+// differently; ideally, they would all treat live ranges in the same way.
+template <typename VREG, bool forLSRA>
 class LiveRangeAllocator : protected RegisterAllocator
 {
   protected:
     // Computed inforamtion
     BitSet **liveIn;
     VirtualRegisterMap<VREG> vregs;
     mozilla::Array<LiveInterval *, AnyRegister::Total> fixedIntervals;
 
     // Union of all ranges in fixedIntervals, used to quickly determine
     // whether an interval intersects with a fixed register.
     LiveInterval *fixedIntervalsUnion;
 
-    // Whether the underlying allocator is LSRA. This changes the generated
-    // live ranges in various ways: inserting additional fixed uses of
-    // registers, and shifting the boundaries of live ranges by small amounts.
-    // This exists because different allocators handle live ranges differently;
-    // ideally, they would all treat live ranges in the same way.
-    bool forLSRA;
-
     // Allocation state
     StackSlotAllocator stackSlotAllocator;
 
-    LiveRangeAllocator(MIRGenerator *mir, LIRGenerator *lir, LIRGraph &graph, bool forLSRA)
+    LiveRangeAllocator(MIRGenerator *mir, LIRGenerator *lir, LIRGraph &graph)
       : RegisterAllocator(mir, lir, graph),
         liveIn(nullptr),
-        fixedIntervalsUnion(nullptr),
-        forLSRA(forLSRA)
+        fixedIntervalsUnion(nullptr)
     {
     }
 
     bool buildLivenessInfo();
 
     bool init();
 
     bool addFixedRangeAtHead(AnyRegister reg, CodePosition from, CodePosition to) {