michael@0: /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- michael@0: * vim: set ts=8 sts=4 et sw=4 tw=99: michael@0: * This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef jit_StackSlotAllocator_h michael@0: #define jit_StackSlotAllocator_h michael@0: michael@0: #include "jit/Registers.h" michael@0: michael@0: namespace js { michael@0: namespace jit { michael@0: michael@0: class StackSlotAllocator michael@0: { michael@0: js::Vector normalSlots; michael@0: js::Vector doubleSlots; michael@0: uint32_t height_; michael@0: michael@0: void freeSlot(uint32_t index) { michael@0: normalSlots.append(index); michael@0: } michael@0: void freeDoubleSlot(uint32_t index) { michael@0: doubleSlots.append(index); michael@0: } michael@0: michael@0: uint32_t allocateDoubleSlot() { michael@0: if (!doubleSlots.empty()) michael@0: return doubleSlots.popCopy(); michael@0: if (height_ % 8 != 0) michael@0: normalSlots.append(height_ += 4); michael@0: return height_ += 8; michael@0: } michael@0: uint32_t allocateSlot() { michael@0: if (!normalSlots.empty()) michael@0: return normalSlots.popCopy(); michael@0: if (!doubleSlots.empty()) { michael@0: uint32_t index = doubleSlots.popCopy(); michael@0: normalSlots.append(index - 4); michael@0: return index; michael@0: } michael@0: return height_ += 4; michael@0: } michael@0: michael@0: public: michael@0: StackSlotAllocator() : height_(0) michael@0: { } michael@0: michael@0: void freeSlot(LDefinition::Type type, uint32_t index) { michael@0: switch (type) { michael@0: #if JS_BITS_PER_WORD == 32 michael@0: case LDefinition::GENERAL: michael@0: case LDefinition::OBJECT: michael@0: case LDefinition::SLOTS: michael@0: #endif michael@0: case LDefinition::INT32: michael@0: case LDefinition::FLOAT32: return freeSlot(index); michael@0: #if JS_BITS_PER_WORD == 64 michael@0: case LDefinition::GENERAL: michael@0: case LDefinition::OBJECT: michael@0: case LDefinition::SLOTS: michael@0: #endif michael@0: #ifdef JS_PUNBOX64 michael@0: case LDefinition::BOX: michael@0: #endif michael@0: #ifdef JS_NUNBOX32 michael@0: case LDefinition::TYPE: michael@0: case LDefinition::PAYLOAD: michael@0: #endif michael@0: case LDefinition::DOUBLE: return freeDoubleSlot(index); michael@0: default: MOZ_ASSUME_UNREACHABLE("Unknown slot type"); michael@0: } michael@0: } michael@0: michael@0: uint32_t allocateSlot(LDefinition::Type type) { michael@0: switch (type) { michael@0: #if JS_BITS_PER_WORD == 32 michael@0: case LDefinition::GENERAL: michael@0: case LDefinition::OBJECT: michael@0: case LDefinition::SLOTS: michael@0: #endif michael@0: case LDefinition::INT32: michael@0: case LDefinition::FLOAT32: return allocateSlot(); michael@0: #if JS_BITS_PER_WORD == 64 michael@0: case LDefinition::GENERAL: michael@0: case LDefinition::OBJECT: michael@0: case LDefinition::SLOTS: michael@0: #endif michael@0: #ifdef JS_PUNBOX64 michael@0: case LDefinition::BOX: michael@0: #endif michael@0: #ifdef JS_NUNBOX32 michael@0: case LDefinition::TYPE: michael@0: case LDefinition::PAYLOAD: michael@0: #endif michael@0: case LDefinition::DOUBLE: return allocateDoubleSlot(); michael@0: default: MOZ_ASSUME_UNREACHABLE("Unknown slot type"); michael@0: } michael@0: } michael@0: michael@0: uint32_t stackHeight() const { michael@0: return height_; michael@0: } michael@0: }; michael@0: michael@0: } // namespace jit michael@0: } // namespace js michael@0: michael@0: #endif /* jit_StackSlotAllocator_h */