Chromium Code Reviews| 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(int index) { |
|
rmcilroy
2016/08/23 10:28:53
nit - operand_index
epertoso
2016/08/23 13:24:28
Done.
| |
| 1207 FeedbackVectorSlot slot = | 1207 FeedbackVectorSlot slot = |
| 1208 feedback_vector()->ToSlot(bytecode_iterator().GetIndexOperand(1)); | 1208 feedback_vector()->ToSlot(bytecode_iterator().GetIndexOperand(index)); |
| 1209 DCHECK_EQ(FeedbackVectorSlotKind::GENERAL, feedback_vector()->GetKind(slot)); | 1209 DCHECK_EQ(FeedbackVectorSlotKind::GENERAL, feedback_vector()->GetKind(slot)); |
| 1210 Object* feedback = feedback_vector()->Get(slot); | 1210 Object* feedback = feedback_vector()->Get(slot); |
| 1211 BinaryOperationHint hint = BinaryOperationHint::kAny; | 1211 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()) { | 1212 if (feedback->IsSmi()) { |
| 1225 hint = BinaryOperationHintFromFeedback((Smi::cast(feedback))->value()); | 1213 hint = BinaryOperationHintFromFeedback((Smi::cast(feedback))->value()); |
| 1226 } | 1214 } |
| 1227 return hint; | 1215 return hint; |
| 1228 } | 1216 } |
| 1229 | 1217 |
| 1230 void BytecodeGraphBuilder::VisitAdd() { | 1218 void BytecodeGraphBuilder::VisitAdd() { |
| 1231 BuildBinaryOp(javascript()->Add(GetBinaryOperationHint())); | 1219 BuildBinaryOp( |
| 1220 javascript()->Add(GetBinaryOperationHint(kBinaryOperationHintIndex))); | |
| 1232 } | 1221 } |
| 1233 | 1222 |
| 1234 void BytecodeGraphBuilder::VisitSub() { | 1223 void BytecodeGraphBuilder::VisitSub() { |
| 1235 BuildBinaryOp(javascript()->Subtract(GetBinaryOperationHint())); | 1224 BuildBinaryOp(javascript()->Subtract( |
| 1225 GetBinaryOperationHint(kBinaryOperationHintIndex))); | |
| 1236 } | 1226 } |
| 1237 | 1227 |
| 1238 void BytecodeGraphBuilder::VisitMul() { | 1228 void BytecodeGraphBuilder::VisitMul() { |
| 1239 BuildBinaryOp(javascript()->Multiply(GetBinaryOperationHint())); | 1229 BuildBinaryOp(javascript()->Multiply( |
| 1230 GetBinaryOperationHint(kBinaryOperationHintIndex))); | |
| 1240 } | 1231 } |
| 1241 | 1232 |
| 1242 void BytecodeGraphBuilder::VisitDiv() { | 1233 void BytecodeGraphBuilder::VisitDiv() { |
| 1243 BuildBinaryOp(javascript()->Divide(GetBinaryOperationHint())); | 1234 BuildBinaryOp( |
| 1235 javascript()->Divide(GetBinaryOperationHint(kBinaryOperationHintIndex))); | |
| 1244 } | 1236 } |
| 1245 | 1237 |
| 1246 void BytecodeGraphBuilder::VisitMod() { | 1238 void BytecodeGraphBuilder::VisitMod() { |
| 1247 BuildBinaryOp(javascript()->Modulus(GetBinaryOperationHint())); | 1239 BuildBinaryOp( |
| 1240 javascript()->Modulus(GetBinaryOperationHint(kBinaryOperationHintIndex))); | |
| 1248 } | 1241 } |
| 1249 | 1242 |
| 1250 void BytecodeGraphBuilder::VisitBitwiseOr() { | 1243 void BytecodeGraphBuilder::VisitBitwiseOr() { |
| 1251 BuildBinaryOp(javascript()->BitwiseOr(GetBinaryOperationHint())); | 1244 BuildBinaryOp(javascript()->BitwiseOr( |
| 1245 GetBinaryOperationHint(kBinaryOperationHintIndex))); | |
| 1252 } | 1246 } |
| 1253 | 1247 |
| 1254 void BytecodeGraphBuilder::VisitBitwiseXor() { | 1248 void BytecodeGraphBuilder::VisitBitwiseXor() { |
| 1255 BuildBinaryOp(javascript()->BitwiseXor(GetBinaryOperationHint())); | 1249 BuildBinaryOp(javascript()->BitwiseXor( |
| 1250 GetBinaryOperationHint(kBinaryOperationHintIndex))); | |
| 1256 } | 1251 } |
| 1257 | 1252 |
| 1258 void BytecodeGraphBuilder::VisitBitwiseAnd() { | 1253 void BytecodeGraphBuilder::VisitBitwiseAnd() { |
| 1259 BuildBinaryOp(javascript()->BitwiseAnd(GetBinaryOperationHint())); | 1254 BuildBinaryOp(javascript()->BitwiseAnd( |
| 1255 GetBinaryOperationHint(kBinaryOperationHintIndex))); | |
| 1260 } | 1256 } |
| 1261 | 1257 |
| 1262 void BytecodeGraphBuilder::VisitShiftLeft() { | 1258 void BytecodeGraphBuilder::VisitShiftLeft() { |
| 1263 BuildBinaryOp(javascript()->ShiftLeft(GetBinaryOperationHint())); | 1259 BuildBinaryOp(javascript()->ShiftLeft( |
| 1260 GetBinaryOperationHint(kBinaryOperationHintIndex))); | |
| 1264 } | 1261 } |
| 1265 | 1262 |
| 1266 void BytecodeGraphBuilder::VisitShiftRight() { | 1263 void BytecodeGraphBuilder::VisitShiftRight() { |
| 1267 BuildBinaryOp(javascript()->ShiftRight(GetBinaryOperationHint())); | 1264 BuildBinaryOp(javascript()->ShiftRight( |
| 1265 GetBinaryOperationHint(kBinaryOperationHintIndex))); | |
| 1268 } | 1266 } |
| 1269 | 1267 |
| 1270 void BytecodeGraphBuilder::VisitShiftRightLogical() { | 1268 void BytecodeGraphBuilder::VisitShiftRightLogical() { |
| 1271 BuildBinaryOp(javascript()->ShiftRightLogical(GetBinaryOperationHint())); | 1269 BuildBinaryOp(javascript()->ShiftRightLogical( |
| 1270 GetBinaryOperationHint(kBinaryOperationHintIndex))); | |
| 1272 } | 1271 } |
| 1273 | 1272 |
| 1274 void BytecodeGraphBuilder::BuildBinaryOpWithImmediate(const Operator* js_op) { | 1273 void BytecodeGraphBuilder::BuildBinaryOpWithImmediate(const Operator* js_op) { |
| 1275 FrameStateBeforeAndAfter states(this); | 1274 FrameStateBeforeAndAfter states(this); |
| 1276 Node* left = | 1275 Node* left = |
| 1277 environment()->LookupRegister(bytecode_iterator().GetRegisterOperand(1)); | 1276 environment()->LookupRegister(bytecode_iterator().GetRegisterOperand(1)); |
| 1278 Node* right = jsgraph()->Constant(bytecode_iterator().GetImmediateOperand(0)); | 1277 Node* right = jsgraph()->Constant(bytecode_iterator().GetImmediateOperand(0)); |
| 1279 Node* node = NewNode(js_op, left, right); | 1278 Node* node = NewNode(js_op, left, right); |
| 1280 environment()->BindAccumulator(node, &states); | 1279 environment()->BindAccumulator(node, &states); |
| 1281 } | 1280 } |
| 1282 | 1281 |
| 1283 void BytecodeGraphBuilder::VisitAddSmi() { | 1282 void BytecodeGraphBuilder::VisitAddSmi() { |
| 1284 BinaryOperationHint hint = BinaryOperationHint::kAny; | 1283 BuildBinaryOpWithImmediate( |
| 1285 BuildBinaryOpWithImmediate(javascript()->Add(hint)); | 1284 javascript()->Add(GetBinaryOperationHint(kBinaryOperationSmiHintIndex))); |
| 1286 } | 1285 } |
| 1287 | 1286 |
| 1288 void BytecodeGraphBuilder::VisitSubSmi() { | 1287 void BytecodeGraphBuilder::VisitSubSmi() { |
| 1289 BinaryOperationHint hint = BinaryOperationHint::kAny; | 1288 BuildBinaryOpWithImmediate(javascript()->Subtract( |
| 1290 BuildBinaryOpWithImmediate(javascript()->Subtract(hint)); | 1289 GetBinaryOperationHint(kBinaryOperationSmiHintIndex))); |
| 1291 } | 1290 } |
| 1292 | 1291 |
| 1293 void BytecodeGraphBuilder::VisitBitwiseOrSmi() { | 1292 void BytecodeGraphBuilder::VisitBitwiseOrSmi() { |
| 1294 BinaryOperationHint hint = BinaryOperationHint::kAny; | 1293 BuildBinaryOpWithImmediate(javascript()->BitwiseOr( |
| 1295 BuildBinaryOpWithImmediate(javascript()->BitwiseOr(hint)); | 1294 GetBinaryOperationHint(kBinaryOperationSmiHintIndex))); |
| 1296 } | 1295 } |
| 1297 | 1296 |
| 1298 void BytecodeGraphBuilder::VisitBitwiseAndSmi() { | 1297 void BytecodeGraphBuilder::VisitBitwiseAndSmi() { |
| 1299 BinaryOperationHint hint = BinaryOperationHint::kAny; | 1298 BuildBinaryOpWithImmediate(javascript()->BitwiseAnd( |
| 1300 BuildBinaryOpWithImmediate(javascript()->BitwiseAnd(hint)); | 1299 GetBinaryOperationHint(kBinaryOperationSmiHintIndex))); |
| 1301 } | 1300 } |
| 1302 | 1301 |
| 1303 void BytecodeGraphBuilder::VisitShiftLeftSmi() { | 1302 void BytecodeGraphBuilder::VisitShiftLeftSmi() { |
| 1304 BinaryOperationHint hint = BinaryOperationHint::kAny; | 1303 BuildBinaryOpWithImmediate(javascript()->ShiftLeft( |
| 1305 BuildBinaryOpWithImmediate(javascript()->ShiftLeft(hint)); | 1304 GetBinaryOperationHint(kBinaryOperationSmiHintIndex))); |
| 1306 } | 1305 } |
| 1307 | 1306 |
| 1308 void BytecodeGraphBuilder::VisitShiftRightSmi() { | 1307 void BytecodeGraphBuilder::VisitShiftRightSmi() { |
| 1309 BinaryOperationHint hint = BinaryOperationHint::kAny; | 1308 BuildBinaryOpWithImmediate(javascript()->ShiftRight( |
| 1310 BuildBinaryOpWithImmediate(javascript()->ShiftRight(hint)); | 1309 GetBinaryOperationHint(kBinaryOperationSmiHintIndex))); |
| 1311 } | 1310 } |
| 1312 | 1311 |
| 1313 void BytecodeGraphBuilder::VisitInc() { | 1312 void BytecodeGraphBuilder::VisitInc() { |
| 1314 FrameStateBeforeAndAfter states(this); | 1313 FrameStateBeforeAndAfter states(this); |
| 1315 // Note: Use subtract -1 here instead of add 1 to ensure we always convert to | 1314 // Note: Use subtract -1 here instead of add 1 to ensure we always convert to |
| 1316 // a number, not a string. | 1315 // a number, not a string. |
| 1317 const Operator* js_op = | 1316 const Operator* js_op = |
| 1318 javascript()->Subtract(GetBinaryOperationHintForIncDec()); | 1317 javascript()->Subtract(GetBinaryOperationHint(kCountOperationHintIndex)); |
| 1319 Node* node = NewNode(js_op, environment()->LookupAccumulator(), | 1318 Node* node = NewNode(js_op, environment()->LookupAccumulator(), |
| 1320 jsgraph()->Constant(-1)); | 1319 jsgraph()->Constant(-1)); |
| 1321 environment()->BindAccumulator(node, &states); | 1320 environment()->BindAccumulator(node, &states); |
| 1322 } | 1321 } |
| 1323 | 1322 |
| 1324 void BytecodeGraphBuilder::VisitDec() { | 1323 void BytecodeGraphBuilder::VisitDec() { |
| 1325 FrameStateBeforeAndAfter states(this); | 1324 FrameStateBeforeAndAfter states(this); |
| 1326 const Operator* js_op = | 1325 const Operator* js_op = |
| 1327 javascript()->Subtract(GetBinaryOperationHintForIncDec()); | 1326 javascript()->Subtract(GetBinaryOperationHint(kCountOperationHintIndex)); |
| 1328 Node* node = NewNode(js_op, environment()->LookupAccumulator(), | 1327 Node* node = NewNode(js_op, environment()->LookupAccumulator(), |
| 1329 jsgraph()->OneConstant()); | 1328 jsgraph()->OneConstant()); |
| 1330 environment()->BindAccumulator(node, &states); | 1329 environment()->BindAccumulator(node, &states); |
| 1331 } | 1330 } |
| 1332 | 1331 |
| 1333 void BytecodeGraphBuilder::VisitLogicalNot() { | 1332 void BytecodeGraphBuilder::VisitLogicalNot() { |
| 1334 Node* value = environment()->LookupAccumulator(); | 1333 Node* value = environment()->LookupAccumulator(); |
| 1335 Node* node = NewNode(common()->Select(MachineRepresentation::kTagged), value, | 1334 Node* node = NewNode(common()->Select(MachineRepresentation::kTagged), value, |
| 1336 jsgraph()->FalseConstant(), jsgraph()->TrueConstant()); | 1335 jsgraph()->FalseConstant(), jsgraph()->TrueConstant()); |
| 1337 environment()->BindAccumulator(node); | 1336 environment()->BindAccumulator(node); |
| (...skipping 592 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1930 // Phi does not exist yet, introduce one. | 1929 // Phi does not exist yet, introduce one. |
| 1931 value = NewPhi(inputs, value, control); | 1930 value = NewPhi(inputs, value, control); |
| 1932 value->ReplaceInput(inputs - 1, other); | 1931 value->ReplaceInput(inputs - 1, other); |
| 1933 } | 1932 } |
| 1934 return value; | 1933 return value; |
| 1935 } | 1934 } |
| 1936 | 1935 |
| 1937 } // namespace compiler | 1936 } // namespace compiler |
| 1938 } // namespace internal | 1937 } // namespace internal |
| 1939 } // namespace v8 | 1938 } // namespace v8 |
| OLD | NEW |