v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
js-graph.h
Go to the documentation of this file.
1// Copyright 2014 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_JS_GRAPH_H_
6#define V8_COMPILER_JS_GRAPH_H_
7
15#include "src/objects/oddball.h"
16
17namespace v8 {
18namespace internal {
19namespace compiler {
20
21class SimplifiedOperatorBuilder;
22class Typer;
23
24// Implements a facade on a TFGraph, enhancing the graph with JS-specific
25// notions, including various builders for operators, canonicalized global
26// constants, and various helper methods.
28 public:
29 JSGraph(Isolate* isolate, TFGraph* graph, CommonOperatorBuilder* common,
30 JSOperatorBuilder* javascript, SimplifiedOperatorBuilder* simplified,
32 : MachineGraph(graph, common, machine),
33 isolate_(isolate),
34 javascript_(javascript),
35 simplified_(simplified) {}
36
37 JSGraph(const JSGraph&) = delete;
38 JSGraph& operator=(const JSGraph&) = delete;
39
40 // CEntryStubs are cached depending on the result size and other flags.
41 Node* CEntryStubConstant(int result_size,
42 ArgvMode argv_mode = ArgvMode::kStack,
43 bool builtin_exit_frame = false);
44
45 // Used for padding frames. (alias: the hole)
46 TNode<Hole> PaddingConstant() { return TheHoleConstant(); }
47
48 // Used for stubs and runtime functions with no context. (alias: SMI zero)
49 TNode<Number> NoContextConstant() { return ZeroConstant(); }
50
51 // Creates a HeapConstant node, possibly canonicalized.
52 // Checks that we don't emit hole values. Use this if possible to emit
53 // JSReceiver heap constants.
55
56 // Creates a HeapConstant node, possibly canonicalized.
57 // This can be used whenever we might need to emit a hole value or a
58 // JSReceiver. Use this cautiously only if you really need it.
59 Node* HeapConstantMaybeHole(Handle<HeapObject> value);
60
61 // Creates a HeapConstant node, possibly canonicalized.
62 // This is only used to emit hole values. Use this if you are sure that you
63 // only emit a Hole value.
65
66 // Createas a TrustedHeapConstant node.
67 // This is similar to HeapConstant, but for constants that live in trusted
68 // space (having a different cage base) and therefore shouldn't be compressed.
69 Node* TrustedHeapConstant(Handle<HeapObject> value);
70
71 // Creates a Constant node of the appropriate type for
72 // the given object. Inspect the (serialized) object and determine whether
73 // one of the canonicalized globals or a number constant should be returned.
74 // Checks that we do not emit a Hole value, use this whenever possible.
75 Node* ConstantNoHole(ObjectRef ref, JSHeapBroker* broker);
76 // Creates a Constant node of the appropriate type for
77 // the given object. Inspect the (serialized) object and determine whether
78 // one of the canonicalized globals or a number constant should be returned.
79 // Use this if you really need to emit Hole values.
80 Node* ConstantMaybeHole(ObjectRef ref, JSHeapBroker* broker);
81
82 // Creates a NumberConstant node, usually canonicalized.
83 Node* ConstantMaybeHole(double value);
84 // Same, but checks that we are not emitting a kHoleNanInt64, please use
85 // whenever you can.
86 Node* ConstantNoHole(double value);
87
88 // Creates a Constant node that holds a mutable Heap Number.
89 // This is different from ConstantNoHole, which reads the double value and
90 // creates a Constant node from it.
91 Node* ConstantMutableHeapNumber(HeapNumberRef ref, JSHeapBroker* broker);
92
93 // Creates a HeapConstant node for either true or false.
95 return is_true ? TNode<Boolean>(TrueConstant())
96 : TNode<Boolean>(FalseConstant());
97 }
98
99 Node* SmiConstant(int32_t immediate) {
100 DCHECK(Smi::IsValid(immediate));
101 return ConstantMaybeHole(immediate);
102 }
103
104 JSOperatorBuilder* javascript() const { return javascript_; }
105 SimplifiedOperatorBuilder* simplified() const { return simplified_; }
106 Isolate* isolate() const { return isolate_; }
107 Factory* factory() const { return isolate()->factory(); }
108
109 // Adds all the cached nodes to the given list.
110 void GetCachedNodes(NodeVector* nodes);
111
112// Cached global nodes.
113#define CACHED_GLOBAL_LIST(V) \
114 V(AllocateInYoungGenerationStubConstant, Code) \
115 V(AllocateInOldGenerationStubConstant, Code) \
116 IF_WASM(V, WasmAllocateInYoungGenerationStubConstant, Code) \
117 IF_WASM(V, WasmAllocateInOldGenerationStubConstant, Code) \
118 V(ArrayConstructorStubConstant, Code) \
119 V(BigIntMapConstant, Map) \
120 V(BooleanMapConstant, Map) \
121 V(ToNumberBuiltinConstant, Code) \
122 V(PlainPrimitiveToNumberBuiltinConstant, Code) \
123 V(EmptyFixedArrayConstant, FixedArray) \
124 V(EmptyStringConstant, String) \
125 V(FixedArrayMapConstant, Map) \
126 V(PropertyArrayMapConstant, Map) \
127 V(FixedDoubleArrayMapConstant, Map) \
128 V(WeakFixedArrayMapConstant, Map) \
129 V(HeapNumberMapConstant, Map) \
130 V(UndefinedConstant, Undefined) \
131 V(TheHoleConstant, Hole) \
132 V(PropertyCellHoleConstant, Hole) \
133 V(HashTableHoleConstant, Hole) \
134 V(PromiseHoleConstant, Hole) \
135 V(UninitializedConstant, Hole) \
136 V(OptimizedOutConstant, Hole) \
137 V(StaleRegisterConstant, Hole) \
138 V(TrueConstant, True) \
139 V(FalseConstant, False) \
140 V(NullConstant, Null) \
141 V(ZeroConstant, Number) \
142 V(MinusZeroConstant, Number) \
143 V(OneConstant, Number) \
144 V(MinusOneConstant, Number) \
145 V(NaNConstant, Number) \
146 V(EmptyStateValues, UntaggedT) \
147 V(SingleDeadTypedStateValues, UntaggedT) \
148 V(ExternalObjectMapConstant, Map)
149
150// Cached global node accessor methods.
151#define DECLARE_GETTER(name, Type) TNode<Type> name();
153#undef DECLARE_GETTER
154
155 private:
159
160#define CACHED_CENTRY_LIST(V) \
161 V(CEntryStub1Constant) \
162 V(CEntryStub2Constant) \
163 V(CEntryStub3Constant) \
164 V(CEntryStub1WithBuiltinExitFrameConstant)
165
166// Canonicalized global node fields.
167#define DECLARE_FIELD(name, ...) Node* name##_ = nullptr;
170#undef DECLARE_FIELD
171
172 // Internal helper to canonicalize a number constant.
173 Node* NumberConstant(double value);
174
175 // Internal helper that creates a Constant node of the appropriate type for
176 // the given object. Inspect the (serialized) object and determine whether
177 // one of the canonicalized globals or a number constant should be returned.
178 Node* Constant(ObjectRef value, JSHeapBroker* broker);
179};
180
181} // namespace compiler
182} // namespace internal
183} // namespace v8
184
185#endif // V8_COMPILER_JS_GRAPH_H_
Isolate * isolate_
JSOperatorBuilder * javascript() const
Definition js-graph.h:104
JSGraph(Isolate *isolate, TFGraph *graph, CommonOperatorBuilder *common, JSOperatorBuilder *javascript, SimplifiedOperatorBuilder *simplified, MachineOperatorBuilder *machine)
Definition js-graph.h:29
SimplifiedOperatorBuilder * simplified() const
Definition js-graph.h:105
JSOperatorBuilder * javascript_
Definition js-graph.h:157
Isolate * isolate() const
Definition js-graph.h:106
JSGraph & operator=(const JSGraph &)=delete
Factory * factory() const
Definition js-graph.h:107
SimplifiedOperatorBuilder * simplified_
Definition js-graph.h:158
TNode< Number > NoContextConstant()
Definition js-graph.h:49
TNode< Hole > PaddingConstant()
Definition js-graph.h:46
TNode< Boolean > BooleanConstant(bool is_true)
Definition js-graph.h:94
JSGraph(const JSGraph &)=delete
Node * SmiConstant(int32_t immediate)
Definition js-graph.h:99
Isolate * isolate
JSHeapBroker * broker
#define DECLARE_GETTER(name, Type)
Definition js-graph.h:151
#define CACHED_GLOBAL_LIST(V)
Definition js-graph.h:113
#define CACHED_CENTRY_LIST(V)
Definition js-graph.h:160
#define DECLARE_FIELD(name,...)
Definition js-graph.h:167
HeapConstantHole(factory() ->the_hole_value())) DEFINE_GETTER(PropertyCellHoleConstant
HeapConstantNoHole(BUILTIN_CODE(isolate(), AllocateInOldGeneration))) DEFINE_GETTER(ArrayConstructorStubConstant
#define DCHECK(condition)
Definition logging.h:482
#define V8_EXPORT_PRIVATE
Definition macros.h:460