a13eea3a02d550840d58f05249aaee8bc98fc48a
[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 Operator;
16
17 // A facade that simplifies access to the different kinds of inputs to a node.
18 class NodeProperties FINAL {
19  public:
20   // ---------------------------------------------------------------------------
21   // Input layout.
22   // Inputs are always arranged in order as follows:
23   //     0 [ values, context, frame state, effects, control ] node->InputCount()
24
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);
35
36
37   // ---------------------------------------------------------------------------
38   // Input accessors.
39
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);
45
46
47   // ---------------------------------------------------------------------------
48   // Edge kinds.
49
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);
55
56
57   // ---------------------------------------------------------------------------
58   // Miscellaneous predicates.
59
60   static bool IsCommon(Node* node) {
61     return IrOpcode::IsCommonOpcode(node->opcode());
62   }
63   static bool IsControl(Node* node) {
64     return IrOpcode::IsControlOpcode(node->opcode());
65   }
66   static bool IsConstant(Node* node) {
67     return IrOpcode::IsConstantOpcode(node->opcode());
68   }
69   static bool IsPhi(Node* node) {
70     return IrOpcode::IsPhiOpcode(node->opcode());
71   }
72
73
74   // ---------------------------------------------------------------------------
75   // Miscellaneous mutators.
76
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);
82
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);
86
87
88   // ---------------------------------------------------------------------------
89   // Miscellaneous utilities.
90
91   static Node* FindProjection(Node* node, size_t projection_index);
92
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);
98
99
100   // ---------------------------------------------------------------------------
101   // Type Bounds.
102
103   static bool IsTyped(Node* node) {
104     Bounds const bounds = node->bounds();
105     DCHECK(!bounds.lower == !bounds.upper);
106     return bounds.upper;
107   }
108   static Bounds GetBounds(Node* node) {
109     DCHECK(IsTyped(node));
110     return node->bounds();
111   }
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);
116   }
117   static void RemoveBounds(Node* node) { node->set_bounds(Bounds()); }
118   static bool AllValueInputsAreTyped(Node* node);
119
120  private:
121   static inline bool IsInputRange(Edge edge, int first, int count);
122 };
123
124 }  // namespace compiler
125 }  // namespace internal
126 }  // namespace v8
127
128 #endif  // V8_COMPILER_NODE_PROPERTIES_H_