2 static char rcsid[] = "$Id: flow.c,v 2.10 1994/06/24 10:40:00 ceriel Exp $";
18 * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
19 * See the copyright notice in the ACK home directory, in the file "Copyright".
21 * Author: Hans van Staveren
26 findreach(); /* determine reachable labels */
27 cleaninstrs(); /* throw away unreachable code */
31 register num_p *npp,np;
34 for(npp=curpro.numhash;npp< &curpro.numhash[NNUMHASH]; npp++)
35 for(np= *npp; np != (num_p) 0 ; np = np->n_next)
36 if (np->n_flags&NUMDATA) {
37 np->n_repl->n_flags |= NUMREACH;
38 np->n_repl->n_jumps++;
39 if (!(np->n_flags&NUMSCAN)) {
40 np->n_flags |= NUMSCAN;
42 reach(np->n_line->l_next);
45 if (!(np->n_repl->n_flags&NUMSCAN)) {
46 np->n_repl->n_flags |= NUMSCAN;
47 if (np->n_repl->n_line)
48 reach(np->n_repl->n_line->l_next);
54 reach(lnp) register line_p lnp; {
57 for (;lnp != (line_p) 0; lnp = lnp->l_next) {
58 if(lnp->l_optyp == OPNUMLAB) {
60 * Branch instruction or label
63 if ((lnp->l_instr&BMASK) != op_lab)
64 lnp->l_a.la_np = np = np->n_repl;
65 np->n_flags |= NUMREACH;
66 if (!(np->n_flags&NUMSCAN)) {
67 np->n_flags |= NUMSCAN;
69 reach(np->n_line->l_next);
72 np->n_flags |= NUMREACH;
73 if (!(np->n_flags & NUMSCAN)) {
74 np->n_flags |= NUMSCAN;
76 reach(np->n_line->l_next);
80 if ((lnp->l_instr&BMASK) == op_lab)
85 if ((lnp->l_instr & BMASK) > sp_lmnem) continue;
86 if ((em_flag[(lnp->l_instr&BMASK)-sp_fmnem]&EM_FLO)==FLO_T)
92 register line_p *lpp,lp,*lastbra;
93 bool reachable,superfluous;
96 lpp = &instrs; lastbra = (line_p *) 0; reachable = TRUE;
97 while ((lp = *lpp) != (line_p) 0) {
98 instr = lp->l_instr&BMASK;
99 if (instr == op_lab) {
100 if ((lp->l_a.la_np->n_flags&NUMREACH) != 0) {
102 if (lastbra != (line_p *) 0
103 && (*lastbra)->l_next == lp
104 && (*lastbra)->l_a.la_np->n_repl==lp->l_a.la_np) {
109 lastbra = (line_p *) 0;
110 lp->l_a.la_np->n_jumps--;
113 if ( lp->l_a.la_np->n_repl != lp->l_a.la_np ||
114 ((lp->l_a.la_np->n_flags&NUMDATA)==0 &&
115 lp->l_a.la_np->n_jumps == 0))
121 if ( (!reachable) || superfluous) {
122 if (instr == op_lab) {
123 lp->l_a.la_np->n_line = 0;
125 else if (instr > sp_lmnem) {
135 if ( instr <= sp_lmnem &&
136 (em_flag[instr-sp_fmnem]&EM_FLO)==FLO_T) {
138 if ((lp->l_instr&BMASK) == op_bra)