11cb0ef41Sopenharmony_ci// Copyright 2018 the V8 project authors. All rights reserved. 21cb0ef41Sopenharmony_ci// Use of this source code is governed by a BSD-style license that can be 31cb0ef41Sopenharmony_ci// found in the LICENSE file. 41cb0ef41Sopenharmony_ci 51cb0ef41Sopenharmony_ci#ifndef V8_COMPILER_ALLOCATION_BUILDER_INL_H_ 61cb0ef41Sopenharmony_ci#define V8_COMPILER_ALLOCATION_BUILDER_INL_H_ 71cb0ef41Sopenharmony_ci 81cb0ef41Sopenharmony_ci#include "src/compiler/access-builder.h" 91cb0ef41Sopenharmony_ci#include "src/compiler/allocation-builder.h" 101cb0ef41Sopenharmony_ci#include "src/heap/heap-inl.h" 111cb0ef41Sopenharmony_ci#include "src/objects/arguments-inl.h" 121cb0ef41Sopenharmony_ci#include "src/objects/map-inl.h" 131cb0ef41Sopenharmony_ci 141cb0ef41Sopenharmony_cinamespace v8 { 151cb0ef41Sopenharmony_cinamespace internal { 161cb0ef41Sopenharmony_cinamespace compiler { 171cb0ef41Sopenharmony_ci 181cb0ef41Sopenharmony_civoid AllocationBuilder::Allocate(int size, AllocationType allocation, 191cb0ef41Sopenharmony_ci Type type) { 201cb0ef41Sopenharmony_ci CHECK_GT(size, 0); 211cb0ef41Sopenharmony_ci DCHECK_LE(size, isolate()->heap()->MaxRegularHeapObjectSize(allocation)); 221cb0ef41Sopenharmony_ci effect_ = graph()->NewNode( 231cb0ef41Sopenharmony_ci common()->BeginRegion(RegionObservability::kNotObservable), effect_); 241cb0ef41Sopenharmony_ci allocation_ = graph()->NewNode(simplified()->Allocate(type, allocation), 251cb0ef41Sopenharmony_ci jsgraph()->Constant(size), effect_, control_); 261cb0ef41Sopenharmony_ci effect_ = allocation_; 271cb0ef41Sopenharmony_ci} 281cb0ef41Sopenharmony_ci 291cb0ef41Sopenharmony_civoid AllocationBuilder::AllocateContext(int variadic_part_length, MapRef map) { 301cb0ef41Sopenharmony_ci DCHECK(base::IsInRange(map.instance_type(), FIRST_CONTEXT_TYPE, 311cb0ef41Sopenharmony_ci LAST_CONTEXT_TYPE)); 321cb0ef41Sopenharmony_ci DCHECK_NE(NATIVE_CONTEXT_TYPE, map.instance_type()); 331cb0ef41Sopenharmony_ci int size = Context::SizeFor(variadic_part_length); 341cb0ef41Sopenharmony_ci Allocate(size, AllocationType::kYoung, Type::OtherInternal()); 351cb0ef41Sopenharmony_ci Store(AccessBuilder::ForMap(), map); 361cb0ef41Sopenharmony_ci STATIC_ASSERT(static_cast<int>(Context::kLengthOffset) == 371cb0ef41Sopenharmony_ci static_cast<int>(FixedArray::kLengthOffset)); 381cb0ef41Sopenharmony_ci Store(AccessBuilder::ForFixedArrayLength(), 391cb0ef41Sopenharmony_ci jsgraph()->Constant(variadic_part_length)); 401cb0ef41Sopenharmony_ci} 411cb0ef41Sopenharmony_ci 421cb0ef41Sopenharmony_cibool AllocationBuilder::CanAllocateArray(int length, MapRef map, 431cb0ef41Sopenharmony_ci AllocationType allocation) { 441cb0ef41Sopenharmony_ci DCHECK(map.instance_type() == FIXED_ARRAY_TYPE || 451cb0ef41Sopenharmony_ci map.instance_type() == FIXED_DOUBLE_ARRAY_TYPE); 461cb0ef41Sopenharmony_ci int const size = (map.instance_type() == FIXED_ARRAY_TYPE) 471cb0ef41Sopenharmony_ci ? FixedArray::SizeFor(length) 481cb0ef41Sopenharmony_ci : FixedDoubleArray::SizeFor(length); 491cb0ef41Sopenharmony_ci return size <= isolate()->heap()->MaxRegularHeapObjectSize(allocation); 501cb0ef41Sopenharmony_ci} 511cb0ef41Sopenharmony_ci 521cb0ef41Sopenharmony_ci// Compound allocation of a FixedArray. 531cb0ef41Sopenharmony_civoid AllocationBuilder::AllocateArray(int length, MapRef map, 541cb0ef41Sopenharmony_ci AllocationType allocation) { 551cb0ef41Sopenharmony_ci DCHECK(CanAllocateArray(length, map, allocation)); 561cb0ef41Sopenharmony_ci int size = (map.instance_type() == FIXED_ARRAY_TYPE) 571cb0ef41Sopenharmony_ci ? FixedArray::SizeFor(length) 581cb0ef41Sopenharmony_ci : FixedDoubleArray::SizeFor(length); 591cb0ef41Sopenharmony_ci Allocate(size, allocation, Type::OtherInternal()); 601cb0ef41Sopenharmony_ci Store(AccessBuilder::ForMap(), map); 611cb0ef41Sopenharmony_ci Store(AccessBuilder::ForFixedArrayLength(), jsgraph()->Constant(length)); 621cb0ef41Sopenharmony_ci} 631cb0ef41Sopenharmony_ci 641cb0ef41Sopenharmony_cibool AllocationBuilder::CanAllocateSloppyArgumentElements( 651cb0ef41Sopenharmony_ci int length, MapRef map, AllocationType allocation) { 661cb0ef41Sopenharmony_ci int const size = SloppyArgumentsElements::SizeFor(length); 671cb0ef41Sopenharmony_ci return size <= isolate()->heap()->MaxRegularHeapObjectSize(allocation); 681cb0ef41Sopenharmony_ci} 691cb0ef41Sopenharmony_ci 701cb0ef41Sopenharmony_civoid AllocationBuilder::AllocateSloppyArgumentElements( 711cb0ef41Sopenharmony_ci int length, MapRef map, AllocationType allocation) { 721cb0ef41Sopenharmony_ci DCHECK(CanAllocateSloppyArgumentElements(length, map, allocation)); 731cb0ef41Sopenharmony_ci int size = SloppyArgumentsElements::SizeFor(length); 741cb0ef41Sopenharmony_ci Allocate(size, allocation, Type::OtherInternal()); 751cb0ef41Sopenharmony_ci Store(AccessBuilder::ForMap(), map); 761cb0ef41Sopenharmony_ci Store(AccessBuilder::ForFixedArrayLength(), jsgraph()->Constant(length)); 771cb0ef41Sopenharmony_ci} 781cb0ef41Sopenharmony_ci 791cb0ef41Sopenharmony_ci} // namespace compiler 801cb0ef41Sopenharmony_ci} // namespace internal 811cb0ef41Sopenharmony_ci} // namespace v8 821cb0ef41Sopenharmony_ci 831cb0ef41Sopenharmony_ci#endif // V8_COMPILER_ALLOCATION_BUILDER_INL_H_ 84