• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2018 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef V8_COMPILER_ALLOCATION_BUILDER_INL_H_
6 #define V8_COMPILER_ALLOCATION_BUILDER_INL_H_
7 
8 #include "src/compiler/access-builder.h"
9 #include "src/compiler/allocation-builder.h"
10 #include "src/objects/arguments-inl.h"
11 #include "src/objects/map-inl.h"
12 
13 namespace v8 {
14 namespace internal {
15 namespace compiler {
16 
AllocateContext(int variadic_part_length,MapRef map)17 void AllocationBuilder::AllocateContext(int variadic_part_length, MapRef map) {
18   DCHECK(base::IsInRange(map.instance_type(), FIRST_CONTEXT_TYPE,
19                          LAST_CONTEXT_TYPE));
20   DCHECK_NE(NATIVE_CONTEXT_TYPE, map.instance_type());
21   int size = Context::SizeFor(variadic_part_length);
22   Allocate(size, AllocationType::kYoung, Type::OtherInternal());
23   Store(AccessBuilder::ForMap(), map);
24   STATIC_ASSERT(static_cast<int>(Context::kLengthOffset) ==
25                 static_cast<int>(FixedArray::kLengthOffset));
26   Store(AccessBuilder::ForFixedArrayLength(),
27         jsgraph()->Constant(variadic_part_length));
28 }
29 
30 // Compound allocation of a FixedArray.
AllocateArray(int length,MapRef map,AllocationType allocation)31 void AllocationBuilder::AllocateArray(int length, MapRef map,
32                                       AllocationType allocation) {
33   DCHECK(map.instance_type() == FIXED_ARRAY_TYPE ||
34          map.instance_type() == FIXED_DOUBLE_ARRAY_TYPE);
35   int size = (map.instance_type() == FIXED_ARRAY_TYPE)
36                  ? FixedArray::SizeFor(length)
37                  : FixedDoubleArray::SizeFor(length);
38   Allocate(size, allocation, Type::OtherInternal());
39   Store(AccessBuilder::ForMap(), map);
40   Store(AccessBuilder::ForFixedArrayLength(), jsgraph()->Constant(length));
41 }
42 
AllocateSloppyArgumentElements(int length,MapRef map,AllocationType allocation)43 void AllocationBuilder::AllocateSloppyArgumentElements(
44     int length, MapRef map, AllocationType allocation) {
45   int size = SloppyArgumentsElements::SizeFor(length);
46   Allocate(size, allocation, Type::OtherInternal());
47   Store(AccessBuilder::ForMap(), map);
48   Store(AccessBuilder::ForFixedArrayLength(), jsgraph()->Constant(length));
49 }
50 
51 }  // namespace compiler
52 }  // namespace internal
53 }  // namespace v8
54 
55 #endif  // V8_COMPILER_ALLOCATION_BUILDER_INL_H_
56