/* * Copyright (c) 2021-2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "regAllocator.h" #include #include namespace panda::es2panda::compiler { // FrontAllocator FrontAllocator::FrontAllocator(PandaGen *pg) : pg_(pg), insn_(std::move(pg_->Insns()), pg_->Allocator()->Adapter()) { } FrontAllocator::~FrontAllocator() { pg_->Insns().splice(pg_->Insns().end(), std::move(insn_)); } // RegAllocator void RegAllocator::PushBack(IRNode *ins) { pg_->Insns().push_back(ins); } ArenaAllocator *RegAllocator::Allocator() const { return pg_->Allocator(); } uint16_t RegAllocator::GetSpillRegsCount() const { return spillRegs_; } void RegAllocator::UpdateIcSlot(IRNode *node) { auto inc = node->SetIcSlot(pg_->GetCurrentSlot()); pg_->IncreaseCurrentSlot(inc); } Label *RegAllocator::AllocLabel(std::string &&id) { const auto *lastInsNode = pg_->Insns().empty() ? FIRST_NODE_OF_FUNCTION : pg_->Insns().back()->Node(); return Alloc