Line data Source code
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 :
8 : #include "src/base/compiler-specific.h"
9 : #include "src/compiler/common-node-cache.h"
10 : #include "src/compiler/common-operator.h"
11 : #include "src/compiler/graph.h"
12 : #include "src/compiler/js-operator.h"
13 : #include "src/compiler/machine-operator.h"
14 : #include "src/compiler/node-properties.h"
15 : #include "src/globals.h"
16 : #include "src/isolate.h"
17 :
18 : namespace v8 {
19 : namespace internal {
20 : namespace compiler {
21 :
22 : class SimplifiedOperatorBuilder;
23 : class Typer;
24 :
25 : // Implements a facade on a Graph, enhancing the graph with JS-specific
26 : // notions, including various builders for operators, canonicalized global
27 : // constants, and various helper methods.
28 : class V8_EXPORT_PRIVATE JSGraph : public NON_EXPORTED_BASE(ZoneObject) {
29 : public:
30 : JSGraph(Isolate* isolate, Graph* graph, CommonOperatorBuilder* common,
31 : JSOperatorBuilder* javascript, SimplifiedOperatorBuilder* simplified,
32 : MachineOperatorBuilder* machine)
33 : : isolate_(isolate),
34 : graph_(graph),
35 : common_(common),
36 : javascript_(javascript),
37 : simplified_(simplified),
38 : machine_(machine),
39 2838706 : cache_(zone()) {
40 39741212 : for (int i = 0; i < kNumCachedNodes; i++) cached_nodes_[i] = nullptr;
41 : }
42 :
43 : // Canonicalized global constants.
44 : Node* AllocateInNewSpaceStubConstant();
45 : Node* AllocateInOldSpaceStubConstant();
46 : Node* ArrayConstructorStubConstant();
47 : Node* ToNumberBuiltinConstant();
48 : Node* CEntryStubConstant(int result_size,
49 : SaveFPRegsMode save_doubles = kDontSaveFPRegs,
50 : ArgvMode argv_mode = kArgvOnStack,
51 : bool builtin_exit_frame = false);
52 : Node* EmptyFixedArrayConstant();
53 : Node* EmptyStringConstant();
54 : Node* FixedArrayMapConstant();
55 : Node* PropertyArrayMapConstant();
56 : Node* FixedDoubleArrayMapConstant();
57 : Node* HeapNumberMapConstant();
58 : Node* OptimizedOutConstant();
59 : Node* StaleRegisterConstant();
60 : Node* UndefinedConstant();
61 : Node* TheHoleConstant();
62 : Node* TrueConstant();
63 : Node* FalseConstant();
64 : Node* NullConstant();
65 : Node* ZeroConstant();
66 : Node* OneConstant();
67 : Node* NaNConstant();
68 : Node* MinusOneConstant();
69 :
70 : // Used for padding frames.
71 7920 : Node* PaddingConstant() { return TheHoleConstant(); }
72 :
73 : // Creates a HeapConstant node, possibly canonicalized, and may access the
74 : // heap to inspect the object.
75 : Node* HeapConstant(Handle<HeapObject> value);
76 :
77 : // Creates a Constant node of the appropriate type for the given object.
78 : // Accesses the heap to inspect the object and determine whether one of the
79 : // canonicalized globals or a number constant should be returned.
80 : Node* Constant(Handle<Object> value);
81 :
82 : // Creates a NumberConstant node, usually canonicalized.
83 : Node* Constant(double value);
84 :
85 : // Creates a NumberConstant node, usually canonicalized.
86 : Node* Constant(int32_t value);
87 :
88 : // Creates a NumberConstant node, usually canonicalized.
89 : Node* Constant(uint32_t value);
90 :
91 : // Creates a Int32Constant node, usually canonicalized.
92 : Node* Int32Constant(int32_t value);
93 : Node* Uint32Constant(uint32_t value) {
94 35186 : return Int32Constant(bit_cast<int32_t>(value));
95 : }
96 :
97 : // Creates a HeapConstant node for either true or false.
98 6007 : Node* BooleanConstant(bool is_true) {
99 6007 : return is_true ? TrueConstant() : FalseConstant();
100 : }
101 :
102 : // Creates a Int64Constant node, usually canonicalized.
103 : Node* Int64Constant(int64_t value);
104 : Node* Uint64Constant(uint64_t value) {
105 : return Int64Constant(bit_cast<int64_t>(value));
106 : }
107 :
108 : // Creates a Int32Constant/Int64Constant node, depending on the word size of
109 : // the target machine.
110 : // TODO(turbofan): Code using Int32Constant/Int64Constant to store pointer
111 : // constants is probably not serializable.
112 6052755 : Node* IntPtrConstant(intptr_t value) {
113 0 : return machine()->Is32() ? Int32Constant(static_cast<int32_t>(value))
114 6052755 : : Int64Constant(static_cast<int64_t>(value));
115 : }
116 :
117 : Node* RelocatableInt32Constant(int32_t value, RelocInfo::Mode rmode);
118 : Node* RelocatableInt64Constant(int64_t value, RelocInfo::Mode rmode);
119 : Node* RelocatableIntPtrConstant(intptr_t value, RelocInfo::Mode rmode);
120 :
121 : // Creates a Float32Constant node, usually canonicalized.
122 : Node* Float32Constant(float value);
123 :
124 : // Creates a Float64Constant node, usually canonicalized.
125 : Node* Float64Constant(double value);
126 :
127 : // Creates a PointerConstant node (asm.js only).
128 : Node* PointerConstant(intptr_t value);
129 : template <typename T>
130 : Node* PointerConstant(T* value) {
131 3344 : return PointerConstant(bit_cast<intptr_t>(value));
132 : }
133 :
134 : // Creates an ExternalConstant node, usually canonicalized.
135 : Node* ExternalConstant(ExternalReference ref);
136 : Node* ExternalConstant(Runtime::FunctionId function_id);
137 :
138 : Node* SmiConstant(int32_t immediate) {
139 : DCHECK(Smi::IsValid(immediate));
140 1983601 : return Constant(immediate);
141 : }
142 :
143 : // Creates a dummy Constant node, used to satisfy calling conventions of
144 : // stubs and runtime functions that do not require a context.
145 193185 : Node* NoContextConstant() { return ZeroConstant(); }
146 :
147 : // Creates an empty StateValues node, used when we don't have any concrete
148 : // values for a certain part of the frame state.
149 : Node* EmptyStateValues();
150 :
151 : // Typed state values with a single dead input. This is useful to represent
152 : // dead accumulator.
153 : Node* SingleDeadTypedStateValues();
154 :
155 : // Create a control node that serves as dependency for dead nodes.
156 : Node* Dead();
157 :
158 : CommonOperatorBuilder* common() const { return common_; }
159 : JSOperatorBuilder* javascript() const { return javascript_; }
160 : SimplifiedOperatorBuilder* simplified() const { return simplified_; }
161 : MachineOperatorBuilder* machine() const { return machine_; }
162 : Graph* graph() const { return graph_; }
163 15742373 : Zone* zone() const { return graph()->zone(); }
164 : Isolate* isolate() const { return isolate_; }
165 3113749 : Factory* factory() const { return isolate()->factory(); }
166 :
167 : void GetCachedNodes(NodeVector* nodes);
168 :
169 : private:
170 : enum CachedNode {
171 : kAllocateInNewSpaceStubConstant,
172 : kAllocateInOldSpaceStubConstant,
173 : kArrayConstructorStubConstant,
174 : kToNumberBuiltinConstant,
175 : kCEntryStub1Constant,
176 : kCEntryStub2Constant,
177 : kCEntryStub3Constant,
178 : kCEntryStub1WithBuiltinExitFrameConstant,
179 : kEmptyFixedArrayConstant,
180 : kEmptyStringConstant,
181 : kFixedArrayMapConstant,
182 : kFixedDoubleArrayMapConstant,
183 : kPropertyArrayMapConstant,
184 : kHeapNumberMapConstant,
185 : kOptimizedOutConstant,
186 : kStaleRegisterConstant,
187 : kUndefinedConstant,
188 : kTheHoleConstant,
189 : kTrueConstant,
190 : kFalseConstant,
191 : kNullConstant,
192 : kZeroConstant,
193 : kOneConstant,
194 : kMinusOneConstant,
195 : kNaNConstant,
196 : kEmptyStateValues,
197 : kSingleDeadTypedStateValues,
198 : kDead,
199 : kNumCachedNodes // Must remain last.
200 : };
201 :
202 : Isolate* isolate_;
203 : Graph* graph_;
204 : CommonOperatorBuilder* common_;
205 : JSOperatorBuilder* javascript_;
206 : SimplifiedOperatorBuilder* simplified_;
207 : MachineOperatorBuilder* machine_;
208 : CommonNodeCache cache_;
209 : Node* cached_nodes_[kNumCachedNodes];
210 :
211 : Node* NumberConstant(double value);
212 :
213 : DISALLOW_COPY_AND_ASSIGN(JSGraph);
214 : };
215 :
216 : } // namespace compiler
217 : } // namespace internal
218 : } // namespace v8
219 :
220 : #endif
|