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 // A facade that simplifies access to the different kinds of inputs to a node.
18 class NodeProperties FINAL {
20 // ---------------------------------------------------------------------------
22 // Inputs are always arranged in order as follows:
23 // 0 [ values, context, frame state, effects, control ] node->InputCount()
25 static int FirstValueIndex(Node* node) { return 0; }
26 static int FirstContextIndex(Node* node) { return PastValueIndex(node); }
27 static int FirstFrameStateIndex(Node* node) { return PastContextIndex(node); }
28 static int FirstEffectIndex(Node* node) { return PastFrameStateIndex(node); }
29 static int FirstControlIndex(Node* node) { return PastEffectIndex(node); }
30 static int PastValueIndex(Node* node);
31 static int PastContextIndex(Node* node);
32 static int PastFrameStateIndex(Node* node);
33 static int PastEffectIndex(Node* node);
34 static int PastControlIndex(Node* node);
37 // ---------------------------------------------------------------------------
40 static Node* GetValueInput(Node* node, int index);
41 static Node* GetContextInput(Node* node);
42 static Node* GetFrameStateInput(Node* node);
43 static Node* GetEffectInput(Node* node, int index = 0);
44 static Node* GetControlInput(Node* node, int index = 0);
47 // ---------------------------------------------------------------------------
50 static bool IsValueEdge(Edge edge);
51 static bool IsContextEdge(Edge edge);
52 static bool IsFrameStateEdge(Edge edge);
53 static bool IsEffectEdge(Edge edge);
54 static bool IsControlEdge(Edge edge);
57 // ---------------------------------------------------------------------------
58 // Miscellaneous predicates.
60 static bool IsCommon(Node* node) {
61 return IrOpcode::IsCommonOpcode(node->opcode());
63 static bool IsControl(Node* node) {
64 return IrOpcode::IsControlOpcode(node->opcode());
66 static bool IsConstant(Node* node) {
67 return IrOpcode::IsConstantOpcode(node->opcode());
69 static bool IsPhi(Node* node) {
70 return IrOpcode::IsPhiOpcode(node->opcode());
74 // ---------------------------------------------------------------------------
75 // Miscellaneous mutators.
77 static void ReplaceContextInput(Node* node, Node* context);
78 static void ReplaceControlInput(Node* node, Node* control);
79 static void ReplaceEffectInput(Node* node, Node* effect, int index = 0);
80 static void ReplaceFrameStateInput(Node* node, Node* frame_state);
81 static void RemoveNonValueInputs(Node* node);
83 // Replace value uses of {node} with {value} and effect uses of {node} with
84 // {effect}. If {effect == NULL}, then use the effect input to {node}.
85 static void ReplaceWithValue(Node* node, Node* value, Node* effect = nullptr);
88 // ---------------------------------------------------------------------------
89 // Miscellaneous utilities.
91 static Node* FindProjection(Node* node, size_t projection_index);
93 // Collect the branch-related projections from a node, such as IfTrue,
94 // IfFalse, IfValue and IfDefault.
95 // - Branch: [ IfTrue, IfFalse ]
96 // - Switch: [ IfValue, ..., IfDefault ]
97 static void CollectControlProjections(Node* node, Node** proj, size_t count);
100 // ---------------------------------------------------------------------------
103 static bool IsTyped(Node* node) {
104 Bounds const bounds = node->bounds();
105 DCHECK(!bounds.lower == !bounds.upper);
108 static Bounds GetBounds(Node* node) {
109 DCHECK(IsTyped(node));
110 return node->bounds();
112 static void SetBounds(Node* node, Bounds bounds) {
113 DCHECK_NOT_NULL(bounds.lower);
114 DCHECK_NOT_NULL(bounds.upper);
115 node->set_bounds(bounds);
117 static void RemoveBounds(Node* node) { node->set_bounds(Bounds()); }
118 static bool AllValueInputsAreTyped(Node* node);
121 static inline bool IsInputRange(Edge edge, int first, int count);
124 } // namespace compiler
125 } // namespace internal
128 #endif // V8_COMPILER_NODE_PROPERTIES_H_