~ubuntu-branches/ubuntu/vivid/golang/vivid

« back to all changes in this revision

Viewing changes to src/cmd/6g/reg.c

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2013-08-20 14:06:23 UTC
  • mfrom: (14.1.23 saucy-proposed)
  • Revision ID: package-import@ubuntu.com-20130820140623-b414jfxi3m0qkmrq
Tags: 2:1.1.2-2ubuntu1
* Merge from Debian unstable (LP: #1211749, #1202027). Remaining changes:
  - 016-armhf-elf-header.patch: Use correct ELF header for armhf binaries.
  - d/control,control.cross: Update Breaks/Replaces for Ubuntu
    versions to ensure smooth upgrades, regenerate control file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
151
151
        ".X15",
152
152
};
153
153
 
 
154
static Node* regnodes[NREGVAR];
 
155
 
154
156
static void fixjmp(Prog*);
155
157
 
156
158
void
164
166
 
165
167
        if(first) {
166
168
                fmtinstall('Q', Qconv);
167
 
                exregoffset = D_R13;    // R14,R15 are external
 
169
                exregoffset = D_R15;
168
170
                first = 0;
169
171
        }
170
172
 
180
182
                return;
181
183
        }
182
184
 
183
 
        r1 = R;
184
185
        firstr = R;
185
186
        lastr = R;
186
187
 
191
192
         */
192
193
        nvar = NREGVAR;
193
194
        memset(var, 0, NREGVAR*sizeof var[0]);
194
 
        for(i=0; i<NREGVAR; i++)
195
 
                var[i].node = newname(lookup(regname[i]));
 
195
        for(i=0; i<NREGVAR; i++) {
 
196
                if(regnodes[i] == N)
 
197
                        regnodes[i] = newname(lookup(regname[i]));
 
198
                var[i].node = regnodes[i];
 
199
        }
196
200
 
197
201
        regbits = RtoB(D_SP);
198
202
        for(z=0; z<BITS; z++) {
219
223
                case AGLOBL:
220
224
                case ANAME:
221
225
                case ASIGNAME:
 
226
                case ALOCALS:
 
227
                case ATYPE:
222
228
                        continue;
223
229
                }
224
230
                r = rega();
247
253
                        }
248
254
                }
249
255
 
 
256
                // Avoid making variables for direct-called functions.
 
257
                if(p->as == ACALL && p->to.type == D_EXTERN)
 
258
                        continue;
 
259
 
 
260
                // Addressing makes some registers used.
 
261
                if(p->from.type >= D_INDIR)
 
262
                        r->use1.b[0] |= RtoB(p->from.type-D_INDIR);
 
263
                if(p->from.index != D_NONE)
 
264
                        r->use1.b[0] |= RtoB(p->from.index);
 
265
                if(p->to.type >= D_INDIR)
 
266
                        r->use2.b[0] |= RtoB(p->to.type-D_INDIR);
 
267
                if(p->to.index != D_NONE)
 
268
                        r->use2.b[0] |= RtoB(p->to.index);
 
269
 
250
270
                bit = mkvar(r, &p->from);
251
271
                if(bany(&bit))
252
272
                switch(p->as) {
326
346
                case AMOVWLZX:
327
347
                case AMOVWQSX:
328
348
                case AMOVWQZX:
 
349
                case AMOVQL:
329
350
                case APOPQ:
330
351
 
331
352
                case AMOVSS:
578
599
                                addrs.b[z] |= bit.b[z];
579
600
                }
580
601
 
581
 
//              print("bit=%2d addr=%d et=%-6E w=%-2d s=%S + %lld\n",
582
 
//                      i, v->addr, v->etype, v->width, v->sym, v->offset);
 
602
                if(debug['R'] && debug['v'])
 
603
                        print("bit=%2d addr=%d et=%-6E w=%-2d s=%N + %lld\n",
 
604
                                i, v->addr, v->etype, v->width, v->node, v->offset);
583
605
        }
584
606
 
585
607
        if(debug['R'] && debug['v'])
593
615
        for(r=firstr; r!=R; r=r->link) {
594
616
                p = r->prog;
595
617
                if(p->to.type == D_BRANCH) {
596
 
                        if(p->to.branch == P)
 
618
                        if(p->to.u.branch == P)
597
619
                                fatal("pnil %P", p);
598
 
                        r1 = p->to.branch->reg;
 
620
                        r1 = p->to.u.branch->reg;
599
621
                        if(r1 == R)
600
622
                                fatal("rnil %P", p);
601
623
                        if(r1 == r) {
742
764
brk:
743
765
        qsort(region, nregion, sizeof(region[0]), rcmp);
744
766
 
 
767
        if(debug['R'] && debug['v'])
 
768
                dumpit("pass5", firstr);
 
769
 
745
770
        /*
746
771
         * pass 6
747
772
         * determine used registers (paint2)
752
777
                bit = blsh(rgp->varno);
753
778
                vreg = paint2(rgp->enter, rgp->varno);
754
779
                vreg = allreg(vreg, rgp);
755
 
                if(rgp->regno != 0)
 
780
                if(rgp->regno != 0) {
 
781
                        if(debug['R'] && debug['v']) {
 
782
                                Var *v;
 
783
 
 
784
                                v = var + rgp->varno;
 
785
                                print("registerize %N+%lld (bit=%2d et=%2E) in %R\n",
 
786
                                                v->node, v->offset, rgp->varno, v->etype, rgp->regno);
 
787
                        }
756
788
                        paint3(rgp->enter, rgp->varno, vreg, rgp->regno);
 
789
                }
757
790
                rgp++;
758
791
        }
759
792
 
776
809
                while(p->link != P && p->link->as == ANOP)
777
810
                        p->link = p->link->link;
778
811
                if(p->to.type == D_BRANCH)
779
 
                        while(p->to.branch != P && p->to.branch->as == ANOP)
780
 
                                p->to.branch = p->to.branch->link;
 
812
                        while(p->to.u.branch != P && p->to.u.branch->as == ANOP)
 
813
                                p->to.u.branch = p->to.u.branch->link;
781
814
        }
782
815
 
783
816
        if(lastr != R) {
838
871
        a->offset = v->offset;
839
872
        a->etype = v->etype;
840
873
        a->type = v->name;
841
 
        a->gotype = v->gotype;
842
874
        a->node = v->node;
843
875
        a->sym = v->node->sym;
844
876
 
847
879
        p1->as = AMOVL;
848
880
        switch(v->etype) {
849
881
        default:
850
 
                fatal("unknown type\n");
 
882
                fatal("unknown type %E", v->etype);
851
883
        case TINT8:
852
884
        case TUINT8:
853
885
        case TBOOL:
915
947
}
916
948
 
917
949
static int
918
 
overlap(int32 o1, int w1, int32 o2, int w2)
 
950
overlap(int64 o1, int w1, int64 o2, int w2)
919
951
{
920
 
        int32 t1, t2;
 
952
        int64 t1, t2;
921
953
 
922
954
        t1 = o1+w1;
923
955
        t2 = o2+w2;
932
964
mkvar(Reg *r, Adr *a)
933
965
{
934
966
        Var *v;
935
 
        int i, t, n, et, z, w, flag;
 
967
        int i, t, n, et, z, flag;
 
968
        int64 w;
936
969
        uint32 regu;
937
 
        int32 o;
 
970
        int64 o;
938
971
        Bits bit;
939
972
        Node *node;
940
973
 
984
1017
        et = a->etype;
985
1018
        o = a->offset;
986
1019
        w = a->width;
 
1020
        if(w < 0)
 
1021
                fatal("bad width %lld for %D", w, a);
987
1022
 
988
1023
        flag = 0;
989
1024
        for(i=0; i<nvar; i++) {
1019
1054
        v = var+i;
1020
1055
        v->offset = o;
1021
1056
        v->name = n;
1022
 
        v->gotype = a->gotype;
1023
1057
        v->etype = et;
1024
1058
        v->width = w;
1025
1059
        v->addr = flag;         // funny punning
1026
1060
        v->node = node;
1027
1061
 
1028
1062
        if(debug['R'])
1029
 
                print("bit=%2d et=%2d w=%d %#N %D\n", i, et, w, node, a);
 
1063
                print("bit=%2d et=%2E w=%d+%lld %#N %D flag=%d\n", i, et, o, w, node, a, v->addr);
 
1064
 
1030
1065
        ostats.nvar++;
1031
1066
 
1032
1067
        bit = blsh(i);
1089
1124
                default:
1090
1125
                        // Work around for issue 1304:
1091
1126
                        // flush modified globals before each instruction.
1092
 
                        for(z=0; z<BITS; z++)
 
1127
                        for(z=0; z<BITS; z++) {
1093
1128
                                cal.b[z] |= externs.b[z];
 
1129
                                // issue 4066: flush modified return variables in case of panic
 
1130
                                if(hasdefer)
 
1131
                                        cal.b[z] |= ovar.b[z];
 
1132
                        }
1094
1133
                        break;
1095
1134
                }
1096
1135
                for(z=0; z<BITS; z++) {
1576
1615
int
1577
1616
BtoR(int32 b)
1578
1617
{
1579
 
        b &= 0x3fffL;           // no R14 or R15
 
1618
        b &= 0xffffL;
1580
1619
        if(b == 0)
1581
1620
                return 0;
1582
1621
        return bitno(b) + D_AX;
1584
1623
 
1585
1624
/*
1586
1625
 *      bit     reg
1587
 
 *      16      X5 (FREGMIN)
 
1626
 *      16      X0
1588
1627
 *      ...
1589
 
 *      26      X15 (FREGEXT)
 
1628
 *      31      X15
1590
1629
 */
1591
1630
int32
1592
1631
FtoB(int f)
1593
1632
{
1594
 
        if(f < FREGMIN || f > FREGEXT)
 
1633
        if(f < D_X0 || f > D_X15)
1595
1634
                return 0;
1596
 
        return 1L << (f - FREGMIN + 16);
 
1635
        return 1L << (f - D_X0 + 16);
1597
1636
}
1598
1637
 
1599
1638
int
1600
1639
BtoF(int32 b)
1601
1640
{
1602
1641
 
1603
 
        b &= 0xFF0000L;
 
1642
        b &= 0xFFFF0000L;
1604
1643
        if(b == 0)
1605
1644
                return 0;
1606
 
        return bitno(b) - 16 + FREGMIN;
 
1645
        return bitno(b) - 16 + D_X0;
1607
1646
}
1608
1647
 
1609
1648
void
1719
1758
                        *jmploop = 1;
1720
1759
                        break;
1721
1760
                }
1722
 
                p = p->to.branch;
 
1761
                p = p->to.u.branch;
1723
1762
        }
1724
1763
        return p;
1725
1764
}
1741
1780
                if(p->reg != dead)
1742
1781
                        break;
1743
1782
                p->reg = alive;
1744
 
                if(p->as != ACALL && p->to.type == D_BRANCH && p->to.branch)
1745
 
                        mark(p->to.branch);
1746
 
                if(p->as == AJMP || p->as == ARET || (p->as == ACALL && noreturn(p)))
 
1783
                if(p->as != ACALL && p->to.type == D_BRANCH && p->to.u.branch)
 
1784
                        mark(p->to.u.branch);
 
1785
                if(p->as == AJMP || p->as == ARET || p->as == AUNDEF)
1747
1786
                        break;
1748
1787
        }
1749
1788
}
1762
1801
        for(p=firstp; p; p=p->link) {
1763
1802
                if(debug['R'] && debug['v'])
1764
1803
                        print("%P\n", p);
1765
 
                if(p->as != ACALL && p->to.type == D_BRANCH && p->to.branch && p->to.branch->as == AJMP) {
1766
 
                        p->to.branch = chasejmp(p->to.branch, &jmploop);
 
1804
                if(p->as != ACALL && p->to.type == D_BRANCH && p->to.u.branch && p->to.u.branch->as == AJMP) {
 
1805
                        p->to.u.branch = chasejmp(p->to.u.branch, &jmploop);
1767
1806
                        if(debug['R'] && debug['v'])
1768
1807
                                print("->%P\n", p);
1769
1808
                }
1799
1838
        if(!jmploop) {
1800
1839
                last = nil;
1801
1840
                for(p=firstp; p; p=p->link) {
1802
 
                        if(p->as == AJMP && p->to.type == D_BRANCH && p->to.branch == p->link) {
 
1841
                        if(p->as == AJMP && p->to.type == D_BRANCH && p->to.u.branch == p->link) {
1803
1842
                                if(debug['R'] && debug['v'])
1804
1843
                                        print("del %P\n", p);
1805
1844
                                continue;