Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / v8 / src / compiler / operator-properties-inl.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_OPERATOR_PROPERTIES_INL_H_
6 #define V8_COMPILER_OPERATOR_PROPERTIES_INL_H_
7
8 #include "src/v8.h"
9
10 #include "src/compiler/js-operator.h"
11 #include "src/compiler/opcodes.h"
12 #include "src/compiler/operator-properties.h"
13
14 namespace v8 {
15 namespace internal {
16 namespace compiler {
17
18 inline bool OperatorProperties::HasValueInput(Operator* op) {
19   return OperatorProperties::GetValueInputCount(op) > 0;
20 }
21
22 inline bool OperatorProperties::HasContextInput(Operator* op) {
23   IrOpcode::Value opcode = static_cast<IrOpcode::Value>(op->opcode());
24   return IrOpcode::IsJsOpcode(opcode);
25 }
26
27 inline bool OperatorProperties::HasEffectInput(Operator* op) {
28   return OperatorProperties::GetEffectInputCount(op) > 0;
29 }
30
31 inline bool OperatorProperties::HasControlInput(Operator* op) {
32   return OperatorProperties::GetControlInputCount(op) > 0;
33 }
34
35
36 inline int OperatorProperties::GetValueInputCount(Operator* op) {
37   return op->InputCount();
38 }
39
40 inline int OperatorProperties::GetContextInputCount(Operator* op) {
41   return OperatorProperties::HasContextInput(op) ? 1 : 0;
42 }
43
44 inline int OperatorProperties::GetEffectInputCount(Operator* op) {
45   if (op->opcode() == IrOpcode::kEffectPhi) {
46     return static_cast<Operator1<int>*>(op)->parameter();
47   }
48   if (op->HasProperty(Operator::kNoRead) && op->HasProperty(Operator::kNoWrite))
49     return 0;  // no effects.
50   return 1;
51 }
52
53 inline int OperatorProperties::GetControlInputCount(Operator* op) {
54   switch (op->opcode()) {
55     case IrOpcode::kPhi:
56     case IrOpcode::kEffectPhi:
57       return 1;
58 #define OPCODE_CASE(x) case IrOpcode::k##x:
59       CONTROL_OP_LIST(OPCODE_CASE)
60 #undef OPCODE_CASE
61       return static_cast<ControlOperator*>(op)->ControlInputCount();
62     default:
63       // If a node can lazily deoptimize, it needs control dependency.
64       if (CanLazilyDeoptimize(op)) {
65         return 1;
66       }
67       // Operators that have write effects must have a control
68       // dependency. Effect dependencies only ensure the correct order of
69       // write/read operations without consideration of control flow. Without an
70       // explicit control dependency writes can be float in the schedule too
71       // early along a path that shouldn't generate a side-effect.
72       return op->HasProperty(Operator::kNoWrite) ? 0 : 1;
73   }
74   return 0;
75 }
76
77 inline int OperatorProperties::GetTotalInputCount(Operator* op) {
78   return GetValueInputCount(op) + GetContextInputCount(op) +
79          GetEffectInputCount(op) + GetControlInputCount(op);
80 }
81
82 // -----------------------------------------------------------------------------
83 // Output properties.
84
85 inline bool OperatorProperties::HasValueOutput(Operator* op) {
86   return GetValueOutputCount(op) > 0;
87 }
88
89 inline bool OperatorProperties::HasEffectOutput(Operator* op) {
90   return op->opcode() == IrOpcode::kStart || GetEffectInputCount(op) > 0;
91 }
92
93 inline bool OperatorProperties::HasControlOutput(Operator* op) {
94   IrOpcode::Value opcode = static_cast<IrOpcode::Value>(op->opcode());
95   return (opcode != IrOpcode::kEnd && IrOpcode::IsControlOpcode(opcode)) ||
96          CanLazilyDeoptimize(op);
97 }
98
99
100 inline int OperatorProperties::GetValueOutputCount(Operator* op) {
101   return op->OutputCount();
102 }
103
104 inline int OperatorProperties::GetEffectOutputCount(Operator* op) {
105   return HasEffectOutput(op) ? 1 : 0;
106 }
107
108 inline int OperatorProperties::GetControlOutputCount(Operator* node) {
109   return node->opcode() == IrOpcode::kBranch ? 2 : HasControlOutput(node) ? 1
110                                                                           : 0;
111 }
112
113
114 inline bool OperatorProperties::IsBasicBlockBegin(Operator* op) {
115   uint8_t opcode = op->opcode();
116   return opcode == IrOpcode::kStart || opcode == IrOpcode::kEnd ||
117          opcode == IrOpcode::kDead || opcode == IrOpcode::kLoop ||
118          opcode == IrOpcode::kMerge || opcode == IrOpcode::kIfTrue ||
119          opcode == IrOpcode::kIfFalse;
120 }
121
122 inline bool OperatorProperties::CanBeScheduled(Operator* op) { return true; }
123
124 inline bool OperatorProperties::HasFixedSchedulePosition(Operator* op) {
125   IrOpcode::Value opcode = static_cast<IrOpcode::Value>(op->opcode());
126   return (IrOpcode::IsControlOpcode(opcode)) ||
127          opcode == IrOpcode::kParameter || opcode == IrOpcode::kEffectPhi ||
128          opcode == IrOpcode::kPhi;
129 }
130
131 inline bool OperatorProperties::IsScheduleRoot(Operator* op) {
132   uint8_t opcode = op->opcode();
133   return opcode == IrOpcode::kEnd || opcode == IrOpcode::kEffectPhi ||
134          opcode == IrOpcode::kPhi;
135 }
136
137 inline bool OperatorProperties::CanLazilyDeoptimize(Operator* op) {
138   // TODO(jarin) This function allows turning on lazy deoptimization
139   // incrementally. It will change as we turn on lazy deopt for
140   // more nodes.
141
142   if (!FLAG_turbo_deoptimization) {
143     return false;
144   }
145
146   switch (op->opcode()) {
147     case IrOpcode::kCall: {
148       CallOperator* call_op = reinterpret_cast<CallOperator*>(op);
149       CallDescriptor* descriptor = call_op->parameter();
150       return descriptor->CanLazilyDeoptimize();
151     }
152     case IrOpcode::kJSCallRuntime: {
153       Runtime::FunctionId function =
154           reinterpret_cast<Operator1<Runtime::FunctionId>*>(op)->parameter();
155       // TODO(jarin) At the moment, we only support lazy deoptimization for
156       // the %DeoptimizeFunction runtime function.
157       return function == Runtime::kDeoptimizeFunction;
158     }
159
160     // JS function calls
161     case IrOpcode::kJSCallFunction:
162     case IrOpcode::kJSCallConstruct:
163
164     // Binary operations
165     case IrOpcode::kJSBitwiseOr:
166     case IrOpcode::kJSBitwiseXor:
167     case IrOpcode::kJSBitwiseAnd:
168     case IrOpcode::kJSShiftLeft:
169     case IrOpcode::kJSShiftRight:
170     case IrOpcode::kJSShiftRightLogical:
171     case IrOpcode::kJSAdd:
172     case IrOpcode::kJSSubtract:
173     case IrOpcode::kJSMultiply:
174     case IrOpcode::kJSDivide:
175     case IrOpcode::kJSModulus:
176     case IrOpcode::kJSLoadProperty:
177     case IrOpcode::kJSStoreProperty:
178     case IrOpcode::kJSLoadNamed:
179     case IrOpcode::kJSStoreNamed:
180       return true;
181
182     default:
183       return false;
184   }
185   return false;
186 }
187 }
188 }
189 }  // namespace v8::internal::compiler
190
191 #endif  // V8_COMPILER_OPERATOR_PROPERTIES_INL_H_