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
HasContextInput(const Operator * op)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
GetFrameStateInputCount(const Operator * op)23 int OperatorProperties::GetFrameStateInputCount(const Operator* op) {
24   switch (op->opcode()) {
25     case IrOpcode::kFrameState:
26       return 1;
27     case IrOpcode::kJSCallRuntime: {
28       const CallRuntimeParameters& p = CallRuntimeParametersOf(op);
29       return Linkage::FrameStateInputCount(p.id());
30     }
31 
32     // Strict equality cannot lazily deoptimize.
33     case IrOpcode::kJSStrictEqual:
34     case IrOpcode::kJSStrictNotEqual:
35       return 0;
36 
37     // We record the frame state immediately before and immediately after every
38     // construct/function call.
39     case IrOpcode::kJSCallConstruct:
40     case IrOpcode::kJSCallFunction:
41       return 2;
42 
43     // Compare operations
44     case IrOpcode::kJSEqual:
45     case IrOpcode::kJSNotEqual:
46     case IrOpcode::kJSHasProperty:
47     case IrOpcode::kJSInstanceOf:
48 
49     // Object operations
50     case IrOpcode::kJSCreate:
51     case IrOpcode::kJSCreateArguments:
52     case IrOpcode::kJSCreateArray:
53     case IrOpcode::kJSCreateLiteralArray:
54     case IrOpcode::kJSCreateLiteralObject:
55     case IrOpcode::kJSCreateLiteralRegExp:
56 
57     // Context operations
58     case IrOpcode::kJSLoadDynamic:
59     case IrOpcode::kJSCreateScriptContext:
60 
61     // Conversions
62     case IrOpcode::kJSToName:
63     case IrOpcode::kJSToNumber:
64     case IrOpcode::kJSToObject:
65     case IrOpcode::kJSToString:
66 
67     // Misc operations
68     case IrOpcode::kJSConvertReceiver:
69     case IrOpcode::kJSForInNext:
70     case IrOpcode::kJSForInPrepare:
71     case IrOpcode::kJSStackCheck:
72     case IrOpcode::kJSDeleteProperty:
73       return 1;
74 
75     // We record the frame state immediately before and immediately after
76     // every property or global variable access.
77     case IrOpcode::kJSLoadNamed:
78     case IrOpcode::kJSStoreNamed:
79     case IrOpcode::kJSLoadProperty:
80     case IrOpcode::kJSStoreProperty:
81     case IrOpcode::kJSLoadGlobal:
82     case IrOpcode::kJSStoreGlobal:
83       return 2;
84 
85     // Binary operators that can deopt in the middle the operation (e.g.,
86     // as a result of lazy deopt in ToNumber conversion) need a second frame
87     // state so that we can resume before the operation.
88     case IrOpcode::kJSMultiply:
89     case IrOpcode::kJSAdd:
90     case IrOpcode::kJSBitwiseAnd:
91     case IrOpcode::kJSBitwiseOr:
92     case IrOpcode::kJSBitwiseXor:
93     case IrOpcode::kJSDivide:
94     case IrOpcode::kJSModulus:
95     case IrOpcode::kJSShiftLeft:
96     case IrOpcode::kJSShiftRight:
97     case IrOpcode::kJSShiftRightLogical:
98     case IrOpcode::kJSSubtract:
99       return 2;
100 
101     // Compare operators that can deopt in the middle the operation (e.g.,
102     // as a result of lazy deopt in ToNumber conversion) need a second frame
103     // state so that we can resume before the operation.
104     case IrOpcode::kJSGreaterThan:
105     case IrOpcode::kJSGreaterThanOrEqual:
106     case IrOpcode::kJSLessThan:
107     case IrOpcode::kJSLessThanOrEqual:
108       return 2;
109 
110     default:
111       return 0;
112   }
113 }
114 
115 
116 // static
GetTotalInputCount(const Operator * op)117 int OperatorProperties::GetTotalInputCount(const Operator* op) {
118   return op->ValueInputCount() + GetContextInputCount(op) +
119          GetFrameStateInputCount(op) + op->EffectInputCount() +
120          op->ControlInputCount();
121 }
122 
123 
124 // static
IsBasicBlockBegin(const Operator * op)125 bool OperatorProperties::IsBasicBlockBegin(const Operator* op) {
126   Operator::Opcode const opcode = op->opcode();
127   return opcode == IrOpcode::kStart || opcode == IrOpcode::kEnd ||
128          opcode == IrOpcode::kDead || opcode == IrOpcode::kLoop ||
129          opcode == IrOpcode::kMerge || opcode == IrOpcode::kIfTrue ||
130          opcode == IrOpcode::kIfFalse || opcode == IrOpcode::kIfSuccess ||
131          opcode == IrOpcode::kIfException || opcode == IrOpcode::kIfValue ||
132          opcode == IrOpcode::kIfDefault;
133 }
134 
135 }  // namespace compiler
136 }  // namespace internal
137 }  // namespace v8
138