| OLD | NEW |
| 1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "src/compiler/bytecode-graph-builder.h" | 5 #include "src/compiler/bytecode-graph-builder.h" |
| 6 | 6 |
| 7 #include "src/compiler/bytecode-branch-analysis.h" | 7 #include "src/compiler/bytecode-branch-analysis.h" |
| 8 #include "src/compiler/linkage.h" | 8 #include "src/compiler/linkage.h" |
| 9 #include "src/compiler/operator-properties.h" | 9 #include "src/compiler/operator-properties.h" |
| 10 #include "src/interpreter/bytecodes.h" | 10 #include "src/interpreter/bytecodes.h" |
| (...skipping 1185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1196 FrameStateBeforeAndAfter states(this); | 1196 FrameStateBeforeAndAfter states(this); |
| 1197 Node* left = | 1197 Node* left = |
| 1198 environment()->LookupRegister(bytecode_iterator().GetRegisterOperand(0)); | 1198 environment()->LookupRegister(bytecode_iterator().GetRegisterOperand(0)); |
| 1199 Node* right = environment()->LookupAccumulator(); | 1199 Node* right = environment()->LookupAccumulator(); |
| 1200 Node* node = NewNode(js_op, left, right); | 1200 Node* node = NewNode(js_op, left, right); |
| 1201 environment()->BindAccumulator(node, &states); | 1201 environment()->BindAccumulator(node, &states); |
| 1202 } | 1202 } |
| 1203 | 1203 |
| 1204 // Helper function to create binary operation hint from the recorded type | 1204 // Helper function to create binary operation hint from the recorded type |
| 1205 // feedback. | 1205 // feedback. |
| 1206 BinaryOperationHint BytecodeGraphBuilder::GetBinaryOperationHint() { | 1206 BinaryOperationHint BytecodeGraphBuilder::GetBinaryOperationHint( |
| 1207 FeedbackVectorSlot slot = | 1207 int operand_index) { |
| 1208 feedback_vector()->ToSlot(bytecode_iterator().GetIndexOperand(1)); | 1208 FeedbackVectorSlot slot = feedback_vector()->ToSlot( |
| 1209 bytecode_iterator().GetIndexOperand(operand_index)); |
| 1209 DCHECK_EQ(FeedbackVectorSlotKind::GENERAL, feedback_vector()->GetKind(slot)); | 1210 DCHECK_EQ(FeedbackVectorSlotKind::GENERAL, feedback_vector()->GetKind(slot)); |
| 1210 Object* feedback = feedback_vector()->Get(slot); | 1211 Object* feedback = feedback_vector()->Get(slot); |
| 1211 BinaryOperationHint hint = BinaryOperationHint::kAny; | 1212 BinaryOperationHint hint = BinaryOperationHint::kAny; |
| 1212 if (feedback->IsSmi()) { | |
| 1213 hint = BinaryOperationHintFromFeedback((Smi::cast(feedback))->value()); | |
| 1214 } | |
| 1215 return hint; | |
| 1216 } | |
| 1217 | |
| 1218 BinaryOperationHint BytecodeGraphBuilder::GetBinaryOperationHintForIncDec() { | |
| 1219 FeedbackVectorSlot slot = | |
| 1220 feedback_vector()->ToSlot(bytecode_iterator().GetIndexOperand(0)); | |
| 1221 DCHECK_EQ(FeedbackVectorSlotKind::GENERAL, feedback_vector()->GetKind(slot)); | |
| 1222 Object* feedback = feedback_vector()->Get(slot); | |
| 1223 BinaryOperationHint hint = BinaryOperationHint::kAny; | |
| 1224 if (feedback->IsSmi()) { | 1213 if (feedback->IsSmi()) { |
| 1225 hint = BinaryOperationHintFromFeedback((Smi::cast(feedback))->value()); | 1214 hint = BinaryOperationHintFromFeedback((Smi::cast(feedback))->value()); |
| 1226 } | 1215 } |
| 1227 return hint; | 1216 return hint; |
| 1228 } | 1217 } |
| 1229 | 1218 |
| 1230 void BytecodeGraphBuilder::VisitAdd() { | 1219 void BytecodeGraphBuilder::VisitAdd() { |
| 1231 BuildBinaryOp(javascript()->Add(GetBinaryOperationHint())); | 1220 BuildBinaryOp( |
| 1221 javascript()->Add(GetBinaryOperationHint(kBinaryOperationHintIndex))); |
| 1232 } | 1222 } |
| 1233 | 1223 |
| 1234 void BytecodeGraphBuilder::VisitSub() { | 1224 void BytecodeGraphBuilder::VisitSub() { |
| 1235 BuildBinaryOp(javascript()->Subtract(GetBinaryOperationHint())); | 1225 BuildBinaryOp(javascript()->Subtract( |
| 1226 GetBinaryOperationHint(kBinaryOperationHintIndex))); |
| 1236 } | 1227 } |
| 1237 | 1228 |
| 1238 void BytecodeGraphBuilder::VisitMul() { | 1229 void BytecodeGraphBuilder::VisitMul() { |
| 1239 BuildBinaryOp(javascript()->Multiply(GetBinaryOperationHint())); | 1230 BuildBinaryOp(javascript()->Multiply( |
| 1231 GetBinaryOperationHint(kBinaryOperationHintIndex))); |
| 1240 } | 1232 } |
| 1241 | 1233 |
| 1242 void BytecodeGraphBuilder::VisitDiv() { | 1234 void BytecodeGraphBuilder::VisitDiv() { |
| 1243 BuildBinaryOp(javascript()->Divide(GetBinaryOperationHint())); | 1235 BuildBinaryOp( |
| 1236 javascript()->Divide(GetBinaryOperationHint(kBinaryOperationHintIndex))); |
| 1244 } | 1237 } |
| 1245 | 1238 |
| 1246 void BytecodeGraphBuilder::VisitMod() { | 1239 void BytecodeGraphBuilder::VisitMod() { |
| 1247 BuildBinaryOp(javascript()->Modulus(GetBinaryOperationHint())); | 1240 BuildBinaryOp( |
| 1241 javascript()->Modulus(GetBinaryOperationHint(kBinaryOperationHintIndex))); |
| 1248 } | 1242 } |
| 1249 | 1243 |
| 1250 void BytecodeGraphBuilder::VisitBitwiseOr() { | 1244 void BytecodeGraphBuilder::VisitBitwiseOr() { |
| 1251 BuildBinaryOp(javascript()->BitwiseOr(GetBinaryOperationHint())); | 1245 BuildBinaryOp(javascript()->BitwiseOr( |
| 1246 GetBinaryOperationHint(kBinaryOperationHintIndex))); |
| 1252 } | 1247 } |
| 1253 | 1248 |
| 1254 void BytecodeGraphBuilder::VisitBitwiseXor() { | 1249 void BytecodeGraphBuilder::VisitBitwiseXor() { |
| 1255 BuildBinaryOp(javascript()->BitwiseXor(GetBinaryOperationHint())); | 1250 BuildBinaryOp(javascript()->BitwiseXor( |
| 1251 GetBinaryOperationHint(kBinaryOperationHintIndex))); |
| 1256 } | 1252 } |
| 1257 | 1253 |
| 1258 void BytecodeGraphBuilder::VisitBitwiseAnd() { | 1254 void BytecodeGraphBuilder::VisitBitwiseAnd() { |
| 1259 BuildBinaryOp(javascript()->BitwiseAnd(GetBinaryOperationHint())); | 1255 BuildBinaryOp(javascript()->BitwiseAnd( |
| 1256 GetBinaryOperationHint(kBinaryOperationHintIndex))); |
| 1260 } | 1257 } |
| 1261 | 1258 |
| 1262 void BytecodeGraphBuilder::VisitShiftLeft() { | 1259 void BytecodeGraphBuilder::VisitShiftLeft() { |
| 1263 BuildBinaryOp(javascript()->ShiftLeft(GetBinaryOperationHint())); | 1260 BuildBinaryOp(javascript()->ShiftLeft( |
| 1261 GetBinaryOperationHint(kBinaryOperationHintIndex))); |
| 1264 } | 1262 } |
| 1265 | 1263 |
| 1266 void BytecodeGraphBuilder::VisitShiftRight() { | 1264 void BytecodeGraphBuilder::VisitShiftRight() { |
| 1267 BuildBinaryOp(javascript()->ShiftRight(GetBinaryOperationHint())); | 1265 BuildBinaryOp(javascript()->ShiftRight( |
| 1266 GetBinaryOperationHint(kBinaryOperationHintIndex))); |
| 1268 } | 1267 } |
| 1269 | 1268 |
| 1270 void BytecodeGraphBuilder::VisitShiftRightLogical() { | 1269 void BytecodeGraphBuilder::VisitShiftRightLogical() { |
| 1271 BuildBinaryOp(javascript()->ShiftRightLogical(GetBinaryOperationHint())); | 1270 BuildBinaryOp(javascript()->ShiftRightLogical( |
| 1271 GetBinaryOperationHint(kBinaryOperationHintIndex))); |
| 1272 } | 1272 } |
| 1273 | 1273 |
| 1274 void BytecodeGraphBuilder::BuildBinaryOpWithImmediate(const Operator* js_op) { | 1274 void BytecodeGraphBuilder::BuildBinaryOpWithImmediate(const Operator* js_op) { |
| 1275 FrameStateBeforeAndAfter states(this); | 1275 FrameStateBeforeAndAfter states(this); |
| 1276 Node* left = | 1276 Node* left = |
| 1277 environment()->LookupRegister(bytecode_iterator().GetRegisterOperand(1)); | 1277 environment()->LookupRegister(bytecode_iterator().GetRegisterOperand(1)); |
| 1278 Node* right = jsgraph()->Constant(bytecode_iterator().GetImmediateOperand(0)); | 1278 Node* right = jsgraph()->Constant(bytecode_iterator().GetImmediateOperand(0)); |
| 1279 Node* node = NewNode(js_op, left, right); | 1279 Node* node = NewNode(js_op, left, right); |
| 1280 environment()->BindAccumulator(node, &states); | 1280 environment()->BindAccumulator(node, &states); |
| 1281 } | 1281 } |
| 1282 | 1282 |
| 1283 void BytecodeGraphBuilder::VisitAddSmi() { | 1283 void BytecodeGraphBuilder::VisitAddSmi() { |
| 1284 BinaryOperationHint hint = BinaryOperationHint::kAny; | 1284 BuildBinaryOpWithImmediate( |
| 1285 BuildBinaryOpWithImmediate(javascript()->Add(hint)); | 1285 javascript()->Add(GetBinaryOperationHint(kBinaryOperationSmiHintIndex))); |
| 1286 } | 1286 } |
| 1287 | 1287 |
| 1288 void BytecodeGraphBuilder::VisitSubSmi() { | 1288 void BytecodeGraphBuilder::VisitSubSmi() { |
| 1289 BinaryOperationHint hint = BinaryOperationHint::kAny; | 1289 BuildBinaryOpWithImmediate(javascript()->Subtract( |
| 1290 BuildBinaryOpWithImmediate(javascript()->Subtract(hint)); | 1290 GetBinaryOperationHint(kBinaryOperationSmiHintIndex))); |
| 1291 } | 1291 } |
| 1292 | 1292 |
| 1293 void BytecodeGraphBuilder::VisitBitwiseOrSmi() { | 1293 void BytecodeGraphBuilder::VisitBitwiseOrSmi() { |
| 1294 BinaryOperationHint hint = BinaryOperationHint::kAny; | 1294 BuildBinaryOpWithImmediate(javascript()->BitwiseOr( |
| 1295 BuildBinaryOpWithImmediate(javascript()->BitwiseOr(hint)); | 1295 GetBinaryOperationHint(kBinaryOperationSmiHintIndex))); |
| 1296 } | 1296 } |
| 1297 | 1297 |
| 1298 void BytecodeGraphBuilder::VisitBitwiseAndSmi() { | 1298 void BytecodeGraphBuilder::VisitBitwiseAndSmi() { |
| 1299 BinaryOperationHint hint = BinaryOperationHint::kAny; | 1299 BuildBinaryOpWithImmediate(javascript()->BitwiseAnd( |
| 1300 BuildBinaryOpWithImmediate(javascript()->BitwiseAnd(hint)); | 1300 GetBinaryOperationHint(kBinaryOperationSmiHintIndex))); |
| 1301 } | 1301 } |
| 1302 | 1302 |
| 1303 void BytecodeGraphBuilder::VisitShiftLeftSmi() { | 1303 void BytecodeGraphBuilder::VisitShiftLeftSmi() { |
| 1304 BinaryOperationHint hint = BinaryOperationHint::kAny; | 1304 BuildBinaryOpWithImmediate(javascript()->ShiftLeft( |
| 1305 BuildBinaryOpWithImmediate(javascript()->ShiftLeft(hint)); | 1305 GetBinaryOperationHint(kBinaryOperationSmiHintIndex))); |
| 1306 } | 1306 } |
| 1307 | 1307 |
| 1308 void BytecodeGraphBuilder::VisitShiftRightSmi() { | 1308 void BytecodeGraphBuilder::VisitShiftRightSmi() { |
| 1309 BinaryOperationHint hint = BinaryOperationHint::kAny; | 1309 BuildBinaryOpWithImmediate(javascript()->ShiftRight( |
| 1310 BuildBinaryOpWithImmediate(javascript()->ShiftRight(hint)); | 1310 GetBinaryOperationHint(kBinaryOperationSmiHintIndex))); |
| 1311 } | 1311 } |
| 1312 | 1312 |
| 1313 void BytecodeGraphBuilder::VisitInc() { | 1313 void BytecodeGraphBuilder::VisitInc() { |
| 1314 FrameStateBeforeAndAfter states(this); | 1314 FrameStateBeforeAndAfter states(this); |
| 1315 // Note: Use subtract -1 here instead of add 1 to ensure we always convert to | 1315 // Note: Use subtract -1 here instead of add 1 to ensure we always convert to |
| 1316 // a number, not a string. | 1316 // a number, not a string. |
| 1317 const Operator* js_op = | 1317 const Operator* js_op = |
| 1318 javascript()->Subtract(GetBinaryOperationHintForIncDec()); | 1318 javascript()->Subtract(GetBinaryOperationHint(kCountOperationHintIndex)); |
| 1319 Node* node = NewNode(js_op, environment()->LookupAccumulator(), | 1319 Node* node = NewNode(js_op, environment()->LookupAccumulator(), |
| 1320 jsgraph()->Constant(-1)); | 1320 jsgraph()->Constant(-1)); |
| 1321 environment()->BindAccumulator(node, &states); | 1321 environment()->BindAccumulator(node, &states); |
| 1322 } | 1322 } |
| 1323 | 1323 |
| 1324 void BytecodeGraphBuilder::VisitDec() { | 1324 void BytecodeGraphBuilder::VisitDec() { |
| 1325 FrameStateBeforeAndAfter states(this); | 1325 FrameStateBeforeAndAfter states(this); |
| 1326 const Operator* js_op = | 1326 const Operator* js_op = |
| 1327 javascript()->Subtract(GetBinaryOperationHintForIncDec()); | 1327 javascript()->Subtract(GetBinaryOperationHint(kCountOperationHintIndex)); |
| 1328 Node* node = NewNode(js_op, environment()->LookupAccumulator(), | 1328 Node* node = NewNode(js_op, environment()->LookupAccumulator(), |
| 1329 jsgraph()->OneConstant()); | 1329 jsgraph()->OneConstant()); |
| 1330 environment()->BindAccumulator(node, &states); | 1330 environment()->BindAccumulator(node, &states); |
| 1331 } | 1331 } |
| 1332 | 1332 |
| 1333 void BytecodeGraphBuilder::VisitLogicalNot() { | 1333 void BytecodeGraphBuilder::VisitLogicalNot() { |
| 1334 Node* value = environment()->LookupAccumulator(); | 1334 Node* value = environment()->LookupAccumulator(); |
| 1335 Node* node = NewNode(common()->Select(MachineRepresentation::kTagged), value, | 1335 Node* node = NewNode(common()->Select(MachineRepresentation::kTagged), value, |
| 1336 jsgraph()->FalseConstant(), jsgraph()->TrueConstant()); | 1336 jsgraph()->FalseConstant(), jsgraph()->TrueConstant()); |
| 1337 environment()->BindAccumulator(node); | 1337 environment()->BindAccumulator(node); |
| (...skipping 592 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1930 // Phi does not exist yet, introduce one. | 1930 // Phi does not exist yet, introduce one. |
| 1931 value = NewPhi(inputs, value, control); | 1931 value = NewPhi(inputs, value, control); |
| 1932 value->ReplaceInput(inputs - 1, other); | 1932 value->ReplaceInput(inputs - 1, other); |
| 1933 } | 1933 } |
| 1934 return value; | 1934 return value; |
| 1935 } | 1935 } |
| 1936 | 1936 |
| 1937 } // namespace compiler | 1937 } // namespace compiler |
| 1938 } // namespace internal | 1938 } // namespace internal |
| 1939 } // namespace v8 | 1939 } // namespace v8 |
| OLD | NEW |