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/compiler/common-operator.h"
9 : #include "src/compiler/graph.h"
10 : #include "src/compiler/js-operator.h"
11 : #include "src/compiler/machine-graph.h"
12 : #include "src/compiler/node-properties.h"
13 : #include "src/globals.h"
14 : #include "src/isolate.h"
15 :
16 : namespace v8 {
17 : namespace internal {
18 : namespace compiler {
19 :
20 : class SimplifiedOperatorBuilder;
21 : class Typer;
22 :
23 : // Implements a facade on a Graph, enhancing the graph with JS-specific
24 : // notions, including various builders for operators, canonicalized global
25 : // constants, and various helper methods.
26 : class V8_EXPORT_PRIVATE JSGraph : public MachineGraph {
27 : public:
28 3660378 : JSGraph(Isolate* isolate, Graph* graph, CommonOperatorBuilder* common,
29 : JSOperatorBuilder* javascript, SimplifiedOperatorBuilder* simplified,
30 : MachineOperatorBuilder* machine)
31 : : MachineGraph(graph, common, machine),
32 : isolate_(isolate),
33 : javascript_(javascript),
34 3660378 : simplified_(simplified) {
35 3660378 : }
36 :
37 : // CEntryStubs are cached depending on the result size and other flags.
38 : Node* CEntryStubConstant(int result_size,
39 : SaveFPRegsMode save_doubles = kDontSaveFPRegs,
40 : ArgvMode argv_mode = kArgvOnStack,
41 : bool builtin_exit_frame = false);
42 :
43 : // Used for padding frames. (alias: the hole)
44 2955 : Node* PaddingConstant() { return TheHoleConstant(); }
45 :
46 : // Used for stubs and runtime functions with no context. (alias: SMI zero)
47 171641 : Node* NoContextConstant() { return ZeroConstant(); }
48 :
49 : // Creates a HeapConstant node, possibly canonicalized, and may access the
50 : // heap to inspect the object.
51 : Node* HeapConstant(Handle<HeapObject> value);
52 :
53 : // Creates a Constant node of the appropriate type for the given object.
54 : // Accesses the heap to inspect the object and determine whether one of the
55 : // canonicalized globals or a number constant should be returned.
56 : Node* Constant(Handle<Object> value);
57 :
58 : // Like above, but doesn't access the heap directly.
59 : Node* Constant(const ObjectRef& value);
60 :
61 : // Creates a NumberConstant node, usually canonicalized.
62 : Node* Constant(double value);
63 :
64 : // Creates a HeapConstant node for either true or false.
65 : Node* BooleanConstant(bool is_true) {
66 4492 : return is_true ? TrueConstant() : FalseConstant();
67 : }
68 :
69 : Node* SmiConstant(int32_t immediate) {
70 : DCHECK(Smi::IsValid(immediate));
71 1776300 : return Constant(immediate);
72 : }
73 :
74 : JSOperatorBuilder* javascript() const { return javascript_; }
75 : SimplifiedOperatorBuilder* simplified() const { return simplified_; }
76 : Isolate* isolate() const { return isolate_; }
77 : Factory* factory() const { return isolate()->factory(); }
78 :
79 : // Adds all the cached nodes to the given list.
80 : void GetCachedNodes(NodeVector* nodes);
81 :
82 : // Cached global nodes.
83 : #define CACHED_GLOBAL_LIST(V) \
84 : V(AllocateInYoungGenerationStubConstant) \
85 : V(AllocateInOldGenerationStubConstant) \
86 : V(ArrayConstructorStubConstant) \
87 : V(BigIntMapConstant) \
88 : V(BooleanMapConstant) \
89 : V(ToNumberBuiltinConstant) \
90 : V(EmptyFixedArrayConstant) \
91 : V(EmptyStringConstant) \
92 : V(FixedArrayMapConstant) \
93 : V(PropertyArrayMapConstant) \
94 : V(FixedDoubleArrayMapConstant) \
95 : V(HeapNumberMapConstant) \
96 : V(OptimizedOutConstant) \
97 : V(StaleRegisterConstant) \
98 : V(UndefinedConstant) \
99 : V(TheHoleConstant) \
100 : V(TrueConstant) \
101 : V(FalseConstant) \
102 : V(NullConstant) \
103 : V(ZeroConstant) \
104 : V(OneConstant) \
105 : V(NaNConstant) \
106 : V(MinusOneConstant) \
107 : V(EmptyStateValues) \
108 : V(SingleDeadTypedStateValues)
109 :
110 : // Cached global node accessor methods.
111 : #define DECLARE_GETTER(name) Node* name();
112 : CACHED_GLOBAL_LIST(DECLARE_GETTER)
113 : #undef DECLARE_FIELD
114 :
115 : private:
116 : Isolate* isolate_;
117 : JSOperatorBuilder* javascript_;
118 : SimplifiedOperatorBuilder* simplified_;
119 :
120 : #define CACHED_CENTRY_LIST(V) \
121 : V(CEntryStub1Constant) \
122 : V(CEntryStub2Constant) \
123 : V(CEntryStub3Constant) \
124 : V(CEntryStub1WithBuiltinExitFrameConstant)
125 :
126 : // Canonicalized global node fields.
127 : #define DECLARE_FIELD(name) Node* name##_ = nullptr;
128 : CACHED_GLOBAL_LIST(DECLARE_FIELD)
129 : CACHED_CENTRY_LIST(DECLARE_FIELD)
130 : #undef DECLARE_FIELD
131 :
132 : // Internal helper to canonicalize a number constant.
133 : Node* NumberConstant(double value);
134 :
135 : DISALLOW_COPY_AND_ASSIGN(JSGraph);
136 : };
137 :
138 : } // namespace compiler
139 : } // namespace internal
140 : } // namespace v8
141 :
142 : #endif // V8_COMPILER_JS_GRAPH_H_
|