deps: update v8 to 4.3.61.21
[platform/upstream/nodejs.git] / deps / v8 / src / compiler / operator-properties.cc
1 // Copyright 2014 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 #include "src/compiler/operator-properties.h"
6
7 #include "src/compiler/js-operator.h"
8 #include "src/compiler/linkage.h"
9 #include "src/compiler/opcodes.h"
10
11 namespace v8 {
12 namespace internal {
13 namespace compiler {
14
15 // static
16 bool OperatorProperties::HasContextInput(const Operator* op) {
17   IrOpcode::Value opcode = static_cast<IrOpcode::Value>(op->opcode());
18   return IrOpcode::IsJsOpcode(opcode);
19 }
20
21
22 // static
23 int OperatorProperties::GetFrameStateInputCount(const Operator* op) {
24   if (!FLAG_turbo_deoptimization) {
25     return 0;
26   }
27   switch (op->opcode()) {
28     case IrOpcode::kFrameState:
29       return 1;
30     case IrOpcode::kJSCallRuntime: {
31       const CallRuntimeParameters& p = CallRuntimeParametersOf(op);
32       return Linkage::NeedsFrameState(p.id());
33     }
34
35     // Strict equality cannot lazily deoptimize.
36     case IrOpcode::kJSStrictEqual:
37     case IrOpcode::kJSStrictNotEqual:
38       return 0;
39
40     // Calls
41     case IrOpcode::kJSCallFunction:
42     case IrOpcode::kJSCallConstruct:
43
44     // Compare operations
45     case IrOpcode::kJSEqual:
46     case IrOpcode::kJSGreaterThan:
47     case IrOpcode::kJSGreaterThanOrEqual:
48     case IrOpcode::kJSHasProperty:
49     case IrOpcode::kJSInstanceOf:
50     case IrOpcode::kJSLessThan:
51     case IrOpcode::kJSLessThanOrEqual:
52     case IrOpcode::kJSNotEqual:
53
54     // Context operations
55     case IrOpcode::kJSCreateWithContext:
56
57     // Conversions
58     case IrOpcode::kJSToObject:
59     case IrOpcode::kJSToNumber:
60     case IrOpcode::kJSToName:
61
62     // Misc operations
63     case IrOpcode::kJSStackCheck:
64
65     // Properties
66     case IrOpcode::kJSLoadNamed:
67     case IrOpcode::kJSStoreNamed:
68     case IrOpcode::kJSLoadProperty:
69     case IrOpcode::kJSDeleteProperty:
70       return 1;
71
72     // StoreProperty provides a second frame state just before
73     // the operation. This is used to lazy-deoptimize a to-number
74     // conversion for typed arrays.
75     case IrOpcode::kJSStoreProperty:
76       return 2;
77
78     // Binary operators that can deopt in the middle the operation (e.g.,
79     // as a result of lazy deopt in ToNumber conversion) need a second frame
80     // state so that we can resume before the operation.
81     case IrOpcode::kJSMultiply:
82     case IrOpcode::kJSAdd:
83     case IrOpcode::kJSBitwiseAnd:
84     case IrOpcode::kJSBitwiseOr:
85     case IrOpcode::kJSBitwiseXor:
86     case IrOpcode::kJSDivide:
87     case IrOpcode::kJSModulus:
88     case IrOpcode::kJSShiftLeft:
89     case IrOpcode::kJSShiftRight:
90     case IrOpcode::kJSShiftRightLogical:
91     case IrOpcode::kJSSubtract:
92       return 2;
93
94     default:
95       return 0;
96   }
97 }
98
99
100 // static
101 int OperatorProperties::GetTotalInputCount(const Operator* op) {
102   return op->ValueInputCount() + GetContextInputCount(op) +
103          GetFrameStateInputCount(op) + op->EffectInputCount() +
104          op->ControlInputCount();
105 }
106
107
108 // static
109 bool OperatorProperties::IsBasicBlockBegin(const Operator* op) {
110   Operator::Opcode const opcode = op->opcode();
111   return opcode == IrOpcode::kStart || opcode == IrOpcode::kEnd ||
112          opcode == IrOpcode::kDead || opcode == IrOpcode::kLoop ||
113          opcode == IrOpcode::kMerge || opcode == IrOpcode::kIfTrue ||
114          opcode == IrOpcode::kIfFalse || opcode == IrOpcode::kIfSuccess ||
115          opcode == IrOpcode::kIfException || opcode == IrOpcode::kIfValue ||
116          opcode == IrOpcode::kIfDefault;
117 }
118
119 }  // namespace compiler
120 }  // namespace internal
121 }  // namespace v8