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.
5 #ifndef V8_COMPILER_NODE_PROPERTIES_H_
6 #define V8_COMPILER_NODE_PROPERTIES_H_
8 #include "src/compiler/node.h"
17 class CommonOperatorBuilder;
19 // A facade that simplifies access to the different kinds of inputs to a node.
20 class NodeProperties FINAL {
22 // ---------------------------------------------------------------------------
24 // Inputs are always arranged in order as follows:
25 // 0 [ values, context, frame state, effects, control ] node->InputCount()
27 static int FirstValueIndex(Node* node) { return 0; }
28 static int FirstContextIndex(Node* node) { return PastValueIndex(node); }
29 static int FirstFrameStateIndex(Node* node) { return PastContextIndex(node); }
30 static int FirstEffectIndex(Node* node) { return PastFrameStateIndex(node); }
31 static int FirstControlIndex(Node* node) { return PastEffectIndex(node); }
32 static int PastValueIndex(Node* node);
33 static int PastContextIndex(Node* node);
34 static int PastFrameStateIndex(Node* node);
35 static int PastEffectIndex(Node* node);
36 static int PastControlIndex(Node* node);
39 // ---------------------------------------------------------------------------
42 static Node* GetValueInput(Node* node, int index);
43 static Node* GetContextInput(Node* node);
44 static Node* GetFrameStateInput(Node* node, int index);
45 static Node* GetEffectInput(Node* node, int index = 0);
46 static Node* GetControlInput(Node* node, int index = 0);
49 // ---------------------------------------------------------------------------
52 static bool IsValueEdge(Edge edge);
53 static bool IsContextEdge(Edge edge);
54 static bool IsFrameStateEdge(Edge edge);
55 static bool IsEffectEdge(Edge edge);
56 static bool IsControlEdge(Edge edge);
59 // ---------------------------------------------------------------------------
60 // Miscellaneous predicates.
62 static bool IsCommon(Node* node) {
63 return IrOpcode::IsCommonOpcode(node->opcode());
65 static bool IsControl(Node* node) {
66 return IrOpcode::IsControlOpcode(node->opcode());
68 static bool IsConstant(Node* node) {
69 return IrOpcode::IsConstantOpcode(node->opcode());
71 static bool IsPhi(Node* node) {
72 return IrOpcode::IsPhiOpcode(node->opcode());
76 // ---------------------------------------------------------------------------
77 // Miscellaneous mutators.
79 static void ReplaceContextInput(Node* node, Node* context);
80 static void ReplaceControlInput(Node* node, Node* control);
81 static void ReplaceEffectInput(Node* node, Node* effect, int index = 0);
82 static void ReplaceFrameStateInput(Node* node, int index, Node* frame_state);
83 static void RemoveNonValueInputs(Node* node);
85 // Merge the control node {node} into the end of the graph, introducing a
86 // merge node or expanding an existing merge node if necessary.
87 static void MergeControlToEnd(Graph* graph, CommonOperatorBuilder* common,
90 // Replace value uses of {node} with {value} and effect uses of {node} with
91 // {effect}. If {effect == NULL}, then use the effect input to {node}. All
92 // control uses will be relaxed assuming {node} cannot throw.
93 static void ReplaceWithValue(Node* node, Node* value, Node* effect = nullptr,
94 Node* control = nullptr);
96 // ---------------------------------------------------------------------------
97 // Miscellaneous utilities.
99 static Node* FindProjection(Node* node, size_t projection_index);
101 // Collect the branch-related projections from a node, such as IfTrue,
102 // IfFalse, IfSuccess, IfException, IfValue and IfDefault.
103 // - Branch: [ IfTrue, IfFalse ]
104 // - Call : [ IfSuccess, IfException ]
105 // - Switch: [ IfValue, ..., IfDefault ]
106 static void CollectControlProjections(Node* node, Node** proj, size_t count);
109 // ---------------------------------------------------------------------------
112 static bool IsTyped(Node* node) {
113 Bounds const bounds = node->bounds();
114 DCHECK(!bounds.lower == !bounds.upper);
117 static Bounds GetBounds(Node* node) {
118 DCHECK(IsTyped(node));
119 return node->bounds();
121 static void SetBounds(Node* node, Bounds bounds) {
122 DCHECK_NOT_NULL(bounds.lower);
123 DCHECK_NOT_NULL(bounds.upper);
124 node->set_bounds(bounds);
126 static void RemoveBounds(Node* node) { node->set_bounds(Bounds()); }
127 static bool AllValueInputsAreTyped(Node* node);
130 static inline bool IsInputRange(Edge edge, int first, int count);
133 } // namespace compiler
134 } // namespace internal
137 #endif // V8_COMPILER_NODE_PROPERTIES_H_