forked from Leffmann/vbcc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathav.c
557 lines (537 loc) · 19.1 KB
/
av.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
/* $VER: vbcc (av.c) V0.8 */
/* aktive Variablen und Elimination unnoetiger Anweisungen */
#include "opt.h"
static char FILE_[]=__FILE__;
/* fuer aktive Variablen */
struct Var **vilist;
unsigned int vcount; /* 0..vcount-rcount-1: vars, vcount-rcount..vcount: DREFOBJs */
unsigned int rcount;
size_t vsize;
bvtype *av_globals,*av_address,*av_statics,*av_drefs;
int report_dead_statements;
void print_av(bvtype *bitvector)
/* druckt Variablen in einem Bitvektor */
{
int i;
if(!bitvector) {printf("active variables not available\n");return;}
for(i=0;i<vcount-rcount;i++)
if(BTST(bitvector,i)) printf("%3d: %s,%ld\n",i,vilist[i]->identifier,zm2l(vilist[i]->offset));
for(i=vcount-rcount;i<vcount;i++)
if(BTST(bitvector,i)) printf("%3d: (%s),%ld\n",i,vilist[i]->identifier,zm2l(vilist[i]->offset));
}
static int clcnt;
/* walks through a clist and numbers variables whose addresses are
contained; if pass==-1, index is set to -1, if pass==0, index is set,
otherwise vilist
clcnt is used as index-counter in pass 0 */
void num_clist_refs(int pass,struct Typ *t,struct const_list *cl)
{
/*FIXME: bei Aufrufen auch auf locale, nicht USEDASDEST|USEDASADDR */
int i;zmax sz;
if(ISARRAY(t->flags)){
for(sz=l2zm(0L);!zmleq(t->size,sz)&&cl;sz=zmadd(sz,l2zm(1L)),cl=cl->next){
if(!cl->other){ierror(0);return;}
num_clist_refs(pass,t->next,cl->other);
}
return;
}
if(ISUNION(t->flags)){
num_clist_refs(pass,(*t->exact->sl)[0].styp,cl);
return;
}
if(ISSTRUCT(t->flags)&&!cl->tree){
struct Typ *st;
for(i=0;i<t->exact->count&&cl;i++){
st=(*t->exact->sl)[i].styp;
if(!(*t->exact->sl)[i].identifier) ierror(0);
if((*t->exact->sl)[i].identifier[0]){
if(!cl->other)
ierror(0);
num_clist_refs(pass,st,cl->other);
cl=cl->next;
}
}
return;
}
if(cl->tree&&(cl->tree->o.flags&VARADR)){
struct Var *v=cl->tree->o.v;
if(pass==-1){
v->index=-1;
}else if(pass==0){
if(v->index<0) {v->index=clcnt++;v->inr=inr;}
}else{
if(v->index<0||v->index>=vcount-rcount)
ierror(0);
vilist[v->index]=v;
}
}
}
int inr;
void num_vars(void)
/* Numeriert Variablen und erzeugt Indexliste */
{
unsigned int i,j,done;struct IC *p;struct Var *v,*a[4],*vp;
unsigned long heapsize=0;
if(DEBUG&1024) printf("numerating variables loop1\n");
inr++;
/* alle Indizes auf -1 */
a[0]=vl0;
a[1]=vl1;
a[2]=vl2;
a[3]=vl3;
#if 1
for(j=0;j<4;j++){
v=a[j];
while(v){
v->index=-1;
/* Variablen von inline-Funktionen */
if(j==0&&v->fi&&v->fi->first_ic){
for(vp=v->fi->vars;vp;vp=vp->next) vp->index=-1;
}
v=v->next;
}
}
/* variables that may be referenced in inter-proc. dflow-info */
for(p=first_ic;p;p=p->next){
if(p->code==CALL&&(p->q1.flags&VAR)&&p->q1.v->fi){
struct function_info *fi=p->q1.v->fi;
if(fi->flags&ALL_USES){
for(i=0;i<fi->use_cnt;i++){
if(v=fi->use_list[i].v) fi->use_list[i].v->index=-1;
}
}
if(fi->flags&ALL_MODS){
for(i=0;i<fi->change_cnt;i++){
if(v=fi->change_list[i].v) fi->change_list[i].v->index=-1;
}
}
}
/* const-lists */
if((p->q1.flags&VAR))
if(p->q1.v->clist&&is_const(p->q1.v->vtyp)) num_clist_refs(-1,p->q1.v->vtyp,p->q1.v->clist);
if((p->q2.flags&VAR))
if(p->q2.v->clist&&is_const(p->q2.v->vtyp)) num_clist_refs(-1,p->q2.v->vtyp,p->q2.v->clist);
if((p->z.flags&VAR))
if(p->z.v->clist&&is_const(p->z.v->vtyp)) num_clist_refs(-1,p->z.v->vtyp,p->z.v->clist);
}
#endif
/* Do we need this? */
for(p=first_ic;p;p=p->next){
if(p->q1.flags&VAR) {p->q1.v->index=-1;p->q1.v->flags&=~USEDASADR;}
if(p->q2.flags&VAR) {p->q2.v->index=-1;p->q2.v->flags&=~USEDASADR;}
if(p->z.flags&VAR) {p->z.v->index=-1;p->z.v->flags&=~USEDASADR;}
}
/* erst alle Variablen, die als DREFOBJ benutzt werden */
if(DEBUG&1024) printf("numerating variables loop2\n");
i=0;
do{
done=1;
if(DEBUG&1024) printf("pass\n");
for(p=first_ic;p;p=p->next){
if(p->code<LABEL||p->code>BRA){
int c=p->code;
/* mark variables ad USEDASADR */
if(c==ADDRESS) p->q1.v->flags|=USEDASADR;
if(p->q1.flags&VARADR) p->q1.v->flags|=USEDASADR;
if(p->q2.flags&VARADR) p->q2.v->flags|=USEDASADR;
if(p->z.flags&VARADR) p->z.v->flags|=USEDASADR;
j=(q1typ(p)&NQ);
if((p->q1.flags&(VAR|DREFOBJ))==(VAR|DREFOBJ)){
v=p->q1.v;
if(!v->vtyp->next||(v->vtyp->next->flags&NQ)!=j) v->flags|=DNOTTYPESAFE;
if(v->index<0) {v->index=i++;v->inr=inr;done=0;}
}
j=(q2typ(p)&NQ);
if((p->q2.flags&(VAR|DREFOBJ))==(VAR|DREFOBJ)){
v=p->q2.v;
if(!v->vtyp->next||(v->vtyp->next->flags&NQ)!=j) v->flags|=DNOTTYPESAFE;
if(v->index<0) {v->index=i++;v->inr=inr;done=0;}
}
j=(ztyp(p)&NQ);
if((p->z.flags&(VAR|DREFOBJ))==(VAR|DREFOBJ)){
v=p->z.v;
if(!v->vtyp->next||(v->vtyp->next->flags&NQ)!=j) v->flags|=DNOTTYPESAFE;
if(v->index<0) {v->index=i++;v->inr=inr;done=0;}
}
/* mark copies from DREFs also as DREFs (necessary?) (check z for !DREFOBJ?) */
if((c==ASSIGN||c==ADDI2P||c==SUBIFP)&&(p->q1.flags&VAR)&&p->q1.v->index>=0&&(p->z.flags&VAR)&&p->z.v->index<0){
if(!(p->z.flags&VAR)) ierror(0);
p->z.v->index=i++;p->z.v->inr=inr;done=0;
}
/* mark copies to DREFs as DREFs (because of copy-propagation */
/* and post-op reordering */
if((c==ASSIGN||c==ADDI2P||c==SUBIFP)&&(p->z.flags&VAR)&&p->z.v->index>=0&&(p->q1.flags&VAR)&&p->q1.v->index<0){
p->q1.v->index=i++;p->q1.v->inr=inr;done=0;
}
}
}
}while(!done);
if(DEBUG&1024) printf("numerating variables loop3\n");
rcount=i; /* Anzahl der DREFOBJ-Variablen */
/* jetzt den Rest */
for(p=first_ic;p;p=p->next){
int c=p->code;
if(1/*p->code<LABEL||p->code>BRA*/){
if((p->q1.flags&(VAR|DREFOBJ))==VAR){
j=(q1typ(p)&NQ);
v=p->q1.v;
if((v->vtyp->flags&NQ)!=j) v->flags|=NOTTYPESAFE;
if(v->index<0) {v->index=i++;v->inr=inr;}
}
if((p->q2.flags&(VAR|DREFOBJ))==VAR){
j=(q2typ(p)&NQ);
v=p->q2.v;
if((v->vtyp->flags&NQ)!=j) v->flags|=NOTTYPESAFE;
if(v->index<0) {v->index=i++;v->inr=inr;}
}
if((p->z.flags&(VAR|DREFOBJ))==VAR){
j=(ztyp(p)&NQ);
v=p->z.v;
if((v->vtyp->flags&NQ)!=j) v->flags|=NOTTYPESAFE;
if(v->index<0) {v->index=i++;v->inr=inr;}
}
}
/* const-lists */
if((p->q1.flags&VAR))
if(p->q1.v->clist&&is_const(p->q1.v->vtyp)) {clcnt=i;num_clist_refs(0,p->q1.v->vtyp,p->q1.v->clist);i=clcnt;}
if((p->q2.flags&VAR))
if(p->q2.v->clist&&is_const(p->q2.v->vtyp)) {clcnt=i;num_clist_refs(0,p->q2.v->vtyp,p->q2.v->clist);i=clcnt;}
if((p->z.flags&VAR))
if(p->z.v->clist&&is_const(p->z.v->vtyp)) {clcnt=i;num_clist_refs(0,p->z.v->vtyp,p->z.v->clist);i=clcnt;}
}
if(DEBUG&1024) printf("numerating variables loop4\n");
vcount=i+rcount; /* alle benutzten Variablen+Anzahl der DREFOBJs */
vilist=mymalloc(vcount*sizeof(struct Var *));
heapsize+=vcount*sizeof(struct Var *);
#if 0
for(j=0;j<4;j++){
int i;
v=a[j];
while(v){
i=v->index;
/* printf("%s has index %d\n",v->identifier,i);*/
if(i>=0){
if(i>=vcount-rcount) ierror(0);
vilist[i]=v;
if(i<rcount) vilist[i+vcount-rcount]=v;
}
/* Variablen von inline-Funktionen */
if(j==0&&v->fi&&v->fi->first_ic){
for(vp=v->fi->vars;vp;vp=vp->next){
i=vp->index;
if(i>=0){
if(i>=vcount-rcount) ierror(0);
vilist[i]=vp;
if(i<rcount) vilist[i+vcount-rcount]=vp;
}
}
}
v=v->next;
}
}
#endif
for(p=first_ic;p;p=p->next){
struct Var *v;
if(p->q1.flags&VAR){
i=p->q1.v->index;
vilist[i]=v=p->q1.v;
if(v->clist&&is_const(v->vtyp)) num_clist_refs(1,v->vtyp,v->clist);
}
if(p->q2.flags&VAR){
i=p->q2.v->index;
vilist[i]=v=p->q2.v;
if(v->clist&&is_const(v->vtyp)) num_clist_refs(1,v->vtyp,v->clist);
}
if(p->z.flags&VAR){
i=p->z.v->index;
vilist[i]=v=p->z.v;
if(v->clist&&is_const(v->vtyp)) num_clist_refs(1,v->vtyp,v->clist);
}
}
for(i=0;i<rcount;i++)
vilist[i+vcount-rcount]=vilist[i];
/*vsize=(vcount+CHAR_BIT-1)/CHAR_BIT;*/
vsize=BVSIZE(vcount);
if(DEBUG&(16384|1024)) printf("%lu variables (%lu DREFOBJs), vsize=%lu\n",(unsigned long)vcount,(unsigned long)rcount,(unsigned long)vsize);
av_drefs=mymalloc(vsize);
memset(av_drefs,0,vsize);
/* alle DREFOBJs */
for(i=vcount-rcount;i<vcount;i++) BSET(av_drefs,i);
/* av_globals enthaelt alle globalen Variablen und av_address */
/* zusaetzlich noch alle Variablen, deren Adressen genommen wurden */
av_globals=mymalloc(vsize);
memset(av_globals,0,vsize);
av_statics=mymalloc(vsize);
memset(av_statics,0,vsize);
av_address=mymalloc(vsize);
memcpy(av_address,av_globals,vsize);
heapsize+=4*vsize;
for(i=0;i<vcount-rcount;i++){
if(vilist[i]->nesting==0||vilist[i]->storage_class==EXTERN) BSET(av_globals,i);
if(vilist[i]->flags&USEDASADR) BSET(av_address,i);
if(vilist[i]->storage_class==STATIC) BSET(av_statics,i);
if(i<rcount){
/* if(!ISPOINTER(vilist[i]->vtyp->flags)){ printf("%s(%ld)\n",vilist[i]->identifier,zm2l(vilist[i]->offset));ierror(0);}*/
BSET(av_address,i+vcount-rcount);
BSET(av_globals,i+vcount-rcount);
}
}
if(DEBUG&16384) printf("num_vars heapsize=%lu\n",heapsize);
}
void print_vi(void)
/* Druckt vilist und testet Konsistenz */
{
int i;
printf("\nprint_vi()\n");
for(i=0;i<vcount;i++){
if(!vilist[i]||(i<rcount&&vilist[i]->index!=i)) ierror(0);
printf("%3d: %s\n",i,vilist[i]->identifier);
}
}
void av_change(struct IC *p,bvtype *use,bvtype *def)
/* Berechnet die Aenderungen, die sich durch IC p an use und def ergeben. */
{
int i,j,n=-1;
int g1,g2;
/* Wenn eine Quelle==Ziel, dann wird dadurch kein neuer use erzeugt, */
/* um z.B. unbenutzte Induktionsvariablen in Schleifen zu eliminieren. */
g1=compare_objs(&p->q1,&p->z,p->typf);
g2=compare_objs(&p->q2,&p->z,p->typf);
if(!g1&&(p->q1.flags&(VAR|DREFOBJ))==VAR) n=p->q1.v->index;
if(!g2&&(p->q2.flags&(VAR|DREFOBJ))==VAR) n=p->q2.v->index;
for(j=0;j<p->use_cnt;j++){
i=p->use_list[j].v->index;
if(p->use_list[j].flags&DREFOBJ) i+=vcount-rcount;
if(i>=vcount) continue;
if(i!=n&&!BTST(def,i)) BSET(use,i);
}
/* Ein Wert wird nicht zerstoert, wenn es kein elementarer Typ ist und */
/* die Groesse kleiner als die Variable (steht in alle solchen ICs in */
/* q2.val.max. */
if((p->z.flags&(VAR|DREFOBJ))==VAR&&(ISSCALAR(p->z.v->vtyp->flags)||p->z.v->vtyp->flags==0||zmeqto(p->q2.val.vmax,szof(p->z.v->vtyp)))){
i=p->z.v->index;
if(i>=vcount) ierror(0);
if(g1&&g2&&!BTST(use,i)) BSET(def,i);
/* Wenn p geaendert wird, wird auch *p geaendert */
if(i<rcount&&!BTST(def,i+vcount-rcount)) BSET(use,i+vcount-rcount);
}
if((p->z.flags&(VAR|DREFOBJ))==(VAR|DREFOBJ)&&g1&&g2&&!(p->z.v->flags&DNOTTYPESAFE)){
i=p->z.v->index+vcount-rcount;
if(i>=vcount) ierror(0);
if(!BTST(use,i)) BSET(def,i);
}
}
void active_vars(struct flowgraph *fg)
/* analysiert aktive Variablen im Flussgraphen, nomain==0, wenn zu */
/* optimierende Funktion main() ist */
{
struct IC *p;
int changed,pass;struct flowgraph *g;
unsigned long heapsize=0;
if(DEBUG&1024){printf("analysing active variables\n");/*scanf("%d",&i);*/}
tmp=mymalloc(vsize);
heapsize+=vsize;
/* av_gen und av_kill fuer jeden Basic Block berechnen */
if(DEBUG&1024){printf("active_vars(): loop1\n");/*scanf("%d",&i);*/}
g=fg;
while(g){
g->av_gen=mymalloc(vsize);
memset(g->av_gen,0,vsize);
g->av_kill=mymalloc(vsize);
memset(g->av_kill,0,vsize);
g->av_in=mymalloc(vsize);
memset(g->av_in,0,vsize);
g->av_out=mymalloc(vsize);
memset(g->av_out,0,vsize);
heapsize+=4*vsize;
for(p=g->start;p;p=p->next){
av_change(p,g->av_gen,g->av_kill);
if(p==g->end) break;
}
g=g->normalout;
}
/* av_in und av_out fuer alle Bloecke berechnen */
if(DEBUG&1024){printf("active_vars(): loop2\npass: ");/*scanf("%d",&i);*/}
pass=0;
do{
if(DEBUG&1024) {printf(" %d",++pass);fflush(stdout);}
changed=0;
g=fg;
while(g){
/* out(B)=U in(C) ueber alle Nachfolger C von B */
memset(g->av_out,0,vsize); /* noetig? */
if(g->branchout) bvunite(g->av_out,g->branchout->av_in,vsize);
if((!g->end||g->end->code!=BRA)&&g->normalout) bvunite(g->av_out,g->normalout->av_in,vsize);
/* Am Ende muessen alle globalen Variablen bekannt sein */
if(!g->normalout){
bvunite(g->av_out,av_globals,vsize);
/*if(!nocall)*/ bvunite(g->av_out,av_statics,vsize);
}
/* in(B)=use(B)U(out(B)-def(B)) */
memcpy(tmp,g->av_out,vsize);
bvdiff(tmp,g->av_kill,vsize);
bvunite(tmp,g->av_gen,vsize);
if(!bvcmp(tmp,g->av_in,vsize)){changed=1;memcpy(g->av_in,tmp,vsize);}
g=g->normalout;
}
}while(changed);
if(DEBUG&1024) printf("\n");
free(tmp);
if(DEBUG&16384) printf("av heapsize=%lu\n",heapsize);
}
void av_update(struct IC *p,bvtype *isused)
{
int i,j;
if((p->z.flags&(VKONST|VAR))==VAR){
i=p->z.v->index;
if(p->z.flags&DREFOBJ) i+=vcount-rcount;
if(i<0||i>=vcount){
printf("i=%d\n",i);pric2(stdout,p); ierror(0);
}
if(p->z.flags&DREFOBJ){
if(!(p->z.v->flags&DNOTTYPESAFE))
BCLR(isused,i);
}else{
if(ISSCALAR(p->z.v->vtyp->flags)||(p->code==ASSIGN&&zmeqto(p->q2.val.vmax,szof(p->z.v->vtyp))))
BCLR(isused,i);
}
/* bei Zuweisung an p wird *p aktiv */
if(i<rcount) BSET(isused,i+vcount-rcount);
}
for(j=0;j<p->use_cnt;j++){
i=p->use_list[j].v->index;
if(p->use_list[j].flags&DREFOBJ) i+=vcount-rcount;
if(i<0||i>=vcount) continue;
BSET(isused,i);
}
}
/* tests, if IC p uses or modifies var v */
static int var_conflicts(struct Var *v,struct IC *p)
{
int i;
for(i=0;i<p->use_cnt;i++)
if(p->use_list[i].v==v&&!(p->use_list[i].flags&DREFOBJ))
return 1;
for(i=0;i<p->change_cnt;i++)
if(p->change_list[i].v==v&&!(p->change_list[i].flags&DREFOBJ))
return 1;
return 0;
}
int dead_assignments(struct flowgraph *fg)
/* Findet Zuweisungen, die unnoetig sind, da die Variable nie mehr */
/* benutzt werden kann. */
{
int changed=0;struct IC *p;bvtype *isused;
int i,j;
if(DEBUG&1024) printf("searching for dead assignments\n");
isused=mymalloc(vsize);
while(fg){
memcpy(isused,fg->av_out,vsize);
p=fg->end;
while(p){
if(p->z.flags&VAR){
i=p->z.v->index;
if(p->z.flags&DREFOBJ) i+=vcount-rcount;
if(!BTST(isused,i)&&!is_volatile_ic(p)&&!(disable&1)){
if(DEBUG&1024){printf("dead assignment deleted:\n");pric2(stdout,p);}
if(*p->z.v->identifier&&p->code!=ASSIGN){ err_ic=p;error(170,i>=vcount-rcount?"*":"",p->z.v->identifier);err_ic=0;}
if(p->code!=GETRETURN) changed=1;
if(p==fg->start){remove_IC_fg(fg,p);break;}
p=p->prev;remove_IC_fg(fg,p->next);
continue;
}
}
if(p->code!=SETRETURN&&p->code!=TEST&&p->code!=COMPARE&&(p->q1.flags&VAR)&&!BTST(isused,p->q1.v->index)&&(!(p->z.flags&VAR)||!p->z.v->reg||p->z.v->identifier)){
struct IC *m,*a;int f=p->q1.flags,dt=p->q1.dtyp;
p->q1.flags&=~DREFOBJ;
a=p->prev;if(a) m=a->prev; else m=0;
if(m&&a&&m->code==ASSIGN&&(a->q1.flags&(VAR|DREFOBJ))==VAR&&!compare_objs(&p->q1,&m->z,0)&&!compare_objs(&a->q1,&a->z,0)&&!compare_objs(&m->q1,&a->z,0)&&(a->q2.flags&KONST)&&!var_conflicts(a->q1.v,p)){
if(DEBUG&1024){
printf("reorder post-op(q1):\n");
pric2(stdout,m);pric2(stdout,a);pric(stdout,p);
}
p->q1=a->q1;
m->next=p;p->prev=m;
if(p->next) p->next->prev=a;
a->next=p->next;
a->prev=p;p->next=a;
if(fg->end==p) fg->end=a;
if(p==last_ic) last_ic=a;
remove_IC_fg(fg,m);
av_update(a,isused);
p->use_list=myrealloc(p->use_list,(p->use_cnt+a->use_cnt)*VLS);
memcpy(&p->use_list[p->use_cnt],a->use_list,a->use_cnt*VLS);
p->use_cnt+=a->use_cnt;
changed=1;
if((f&DREFOBJ)&&p->q1.v->index>=rcount)
ierror(0);
}
p->q1.flags=f;
p->q1.dtyp=dt;
}
if(p->code!=TEST&&p->code!=COMPARE&&(p->q2.flags&VAR)&&!BTST(isused,p->q2.v->index)&&(!(p->z.flags&VAR)||!p->z.v->reg||p->z.v->identifier)){
struct IC *m,*a;int f=p->q2.flags,dt=p->q2.dtyp;
p->q2.flags&=~DREFOBJ;
a=p->prev;if(a) m=a->prev; else m=0;
if(m&&a&&m->code==ASSIGN&&(a->q1.flags&(VAR|DREFOBJ))==VAR&&!compare_objs(&p->q2,&m->z,0)&&!compare_objs(&a->q1,&a->z,0)&&!compare_objs(&m->q1,&a->z,0)&&(a->q2.flags&KONST)&&!var_conflicts(a->q1.v,p)){
if(DEBUG&1024){
printf("reorder post-op(q2):\n");
pric2(stdout,m);pric2(stdout,a);pric(stdout,p);
}
p->q2=a->q1;
m->next=p;p->prev=m;
if(p->next) p->next->prev=a;
a->next=p->next;
a->prev=p;p->next=a;
if(fg->end==p) fg->end=a;
if(p==last_ic) last_ic=a;
remove_IC_fg(fg,m);
av_update(a,isused);
p->use_list=myrealloc(p->use_list,(p->use_cnt+a->use_cnt)*VLS);
memcpy(&p->use_list[p->use_cnt],a->use_list,a->use_cnt*VLS);
p->use_cnt+=a->use_cnt;
changed=1;
if((f&DREFOBJ)&&p->q2.v->index>=rcount)
ierror(0);
}
p->q2.flags=f;
p->q2.dtyp=dt;
}
if(p->code!=TEST&&p->code!=COMPARE&&(p->z.flags&(VAR|DREFOBJ))==(VAR|DREFOBJ)&&!BTST(isused,p->z.v->index)){
struct IC *m,*a;int f=p->z.flags,dt=p->z.dtyp;
p->z.flags&=~DREFOBJ;
a=p->prev;if(a) m=a->prev; else m=0;
if(m&&a&&m->code==ASSIGN&&(a->q1.flags&(VAR|DREFOBJ))==VAR&&!compare_objs(&p->z,&m->z,0)&&!compare_objs(&a->q1,&a->z,0)&&!compare_objs(&m->q1,&a->z,0)&&(a->q2.flags&KONST)&&!var_conflicts(a->q1.v,p)){
if(DEBUG&1024){
printf("reorder post-op(z):\n");
pric2(stdout,m);pric2(stdout,a);pric2(stdout,p);
printf("--");
}
p->z=a->q1;
m->next=p;p->prev=m;
if(p->next) p->next->prev=a;
a->next=p->next;
a->prev=p;p->next=a;
if(fg->end==p) fg->end=a;
if(p==last_ic) last_ic=a;
remove_IC_fg(fg,m);
av_update(a,isused);
p->use_list=myrealloc(p->use_list,(p->use_cnt+a->use_cnt)*VLS);
memcpy(&p->use_list[p->use_cnt],a->use_list,a->use_cnt*VLS);
p->use_cnt+=a->use_cnt;
changed=1;
if((f&DREFOBJ)&&p->z.v->index>=rcount)
ierror(0);
}
p->z.flags=f;
p->z.dtyp=dt;
}
av_update(p,isused);
if(p==fg->start) break;
p=p->prev;
}
fg=fg->normalout;
}
free(isused);
return(changed);
}