/* * substitute s for v in a * return failure to substitute */ int copysub(Adr *a, Adr *v, Adr *s, int f) { int t; if(copyas(a, v)) { t = s->type; if(t >= D_AX && t <= D_DI) { if(f) a->type = t; } return 0; } if(regtyp(v)) { t = v->type; if(a->type == t+D_INDIR) { if(s->type == D_BP && a->index != D_NONE) return 1; /* can't use BP-base with index */ if(f) a->type = s->type+D_INDIR; // return 0; } if(a->index == t) { if(f) a->index = s->type; return 0; } return 0; } return 0; }
/* * The idea is to remove redundant constants. * $c1->v1 * ($c1->v2 s/$c1/v1)* * set v1 return * The v1->v2 should be eliminated by copy propagation. */ void constprop(Adr *c1, Adr *v1, Reg *r) { Prog *p; if(debug['C']) print("constprop %D->%D\n", c1, v1); for(; r != R; r = r->s1) { p = r->prog; if(debug['C']) print("%P", p); if(uniqp(r) == R) { if(debug['C']) print("; merge; return\n"); return; } if(p->as == AMOVW && copyas(&p->from, c1)) { if(debug['C']) print("; sub%D/%D", &p->from, v1); p->from = *v1; } else if(copyu(p, v1, A) > 1) { if(debug['C']) print("; %Dset; return\n", v1); return; } if(debug['C']) print("\n"); if(r->s2) constprop(c1, v1, r->s2); } }
/* * either direct or indirect */ static int copyau(Adr *a, Adr *v) { if(copyas(a, v)) return 1; if(v->type == D_REG) { if(a->type == D_CONST && a->reg != NREG) { if(a->reg == v->reg) return 1; } else if(a->type == D_OREG) { if(a->reg == v->reg) return 1; } else if(a->type == D_REGREG || a->type == D_REGREG2) { if(a->reg == v->reg) return 1; if(a->offset == v->reg) return 1; } else if(a->type == D_SHIFT) { if((a->offset&0xf) == v->reg) return 1; if((a->offset&(1<<4)) && (a->offset>>8) == v->reg) return 1; } } return 0; }
/* * either direct or indirect */ int copyau(Adr *a, Adr *v) { if(copyas(a, v)) return 1; if(v->type == D_REG) if(a->type == D_OREG) if(v->reg == a->reg) return 1; return 0; }
/* * either direct or indirect */ int copyau(Adr *a, Adr *v) { if(copyas(a, v)) return 1; if(regtyp(v)) { if(a->type-D_INDIR == v->type) return 1; if(a->index == v->type) return 1; } return 0; }
/* * The idea is to remove redundant copies. * v1->v2 F=0 * (use v2 s/v2/v1/)* * set v1 F=1 * use v2 return fail * ----------------- * v1->v2 F=0 * (use v2 s/v2/v1/)* * set v1 F=1 * set v2 return success */ static int copyprop(Graph *g, Flow *r0) { Prog *p; Adr *v1, *v2; USED(g); p = r0->prog; v1 = &p->from; v2 = &p->to; if(copyas(v1, v2)) return 1; gactive++; return copy1(v1, v2, r0->s1, 0); }
/* * The idea is to remove redundant copies. * v1->v2 F=0 * (use v2 s/v2/v1/)* * set v1 F=1 * use v2 return fail * ----------------- * v1->v2 F=0 * (use v2 s/v2/v1/)* * set v1 F=1 * set v2 return success */ int copyprop(Reg *r0) { Prog *p; Adr *v1, *v2; Reg *r; p = r0->prog; v1 = &p->from; v2 = &p->to; if(copyas(v1, v2)) return 1; for(r=firstr; r!=R; r=r->link) r->active = 0; return copy1(v1, v2, r0->s1, 0); }
/* * The idea is to remove redundant copies. * v1->v2 F=0 * (use v2 s/v2/v1/)* * set v1 F=1 * use v2 return fail * ----------------- * v1->v2 F=0 * (use v2 s/v2/v1/)* * set v1 F=1 * set v2 return success */ int copyprop(Reg *r0) { Prog *p; Adr *v1, *v2; Reg *r; if(debug['P'] && debug['v']) print("copyprop %P\n", r0->prog); p = r0->prog; v1 = &p->from; v2 = &p->to; if(copyas(v1, v2)) return 1; for(r=firstr; r!=R; r=r->link) r->active = 0; return copy1(v1, v2, r0->s1, 0); }
/* * The idea is to remove redundant copies. * v1->v2 F=0 * (use v2 s/v2/v1/)* * set v1 F=1 * use v2 return fail * ----------------- * v1->v2 F=0 * (use v2 s/v2/v1/)* * set v1 F=1 * set v2 return success */ static int copyprop(Graph *g, Flow *r0) { Prog *p; Adr *v1, *v2; p = r0->prog; v1 = &p->from; v2 = &p->to; if(copyas(v1, v2)) return 1; if(nactive < g->num) { nactive = g->num; active = realloc(active, g->num); } memset(active, 0, g->num); return copy1(v1, v2, r0->s1, 0); }
/* * either direct or indirect */ int copyau(Adr *a, Adr *v) { if(copyas(a, v)) return 1; if(v->type == D_REG) { if(a->type == D_OREG) { if(v->reg == a->reg) return 1; } else if(a->type == D_SHIFT) { if((a->offset&0xf) == v->reg) return 1; if((a->offset&(1<<4)) && (a->offset>>8) == v->reg) return 1; } } return 0; }
/* * either direct or indirect */ int copyau(Adr *a, Adr *v) { if(copyas(a, v)) { if(debug['P'] && debug['v']) print("\tcopyau: copyas returned 1\n"); return 1; } if(regtyp(v)) { if(a->type-D_INDIR == v->type) { if(debug['P'] && debug['v']) print("\tcopyau: found indir use - return 1\n"); return 1; } if(a->index == v->type) { if(debug['P'] && debug['v']) print("\tcopyau: found index use - return 1\n"); return 1; } } return 0; }
/* * return * 1 if v only used (and substitute), * 2 if read-alter-rewrite * 3 if set * 4 if set and used * 0 otherwise (not touched) */ int copyu(Prog *p, Adr *v, Adr *s) { switch(p->as) { default: if(debug['P']) print("unknown op %A\n", p->as); /* SBBL; ADCL; FLD1; SAHF */ return 2; case ANEGB: case ANEGW: case ANEGL: case ANEGQ: case ANOTB: case ANOTW: case ANOTL: case ANOTQ: if(copyas(&p->to, v)) return 2; break; case ALEAL: /* lhs addr, rhs store */ case ALEAQ: if(copyas(&p->from, v)) return 2; case ANOP: /* rhs store */ case AMOVL: case AMOVQ: case AMOVBLSX: case AMOVBLZX: case AMOVBQSX: case AMOVBQZX: case AMOVLQSX: case AMOVLQZX: case AMOVWLSX: case AMOVWLZX: case AMOVWQSX: case AMOVWQZX: case AMOVQL: case AMOVSS: case AMOVSD: case ACVTSD2SL: case ACVTSD2SQ: case ACVTSD2SS: case ACVTSL2SD: case ACVTSL2SS: case ACVTSQ2SD: case ACVTSQ2SS: case ACVTSS2SD: case ACVTSS2SL: case ACVTSS2SQ: case ACVTTSD2SL: case ACVTTSD2SQ: case ACVTTSS2SL: case ACVTTSS2SQ: if(copyas(&p->to, v)) { if(s != A) return copysub(&p->from, v, s, 1); if(copyau(&p->from, v)) return 4; return 3; } goto caseread; case ARCLB: case ARCLL: case ARCLQ: case ARCLW: case ARCRB: case ARCRL: case ARCRQ: case ARCRW: case AROLB: case AROLL: case AROLQ: case AROLW: case ARORB: case ARORL: case ARORQ: case ARORW: case ASALB: case ASALL: case ASALQ: case ASALW: case ASARB: case ASARL: case ASARQ: case ASARW: case ASHLB: case ASHLL: case ASHLQ: case ASHLW: case ASHRB: case ASHRL: case ASHRQ: case ASHRW: if(copyas(&p->to, v)) return 2; if(copyas(&p->from, v)) if(p->from.type == D_CX) return 2; goto caseread; case AADDB: /* rhs rar */ case AADDL: case AADDQ: case AADDW: case AANDB: case AANDL: case AANDQ: case AANDW: case ADECL: case ADECQ: case ADECW: case AINCL: case AINCQ: case AINCW: case ASUBB: case ASUBL: case ASUBQ: case ASUBW: case AORB: case AORL: case AORQ: case AORW: case AXORB: case AXORL: case AXORQ: case AXORW: case AMOVB: case AMOVW: case AADDSD: case AADDSS: case ACMPSD: case ACMPSS: case ADIVSD: case ADIVSS: case AMAXSD: case AMAXSS: case AMINSD: case AMINSS: case AMULSD: case AMULSS: case ARCPSS: case ARSQRTSS: case ASQRTSD: case ASQRTSS: case ASUBSD: case ASUBSS: case AXORPD: if(copyas(&p->to, v)) return 2; goto caseread; case ACMPL: /* read only */ case ACMPW: case ACMPB: case ACMPQ: case ACOMISD: case ACOMISS: case AUCOMISD: case AUCOMISS: caseread: if(s != A) { if(copysub(&p->from, v, s, 1)) return 1; return copysub(&p->to, v, s, 1); } if(copyau(&p->from, v)) return 1; if(copyau(&p->to, v)) return 1; break; case AJGE: /* no reference */ case AJNE: case AJLE: case AJEQ: case AJHI: case AJLS: case AJMI: case AJPL: case AJGT: case AJLT: case AJCC: case AJCS: case AADJSP: case AWAIT: case ACLD: break; case AIMULL: case AIMULQ: case AIMULW: if(p->to.type != D_NONE) { if(copyas(&p->to, v)) return 2; goto caseread; } case ADIVB: case ADIVL: case ADIVQ: case ADIVW: case AIDIVB: case AIDIVL: case AIDIVQ: case AIDIVW: case AIMULB: case AMULB: case AMULL: case AMULQ: case AMULW: case ACWD: case ACDQ: case ACQO: if(v->type == D_AX || v->type == D_DX) return 2; goto caseread; case AREP: case AREPN: if(v->type == D_CX) return 2; goto caseread; case AMOVSB: case AMOVSL: case AMOVSQ: if(v->type == D_DI || v->type == D_SI) return 2; goto caseread; case ASTOSB: case ASTOSL: case ASTOSQ: if(v->type == D_AX || v->type == D_DI) return 2; goto caseread; case AJMP: /* funny */ if(s != A) { if(copysub(&p->to, v, s, 1)) return 1; return 0; } if(copyau(&p->to, v)) return 1; return 0; case ARET: /* funny */ if(s != A) return 1; return 3; case ACALL: /* funny */ if(REGEXT && v->type <= REGEXT && v->type > exregoffset) return 2; if(REGARG >= 0 && v->type == (uchar)REGARG) return 2; if(v->type == p->from.type) return 2; if(s != A) { if(copysub(&p->to, v, s, 1)) return 1; return 0; } if(copyau(&p->to, v)) return 4; return 3; case ATEXT: /* funny */ if(REGARG >= 0 && v->type == (uchar)REGARG) return 3; return 0; } return 0; }
/* * return * 1 if v only used (and substitute), * 2 if read-alter-rewrite * 3 if set * 4 if set and used * 0 otherwise (not touched) */ int copyu(Prog *p, Adr *v, Adr *s) { ProgInfo info; switch(p->as) { case AJMP: if(s != A) { if(copysub(&p->to, v, s, 1)) return 1; return 0; } if(copyau(&p->to, v)) return 1; return 0; case ARET: if(s != A) return 1; return 3; case ACALL: if(REGEXT && v->type <= REGEXT && v->type > exregoffset) return 2; if(REGARG >= 0 && v->type == (uchar)REGARG) return 2; if(v->type == p->from.type) return 2; if(s != A) { if(copysub(&p->to, v, s, 1)) return 1; return 0; } if(copyau(&p->to, v)) return 4; return 3; case ATEXT: if(REGARG >= 0 && v->type == (uchar)REGARG) return 3; return 0; } proginfo(&info, p); if((info.reguse|info.regset) & RtoB(v->type)) return 2; if(info.flags & LeftAddr) if(copyas(&p->from, v)) return 2; if((info.flags & (RightRead|RightWrite)) == (RightRead|RightWrite)) if(copyas(&p->to, v)) return 2; if(info.flags & RightWrite) { if(copyas(&p->to, v)) { if(s != A) return copysub(&p->from, v, s, 1); if(copyau(&p->from, v)) return 4; return 3; } } if(info.flags & (LeftAddr|LeftRead|LeftWrite|RightAddr|RightRead|RightWrite)) { if(s != A) { if(copysub(&p->from, v, s, 1)) return 1; return copysub(&p->to, v, s, 1); } if(copyau(&p->from, v)) return 1; if(copyau(&p->to, v)) return 1; } return 0; }
/* * return * 1 if v only used (and substitute), * 2 if read-alter-rewrite * 3 if set * 4 if set and used * 0 otherwise (not touched) */ int copyu(Prog *p, Adr *v, Adr *s) { switch(p->as) { default: if(debug['P']) print(" (???)"); return 2; case ANOP: /* read, write */ case AMOVW: case AMOVH: case AMOVHU: case AMOVB: case AMOVBU: case AFMOVF: case AFMOVD: case AFMOVDW: case AFMOVWD: case AFMOVFW: case AFMOVWF: case AFMOVFD: case AFMOVDF: if(s != A) { if(copysub(&p->from, v, s, 1)) return 1; if(!copyas(&p->to, v)) if(copysub(&p->to, v, s, 1)) return 1; return 0; } if(copyas(&p->to, v)) { if(copyau(&p->from, v)) return 4; return 3; } if(copyau(&p->from, v)) return 1; if(copyau(&p->to, v)) return 1; return 0; case AADD: /* read read write */ case ASUB: case ASLL: case ASRL: case ASRA: case AOR: case AAND: case AXOR: case AMUL: case ADIV: case ADIVL: case AMOD: case AMODL: case AFADDF: case AFADDD: case AFSUBF: case AFSUBD: case AFMULF: case AFMULD: case AFDIVF: case AFDIVD: if(s != A) { if(copysub(&p->from, v, s, 1)) return 1; if(copysub1(p, v, s, 1)) return 1; if(!copyas(&p->to, v)) if(copysub(&p->to, v, s, 1)) return 1; return 0; } if(copyas(&p->to, v)) { if(p->reg == NREG) p->reg = p->to.reg; if(copyau(&p->from, v)) return 4; if(copyau1(p, v)) return 4; return 3; } if(copyau(&p->from, v)) return 1; if(copyau1(p, v)) return 1; if(copyau(&p->to, v)) return 1; return 0; case ABA: /* no reference */ case ABCC: case ABCS: case ABE: case ABG: case ABGE: case ABGU: case ABL: case ABLE: case ABLEU: case ABN: case ABNE: case ABNEG: case ABPOS: case ABVC: case ABVS: case AFBA: case AFBE: case AFBG: case AFBGE: case AFBL: case AFBLE: case AFBNE: case AFBN: case AFBLG: case AFBO: case AFBU: case AFBUE: case AFBUG: case AFBUGE: case AFBUL: case AFBULE: break; case ACMP: /* read read */ case AFCMPD: case AFCMPF: if(s != A) { if(copysub(&p->from, v, s, 1)) return 1; return copysub(&p->to, v, s, 1); } if(copyau(&p->from, v)) return 1; if(copyau(&p->to, v)) return 1; break; case AJMP: /* funny */ if(s != A) { if(copysub(&p->to, v, s, 1)) return 1; return 0; } if(copyau(&p->to, v)) return 1; return 0; case ARETURN: /* funny */ if(v->type == D_REG) if(v->reg == REGRET) return 2; if(v->type == D_FREG) if(v->reg == FREGRET) return 2; case AJMPL: /* funny */ if(v->type == D_REG) { if(v->reg <= REGEXT && v->reg > exregoffset) return 2; if(v->reg == REGARG) return 2; } if(v->type == D_FREG) { if(v->reg <= FREGEXT && v->reg > exfregoffset) return 2; } if(s != A) { if(copysub(&p->to, v, s, 1)) return 1; return 0; } if(copyau(&p->to, v)) return 4; return 3; case ATEXT: /* funny */ if(v->type == D_REG) if(v->reg == REGARG) return 3; return 0; } return 0; }
/* * return * 1 if v only used (and substitute), * 2 if read-alter-rewrite * 3 if set * 4 if set and used * 0 otherwise (not touched) */ int copyu(Prog *p, Adr *v, Adr *s) { switch(p->as) { default: if(debug['P']) print(" (?)"); return 2; case AMOVM: if(v->type != D_REG) return 0; if(p->from.type == D_CONST) { /* read reglist, read/rar */ if(s != A) { if(p->from.offset&(1<<v->reg)) return 1; if(copysub(&p->to, v, s, 1)) return 1; return 0; } if(copyau(&p->to, v)) { if(p->scond&C_WBIT) return 2; return 1; } if(p->from.offset&(1<<v->reg)) return 1; } else { /* read/rar, write reglist */ if(s != A) { if(p->to.offset&(1<<v->reg)) return 1; if(copysub(&p->from, v, s, 1)) return 1; return 0; } if(copyau(&p->from, v)) { if(p->scond&C_WBIT) return 2; if(p->to.offset&(1<<v->reg)) return 4; return 1; } if(p->to.offset&(1<<v->reg)) return 3; } return 0; case ANOP: /* read, write */ case AMOVW: case AMOVF: case AMOVD: case AMOVH: case AMOVHU: case AMOVB: case AMOVBU: case AMOVDW: case AMOVWD: case AMOVFD: case AMOVDF: if(p->scond&(C_WBIT|C_PBIT)) if(v->type == D_REG) { if(p->from.type == D_OREG || p->from.type == D_SHIFT) { if(p->from.reg == v->reg) return 2; } else { if(p->to.reg == v->reg) return 2; } } if(s != A) { if(copysub(&p->from, v, s, 1)) return 1; if(!copyas(&p->to, v)) if(copysub(&p->to, v, s, 1)) return 1; return 0; } if(copyas(&p->to, v)) { if(copyau(&p->from, v)) return 4; return 3; } if(copyau(&p->from, v)) return 1; if(copyau(&p->to, v)) return 1; return 0; case AADD: /* read, read, write */ case ASUB: case ARSB: case ASLL: case ASRL: case ASRA: case AORR: case AAND: case AEOR: case AMUL: case ADIV: case ADIVU: case AADDF: case AADDD: case ASUBF: case ASUBD: case AMULF: case AMULD: case ADIVF: case ADIVD: case ACMPF: case ACMPD: case ACMP: case ACMN: case ACASE: if(s != A) { if(copysub(&p->from, v, s, 1)) return 1; if(copysub1(p, v, s, 1)) return 1; if(!copyas(&p->to, v)) if(copysub(&p->to, v, s, 1)) return 1; return 0; } if(copyas(&p->to, v)) { if(p->reg == NREG) p->reg = p->to.reg; if(copyau(&p->from, v)) return 4; if(copyau1(p, v)) return 4; return 3; } if(copyau(&p->from, v)) return 1; if(copyau1(p, v)) return 1; if(copyau(&p->to, v)) return 1; return 0; case ABEQ: /* read, read */ case ABNE: case ABCS: case ABHS: case ABCC: case ABLO: case ABMI: case ABPL: case ABVS: case ABVC: case ABHI: case ABLS: case ABGE: case ABLT: case ABGT: case ABLE: if(s != A) { if(copysub(&p->from, v, s, 1)) return 1; return copysub1(p, v, s, 1); } if(copyau(&p->from, v)) return 1; if(copyau1(p, v)) return 1; return 0; case AB: /* funny */ if(s != A) { if(copysub(&p->to, v, s, 1)) return 1; return 0; } if(copyau(&p->to, v)) return 1; return 0; case ARET: /* funny */ if(v->type == D_REG) if(v->reg == REGRET) return 2; if(v->type == D_FREG) if(v->reg == FREGRET) return 2; case ABL: /* funny */ if(v->type == D_REG) { if(v->reg <= REGEXT && v->reg > exregoffset) return 2; if(v->reg == REGARG) return 2; } if(v->type == D_FREG) if(v->reg <= FREGEXT && v->reg > exfregoffset) return 2; if(s != A) { if(copysub(&p->to, v, s, 1)) return 1; return 0; } if(copyau(&p->to, v)) return 4; return 3; case ATEXT: /* funny */ if(v->type == D_REG) if(v->reg == REGARG) return 3; return 0; } return 0; }
/* * return * 1 if v only used (and substitute), * 2 if read-alter-rewrite * 3 if set * 4 if set and used * 0 otherwise (not touched) */ int copyu(Prog *p, Adr *v, Adr *s) { switch(p->as) { default: print("copyu: can't find %A\n", p->as); return 2; case AMOVM: if(v->type != D_REG) return 0; if(p->from.type == D_CONST) { /* read reglist, read/rar */ if(s != A) { if(p->from.offset&(1<<v->reg)) return 1; if(copysub(&p->to, v, s, 1)) return 1; return 0; } if(copyau(&p->to, v)) { if(p->scond&C_WBIT) return 2; return 1; } if(p->from.offset&(1<<v->reg)) return 1; } else { /* read/rar, write reglist */ if(s != A) { if(p->to.offset&(1<<v->reg)) return 1; if(copysub(&p->from, v, s, 1)) return 1; return 0; } if(copyau(&p->from, v)) { if(p->scond&C_WBIT) return 2; if(p->to.offset&(1<<v->reg)) return 4; return 1; } if(p->to.offset&(1<<v->reg)) return 3; } return 0; case ANOP: /* read,, write */ case AMOVW: case AMOVF: case AMOVD: case AMOVH: case AMOVHS: case AMOVHU: case AMOVB: case AMOVBS: case AMOVBU: case AMOVFW: case AMOVWF: case AMOVDW: case AMOVWD: case AMOVFD: case AMOVDF: if(p->scond&(C_WBIT|C_PBIT)) if(v->type == D_REG) { if(p->from.type == D_OREG || p->from.type == D_SHIFT) { if(p->from.reg == v->reg) return 2; } else { if(p->to.reg == v->reg) return 2; } } if(s != A) { if(copysub(&p->from, v, s, 1)) return 1; if(!copyas(&p->to, v)) if(copysub(&p->to, v, s, 1)) return 1; return 0; } if(copyas(&p->to, v)) { if(p->scond != C_SCOND_NONE) return 2; if(copyau(&p->from, v)) return 4; return 3; } if(copyau(&p->from, v)) return 1; if(copyau(&p->to, v)) return 1; return 0; case AMULLU: /* read, read, write, write */ case AMULL: case AMULA: case AMVN: return 2; case AADD: /* read, read, write */ case AADC: case ASUB: case ASBC: case ARSB: case ASLL: case ASRL: case ASRA: case AORR: case AAND: case AEOR: case AMUL: case AMULU: case ADIV: case ADIVU: case AMOD: case AMODU: case AADDF: case AADDD: case ASUBF: case ASUBD: case AMULF: case AMULD: case ADIVF: case ADIVD: case ACHECKNIL: /* read */ case ACMPF: /* read, read, */ case ACMPD: case ACMP: case ACMN: case ACASE: case ATST: /* read,, */ if(s != A) { if(copysub(&p->from, v, s, 1)) return 1; if(copysub1(p, v, s, 1)) return 1; if(!copyas(&p->to, v)) if(copysub(&p->to, v, s, 1)) return 1; return 0; } if(copyas(&p->to, v)) { if(p->scond != C_SCOND_NONE) return 2; if(p->reg == NREG) p->reg = p->to.reg; if(copyau(&p->from, v)) return 4; if(copyau1(p, v)) return 4; return 3; } if(copyau(&p->from, v)) return 1; if(copyau1(p, v)) return 1; if(copyau(&p->to, v)) return 1; return 0; case ABEQ: /* read, read */ case ABNE: case ABCS: case ABHS: case ABCC: case ABLO: case ABMI: case ABPL: case ABVS: case ABVC: case ABHI: case ABLS: case ABGE: case ABLT: case ABGT: case ABLE: if(s != A) { if(copysub(&p->from, v, s, 1)) return 1; return copysub1(p, v, s, 1); } if(copyau(&p->from, v)) return 1; if(copyau1(p, v)) return 1; return 0; case AB: /* funny */ if(s != A) { if(copysub(&p->to, v, s, 1)) return 1; return 0; } if(copyau(&p->to, v)) return 1; return 0; case ARET: /* funny */ if(s != A) return 1; return 3; case ABL: /* funny */ if(v->type == D_REG) { if(v->reg <= REGEXT && v->reg > exregoffset) return 2; if(v->reg == (uchar)REGARG) return 2; } if(v->type == D_FREG) if(v->reg <= FREGEXT && v->reg > exfregoffset) return 2; if(p->from.type == D_REG && v->type == D_REG && p->from.reg == v->reg) return 2; if(s != A) { if(copysub(&p->to, v, s, 1)) return 1; return 0; } if(copyau(&p->to, v)) return 4; return 3; case ATEXT: /* funny */ if(v->type == D_REG) if(v->reg == (uchar)REGARG) return 3; return 0; case APCDATA: case AFUNCDATA: return 0; } }
/* * return * 1 if v only used (and substitute), * 2 if read-alter-rewrite * 3 if set * 4 if set and used * 0 otherwise (not touched) */ int copyu(Prog *p, Adr *v, Adr *s) { switch(p->as) { default: if(debug['P']) print("unknown op %A\n", p->as); return 2; case ANEGB: case ANEGW: case ANEGL: case ANOTB: case ANOTW: case ANOTL: if(copyas(&p->to, v)) return 2; break; case ALEAL: /* lhs addr, rhs store */ if(copyas(&p->from, v)) return 2; case ANOP: /* rhs store */ case AMOVL: case AMOVBLSX: case AMOVBLZX: case AMOVWLSX: case AMOVWLZX: if(copyas(&p->to, v)) { if(s != A) return copysub(&p->from, v, s, 1); if(copyau(&p->from, v)) return 4; return 3; } goto caseread; case AROLB: case AROLL: case AROLW: case ARORB: case ARORL: case ARORW: case ASALB: case ASALL: case ASALW: case ASARB: case ASARL: case ASARW: case ASHLB: case ASHLL: case ASHLW: case ASHRB: case ASHRL: case ASHRW: if(copyas(&p->to, v)) return 2; if(copyas(&p->from, v)) if(p->from.type == D_CX) return 2; goto caseread; case AADDB: /* rhs rar */ case AADDL: case AADDW: case AANDB: case AANDL: case AANDW: case ADECL: case ADECW: case AINCL: case AINCW: case ASUBB: case ASUBL: case ASUBW: case AORB: case AORL: case AORW: case AXORB: case AXORL: case AXORW: case AMOVB: case AMOVW: case AFMOVB: case AFMOVBP: case AFMOVD: case AFMOVDP: case AFMOVF: case AFMOVFP: case AFMOVL: case AFMOVLP: case AFMOVV: case AFMOVVP: case AFMOVW: case AFMOVWP: case AFMOVX: case AFMOVXP: case AFADDDP: case AFADDW: case AFADDL: case AFADDF: case AFADDD: case AFMULDP: case AFMULW: case AFMULL: case AFMULF: case AFMULD: case AFSUBDP: case AFSUBW: case AFSUBL: case AFSUBF: case AFSUBD: case AFSUBRDP: case AFSUBRW: case AFSUBRL: case AFSUBRF: case AFSUBRD: case AFDIVDP: case AFDIVW: case AFDIVL: case AFDIVF: case AFDIVD: case AFDIVRDP: case AFDIVRW: case AFDIVRL: case AFDIVRF: case AFDIVRD: if(copyas(&p->to, v)) return 2; goto caseread; case ACMPL: /* read only */ case ACMPW: case ACMPB: case APREFETCHT0: case APREFETCHT1: case APREFETCHT2: case APREFETCHNTA: case AFCOMB: case AFCOMBP: case AFCOMD: case AFCOMDP: case AFCOMDPP: case AFCOMF: case AFCOMFP: case AFCOML: case AFCOMLP: case AFCOMW: case AFCOMWP: case AFUCOM: case AFUCOMP: case AFUCOMPP: caseread: if(s != A) { if(copysub(&p->from, v, s, 1)) return 1; return copysub(&p->to, v, s, 1); } if(copyau(&p->from, v)) return 1; if(copyau(&p->to, v)) return 1; break; case AJGE: /* no reference */ case AJNE: case AJLE: case AJEQ: case AJHI: case AJLS: case AJMI: case AJPL: case AJGT: case AJLT: case AJCC: case AJCS: case AADJSP: case AFLDZ: case AWAIT: break; case AIMULL: case AIMULW: if(p->to.type != D_NONE) { if(copyas(&p->to, v)) return 2; goto caseread; } case ADIVB: case ADIVL: case ADIVW: case AIDIVB: case AIDIVL: case AIDIVW: case AIMULB: case AMULB: case AMULL: case AMULW: case ACWD: case ACDQ: if(v->type == D_AX || v->type == D_DX) return 2; goto caseread; case AREP: case AREPN: if(v->type == D_CX) return 2; goto caseread; case AMOVSB: case AMOVSL: if(v->type == D_DI || v->type == D_SI) return 2; goto caseread; case ASTOSB: case ASTOSL: if(v->type == D_AX || v->type == D_DI) return 2; goto caseread; case AFSTSW: if(v->type == D_AX) return 2; goto caseread; case AJMP: /* funny */ if(s != A) { if(copysub(&p->to, v, s, 1)) return 1; return 0; } if(copyau(&p->to, v)) return 1; return 0; case ARET: /* funny */ if(v->type == REGRET) return 2; if(s != A) return 1; return 3; case ACALL: /* funny */ if(REGARG >= 0 && v->type == (uchar)REGARG) return 2; if(s != A) { if(copysub(&p->to, v, s, 1)) return 1; return 0; } if(copyau(&p->to, v)) return 4; return 3; } return 0; }
/* * return * 1 if v only used (and substitute), * 2 if read-alter-rewrite * 3 if set * 4 if set and used * 0 otherwise (not touched) */ int copyu(Prog *p, Adr *v, Adr *s) { switch(p->as) { default: if(debug['P']) print(" (?)"); return 2; case ANOP: /* read, write */ case AMOVW: case AMOVH: case AMOVHZ: case AMOVB: case AMOVBZ: case ANEG: case ANEGCC: case AFCTIW: case AFCTIWZ: case AFMOVS: case AFMOVD: case AFRSP: case AFNEG: case AFNEGCC: if(s != A) { if(copysub(&p->from, v, s, 1)) return 1; if(!copyas(&p->to, v)) if(copysub(&p->to, v, s, 1)) return 1; return 0; } if(copyas(&p->to, v)) { if(copyau(&p->from, v)) return 4; return 3; } if(copyau(&p->from, v)) return 1; if(copyau(&p->to, v)) return 1; return 0; case AADD: /* read read write */ case ASUB: case ASLW: case ASRW: case ASRAW: case AOR: case AORCC: case AORN: case AORNCC: case AAND: case AANDCC: case AANDN: case AANDNCC: case ANAND: case ANANDCC: case ANOR: case ANORCC: case AXOR: case AMULLW: case ADIVW: case ADIVWU: case AREM: case AREMU: case AFADDS: case AFADD: case AFSUBS: case AFSUB: case AFMULS: case AFMUL: case AFDIVS: case AFDIV: if(s != A) { if(copysub(&p->from, v, s, 1)) return 1; if(copysub1(p, v, s, 1)) return 1; if(!copyas(&p->to, v)) if(copysub(&p->to, v, s, 1)) return 1; return 0; } if(copyas(&p->to, v)) { if(p->reg == NREG) p->reg = p->to.reg; if(copyau(&p->from, v)) return 4; if(copyau1(p, v)) return 4; return 3; } if(copyau(&p->from, v)) return 1; if(copyau1(p, v)) return 1; if(copyau(&p->to, v)) return 1; return 0; case ABEQ: case ABGT: case ABGE: case ABLT: case ABLE: case ABNE: case ABVC: case ABVS: break; case ACMP: /* read read */ case ACMPU: case AFCMPO: case AFCMPU: if(s != A) { if(copysub(&p->from, v, s, 1)) return 1; return copysub(&p->to, v, s, 1); } if(copyau(&p->from, v)) return 1; if(copyau(&p->to, v)) return 1; break; case ABR: /* funny */ if(s != A) { if(copysub(&p->to, v, s, 1)) return 1; return 0; } if(copyau(&p->to, v)) return 1; return 0; case ARETURN: /* funny */ if(v->type == D_REG) if(v->reg == REGRET) return 2; if(v->type == D_FREG) if(v->reg == FREGRET) return 2; case ABL: /* funny */ if(v->type == D_REG) { if(v->reg <= REGEXT && v->reg > exregoffset) return 2; if(v->reg == REGARG) return 2; } if(v->type == D_FREG) { if(v->reg <= FREGEXT && v->reg > exfregoffset) return 2; } if(s != A) { if(copysub(&p->to, v, s, 1)) return 1; return 0; } if(copyau(&p->to, v)) return 4; return 3; case ATEXT: /* funny */ if(v->type == D_REG) if(v->reg == REGARG) return 3; return 0; } return 0; }
/* * return * 1 if v only used (and substitute), * 2 if read-alter-rewrite * 3 if set * 4 if set and used * 0 otherwise (not touched) */ int copyu(Prog *p, Adr *v, Adr *s) { switch(p->as) { default: if(debug['P']) print(" (?)"); return 2; case ANOP: /* read, write */ case AMOVW: case AMOVF: case AMOVD: case AMOVH: case AMOVHU: case AMOVB: case AMOVBU: case AMOVDW: case AMOVWD: case AMOVFD: case AMOVDF: if(s != A) { if(copysub(&p->from, v, s, 1)) return 1; if(!copyas(&p->to, v)) if(copysub(&p->to, v, s, 1)) return 1; return 0; } if(copyas(&p->to, v)) { if(copyau(&p->from, v)) return 4; return 3; } if(copyau(&p->from, v)) return 1; if(copyau(&p->to, v)) return 1; return 0; case ASGT: /* read, read, write */ case ASGTU: case AADD: case AADDU: case ASUB: case ASUBU: case ASLL: case ASRL: case ASRA: case AOR: case ANOR: case AAND: case AXOR: case AMUL: case AMULU: case ADIV: case ADIVU: case AADDF: case AADDD: case ASUBF: case ASUBD: case AMULF: case AMULD: case ADIVF: case ADIVD: if(s != A) { if(copysub(&p->from, v, s, 1)) return 1; if(copysub1(p, v, s, 1)) return 1; if(!copyas(&p->to, v)) if(copysub(&p->to, v, s, 1)) return 1; return 0; } if(copyas(&p->to, v)) { if(p->reg == NREG) p->reg = p->to.reg; if(copyau(&p->from, v)) return 4; if(copyau1(p, v)) return 4; return 3; } if(copyau(&p->from, v)) return 1; if(copyau1(p, v)) return 1; if(copyau(&p->to, v)) return 1; return 0; case ABEQ: /* read, read */ case ABNE: case ABGTZ: case ABGEZ: case ABLTZ: case ABLEZ: case ACMPEQD: case ACMPEQF: case ACMPGED: case ACMPGEF: case ACMPGTD: case ACMPGTF: case ABFPF: case ABFPT: if(s != A) { if(copysub(&p->from, v, s, 1)) return 1; return copysub1(p, v, s, 1); } if(copyau(&p->from, v)) return 1; if(copyau1(p, v)) return 1; return 0; case AJMP: /* funny */ if(s != A) { if(copysub(&p->to, v, s, 1)) return 1; return 0; } if(copyau(&p->to, v)) return 1; return 0; case ARET: /* funny */ if(v->type == D_REG) if(v->reg == REGRET) return 2; if(v->type == D_FREG) if(v->reg == FREGRET) return 2; case AJAL: /* funny */ if(v->type == D_REG) { if(v->reg <= REGEXT && v->reg > exregoffset) return 2; if(REGARG && v->reg == REGARG) return 2; } if(v->type == D_FREG) if(v->reg <= FREGEXT && v->reg > exfregoffset) return 2; if(s != A) { if(copysub(&p->to, v, s, 1)) return 1; return 0; } if(copyau(&p->to, v)) return 4; return 3; case ATEXT: /* funny */ if(v->type == D_REG) if(v->reg == REGARG) return 3; return 0; } }