Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(252)

Side by Side Diff: src/arm/fast-codegen-arm.cc

Issue 550010: Cleanup the handling of control flow in the toplevel code generator.... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 10 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | src/fast-codegen.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2009 the V8 project authors. All rights reserved. 1 // Copyright 2009 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 1247 matching lines...) Expand 10 before | Expand all | Expand 10 after
1258 __ jmp(false_label_); 1258 __ jmp(false_label_);
1259 break; 1259 break;
1260 } 1260 }
1261 break; 1261 break;
1262 } 1262 }
1263 1263
1264 case Token::NOT: { 1264 case Token::NOT: {
1265 Comment cmnt(masm_, "[ UnaryOperation (NOT)"); 1265 Comment cmnt(masm_, "[ UnaryOperation (NOT)");
1266 ASSERT_EQ(Expression::kTest, expr->expression()->context()); 1266 ASSERT_EQ(Expression::kTest, expr->expression()->context());
1267 1267
1268 Label push_true; 1268 Label push_true, push_false, done;
1269 Label push_false;
1270 Label done;
1271 Label* saved_true = true_label_;
1272 Label* saved_false = false_label_;
1273 switch (expr->context()) { 1269 switch (expr->context()) {
1274 case Expression::kUninitialized: 1270 case Expression::kUninitialized:
1275 UNREACHABLE(); 1271 UNREACHABLE();
1276 break; 1272 break;
1277 1273
1274 case Expression::kEffect:
1275 VisitForControl(expr->expression(), &done, &done);
1276 __ bind(&done);
1277 break;
1278
1278 case Expression::kValue: 1279 case Expression::kValue:
1279 true_label_ = &push_false; 1280 VisitForControl(expr->expression(), &push_false, &push_true);
1280 false_label_ = &push_true;
1281 Visit(expr->expression());
1282 __ bind(&push_true); 1281 __ bind(&push_true);
1283 __ LoadRoot(ip, Heap::kTrueValueRootIndex); 1282 __ LoadRoot(ip, Heap::kTrueValueRootIndex);
1284 __ push(ip); 1283 __ push(ip);
1285 __ jmp(&done); 1284 __ jmp(&done);
1286 __ bind(&push_false); 1285 __ bind(&push_false);
1287 __ LoadRoot(ip, Heap::kFalseValueRootIndex); 1286 __ LoadRoot(ip, Heap::kFalseValueRootIndex);
1288 __ push(ip); 1287 __ push(ip);
1289 __ bind(&done); 1288 __ bind(&done);
1290 break; 1289 break;
1291 1290
1292 case Expression::kEffect:
1293 true_label_ = &done;
1294 false_label_ = &done;
1295 Visit(expr->expression());
1296 __ bind(&done);
1297 break;
1298
1299 case Expression::kTest: 1291 case Expression::kTest:
1300 true_label_ = saved_false; 1292 VisitForControl(expr->expression(), false_label_, true_label_);
1301 false_label_ = saved_true;
1302 Visit(expr->expression());
1303 break; 1293 break;
1304 1294
1305 case Expression::kValueTest: 1295 case Expression::kValueTest:
1306 true_label_ = saved_false; 1296 VisitForControl(expr->expression(), false_label_, &push_true);
1307 false_label_ = &push_true;
1308 Visit(expr->expression());
1309 __ bind(&push_true); 1297 __ bind(&push_true);
1310 __ LoadRoot(ip, Heap::kTrueValueRootIndex); 1298 __ LoadRoot(ip, Heap::kTrueValueRootIndex);
1311 __ push(ip); 1299 __ push(ip);
1312 __ jmp(saved_true); 1300 __ jmp(true_label_);
1313 break; 1301 break;
1314 1302
1315 case Expression::kTestValue: 1303 case Expression::kTestValue:
1316 true_label_ = &push_false; 1304 VisitForControl(expr->expression(), &push_false, true_label_);
1317 false_label_ = saved_true;
1318 Visit(expr->expression());
1319 __ bind(&push_false); 1305 __ bind(&push_false);
1320 __ LoadRoot(ip, Heap::kFalseValueRootIndex); 1306 __ LoadRoot(ip, Heap::kFalseValueRootIndex);
1321 __ push(ip); 1307 __ push(ip);
1322 __ jmp(saved_false); 1308 __ jmp(false_label_);
1323 break; 1309 break;
1324 } 1310 }
1325 true_label_ = saved_true;
1326 false_label_ = saved_false;
1327 break; 1311 break;
1328 } 1312 }
1329 1313
1330 case Token::TYPEOF: { 1314 case Token::TYPEOF: {
1331 Comment cmnt(masm_, "[ UnaryOperation (TYPEOF)"); 1315 Comment cmnt(masm_, "[ UnaryOperation (TYPEOF)");
1332 ASSERT_EQ(Expression::kValue, expr->expression()->context()); 1316 ASSERT_EQ(Expression::kValue, expr->expression()->context());
1333 1317
1334 VariableProxy* proxy = expr->expression()->AsVariableProxy(); 1318 VariableProxy* proxy = expr->expression()->AsVariableProxy();
1335 if (proxy != NULL && 1319 if (proxy != NULL &&
1336 !proxy->var()->is_this() && 1320 !proxy->var()->is_this() &&
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
1542 } 1526 }
1543 1527
1544 1528
1545 void FastCodeGenerator::VisitCompareOperation(CompareOperation* expr) { 1529 void FastCodeGenerator::VisitCompareOperation(CompareOperation* expr) {
1546 Comment cmnt(masm_, "[ CompareOperation"); 1530 Comment cmnt(masm_, "[ CompareOperation");
1547 ASSERT_EQ(Expression::kValue, expr->left()->context()); 1531 ASSERT_EQ(Expression::kValue, expr->left()->context());
1548 ASSERT_EQ(Expression::kValue, expr->right()->context()); 1532 ASSERT_EQ(Expression::kValue, expr->right()->context());
1549 Visit(expr->left()); 1533 Visit(expr->left());
1550 Visit(expr->right()); 1534 Visit(expr->right());
1551 1535
1552 // Convert current context to test context: Pre-test code. 1536 // Always perform the comparison for its control flow. Pack the result
1553 Label push_true; 1537 // into the expression's context after the comparison is performed.
1554 Label push_false; 1538 Label push_true, push_false, done;
1555 Label done; 1539 // Initially assume we are in a test context.
1556 Label* saved_true = true_label_; 1540 Label* if_true = true_label_;
1557 Label* saved_false = false_label_; 1541 Label* if_false = false_label_;
1558 switch (expr->context()) { 1542 switch (expr->context()) {
1559 case Expression::kUninitialized: 1543 case Expression::kUninitialized:
1560 UNREACHABLE(); 1544 UNREACHABLE();
1561 break; 1545 break;
1562 1546 case Expression::kEffect:
1547 if_true = &done;
1548 if_false = &done;
1549 break;
1563 case Expression::kValue: 1550 case Expression::kValue:
1564 true_label_ = &push_true; 1551 if_true = &push_true;
1565 false_label_ = &push_false; 1552 if_false = &push_false;
1566 break; 1553 break;
1567
1568 case Expression::kEffect:
1569 true_label_ = &done;
1570 false_label_ = &done;
1571 break;
1572
1573 case Expression::kTest: 1554 case Expression::kTest:
1574 break; 1555 break;
1575
1576 case Expression::kValueTest: 1556 case Expression::kValueTest:
1577 true_label_ = &push_true; 1557 if_true = &push_true;
1578 break; 1558 break;
1579
1580 case Expression::kTestValue: 1559 case Expression::kTestValue:
1581 false_label_ = &push_false; 1560 if_false = &push_false;
1582 break; 1561 break;
1583 } 1562 }
1584 // Convert current context to test context: End pre-test code.
1585 1563
1586 switch (expr->op()) { 1564 switch (expr->op()) {
1587 case Token::IN: { 1565 case Token::IN: {
1588 __ InvokeBuiltin(Builtins::IN, CALL_JS); 1566 __ InvokeBuiltin(Builtins::IN, CALL_JS);
1589 __ LoadRoot(ip, Heap::kTrueValueRootIndex); 1567 __ LoadRoot(ip, Heap::kTrueValueRootIndex);
1590 __ cmp(r0, ip); 1568 __ cmp(r0, ip);
1591 __ b(eq, true_label_); 1569 __ b(eq, if_true);
1592 __ jmp(false_label_); 1570 __ jmp(if_false);
1593 break; 1571 break;
1594 } 1572 }
1595 1573
1596 case Token::INSTANCEOF: { 1574 case Token::INSTANCEOF: {
1597 InstanceofStub stub; 1575 InstanceofStub stub;
1598 __ CallStub(&stub); 1576 __ CallStub(&stub);
1599 __ tst(r0, r0); 1577 __ tst(r0, r0);
1600 __ b(eq, true_label_); // The stub returns 0 for true. 1578 __ b(eq, if_true); // The stub returns 0 for true.
1601 __ jmp(false_label_); 1579 __ jmp(if_false);
1602 break; 1580 break;
1603 } 1581 }
1604 1582
1605 default: { 1583 default: {
1606 Condition cc = eq; 1584 Condition cc = eq;
1607 bool strict = false; 1585 bool strict = false;
1608 switch (expr->op()) { 1586 switch (expr->op()) {
1609 case Token::EQ_STRICT: 1587 case Token::EQ_STRICT:
1610 strict = true; 1588 strict = true;
1611 // Fall through 1589 // Fall through
(...skipping 30 matching lines...) Expand all
1642 UNREACHABLE(); 1620 UNREACHABLE();
1643 } 1621 }
1644 1622
1645 // The comparison stub expects the smi vs. smi case to be handled 1623 // The comparison stub expects the smi vs. smi case to be handled
1646 // before it is called. 1624 // before it is called.
1647 Label slow_case; 1625 Label slow_case;
1648 __ orr(r2, r0, Operand(r1)); 1626 __ orr(r2, r0, Operand(r1));
1649 __ tst(r2, Operand(kSmiTagMask)); 1627 __ tst(r2, Operand(kSmiTagMask));
1650 __ b(ne, &slow_case); 1628 __ b(ne, &slow_case);
1651 __ cmp(r1, r0); 1629 __ cmp(r1, r0);
1652 __ b(cc, true_label_); 1630 __ b(cc, if_true);
1653 __ jmp(false_label_); 1631 __ jmp(if_false);
1654 1632
1655 __ bind(&slow_case); 1633 __ bind(&slow_case);
1656 CompareStub stub(cc, strict); 1634 CompareStub stub(cc, strict);
1657 __ CallStub(&stub); 1635 __ CallStub(&stub);
1658 __ tst(r0, r0); 1636 __ tst(r0, r0);
1659 __ b(cc, true_label_); 1637 __ b(cc, if_true);
1660 __ jmp(false_label_); 1638 __ jmp(if_false);
1661 } 1639 }
1662 } 1640 }
1663 1641
1664 // Convert current context to test context: Post-test code. 1642 // Convert the result of the comparison into one expected for this
1643 // expression's context.
1665 switch (expr->context()) { 1644 switch (expr->context()) {
1666 case Expression::kUninitialized: 1645 case Expression::kUninitialized:
1667 UNREACHABLE(); 1646 UNREACHABLE();
1668 break; 1647 break;
1669 1648
1649 case Expression::kEffect:
1650 __ bind(&done);
1651 break;
1652
1670 case Expression::kValue: 1653 case Expression::kValue:
1671 __ bind(&push_true); 1654 __ bind(&push_true);
1672 __ LoadRoot(ip, Heap::kTrueValueRootIndex); 1655 __ LoadRoot(ip, Heap::kTrueValueRootIndex);
1673 __ push(ip); 1656 __ push(ip);
1674 __ jmp(&done); 1657 __ jmp(&done);
1675 __ bind(&push_false); 1658 __ bind(&push_false);
1676 __ LoadRoot(ip, Heap::kFalseValueRootIndex); 1659 __ LoadRoot(ip, Heap::kFalseValueRootIndex);
1677 __ push(ip); 1660 __ push(ip);
1678 __ bind(&done); 1661 __ bind(&done);
1679 break; 1662 break;
1680 1663
1681 case Expression::kEffect:
1682 __ bind(&done);
1683 break;
1684
1685 case Expression::kTest: 1664 case Expression::kTest:
1686 break; 1665 break;
1687 1666
1688 case Expression::kValueTest: 1667 case Expression::kValueTest:
1689 __ bind(&push_true); 1668 __ bind(&push_true);
1690 __ LoadRoot(ip, Heap::kTrueValueRootIndex); 1669 __ LoadRoot(ip, Heap::kTrueValueRootIndex);
1691 __ push(ip); 1670 __ push(ip);
1692 __ jmp(saved_true); 1671 __ jmp(true_label_);
1693 break; 1672 break;
1694 1673
1695 case Expression::kTestValue: 1674 case Expression::kTestValue:
1696 __ bind(&push_false); 1675 __ bind(&push_false);
1697 __ LoadRoot(ip, Heap::kFalseValueRootIndex); 1676 __ LoadRoot(ip, Heap::kFalseValueRootIndex);
1698 __ push(ip); 1677 __ push(ip);
1699 __ jmp(saved_false); 1678 __ jmp(false_label_);
1700 break; 1679 break;
1701 } 1680 }
1702 true_label_ = saved_true;
1703 false_label_ = saved_false;
1704 // Convert current context to test context: End post-test code.
1705 } 1681 }
1706 1682
1707 1683
1708 void FastCodeGenerator::VisitThisFunction(ThisFunction* expr) { 1684 void FastCodeGenerator::VisitThisFunction(ThisFunction* expr) {
1709 __ ldr(r0, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset)); 1685 __ ldr(r0, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset));
1710 Apply(expr->context(), r0); 1686 Apply(expr->context(), r0);
1711 } 1687 }
1712 1688
1713 1689
1714 Register FastCodeGenerator::result_register() { return r0; } 1690 Register FastCodeGenerator::result_register() { return r0; }
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1752 __ pop(result_register()); 1728 __ pop(result_register());
1753 ASSERT_EQ(1, kSmiTagSize + kSmiShiftSize); 1729 ASSERT_EQ(1, kSmiTagSize + kSmiShiftSize);
1754 __ mov(r1, Operand(r1, ASR, 1)); // Un-smi-tag value. 1730 __ mov(r1, Operand(r1, ASR, 1)); // Un-smi-tag value.
1755 __ add(pc, r1, Operand(masm_->CodeObject())); 1731 __ add(pc, r1, Operand(masm_->CodeObject()));
1756 } 1732 }
1757 1733
1758 1734
1759 #undef __ 1735 #undef __
1760 1736
1761 } } // namespace v8::internal 1737 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « no previous file | src/fast-codegen.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698