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_StupidAllocator_h |
michael@0 | 8 | #define jit_StupidAllocator_h |
michael@0 | 9 | |
michael@0 | 10 | #include "jit/RegisterAllocator.h" |
michael@0 | 11 | |
michael@0 | 12 | // Simple register allocator that only carries registers within basic blocks. |
michael@0 | 13 | |
michael@0 | 14 | namespace js { |
michael@0 | 15 | namespace jit { |
michael@0 | 16 | |
michael@0 | 17 | class StupidAllocator : public RegisterAllocator |
michael@0 | 18 | { |
michael@0 | 19 | static const uint32_t MAX_REGISTERS = Registers::Allocatable + FloatRegisters::Allocatable; |
michael@0 | 20 | static const uint32_t MISSING_ALLOCATION = UINT32_MAX; |
michael@0 | 21 | |
michael@0 | 22 | struct AllocatedRegister { |
michael@0 | 23 | AnyRegister reg; |
michael@0 | 24 | |
michael@0 | 25 | // The type of the value in the register. |
michael@0 | 26 | LDefinition::Type type; |
michael@0 | 27 | |
michael@0 | 28 | // Virtual register this physical reg backs, or MISSING_ALLOCATION. |
michael@0 | 29 | uint32_t vreg; |
michael@0 | 30 | |
michael@0 | 31 | // id of the instruction which most recently used this register. |
michael@0 | 32 | uint32_t age; |
michael@0 | 33 | |
michael@0 | 34 | // Whether the physical register is not synced with the backing stack slot. |
michael@0 | 35 | bool dirty; |
michael@0 | 36 | |
michael@0 | 37 | void set(uint32_t vreg, LInstruction *ins = nullptr, bool dirty = false) { |
michael@0 | 38 | this->vreg = vreg; |
michael@0 | 39 | this->age = ins ? ins->id() : 0; |
michael@0 | 40 | this->dirty = dirty; |
michael@0 | 41 | } |
michael@0 | 42 | }; |
michael@0 | 43 | |
michael@0 | 44 | // Active allocation for the current code position. |
michael@0 | 45 | mozilla::Array<AllocatedRegister, MAX_REGISTERS> registers; |
michael@0 | 46 | uint32_t registerCount; |
michael@0 | 47 | |
michael@0 | 48 | // Type indicating an index into registers. |
michael@0 | 49 | typedef uint32_t RegisterIndex; |
michael@0 | 50 | |
michael@0 | 51 | // Information about each virtual register. |
michael@0 | 52 | Vector<LDefinition*, 0, SystemAllocPolicy> virtualRegisters; |
michael@0 | 53 | |
michael@0 | 54 | public: |
michael@0 | 55 | StupidAllocator(MIRGenerator *mir, LIRGenerator *lir, LIRGraph &graph) |
michael@0 | 56 | : RegisterAllocator(mir, lir, graph) |
michael@0 | 57 | { |
michael@0 | 58 | } |
michael@0 | 59 | |
michael@0 | 60 | bool go(); |
michael@0 | 61 | |
michael@0 | 62 | private: |
michael@0 | 63 | bool init(); |
michael@0 | 64 | |
michael@0 | 65 | void syncForBlockEnd(LBlock *block, LInstruction *ins); |
michael@0 | 66 | void allocateForInstruction(LInstruction *ins); |
michael@0 | 67 | void allocateForDefinition(LInstruction *ins, LDefinition *def); |
michael@0 | 68 | |
michael@0 | 69 | LAllocation *stackLocation(uint32_t vreg); |
michael@0 | 70 | |
michael@0 | 71 | RegisterIndex registerIndex(AnyRegister reg); |
michael@0 | 72 | |
michael@0 | 73 | AnyRegister ensureHasRegister(LInstruction *ins, uint32_t vreg); |
michael@0 | 74 | RegisterIndex allocateRegister(LInstruction *ins, uint32_t vreg); |
michael@0 | 75 | |
michael@0 | 76 | void syncRegister(LInstruction *ins, RegisterIndex index); |
michael@0 | 77 | void evictRegister(LInstruction *ins, RegisterIndex index); |
michael@0 | 78 | void loadRegister(LInstruction *ins, uint32_t vreg, RegisterIndex index, LDefinition::Type type); |
michael@0 | 79 | |
michael@0 | 80 | RegisterIndex findExistingRegister(uint32_t vreg); |
michael@0 | 81 | |
michael@0 | 82 | bool allocationRequiresRegister(const LAllocation *alloc, AnyRegister reg); |
michael@0 | 83 | bool registerIsReserved(LInstruction *ins, AnyRegister reg); |
michael@0 | 84 | }; |
michael@0 | 85 | |
michael@0 | 86 | } // namespace jit |
michael@0 | 87 | } // namespace js |
michael@0 | 88 | |
michael@0 | 89 | #endif /* jit_StupidAllocator_h */ |