Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- |
michael@0 | 2 | * vim: set ts=8 sts=4 et sw=4 tw=99: |
michael@0 | 3 | * This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 4 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 5 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 6 | |
michael@0 | 7 | #ifndef jit_LinearScan_h |
michael@0 | 8 | #define jit_LinearScan_h |
michael@0 | 9 | |
michael@0 | 10 | #include "jit/LiveRangeAllocator.h" |
michael@0 | 11 | #include "js/Vector.h" |
michael@0 | 12 | |
michael@0 | 13 | namespace js { |
michael@0 | 14 | namespace jit { |
michael@0 | 15 | |
michael@0 | 16 | class LinearScanVirtualRegister : public VirtualRegister |
michael@0 | 17 | { |
michael@0 | 18 | private: |
michael@0 | 19 | LAllocation *canonicalSpill_; |
michael@0 | 20 | CodePosition spillPosition_ ; |
michael@0 | 21 | |
michael@0 | 22 | bool spillAtDefinition_ : 1; |
michael@0 | 23 | |
michael@0 | 24 | // This bit is used to determine whether both halves of a nunbox have been |
michael@0 | 25 | // processed by freeAllocation(). |
michael@0 | 26 | bool finished_ : 1; |
michael@0 | 27 | |
michael@0 | 28 | public: |
michael@0 | 29 | LinearScanVirtualRegister(TempAllocator &alloc) |
michael@0 | 30 | : VirtualRegister(alloc) |
michael@0 | 31 | {} |
michael@0 | 32 | void setCanonicalSpill(LAllocation *alloc) { |
michael@0 | 33 | canonicalSpill_ = alloc; |
michael@0 | 34 | } |
michael@0 | 35 | LAllocation *canonicalSpill() const { |
michael@0 | 36 | return canonicalSpill_; |
michael@0 | 37 | } |
michael@0 | 38 | unsigned canonicalSpillSlot() const { |
michael@0 | 39 | return canonicalSpill_->toStackSlot()->slot(); |
michael@0 | 40 | } |
michael@0 | 41 | void setFinished() { |
michael@0 | 42 | finished_ = true; |
michael@0 | 43 | } |
michael@0 | 44 | bool finished() const { |
michael@0 | 45 | return finished_; |
michael@0 | 46 | } |
michael@0 | 47 | void setSpillAtDefinition(CodePosition pos) { |
michael@0 | 48 | spillAtDefinition_ = true; |
michael@0 | 49 | setSpillPosition(pos); |
michael@0 | 50 | } |
michael@0 | 51 | bool mustSpillAtDefinition() const { |
michael@0 | 52 | return spillAtDefinition_; |
michael@0 | 53 | } |
michael@0 | 54 | CodePosition spillPosition() const { |
michael@0 | 55 | return spillPosition_; |
michael@0 | 56 | } |
michael@0 | 57 | void setSpillPosition(CodePosition pos) { |
michael@0 | 58 | spillPosition_ = pos; |
michael@0 | 59 | } |
michael@0 | 60 | }; |
michael@0 | 61 | |
michael@0 | 62 | class LinearScanAllocator |
michael@0 | 63 | : private LiveRangeAllocator<LinearScanVirtualRegister, /* forLSRA = */ true> |
michael@0 | 64 | { |
michael@0 | 65 | friend class C1Spewer; |
michael@0 | 66 | friend class JSONSpewer; |
michael@0 | 67 | |
michael@0 | 68 | // Work set of LiveIntervals, sorted by start() and then by priority, |
michael@0 | 69 | // non-monotonically descending from tail to head. |
michael@0 | 70 | class UnhandledQueue : public InlineList<LiveInterval> |
michael@0 | 71 | { |
michael@0 | 72 | public: |
michael@0 | 73 | void enqueueForward(LiveInterval *after, LiveInterval *interval); |
michael@0 | 74 | void enqueueBackward(LiveInterval *interval); |
michael@0 | 75 | |
michael@0 | 76 | void assertSorted(); |
michael@0 | 77 | |
michael@0 | 78 | LiveInterval *dequeue(); |
michael@0 | 79 | }; |
michael@0 | 80 | |
michael@0 | 81 | typedef Vector<LiveInterval *, 0, SystemAllocPolicy> SlotList; |
michael@0 | 82 | SlotList finishedSlots_; |
michael@0 | 83 | SlotList finishedDoubleSlots_; |
michael@0 | 84 | #ifdef JS_NUNBOX32 |
michael@0 | 85 | SlotList finishedNunboxSlots_; |
michael@0 | 86 | #endif |
michael@0 | 87 | |
michael@0 | 88 | // Run-time state |
michael@0 | 89 | UnhandledQueue unhandled; |
michael@0 | 90 | InlineList<LiveInterval> active; |
michael@0 | 91 | InlineList<LiveInterval> inactive; |
michael@0 | 92 | InlineList<LiveInterval> fixed; |
michael@0 | 93 | InlineList<LiveInterval> handled; |
michael@0 | 94 | LiveInterval *current; |
michael@0 | 95 | |
michael@0 | 96 | bool allocateRegisters(); |
michael@0 | 97 | bool resolveControlFlow(); |
michael@0 | 98 | bool reifyAllocations(); |
michael@0 | 99 | bool populateSafepoints(); |
michael@0 | 100 | |
michael@0 | 101 | // Optimization for the UnsortedQueue. |
michael@0 | 102 | void enqueueVirtualRegisterIntervals(); |
michael@0 | 103 | |
michael@0 | 104 | uint32_t allocateSlotFor(const LiveInterval *interval); |
michael@0 | 105 | bool splitInterval(LiveInterval *interval, CodePosition pos); |
michael@0 | 106 | bool splitBlockingIntervals(LAllocation allocation); |
michael@0 | 107 | bool assign(LAllocation allocation); |
michael@0 | 108 | bool spill(); |
michael@0 | 109 | void freeAllocation(LiveInterval *interval, LAllocation *alloc); |
michael@0 | 110 | void finishInterval(LiveInterval *interval); |
michael@0 | 111 | AnyRegister::Code findBestFreeRegister(CodePosition *freeUntil); |
michael@0 | 112 | AnyRegister::Code findBestBlockedRegister(CodePosition *nextUsed); |
michael@0 | 113 | bool canCoexist(LiveInterval *a, LiveInterval *b); |
michael@0 | 114 | bool moveInputAlloc(CodePosition pos, LAllocation *from, LAllocation *to, LDefinition::Type type); |
michael@0 | 115 | void setIntervalRequirement(LiveInterval *interval); |
michael@0 | 116 | bool isSpilledAt(LiveInterval *interval, CodePosition pos); |
michael@0 | 117 | |
michael@0 | 118 | #ifdef DEBUG |
michael@0 | 119 | void validateIntervals(); |
michael@0 | 120 | void validateAllocations(); |
michael@0 | 121 | #else |
michael@0 | 122 | inline void validateIntervals() { } |
michael@0 | 123 | inline void validateAllocations() { } |
michael@0 | 124 | #endif |
michael@0 | 125 | |
michael@0 | 126 | public: |
michael@0 | 127 | LinearScanAllocator(MIRGenerator *mir, LIRGenerator *lir, LIRGraph &graph) |
michael@0 | 128 | : LiveRangeAllocator<LinearScanVirtualRegister, /* forLSRA = */ true>(mir, lir, graph) |
michael@0 | 129 | { |
michael@0 | 130 | } |
michael@0 | 131 | |
michael@0 | 132 | bool go(); |
michael@0 | 133 | }; |
michael@0 | 134 | |
michael@0 | 135 | } // namespace jit |
michael@0 | 136 | } // namespace js |
michael@0 | 137 | |
michael@0 | 138 | #endif /* jit_LinearScan_h */ |