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 return false; 36 37 // Generator creation cannot call back into arbitrary JavaScript. 38 case IrOpcode::kJSCreateGeneratorObject: 39 return false; 40 41 // Binary operations 42 case IrOpcode::kJSAdd: 43 case IrOpcode::kJSSubtract: 44 case IrOpcode::kJSMultiply: 45 case IrOpcode::kJSDivide: 46 case IrOpcode::kJSModulus: 47 case IrOpcode::kJSExponentiate: 48 49 // Bitwise operations 50 case IrOpcode::kJSBitwiseOr: 51 case IrOpcode::kJSBitwiseXor: 52 case IrOpcode::kJSBitwiseAnd: 53 54 // Shift operations 55 case IrOpcode::kJSShiftLeft: 56 case IrOpcode::kJSShiftRight: 57 case IrOpcode::kJSShiftRightLogical: 58 59 // Compare operations 60 case IrOpcode::kJSEqual: 61 case IrOpcode::kJSGreaterThan: 62 case IrOpcode::kJSGreaterThanOrEqual: 63 case IrOpcode::kJSLessThan: 64 case IrOpcode::kJSLessThanOrEqual: 65 case IrOpcode::kJSHasProperty: 66 case IrOpcode::kJSHasInPrototypeChain: 67 case IrOpcode::kJSInstanceOf: 68 case IrOpcode::kJSOrdinaryHasInstance: 69 70 // Object operations 71 case IrOpcode::kJSCreate: 72 case IrOpcode::kJSCreateArguments: 73 case IrOpcode::kJSCreateArray: 74 case IrOpcode::kJSCreateTypedArray: 75 case IrOpcode::kJSCreateLiteralArray: 76 case IrOpcode::kJSCreateLiteralObject: 77 case IrOpcode::kJSCreateLiteralRegExp: 78 case IrOpcode::kJSCreateObject: 79 case IrOpcode::kJSCloneObject: 80 81 // Property access operations 82 case IrOpcode::kJSLoadNamed: 83 case IrOpcode::kJSStoreNamed: 84 case IrOpcode::kJSLoadProperty: 85 case IrOpcode::kJSStoreProperty: 86 case IrOpcode::kJSLoadGlobal: 87 case IrOpcode::kJSStoreGlobal: 88 case IrOpcode::kJSStoreNamedOwn: 89 case IrOpcode::kJSStoreDataPropertyInLiteral: 90 case IrOpcode::kJSDeleteProperty: 91 92 // Conversions 93 case IrOpcode::kJSToInteger: 94 case IrOpcode::kJSToLength: 95 case IrOpcode::kJSToName: 96 case IrOpcode::kJSToNumber: 97 case IrOpcode::kJSToNumberConvertBigInt: 98 case IrOpcode::kJSToNumeric: 99 case IrOpcode::kJSToObject: 100 case IrOpcode::kJSToString: 101 case IrOpcode::kJSParseInt: 102 103 // Call operations 104 case IrOpcode::kJSConstructForwardVarargs: 105 case IrOpcode::kJSConstruct: 106 case IrOpcode::kJSConstructWithArrayLike: 107 case IrOpcode::kJSConstructWithSpread: 108 case IrOpcode::kJSCallForwardVarargs: 109 case IrOpcode::kJSCall: 110 case IrOpcode::kJSCallWithArrayLike: 111 case IrOpcode::kJSCallWithSpread: 112 113 // Misc operations 114 case IrOpcode::kJSForInEnumerate: 115 case IrOpcode::kJSForInNext: 116 case IrOpcode::kJSStackCheck: 117 case IrOpcode::kJSDebugger: 118 case IrOpcode::kJSGetSuperConstructor: 119 case IrOpcode::kJSBitwiseNot: 120 case IrOpcode::kJSDecrement: 121 case IrOpcode::kJSIncrement: 122 case IrOpcode::kJSNegate: 123 case IrOpcode::kJSPromiseResolve: 124 case IrOpcode::kJSRejectPromise: 125 case IrOpcode::kJSResolvePromise: 126 case IrOpcode::kJSPerformPromiseThen: 127 case IrOpcode::kJSObjectIsArray: 128 case IrOpcode::kJSRegExpTest: 129 return true; 130 131 default: 132 return false; 133 } 134 } 135 136 137 // static GetTotalInputCount(const Operator * op)138int OperatorProperties::GetTotalInputCount(const Operator* op) { 139 return op->ValueInputCount() + GetContextInputCount(op) + 140 GetFrameStateInputCount(op) + op->EffectInputCount() + 141 op->ControlInputCount(); 142 } 143 144 145 // static IsBasicBlockBegin(const Operator * op)146bool OperatorProperties::IsBasicBlockBegin(const Operator* op) { 147 Operator::Opcode const opcode = op->opcode(); 148 return opcode == IrOpcode::kStart || opcode == IrOpcode::kEnd || 149 opcode == IrOpcode::kDead || opcode == IrOpcode::kLoop || 150 opcode == IrOpcode::kMerge || opcode == IrOpcode::kIfTrue || 151 opcode == IrOpcode::kIfFalse || opcode == IrOpcode::kIfSuccess || 152 opcode == IrOpcode::kIfException || opcode == IrOpcode::kIfValue || 153 opcode == IrOpcode::kIfDefault; 154 } 155 156 } // namespace compiler 157 } // namespace internal 158 } // namespace v8 159