1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/src/jit/StackSlotAllocator.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,110 @@ 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_StackSlotAllocator_h 1.11 +#define jit_StackSlotAllocator_h 1.12 + 1.13 +#include "jit/Registers.h" 1.14 + 1.15 +namespace js { 1.16 +namespace jit { 1.17 + 1.18 +class StackSlotAllocator 1.19 +{ 1.20 + js::Vector<uint32_t, 4, SystemAllocPolicy> normalSlots; 1.21 + js::Vector<uint32_t, 4, SystemAllocPolicy> doubleSlots; 1.22 + uint32_t height_; 1.23 + 1.24 + void freeSlot(uint32_t index) { 1.25 + normalSlots.append(index); 1.26 + } 1.27 + void freeDoubleSlot(uint32_t index) { 1.28 + doubleSlots.append(index); 1.29 + } 1.30 + 1.31 + uint32_t allocateDoubleSlot() { 1.32 + if (!doubleSlots.empty()) 1.33 + return doubleSlots.popCopy(); 1.34 + if (height_ % 8 != 0) 1.35 + normalSlots.append(height_ += 4); 1.36 + return height_ += 8; 1.37 + } 1.38 + uint32_t allocateSlot() { 1.39 + if (!normalSlots.empty()) 1.40 + return normalSlots.popCopy(); 1.41 + if (!doubleSlots.empty()) { 1.42 + uint32_t index = doubleSlots.popCopy(); 1.43 + normalSlots.append(index - 4); 1.44 + return index; 1.45 + } 1.46 + return height_ += 4; 1.47 + } 1.48 + 1.49 + public: 1.50 + StackSlotAllocator() : height_(0) 1.51 + { } 1.52 + 1.53 + void freeSlot(LDefinition::Type type, uint32_t index) { 1.54 + switch (type) { 1.55 +#if JS_BITS_PER_WORD == 32 1.56 + case LDefinition::GENERAL: 1.57 + case LDefinition::OBJECT: 1.58 + case LDefinition::SLOTS: 1.59 +#endif 1.60 + case LDefinition::INT32: 1.61 + case LDefinition::FLOAT32: return freeSlot(index); 1.62 +#if JS_BITS_PER_WORD == 64 1.63 + case LDefinition::GENERAL: 1.64 + case LDefinition::OBJECT: 1.65 + case LDefinition::SLOTS: 1.66 +#endif 1.67 +#ifdef JS_PUNBOX64 1.68 + case LDefinition::BOX: 1.69 +#endif 1.70 +#ifdef JS_NUNBOX32 1.71 + case LDefinition::TYPE: 1.72 + case LDefinition::PAYLOAD: 1.73 +#endif 1.74 + case LDefinition::DOUBLE: return freeDoubleSlot(index); 1.75 + default: MOZ_ASSUME_UNREACHABLE("Unknown slot type"); 1.76 + } 1.77 + } 1.78 + 1.79 + uint32_t allocateSlot(LDefinition::Type type) { 1.80 + switch (type) { 1.81 +#if JS_BITS_PER_WORD == 32 1.82 + case LDefinition::GENERAL: 1.83 + case LDefinition::OBJECT: 1.84 + case LDefinition::SLOTS: 1.85 +#endif 1.86 + case LDefinition::INT32: 1.87 + case LDefinition::FLOAT32: return allocateSlot(); 1.88 +#if JS_BITS_PER_WORD == 64 1.89 + case LDefinition::GENERAL: 1.90 + case LDefinition::OBJECT: 1.91 + case LDefinition::SLOTS: 1.92 +#endif 1.93 +#ifdef JS_PUNBOX64 1.94 + case LDefinition::BOX: 1.95 +#endif 1.96 +#ifdef JS_NUNBOX32 1.97 + case LDefinition::TYPE: 1.98 + case LDefinition::PAYLOAD: 1.99 +#endif 1.100 + case LDefinition::DOUBLE: return allocateDoubleSlot(); 1.101 + default: MOZ_ASSUME_UNREACHABLE("Unknown slot type"); 1.102 + } 1.103 + } 1.104 + 1.105 + uint32_t stackHeight() const { 1.106 + return height_; 1.107 + } 1.108 +}; 1.109 + 1.110 +} // namespace jit 1.111 +} // namespace js 1.112 + 1.113 +#endif /* jit_StackSlotAllocator_h */