v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
memory-lowering.h
Go to the documentation of this file.
1// Copyright 2019 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_MEMORY_LOWERING_H_
6#define V8_COMPILER_MEMORY_LOWERING_H_
7
10
11namespace v8 {
12namespace internal {
13namespace compiler {
14
15// Forward declarations.
16class CommonOperatorBuilder;
17struct ElementAccess;
18class TFGraph;
19class JSGraph;
20class MachineOperatorBuilder;
21class Node;
22class Operator;
23
24// Provides operations to lower all simplified memory access and allocation
25// related nodes (i.e. Allocate, LoadField, StoreField and friends) to machine
26// operators.
27class MemoryLowering final : public Reducer {
28 public:
30 class AllocationGroup;
31
32 // An allocation state is propagated on the effect paths through the graph.
33 class AllocationState final : public ZoneObject {
34 public:
37
38 static AllocationState const* Empty(Zone* zone) {
39 return zone->New<AllocationState>();
40 }
42 Zone* zone) {
44 }
45 static AllocationState const* Open(AllocationGroup* group, intptr_t size,
46 Node* top, Node* effect, Zone* zone) {
48 }
49
50 bool IsYoungGenerationAllocation() const;
51
52 AllocationGroup* group() const { return group_; }
53 Node* top() const { return top_; }
54 Node* effect() const { return effect_; }
55 intptr_t size() const { return size_; }
56
57 private:
58 friend Zone;
59
61 explicit AllocationState(AllocationGroup* group, Node* effect);
62 AllocationState(AllocationGroup* group, intptr_t size, Node* top,
63 Node* effect);
64
66 // The upper bound of the combined allocated object size on the current path
67 // (max int if allocation folding is impossible on this path).
68 intptr_t const size_;
69 Node* const top_;
70 Node* const effect_;
71 };
72
73 using WriteBarrierAssertFailedCallback = std::function<void(
74 Node* node, Node* object, const char* name, Zone* temp_zone)>;
75
77 JSGraph* jsgraph, Zone* zone, JSGraphAssembler* graph_assembler,
78 bool is_wasm,
79 AllocationFolding allocation_folding =
82 Zone*) { UNREACHABLE(); },
83 const char* function_debug_name = nullptr);
84
85 const char* reducer_name() const override { return "MemoryReducer"; }
86
87 // Perform memory lowering reduction on the given Node.
88 Reduction Reduce(Node* node) override;
89
90 // Specific reducers for each optype to enable keeping track of
91 // AllocationState by the MemoryOptimizer.
92 Reduction ReduceAllocateRaw(Node* node, AllocationType allocation_type,
93 AllocationState const** state);
98 AllocationState const* state = nullptr);
100 AllocationState const* state = nullptr);
102 AllocationState const* state = nullptr);
103 Reduction ReduceStore(Node* node, AllocationState const* state = nullptr);
104
105 private:
108 Node* value,
109 AllocationState const* state,
114 Node* ComputeIndex(ElementAccess const& access, Node* node);
117
118 // Align the value to kObjectAlignment8GbHeap if V8_COMPRESS_POINTERS_8GB is
119 // defined.
121
122 TFGraph* graph() const { return graph_; }
123 Isolate* isolate() const { return isolate_; }
124 Zone* zone() const { return zone_; }
125 inline Zone* graph_zone() const;
129
142
144};
145
146} // namespace compiler
147} // namespace internal
148} // namespace v8
149
150#endif // V8_COMPILER_MEMORY_LOWERING_H_
JSGraph * jsgraph
T * New(Args &&... args)
Definition zone.h:114
static AllocationState const * Open(AllocationGroup *group, intptr_t size, Node *top, Node *effect, Zone *zone)
AllocationState & operator=(const AllocationState &)=delete
static AllocationState const * Empty(Zone *zone)
static AllocationState const * Closed(AllocationGroup *group, Node *effect, Zone *zone)
const char * reducer_name() const override
Node * ComputeIndex(ElementAccess const &access, Node *node)
SetOncePointer< const Operator > allocate_operator_
Reduction ReduceStoreToObject(Node *node, AllocationState const *state=nullptr)
Node * AlignToAllocationAlignment(Node *address)
Reduction ReduceStoreElement(Node *node, AllocationState const *state=nullptr)
WriteBarrierKind ComputeWriteBarrierKind(Node *node, Node *object, Node *value, AllocationState const *state, WriteBarrierKind)
MachineOperatorBuilder * machine() const
WriteBarrierAssertFailedCallback write_barrier_assert_failed_
Reduction Reduce(Node *node) override
Reduction ReduceStoreField(Node *node, AllocationState const *state=nullptr)
Reduction ReduceAllocateRaw(Node *node, AllocationType allocation_type, AllocationState const **state)
Reduction ReduceLoadExternalPointerField(Node *node)
std::function< void( Node *node, Node *object, const char *name, Zone *temp_zone)> WriteBarrierAssertFailedCallback
CommonOperatorBuilder * common() const
MemoryLowering(JSGraph *jsgraph, Zone *zone, JSGraphAssembler *graph_assembler, bool is_wasm, AllocationFolding allocation_folding=AllocationFolding::kDontAllocationFolding, WriteBarrierAssertFailedCallback callback=[](Node *, Node *, const char *, Zone *) { UNREACHABLE();}, const char *function_debug_name=nullptr)
Reduction ReduceStore(Node *node, AllocationState const *state=nullptr)
TNode< Object > callback