v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
allocation-builder.h
Go to the documentation of this file.
1// Copyright 2017 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_H_
6#define V8_COMPILER_ALLOCATION_BUILDER_H_
7
9#include "src/compiler/node.h"
11
12namespace v8 {
13namespace internal {
14namespace compiler {
15
16// A helper class to construct inline allocations on the simplified operator
17// level. This keeps track of the effect chain for initial stores on a newly
18// allocated object and also provides helpers for commonly allocated objects.
19class AllocationBuilder final {
20 public:
22 Node* control)
25 allocation_(nullptr),
26 effect_(effect),
27 control_(control) {}
28
29 // Primitive allocation of static size.
30 inline void Allocate(int size,
32 Type type = Type::Any());
33
34 // Primitive store into a field.
35 void Store(const FieldAccess& access, Node* value) {
36 effect_ = graph()->NewNode(simplified()->StoreField(access), allocation_,
37 value, effect_, control_);
38 }
39
40 // Primitive store into an element.
41 void Store(ElementAccess const& access, Node* index, Node* value) {
42 effect_ = graph()->NewNode(simplified()->StoreElement(access), allocation_,
43 index, value, effect_, control_);
44 }
45
46 // Compound allocation of a context.
47 inline void AllocateContext(int variadic_part_length, MapRef map);
48
49 // Compound allocation of a FixedArray.
50 inline bool CanAllocateArray(
51 int length, MapRef map,
53 inline void AllocateArray(int length, MapRef map,
55
56 // Compound allocation of a SloppyArgumentsElements
58 int length, MapRef map,
61 int length, MapRef map,
63
64 // Compound store of a constant into a field.
65 void Store(const FieldAccess& access, ObjectRef value) {
66 if (access.machine_type == MachineType::IndirectPointer()) {
67 Store(access,
68 jsgraph()->TrustedHeapConstant(value.AsHeapObject().object()));
69 } else {
70 Store(access, jsgraph()->ConstantNoHole(value, broker_));
71 }
72 }
73
74 void FinishAndChange(Node* node) {
76 node->ReplaceInput(0, allocation_);
77 node->ReplaceInput(1, effect_);
78 node->TrimInputCount(2);
79 NodeProperties::ChangeOp(node, common()->FinishRegion());
80 }
81
83 return graph()->NewNode(common()->FinishRegion(), allocation_, effect_);
84 }
85
86 protected:
87 JSGraph* jsgraph() { return jsgraph_; }
88 Isolate* isolate() const { return jsgraph_->isolate(); }
89 TFGraph* graph() { return jsgraph_->graph(); }
92
93 private:
99};
100
101} // namespace compiler
102} // namespace internal
103} // namespace v8
104
105#endif // V8_COMPILER_ALLOCATION_BUILDER_H_
static constexpr MachineType IndirectPointer()
void Store(const FieldAccess &access, ObjectRef value)
void AllocateSloppyArgumentElements(int length, MapRef map, AllocationType allocation=AllocationType::kYoung)
void AllocateArray(int length, MapRef map, AllocationType allocation=AllocationType::kYoung)
void Allocate(int size, AllocationType allocation=AllocationType::kYoung, Type type=Type::Any())
void AllocateContext(int variadic_part_length, MapRef map)
bool CanAllocateArray(int length, MapRef map, AllocationType allocation=AllocationType::kYoung)
bool CanAllocateSloppyArgumentElements(int length, MapRef map, AllocationType allocation=AllocationType::kYoung)
void Store(ElementAccess const &access, Node *index, Node *value)
void Store(const FieldAccess &access, Node *value)
AllocationBuilder(JSGraph *jsgraph, JSHeapBroker *broker, Node *effect, Node *control)
SimplifiedOperatorBuilder * simplified()
SimplifiedOperatorBuilder * simplified() const
Definition js-graph.h:105
Isolate * isolate() const
Definition js-graph.h:106
CommonOperatorBuilder * common() const
static void ChangeOp(Node *node, const Operator *new_op)
static Type GetType(const Node *node)
static void SetType(Node *node, Type type)
Node * NewNode(const Operator *op, int input_count, Node *const *inputs, bool incomplete=false)
JSHeapBroker * broker