deps: update v8 to 4.3.61.21
[platform/upstream/nodejs.git] / deps / v8 / src / compiler / node-properties.h
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/types.h"
10
11 namespace v8 {
12 namespace internal {
13 namespace compiler {
14
15 class Graph;
16 class Operator;
17 class CommonOperatorBuilder;
18
19 // A facade that simplifies access to the different kinds of inputs to a node.
20 class NodeProperties FINAL {
21  public:
22   // ---------------------------------------------------------------------------
23   // Input layout.
24   // Inputs are always arranged in order as follows:
25   //     0 [ values, context, frame state, effects, control ] node->InputCount()
26
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);
37
38
39   // ---------------------------------------------------------------------------
40   // Input accessors.
41
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);
47
48
49   // ---------------------------------------------------------------------------
50   // Edge kinds.
51
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);
57
58
59   // ---------------------------------------------------------------------------
60   // Miscellaneous predicates.
61
62   static bool IsCommon(Node* node) {
63     return IrOpcode::IsCommonOpcode(node->opcode());
64   }
65   static bool IsControl(Node* node) {
66     return IrOpcode::IsControlOpcode(node->opcode());
67   }
68   static bool IsConstant(Node* node) {
69     return IrOpcode::IsConstantOpcode(node->opcode());
70   }
71   static bool IsPhi(Node* node) {
72     return IrOpcode::IsPhiOpcode(node->opcode());
73   }
74
75
76   // ---------------------------------------------------------------------------
77   // Miscellaneous mutators.
78
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);
84
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,
88                                 Node* node);
89
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);
95
96   // ---------------------------------------------------------------------------
97   // Miscellaneous utilities.
98
99   static Node* FindProjection(Node* node, size_t projection_index);
100
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);
107
108
109   // ---------------------------------------------------------------------------
110   // Type Bounds.
111
112   static bool IsTyped(Node* node) {
113     Bounds const bounds = node->bounds();
114     DCHECK(!bounds.lower == !bounds.upper);
115     return bounds.upper;
116   }
117   static Bounds GetBounds(Node* node) {
118     DCHECK(IsTyped(node));
119     return node->bounds();
120   }
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);
125   }
126   static void RemoveBounds(Node* node) { node->set_bounds(Bounds()); }
127   static bool AllValueInputsAreTyped(Node* node);
128
129  private:
130   static inline bool IsInputRange(Edge edge, int first, int count);
131 };
132
133 }  // namespace compiler
134 }  // namespace internal
135 }  // namespace v8
136
137 #endif  // V8_COMPILER_NODE_PROPERTIES_H_