• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
HasFrameStateInput(const Operator * op)23 bool OperatorProperties::HasFrameStateInput(const Operator* op) {
24   switch (op->opcode()) {
25     case IrOpcode::kCheckpoint:
26     case IrOpcode::kFrameState:
27       return true;
28     case IrOpcode::kJSCallRuntime: {
29       const CallRuntimeParameters& p = CallRuntimeParametersOf(op);
30       return Linkage::NeedsFrameStateInput(p.id());
31     }
32 
33     // Strict equality cannot lazily deoptimize.
34     case IrOpcode::kJSStrictEqual:
35     case IrOpcode::kJSStrictNotEqual:
36       return false;
37 
38     // Binary operations
39     case IrOpcode::kJSAdd:
40     case IrOpcode::kJSSubtract:
41     case IrOpcode::kJSMultiply:
42     case IrOpcode::kJSDivide:
43     case IrOpcode::kJSModulus:
44 
45     // Bitwise operations
46     case IrOpcode::kJSBitwiseOr:
47     case IrOpcode::kJSBitwiseXor:
48     case IrOpcode::kJSBitwiseAnd:
49 
50     // Shift operations
51     case IrOpcode::kJSShiftLeft:
52     case IrOpcode::kJSShiftRight:
53     case IrOpcode::kJSShiftRightLogical:
54 
55     // Compare operations
56     case IrOpcode::kJSEqual:
57     case IrOpcode::kJSNotEqual:
58     case IrOpcode::kJSGreaterThan:
59     case IrOpcode::kJSGreaterThanOrEqual:
60     case IrOpcode::kJSLessThan:
61     case IrOpcode::kJSLessThanOrEqual:
62     case IrOpcode::kJSHasProperty:
63     case IrOpcode::kJSInstanceOf:
64     case IrOpcode::kJSOrdinaryHasInstance:
65 
66     // Object operations
67     case IrOpcode::kJSCreate:
68     case IrOpcode::kJSCreateArguments:
69     case IrOpcode::kJSCreateArray:
70     case IrOpcode::kJSCreateLiteralArray:
71     case IrOpcode::kJSCreateLiteralObject:
72     case IrOpcode::kJSCreateLiteralRegExp:
73 
74     // Property access operations
75     case IrOpcode::kJSLoadNamed:
76     case IrOpcode::kJSStoreNamed:
77     case IrOpcode::kJSLoadProperty:
78     case IrOpcode::kJSStoreProperty:
79     case IrOpcode::kJSLoadGlobal:
80     case IrOpcode::kJSStoreGlobal:
81     case IrOpcode::kJSStoreNamedOwn:
82     case IrOpcode::kJSStoreDataPropertyInLiteral:
83     case IrOpcode::kJSDeleteProperty:
84 
85     // Context operations
86     case IrOpcode::kJSCreateScriptContext:
87 
88     // Conversions
89     case IrOpcode::kJSToInteger:
90     case IrOpcode::kJSToLength:
91     case IrOpcode::kJSToName:
92     case IrOpcode::kJSToNumber:
93     case IrOpcode::kJSToObject:
94     case IrOpcode::kJSToString:
95 
96     // Call operations
97     case IrOpcode::kJSConstruct:
98     case IrOpcode::kJSConstructWithSpread:
99     case IrOpcode::kJSCallForwardVarargs:
100     case IrOpcode::kJSCall:
101     case IrOpcode::kJSCallWithSpread:
102 
103     // Misc operations
104     case IrOpcode::kJSForInNext:
105     case IrOpcode::kJSForInPrepare:
106     case IrOpcode::kJSStackCheck:
107     case IrOpcode::kJSDebugger:
108     case IrOpcode::kJSGetSuperConstructor:
109       return true;
110 
111     default:
112       return false;
113   }
114 }
115 
116 
117 // static
GetTotalInputCount(const Operator * op)118 int OperatorProperties::GetTotalInputCount(const Operator* op) {
119   return op->ValueInputCount() + GetContextInputCount(op) +
120          GetFrameStateInputCount(op) + op->EffectInputCount() +
121          op->ControlInputCount();
122 }
123 
124 
125 // static
IsBasicBlockBegin(const Operator * op)126 bool OperatorProperties::IsBasicBlockBegin(const Operator* op) {
127   Operator::Opcode const opcode = op->opcode();
128   return opcode == IrOpcode::kStart || opcode == IrOpcode::kEnd ||
129          opcode == IrOpcode::kDead || opcode == IrOpcode::kLoop ||
130          opcode == IrOpcode::kMerge || opcode == IrOpcode::kIfTrue ||
131          opcode == IrOpcode::kIfFalse || opcode == IrOpcode::kIfSuccess ||
132          opcode == IrOpcode::kIfException || opcode == IrOpcode::kIfValue ||
133          opcode == IrOpcode::kIfDefault;
134 }
135 
136 }  // namespace compiler
137 }  // namespace internal
138 }  // namespace v8
139