~ubuntu-branches/ubuntu/utopic/golang/utopic

« back to all changes in this revision

Viewing changes to src/cmd/8g/peep.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:
36
36
#define REGEXT  0
37
37
 
38
38
static void     conprop(Reg *r);
 
39
static void elimshortmov(Reg *r);
39
40
 
40
41
// do we need the carry bit
41
42
static int
45
46
                switch(p->as) {
46
47
                case AADCL:
47
48
                case ASBBL:
 
49
                case ARCRB:
 
50
                case ARCRW:
48
51
                case ARCRL:
49
52
                        return 1;
 
53
                case AADDB:
 
54
                case AADDW:
50
55
                case AADDL:
 
56
                case ASUBB:
 
57
                case ASUBW:
51
58
                case ASUBL:
52
59
                case AJMP:
53
60
                case ARET:
119
126
                case AGLOBL:
120
127
                case ANAME:
121
128
                case ASIGNAME:
 
129
                case ALOCALS:
 
130
                case ATYPE:
122
131
                        p = p->link;
123
132
                }
124
133
        }
125
 
        
126
 
        // movb elimination.
127
 
        // movb is simulated by the linker
128
 
        // when a register other than ax, bx, cx, dx
129
 
        // is used, so rewrite to other instructions
130
 
        // when possible.  a movb into a register
131
 
        // can smash the entire 32-bit register without
132
 
        // causing any trouble.
133
 
        for(r=firstr; r!=R; r=r->link) {
134
 
                p = r->prog;
135
 
                if(p->as == AMOVB && regtyp(&p->to)) {
136
 
                        // movb into register.
137
 
                        // from another register or constant can be movl.
138
 
                        if(regtyp(&p->from) || p->from.type == D_CONST)
139
 
                                p->as = AMOVL;
140
 
                        else
141
 
                                p->as = AMOVBLZX;
142
 
                }
143
 
        }
 
134
 
 
135
        // byte, word arithmetic elimination.
 
136
        elimshortmov(r);
144
137
 
145
138
        // constant propagation
146
139
        // find MOV $con,R followed by
152
145
                case ALEAL:
153
146
                        if(regtyp(&p->to))
154
147
                        if(p->from.sym != S)
 
148
                        if(p->from.index == D_NONE || p->from.index == D_CONST)
155
149
                                conprop(r);
156
150
                        break;
157
151
 
158
152
                case AMOVB:
159
153
                case AMOVW:
160
154
                case AMOVL:
 
155
                case AMOVSS:
 
156
                case AMOVSD:
161
157
                        if(regtyp(&p->to))
162
158
                        if(p->from.type == D_CONST)
163
159
                                conprop(r);
173
169
        for(r=firstr; r!=R; r=r->link) {
174
170
                p = r->prog;
175
171
                switch(p->as) {
176
 
                case AMOVB:
177
 
                case AMOVW:
178
172
                case AMOVL:
 
173
                case AMOVSS:
 
174
                case AMOVSD:
179
175
                        if(regtyp(&p->to))
180
176
                        if(regtyp(&p->from)) {
181
177
                                if(copyprop(r)) {
205
201
                        }
206
202
                        break;
207
203
 
208
 
                case AADDB:
209
204
                case AADDL:
210
205
                case AADDW:
211
206
                        if(p->from.type != D_CONST || needc(p->link))
228
223
                        }
229
224
                        break;
230
225
 
231
 
                case ASUBB:
232
226
                case ASUBL:
233
227
                case ASUBW:
234
228
                        if(p->from.type != D_CONST || needc(p->link))
254
248
        }
255
249
        if(t)
256
250
                goto loop1;
 
251
 
 
252
        // MOVSD removal.
 
253
        // We never use packed registers, so a MOVSD between registers
 
254
        // can be replaced by MOVAPD, which moves the pair of float64s
 
255
        // instead of just the lower one.  We only use the lower one, but
 
256
        // the processor can do better if we do moves using both.
 
257
        for(r=firstr; r!=R; r=r->link) {
 
258
                p = r->prog;
 
259
                if(p->as == AMOVSD)
 
260
                if(regtyp(&p->from))
 
261
                if(regtyp(&p->to))
 
262
                        p->as = AMOVAPD;
 
263
        }
257
264
}
258
265
 
259
266
void
312
319
        t = a->type;
313
320
        if(t >= D_AX && t <= D_DI)
314
321
                return 1;
 
322
        if(t >= D_X0 && t <= D_X7)
 
323
                return 1;
315
324
        return 0;
316
325
}
317
326
 
 
327
// movb elimination.
 
328
// movb is simulated by the linker
 
329
// when a register other than ax, bx, cx, dx
 
330
// is used, so rewrite to other instructions
 
331
// when possible.  a movb into a register
 
332
// can smash the entire 64-bit register without
 
333
// causing any trouble.
 
334
static void
 
335
elimshortmov(Reg *r)
 
336
{
 
337
        Prog *p;
 
338
 
 
339
        for(r=firstr; r!=R; r=r->link) {
 
340
                p = r->prog;
 
341
                if(regtyp(&p->to)) {
 
342
                        switch(p->as) {
 
343
                        case AINCB:
 
344
                        case AINCW:
 
345
                                p->as = AINCL;
 
346
                                break;
 
347
                        case ADECB:
 
348
                        case ADECW:
 
349
                                p->as = ADECL;
 
350
                                break;
 
351
                        case ANEGB:
 
352
                        case ANEGW:
 
353
                                p->as = ANEGL;
 
354
                                break;
 
355
                        case ANOTB:
 
356
                        case ANOTW:
 
357
                                p->as = ANOTL;
 
358
                                break;
 
359
                        }
 
360
                        if(regtyp(&p->from) || p->from.type == D_CONST) {
 
361
                                // move or artihmetic into partial register.
 
362
                                // from another register or constant can be movl.
 
363
                                // we don't switch to 32-bit arithmetic if it can
 
364
                                // change how the carry bit is set (and the carry bit is needed).
 
365
                                switch(p->as) {
 
366
                                case AMOVB:
 
367
                                case AMOVW:
 
368
                                        p->as = AMOVL;
 
369
                                        break;
 
370
                                case AADDB:
 
371
                                case AADDW:
 
372
                                        if(!needc(p->link))
 
373
                                                p->as = AADDL;
 
374
                                        break;
 
375
                                case ASUBB:
 
376
                                case ASUBW:
 
377
                                        if(!needc(p->link))
 
378
                                                p->as = ASUBL;
 
379
                                        break;
 
380
                                case AMULB:
 
381
                                case AMULW:
 
382
                                        p->as = AMULL;
 
383
                                        break;
 
384
                                case AIMULB:
 
385
                                case AIMULW:
 
386
                                        p->as = AIMULL;
 
387
                                        break;
 
388
                                case AANDB:
 
389
                                case AANDW:
 
390
                                        p->as = AANDL;
 
391
                                        break;
 
392
                                case AORB:
 
393
                                case AORW:
 
394
                                        p->as = AORL;
 
395
                                        break;
 
396
                                case AXORB:
 
397
                                case AXORW:
 
398
                                        p->as = AXORL;
 
399
                                        break;
 
400
                                case ASHLB:
 
401
                                case ASHLW:
 
402
                                        p->as = ASHLL;
 
403
                                        break;
 
404
                                }
 
405
                        } else {
 
406
                                // explicit zero extension
 
407
                                switch(p->as) {
 
408
                                case AMOVB:
 
409
                                        p->as = AMOVBLZX;
 
410
                                        break;
 
411
                                case AMOVW:
 
412
                                        p->as = AMOVWLZX;
 
413
                                        break;
 
414
                                }
 
415
                        }
 
416
                }
 
417
        }
 
418
}
 
419
 
318
420
/*
319
421
 * the idea is to substitute
320
422
 * one register for another
357
459
                        if(p->to.type != D_NONE)
358
460
                                break;
359
461
 
360
 
                case ADIVB:
361
 
                case ADIVL:
362
 
                case ADIVW:
363
 
                case AIDIVB:
364
 
                case AIDIVL:
365
 
                case AIDIVW:
366
 
                case AIMULB:
367
 
                case AMULB:
368
 
                case AMULL:
369
 
                case AMULW:
370
 
 
371
462
                case ARCLB:
372
463
                case ARCLL:
373
464
                case ARCLW:
392
483
                case ASHRB:
393
484
                case ASHRL:
394
485
                case ASHRW:
 
486
                        if(p->from.type == D_CONST)
 
487
                                break;
 
488
 
 
489
                case ADIVB:
 
490
                case ADIVL:
 
491
                case ADIVW:
 
492
                case AIDIVB:
 
493
                case AIDIVL:
 
494
                case AIDIVW:
 
495
                case AIMULB:
 
496
                case AMULB:
 
497
                case AMULL:
 
498
                case AMULW:
395
499
 
396
500
                case AREP:
397
501
                case AREPN:
403
507
                case ASTOSL:
404
508
                case AMOVSB:
405
509
                case AMOVSL:
 
510
 
 
511
                case AFMOVF:
 
512
                case AFMOVD:
 
513
                case AFMOVFP:
 
514
                case AFMOVDP:
406
515
                        return 0;
407
516
 
408
 
                case AMOVB:
409
 
                case AMOVW:
410
517
                case AMOVL:
 
518
                case AMOVSS:
 
519
                case AMOVSD:
411
520
                        if(p->to.type == v1->type)
412
521
                                goto gotit;
413
522
                        break;
587
696
 
588
697
 
589
698
        case ANOP:      /* rhs store */
590
 
        case AMOVB:
591
 
        case AMOVW:
592
699
        case AMOVL:
593
700
        case AMOVBLSX:
594
701
        case AMOVBLZX:
595
702
        case AMOVWLSX:
596
703
        case AMOVWLZX:
 
704
        
 
705
        case AMOVSS:
 
706
        case AMOVSD:
 
707
        case ACVTSD2SL:
 
708
        case ACVTSD2SS:
 
709
        case ACVTSL2SD:
 
710
        case ACVTSL2SS:
 
711
        case ACVTSS2SD:
 
712
        case ACVTSS2SL:
 
713
        case ACVTTSD2SL:
 
714
        case ACVTTSS2SL:
597
715
                if(copyas(&p->to, v)) {
598
716
                        if(s != A)
599
717
                                return copysub(&p->from, v, s, 1);
653
771
        case AXORB:
654
772
        case AXORL:
655
773
        case AXORW:
 
774
        case AMOVB:
 
775
        case AMOVW:
 
776
 
 
777
        case AADDSD:
 
778
        case AADDSS:
 
779
        case ACMPSD:
 
780
        case ACMPSS:
 
781
        case ADIVSD:
 
782
        case ADIVSS:
 
783
        case AMAXSD:
 
784
        case AMAXSS:
 
785
        case AMINSD:
 
786
        case AMINSS:
 
787
        case AMULSD:
 
788
        case AMULSS:
 
789
        case ARCPSS:
 
790
        case ARSQRTSS:
 
791
        case ASQRTSD:
 
792
        case ASQRTSS:
 
793
        case ASUBSD:
 
794
        case ASUBSS:
 
795
        case AXORPD:
656
796
                if(copyas(&p->to, v))
657
797
                        return 2;
658
798
                goto caseread;
660
800
        case ACMPL:     /* read only */
661
801
        case ACMPW:
662
802
        case ACMPB:
 
803
 
 
804
        case ACOMISD:
 
805
        case ACOMISS:
 
806
        case AUCOMISD:
 
807
        case AUCOMISS:
663
808
        caseread:
664
809
                if(s != A) {
665
810
                        if(copysub(&p->from, v, s, 1))
744
889
                return 0;
745
890
 
746
891
        case ARET:      /* funny */
747
 
                if(v->type == REGRET || v->type == FREGRET)
748
 
                        return 2;
749
892
                if(s != A)
750
893
                        return 1;
751
894
                return 3;
755
898
                        return 2;
756
899
                if(REGARG >= 0 && v->type == (uchar)REGARG)
757
900
                        return 2;
 
901
                if(v->type == p->from.type)
 
902
                        return 2;
758
903
 
759
904
                if(s != A) {
760
905
                        if(copysub(&p->to, v, s, 1))
820
965
 
821
966
        if(copyas(a, v)) {
822
967
                t = s->type;
823
 
                if(t >= D_AX && t <= D_DI) {
 
968
                if(t >= D_AX && t <= D_DI || t >= D_X0 && t <= D_X7) {
824
969
                        if(f)
825
970
                                a->type = t;
826
971
                }
881
1026
                if(p->from.node == p0->from.node)
882
1027
                if(p->from.offset == p0->from.offset)
883
1028
                if(p->from.scale == p0->from.scale)
884
 
                if(p->from.dval == p0->from.dval)
 
1029
                if(p->from.u.vval == p0->from.u.vval)
885
1030
                if(p->from.index == p0->from.index) {
886
1031
                        excise(r);
887
1032
                        goto loop;