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)16bool 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)23bool 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::kJSDeleteProperty: 82 83 // Context operations 84 case IrOpcode::kJSCreateScriptContext: 85 86 // Conversions 87 case IrOpcode::kJSToInteger: 88 case IrOpcode::kJSToLength: 89 case IrOpcode::kJSToName: 90 case IrOpcode::kJSToNumber: 91 case IrOpcode::kJSToObject: 92 case IrOpcode::kJSToString: 93 94 // Call operations 95 case IrOpcode::kJSCallConstruct: 96 case IrOpcode::kJSCallFunction: 97 98 // Misc operations 99 case IrOpcode::kJSConvertReceiver: 100 case IrOpcode::kJSForInNext: 101 case IrOpcode::kJSForInPrepare: 102 case IrOpcode::kJSStackCheck: 103 return true; 104 105 default: 106 return false; 107 } 108 } 109 110 111 // static GetTotalInputCount(const Operator * op)112int OperatorProperties::GetTotalInputCount(const Operator* op) { 113 return op->ValueInputCount() + GetContextInputCount(op) + 114 GetFrameStateInputCount(op) + op->EffectInputCount() + 115 op->ControlInputCount(); 116 } 117 118 119 // static IsBasicBlockBegin(const Operator * op)120bool OperatorProperties::IsBasicBlockBegin(const Operator* op) { 121 Operator::Opcode const opcode = op->opcode(); 122 return opcode == IrOpcode::kStart || opcode == IrOpcode::kEnd || 123 opcode == IrOpcode::kDead || opcode == IrOpcode::kLoop || 124 opcode == IrOpcode::kMerge || opcode == IrOpcode::kIfTrue || 125 opcode == IrOpcode::kIfFalse || opcode == IrOpcode::kIfSuccess || 126 opcode == IrOpcode::kIfException || opcode == IrOpcode::kIfValue || 127 opcode == IrOpcode::kIfDefault; 128 } 129 130 } // namespace compiler 131 } // namespace internal 132 } // namespace v8 133