Line data Source code
1 : // Copyright 2013 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_NODE_PROPERTIES_H_
6 : #define V8_COMPILER_NODE_PROPERTIES_H_
7 :
8 : #include "src/compiler/node.h"
9 : #include "src/compiler/types.h"
10 : #include "src/globals.h"
11 : #include "src/zone/zone-handle-set.h"
12 :
13 : namespace v8 {
14 : namespace internal {
15 : namespace compiler {
16 :
17 : class Graph;
18 : class Operator;
19 : class CommonOperatorBuilder;
20 :
21 : // A facade that simplifies access to the different kinds of inputs to a node.
22 : class V8_EXPORT_PRIVATE NodeProperties final {
23 : public:
24 : // ---------------------------------------------------------------------------
25 : // Input layout.
26 : // Inputs are always arranged in order as follows:
27 : // 0 [ values, context, frame state, effects, control ] node->InputCount()
28 :
29 : static int FirstValueIndex(Node* node) { return 0; }
30 16201 : static int FirstContextIndex(Node* node) { return PastValueIndex(node); }
31 21 : static int FirstFrameStateIndex(Node* node) { return PastContextIndex(node); }
32 802070235 : static int FirstEffectIndex(Node* node) { return PastFrameStateIndex(node); }
33 53555945 : static int FirstControlIndex(Node* node) { return PastEffectIndex(node); }
34 : static int PastValueIndex(Node* node);
35 : static int PastContextIndex(Node* node);
36 : static int PastFrameStateIndex(Node* node);
37 : static int PastEffectIndex(Node* node);
38 : static int PastControlIndex(Node* node);
39 :
40 :
41 : // ---------------------------------------------------------------------------
42 : // Input accessors.
43 :
44 : static Node* GetValueInput(Node* node, int index);
45 : static Node* GetContextInput(Node* node);
46 : static Node* GetFrameStateInput(Node* node);
47 : static Node* GetEffectInput(Node* node, int index = 0);
48 : static Node* GetControlInput(Node* node, int index = 0);
49 :
50 :
51 : // ---------------------------------------------------------------------------
52 : // Edge kinds.
53 :
54 : static bool IsValueEdge(Edge edge);
55 : static bool IsContextEdge(Edge edge);
56 : static bool IsFrameStateEdge(Edge edge);
57 : static bool IsEffectEdge(Edge edge);
58 : static bool IsControlEdge(Edge edge);
59 :
60 :
61 : // ---------------------------------------------------------------------------
62 : // Miscellaneous predicates.
63 :
64 : static bool IsCommon(Node* node) {
65 : return IrOpcode::IsCommonOpcode(node->opcode());
66 : }
67 140 : static bool IsControl(Node* node) {
68 : return IrOpcode::IsControlOpcode(node->opcode());
69 : }
70 31802129 : static bool IsConstant(Node* node) {
71 : return IrOpcode::IsConstantOpcode(node->opcode());
72 : }
73 24022434 : static bool IsPhi(Node* node) {
74 : return IrOpcode::IsPhiOpcode(node->opcode());
75 : }
76 :
77 : // Determines whether exceptions thrown by the given node are handled locally
78 : // within the graph (i.e. an IfException projection is present). Optionally
79 : // the present IfException projection is returned via {out_exception}.
80 : static bool IsExceptionalCall(Node* node, Node** out_exception = nullptr);
81 :
82 : // ---------------------------------------------------------------------------
83 : // Miscellaneous mutators.
84 :
85 : static void ReplaceValueInput(Node* node, Node* value, int index);
86 : static void ReplaceContextInput(Node* node, Node* context);
87 : static void ReplaceControlInput(Node* node, Node* control, int index = 0);
88 : static void ReplaceEffectInput(Node* node, Node* effect, int index = 0);
89 : static void ReplaceFrameStateInput(Node* node, Node* frame_state);
90 : static void RemoveNonValueInputs(Node* node);
91 : static void RemoveValueInputs(Node* node);
92 :
93 : // Replaces all value inputs of {node} with the single input {value}.
94 : static void ReplaceValueInputs(Node* node, Node* value);
95 :
96 : // Merge the control node {node} into the end of the graph, introducing a
97 : // merge node or expanding an existing merge node if necessary.
98 : static void MergeControlToEnd(Graph* graph, CommonOperatorBuilder* common,
99 : Node* node);
100 :
101 : // Replace all uses of {node} with the given replacement nodes. All occurring
102 : // use kinds need to be replaced, {nullptr} is only valid if a use kind is
103 : // guaranteed not to exist.
104 : static void ReplaceUses(Node* node, Node* value, Node* effect = nullptr,
105 : Node* success = nullptr, Node* exception = nullptr);
106 :
107 : // Safe wrapper to mutate the operator of a node. Checks that the node is
108 : // currently in a state that satisfies constraints of the new operator.
109 : static void ChangeOp(Node* node, const Operator* new_op);
110 :
111 : // ---------------------------------------------------------------------------
112 : // Miscellaneous utilities.
113 :
114 : // Find the last frame state that is effect-wise before the given node. This
115 : // assumes a linear effect-chain up to a {CheckPoint} node in the graph.
116 : static Node* FindFrameStateBefore(Node* node);
117 :
118 : // Collect the output-value projection for the given output index.
119 : static Node* FindProjection(Node* node, size_t projection_index);
120 :
121 : // Collect the branch-related projections from a node, such as IfTrue,
122 : // IfFalse, IfSuccess, IfException, IfValue and IfDefault.
123 : // - Branch: [ IfTrue, IfFalse ]
124 : // - Call : [ IfSuccess, IfException ]
125 : // - Switch: [ IfValue, ..., IfDefault ]
126 : static void CollectControlProjections(Node* node, Node** proj, size_t count);
127 :
128 : // Checks if two nodes are the same, looking past {CheckHeapObject}.
129 : static bool IsSame(Node* a, Node* b);
130 :
131 : // Walks up the {effect} chain to find a witness that provides map
132 : // information about the {receiver}. Can look through potentially
133 : // side effecting nodes.
134 : enum InferReceiverMapsResult {
135 : kNoReceiverMaps, // No receiver maps inferred.
136 : kReliableReceiverMaps, // Receiver maps can be trusted.
137 : kUnreliableReceiverMaps // Receiver maps might have changed (side-effect).
138 : };
139 : static InferReceiverMapsResult InferReceiverMaps(
140 : Node* receiver, Node* effect, ZoneHandleSet<Map>* maps_return);
141 :
142 : // ---------------------------------------------------------------------------
143 : // Context.
144 :
145 : // Try to retrieve the specialization context from the given {node},
146 : // optionally utilizing the knowledge about the (outermost) function
147 : // {context}.
148 : static MaybeHandle<Context> GetSpecializationContext(
149 : Node* node, MaybeHandle<Context> context = MaybeHandle<Context>());
150 :
151 : // Walk up the context chain from the given {node} until we reduce the {depth}
152 : // to 0 or hit a node that does not extend the context chain ({depth} will be
153 : // updated accordingly).
154 : static Node* GetOuterContext(Node* node, size_t* depth);
155 :
156 : // ---------------------------------------------------------------------------
157 : // Type.
158 :
159 64944559 : static bool IsTyped(Node* node) { return node->type() != nullptr; }
160 62221894 : static Type* GetType(Node* node) {
161 : DCHECK(IsTyped(node));
162 : return node->type();
163 : }
164 : static Type* GetTypeOrAny(Node* node);
165 : static void SetType(Node* node, Type* type) {
166 : DCHECK_NOT_NULL(type);
167 : node->set_type(type);
168 : }
169 : static void RemoveType(Node* node) { node->set_type(nullptr); }
170 : static bool AllValueInputsAreTyped(Node* node);
171 :
172 : private:
173 : static inline bool IsInputRange(Edge edge, int first, int count);
174 : };
175 :
176 : } // namespace compiler
177 : } // namespace internal
178 : } // namespace v8
179 :
180 : #endif // V8_COMPILER_NODE_PROPERTIES_H_
|