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.
5 #ifndef V8_COMPILER_OPERATOR_PROPERTIES_INL_H_
6 #define V8_COMPILER_OPERATOR_PROPERTIES_INL_H_
10 #include "src/compiler/js-operator.h"
11 #include "src/compiler/opcodes.h"
12 #include "src/compiler/operator-properties.h"
18 inline bool OperatorProperties::HasValueInput(Operator* op) {
19 return OperatorProperties::GetValueInputCount(op) > 0;
22 inline bool OperatorProperties::HasContextInput(Operator* op) {
23 IrOpcode::Value opcode = static_cast<IrOpcode::Value>(op->opcode());
24 return IrOpcode::IsJsOpcode(opcode);
27 inline bool OperatorProperties::HasEffectInput(Operator* op) {
28 return OperatorProperties::GetEffectInputCount(op) > 0;
31 inline bool OperatorProperties::HasControlInput(Operator* op) {
32 return OperatorProperties::GetControlInputCount(op) > 0;
36 inline int OperatorProperties::GetValueInputCount(Operator* op) {
37 return op->InputCount();
40 inline int OperatorProperties::GetContextInputCount(Operator* op) {
41 return OperatorProperties::HasContextInput(op) ? 1 : 0;
44 inline int OperatorProperties::GetEffectInputCount(Operator* op) {
45 if (op->opcode() == IrOpcode::kEffectPhi) {
46 return static_cast<Operator1<int>*>(op)->parameter();
48 if (op->HasProperty(Operator::kNoRead) && op->HasProperty(Operator::kNoWrite))
49 return 0; // no effects.
53 inline int OperatorProperties::GetControlInputCount(Operator* op) {
54 switch (op->opcode()) {
56 case IrOpcode::kEffectPhi:
58 #define OPCODE_CASE(x) case IrOpcode::k##x:
59 CONTROL_OP_LIST(OPCODE_CASE)
61 return static_cast<ControlOperator*>(op)->ControlInputCount();
63 // If a node can lazily deoptimize, it needs control dependency.
64 if (CanLazilyDeoptimize(op)) {
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;
77 inline int OperatorProperties::GetTotalInputCount(Operator* op) {
78 return GetValueInputCount(op) + GetContextInputCount(op) +
79 GetEffectInputCount(op) + GetControlInputCount(op);
82 // -----------------------------------------------------------------------------
85 inline bool OperatorProperties::HasValueOutput(Operator* op) {
86 return GetValueOutputCount(op) > 0;
89 inline bool OperatorProperties::HasEffectOutput(Operator* op) {
90 return op->opcode() == IrOpcode::kStart || GetEffectInputCount(op) > 0;
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);
100 inline int OperatorProperties::GetValueOutputCount(Operator* op) {
101 return op->OutputCount();
104 inline int OperatorProperties::GetEffectOutputCount(Operator* op) {
105 return HasEffectOutput(op) ? 1 : 0;
108 inline int OperatorProperties::GetControlOutputCount(Operator* node) {
109 return node->opcode() == IrOpcode::kBranch ? 2 : HasControlOutput(node) ? 1
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;
122 inline bool OperatorProperties::CanBeScheduled(Operator* op) { return true; }
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;
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;
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
142 if (!FLAG_turbo_deoptimization) {
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();
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;
161 case IrOpcode::kJSCallFunction:
162 case IrOpcode::kJSCallConstruct:
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:
189 } // namespace v8::internal::compiler
191 #endif // V8_COMPILER_OPERATOR_PROPERTIES_INL_H_