Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(353)

Delta Between Two Patch Sets: src/cmd/6g/reg.c

Issue 6922048: code review 6922048: cmd/{5,6,8}g: reduce size of Prog and Addr (Closed)
Left Patch Set: Created 12 years, 3 months ago
Right Patch Set: diff -r 8ea9d438b64e https://go.googlecode.com/hg/ Created 12 years, 3 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Right: Side by side diff | Download
« no previous file with change/comment | « src/cmd/6g/peep.c ('k') | src/cmd/8g/gg.h » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
(no file at all)
1 // Derived from Inferno utils/6c/reg.c 1 // Derived from Inferno utils/6c/reg.c
2 // http://code.google.com/p/inferno-os/source/browse/utils/6c/reg.c 2 // http://code.google.com/p/inferno-os/source/browse/utils/6c/reg.c
3 // 3 //
4 // Copyright © 1994-1999 Lucent Technologies Inc. All rights reserved. 4 // Copyright © 1994-1999 Lucent Technologies Inc. All rights reserved.
5 // Portions Copyright © 1995-1997 C H Forsyth (forsyth@terzarima.net) 5 // Portions Copyright © 1995-1997 C H Forsyth (forsyth@terzarima.net)
6 // Portions Copyright © 1997-1999 Vita Nuova Limited 6 // Portions Copyright © 1997-1999 Vita Nuova Limited
7 // Portions Copyright © 2000-2007 Vita Nuova Holdings Limited (www.vitanuov a.com) 7 // Portions Copyright © 2000-2007 Vita Nuova Holdings Limited (www.vitanuov a.com)
8 // Portions Copyright © 2004,2006 Bruce Ellis 8 // Portions Copyright © 2004,2006 Bruce Ellis
9 // Portions Copyright © 2005-2007 C H Forsyth (forsyth@terzarima.net) 9 // Portions Copyright © 2005-2007 C H Forsyth (forsyth@terzarima.net)
10 // Revisions Copyright © 2000-2007 Lucent Technologies Inc. and others 10 // Revisions Copyright © 2000-2007 Lucent Technologies Inc. and others
(...skipping 592 matching lines...) Expand 10 before | Expand all | Expand 10 after
603 dumpit("pass1", firstr); 603 dumpit("pass1", firstr);
604 604
605 /* 605 /*
606 * pass 2 606 * pass 2
607 * turn branch references to pointers 607 * turn branch references to pointers
608 * build back pointers 608 * build back pointers
609 */ 609 */
610 for(r=firstr; r!=R; r=r->link) { 610 for(r=firstr; r!=R; r=r->link) {
611 p = r->prog; 611 p = r->prog;
612 if(p->to.type == D_BRANCH) { 612 if(p->to.type == D_BRANCH) {
613 » » » if(p->to.branch == P) 613 » » » if(p->to.u.branch == P)
614 fatal("pnil %P", p); 614 fatal("pnil %P", p);
615 » » » r1 = p->to.branch->reg; 615 » » » r1 = p->to.u.branch->reg;
616 if(r1 == R) 616 if(r1 == R)
617 fatal("rnil %P", p); 617 fatal("rnil %P", p);
618 if(r1 == r) { 618 if(r1 == r) {
619 //fatal("ref to self %P", p); 619 //fatal("ref to self %P", p);
620 continue; 620 continue;
621 } 621 }
622 r->s2 = r1; 622 r->s2 = r1;
623 r->p2link = r1->p2; 623 r->p2link = r1->p2;
624 r1->p2 = r; 624 r1->p2 = r;
625 } 625 }
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
797 } 797 }
798 798
799 /* 799 /*
800 * eliminate nops 800 * eliminate nops
801 * free aux structures 801 * free aux structures
802 */ 802 */
803 for(p=firstp; p!=P; p=p->link) { 803 for(p=firstp; p!=P; p=p->link) {
804 while(p->link != P && p->link->as == ANOP) 804 while(p->link != P && p->link->as == ANOP)
805 p->link = p->link->link; 805 p->link = p->link->link;
806 if(p->to.type == D_BRANCH) 806 if(p->to.type == D_BRANCH)
807 » » » while(p->to.branch != P && p->to.branch->as == ANOP) 807 » » » while(p->to.u.branch != P && p->to.u.branch->as == ANOP)
808 » » » » p->to.branch = p->to.branch->link; 808 » » » » p->to.u.branch = p->to.u.branch->link;
809 } 809 }
810 810
811 if(lastr != R) { 811 if(lastr != R) {
812 lastr->link = freer; 812 lastr->link = freer;
813 freer = firstr; 813 freer = firstr;
814 } 814 }
815 815
816 if(debug['R']) { 816 if(debug['R']) {
817 if(ostats.ncvtreg || 817 if(ostats.ncvtreg ||
818 ostats.nspill || 818 ostats.nspill ||
(...skipping 925 matching lines...) Expand 10 before | Expand all | Expand 10 after
1744 chasejmp(Prog *p, int *jmploop) 1744 chasejmp(Prog *p, int *jmploop)
1745 { 1745 {
1746 int n; 1746 int n;
1747 1747
1748 n = 0; 1748 n = 0;
1749 while(p != P && p->as == AJMP && p->to.type == D_BRANCH) { 1749 while(p != P && p->as == AJMP && p->to.type == D_BRANCH) {
1750 if(++n > 10) { 1750 if(++n > 10) {
1751 *jmploop = 1; 1751 *jmploop = 1;
1752 break; 1752 break;
1753 } 1753 }
1754 » » p = p->to.branch; 1754 » » p = p->to.u.branch;
1755 } 1755 }
1756 return p; 1756 return p;
1757 } 1757 }
1758 1758
1759 /* 1759 /*
1760 * reuse reg pointer for mark/sweep state. 1760 * reuse reg pointer for mark/sweep state.
1761 * leave reg==nil at end because alive==nil. 1761 * leave reg==nil at end because alive==nil.
1762 */ 1762 */
1763 #define alive ((void*)0) 1763 #define alive ((void*)0)
1764 #define dead ((void*)1) 1764 #define dead ((void*)1)
1765 1765
1766 /* mark all code reachable from firstp as alive */ 1766 /* mark all code reachable from firstp as alive */
1767 static void 1767 static void
1768 mark(Prog *firstp) 1768 mark(Prog *firstp)
1769 { 1769 {
1770 Prog *p; 1770 Prog *p;
1771 ········ 1771 ········
1772 for(p=firstp; p; p=p->link) { 1772 for(p=firstp; p; p=p->link) {
1773 if(p->reg != dead) 1773 if(p->reg != dead)
1774 break; 1774 break;
1775 p->reg = alive; 1775 p->reg = alive;
1776 » » if(p->as != ACALL && p->to.type == D_BRANCH && p->to.branch) 1776 » » if(p->as != ACALL && p->to.type == D_BRANCH && p->to.u.branch)
1777 » » » mark(p->to.branch); 1777 » » » mark(p->to.u.branch);
1778 if(p->as == AJMP || p->as == ARET || p->as == AUNDEF) 1778 if(p->as == AJMP || p->as == ARET || p->as == AUNDEF)
1779 break; 1779 break;
1780 } 1780 }
1781 } 1781 }
1782 1782
1783 static void 1783 static void
1784 fixjmp(Prog *firstp) 1784 fixjmp(Prog *firstp)
1785 { 1785 {
1786 int jmploop; 1786 int jmploop;
1787 Prog *p, *last; 1787 Prog *p, *last;
1788 ········ 1788 ········
1789 if(debug['R'] && debug['v']) 1789 if(debug['R'] && debug['v'])
1790 print("\nfixjmp\n"); 1790 print("\nfixjmp\n");
1791 1791
1792 // pass 1: resolve jump to AJMP, mark all code as dead. 1792 // pass 1: resolve jump to AJMP, mark all code as dead.
1793 jmploop = 0; 1793 jmploop = 0;
1794 for(p=firstp; p; p=p->link) { 1794 for(p=firstp; p; p=p->link) {
1795 if(debug['R'] && debug['v']) 1795 if(debug['R'] && debug['v'])
1796 print("%P\n", p); 1796 print("%P\n", p);
1797 » » if(p->as != ACALL && p->to.type == D_BRANCH && p->to.branch && p ->to.branch->as == AJMP) { 1797 » » if(p->as != ACALL && p->to.type == D_BRANCH && p->to.u.branch && p->to.u.branch->as == AJMP) {
1798 » » » p->to.branch = chasejmp(p->to.branch, &jmploop); 1798 » » » p->to.u.branch = chasejmp(p->to.u.branch, &jmploop);
1799 if(debug['R'] && debug['v']) 1799 if(debug['R'] && debug['v'])
1800 print("->%P\n", p); 1800 print("->%P\n", p);
1801 } 1801 }
1802 p->reg = dead; 1802 p->reg = dead;
1803 } 1803 }
1804 if(debug['R'] && debug['v']) 1804 if(debug['R'] && debug['v'])
1805 print("\n"); 1805 print("\n");
1806 1806
1807 // pass 2: mark all reachable code alive 1807 // pass 2: mark all reachable code alive
1808 mark(firstp); 1808 mark(firstp);
(...skipping 15 matching lines...) Expand all
1824 last->link = p; 1824 last->link = p;
1825 last = p; 1825 last = p;
1826 } 1826 }
1827 last->link = P; 1827 last->link = P;
1828 ········ 1828 ········
1829 // pass 4: elide JMP to next instruction. 1829 // pass 4: elide JMP to next instruction.
1830 // only safe if there are no jumps to JMPs anymore. 1830 // only safe if there are no jumps to JMPs anymore.
1831 if(!jmploop) { 1831 if(!jmploop) {
1832 last = nil; 1832 last = nil;
1833 for(p=firstp; p; p=p->link) { 1833 for(p=firstp; p; p=p->link) {
1834 » » » if(p->as == AJMP && p->to.type == D_BRANCH && p->to.bran ch == p->link) { 1834 » » » if(p->as == AJMP && p->to.type == D_BRANCH && p->to.u.br anch == p->link) {
1835 if(debug['R'] && debug['v']) 1835 if(debug['R'] && debug['v'])
1836 print("del %P\n", p); 1836 print("del %P\n", p);
1837 continue; 1837 continue;
1838 } 1838 }
1839 if(last) 1839 if(last)
1840 last->link = p; 1840 last->link = p;
1841 last = p; 1841 last = p;
1842 } 1842 }
1843 last->link = P; 1843 last->link = P;
1844 } 1844 }
1845 ········ 1845 ········
1846 if(debug['R'] && debug['v']) { 1846 if(debug['R'] && debug['v']) {
1847 print("\n"); 1847 print("\n");
1848 for(p=firstp; p; p=p->link) 1848 for(p=firstp; p; p=p->link)
1849 print("%P\n", p); 1849 print("%P\n", p);
1850 print("\n"); 1850 print("\n");
1851 } 1851 }
1852 } 1852 }
LEFTRIGHT

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b