1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/src/jit/StupidAllocator.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,89 @@ 1.4 +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- 1.5 + * vim: set ts=8 sts=4 et sw=4 tw=99: 1.6 + * This Source Code Form is subject to the terms of the Mozilla Public 1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.9 + 1.10 +#ifndef jit_StupidAllocator_h 1.11 +#define jit_StupidAllocator_h 1.12 + 1.13 +#include "jit/RegisterAllocator.h" 1.14 + 1.15 +// Simple register allocator that only carries registers within basic blocks. 1.16 + 1.17 +namespace js { 1.18 +namespace jit { 1.19 + 1.20 +class StupidAllocator : public RegisterAllocator 1.21 +{ 1.22 + static const uint32_t MAX_REGISTERS = Registers::Allocatable + FloatRegisters::Allocatable; 1.23 + static const uint32_t MISSING_ALLOCATION = UINT32_MAX; 1.24 + 1.25 + struct AllocatedRegister { 1.26 + AnyRegister reg; 1.27 + 1.28 + // The type of the value in the register. 1.29 + LDefinition::Type type; 1.30 + 1.31 + // Virtual register this physical reg backs, or MISSING_ALLOCATION. 1.32 + uint32_t vreg; 1.33 + 1.34 + // id of the instruction which most recently used this register. 1.35 + uint32_t age; 1.36 + 1.37 + // Whether the physical register is not synced with the backing stack slot. 1.38 + bool dirty; 1.39 + 1.40 + void set(uint32_t vreg, LInstruction *ins = nullptr, bool dirty = false) { 1.41 + this->vreg = vreg; 1.42 + this->age = ins ? ins->id() : 0; 1.43 + this->dirty = dirty; 1.44 + } 1.45 + }; 1.46 + 1.47 + // Active allocation for the current code position. 1.48 + mozilla::Array<AllocatedRegister, MAX_REGISTERS> registers; 1.49 + uint32_t registerCount; 1.50 + 1.51 + // Type indicating an index into registers. 1.52 + typedef uint32_t RegisterIndex; 1.53 + 1.54 + // Information about each virtual register. 1.55 + Vector<LDefinition*, 0, SystemAllocPolicy> virtualRegisters; 1.56 + 1.57 + public: 1.58 + StupidAllocator(MIRGenerator *mir, LIRGenerator *lir, LIRGraph &graph) 1.59 + : RegisterAllocator(mir, lir, graph) 1.60 + { 1.61 + } 1.62 + 1.63 + bool go(); 1.64 + 1.65 + private: 1.66 + bool init(); 1.67 + 1.68 + void syncForBlockEnd(LBlock *block, LInstruction *ins); 1.69 + void allocateForInstruction(LInstruction *ins); 1.70 + void allocateForDefinition(LInstruction *ins, LDefinition *def); 1.71 + 1.72 + LAllocation *stackLocation(uint32_t vreg); 1.73 + 1.74 + RegisterIndex registerIndex(AnyRegister reg); 1.75 + 1.76 + AnyRegister ensureHasRegister(LInstruction *ins, uint32_t vreg); 1.77 + RegisterIndex allocateRegister(LInstruction *ins, uint32_t vreg); 1.78 + 1.79 + void syncRegister(LInstruction *ins, RegisterIndex index); 1.80 + void evictRegister(LInstruction *ins, RegisterIndex index); 1.81 + void loadRegister(LInstruction *ins, uint32_t vreg, RegisterIndex index, LDefinition::Type type); 1.82 + 1.83 + RegisterIndex findExistingRegister(uint32_t vreg); 1.84 + 1.85 + bool allocationRequiresRegister(const LAllocation *alloc, AnyRegister reg); 1.86 + bool registerIsReserved(LInstruction *ins, AnyRegister reg); 1.87 +}; 1.88 + 1.89 +} // namespace jit 1.90 +} // namespace js 1.91 + 1.92 +#endif /* jit_StupidAllocator_h */