Added removal of dead code patterns
authorbruce <none@none>
Wed, 29 Jul 1987 16:10:27 +0000 (16:10 +0000)
committerbruce <none@none>
Wed, 29 Jul 1987 16:10:27 +0000 (16:10 +0000)
modules/src/em_opt/Makefile
modules/src/em_opt/main.c
modules/src/em_opt/outputdfa.c
modules/src/em_opt/patterns
modules/src/em_opt/pseudo.r

index 246829b..b867908 100644 (file)
@@ -1,5 +1,5 @@
 # $Header$
-EMHOME =       ../../..
+# EMHOME =     ../../..
 INSTALL =      $(EMHOME)/modules/install
 COMPARE =      $(EMHOME)/modules/compare
 LINT   =       lint
index 8e555f4..a3f7482 100644 (file)
@@ -61,21 +61,21 @@ main(argc,argv)
                                break;
                        }
                        break;
-               default:
-                       p->em_opcode = OTHER;
-                       /* fall thru */
-                       if (OO_state) {
-                               buff = *p;
-                               OO_dfa(OTHER);
-                               EM_mkcalls(&buff);
-                       }
-                       else {
-                               OO_flush();
+               case EM_PSEU:
+                       switch(p->em_opcode) {
+                       case ps_pro:
+                       case ps_end:
+                               break;
+                       default:
                                EM_mkcalls(p);
+                               OO_nxtpatt--;
+                               continue;
                        }
-                       continue;
-               case EM_PSEU:
                        break;
+               default:
+                       EM_mkcalls(p);
+                       OO_nxtpatt--;
+                       continue;
                case EM_EOF:
                        goto got_eof;
                case EM_ERROR:
index 0e5bb93..ca1a662 100644 (file)
@@ -195,7 +195,8 @@ outdfa()
        printf("Number of patterns: %d\n", numpatterns);
        printf("Longest pattern: %d\n", maxpattern);
        printf("Longest replacement: %d\n", maxreplacement);
-       printf("Dfa contains %d distinct state/opcode pairs\n", numentries);
+       printf("Dfa contains %d states and %d distinct state/opcode pairs\n",
+              higheststate+1,numentries);
        printf("Compacted using row displacement into %d entries\n",maxpos);
        /* output the arrays */
        fprintf(ofile,"struct dfa OO_checknext[] = {\n");
@@ -235,30 +236,131 @@ outmnems(l)
                fprintf(ofile,"%s ",l.m_elems[i-1]->op_code->id_text);
 }
 
+PRIVATE int
+sametest(s1,s2,e1,e2)
+       int s1,s2;
+       struct exp_node *e1,*e2;
+{
+       /* retrun 1 if tests are identical */
+       if(e1) {
+               if(!e2) return 0;
+               if(e1->node_type!=e2->node_type) return 0;
+               switch(e1->node_type) {
+               case LOGAND:
+               case LOGOR:
+               case BITAND:
+               case BITOR:
+               case XOR:
+               case MINUS:
+               case PLUS:
+               case TIMES:
+               case DIV:
+               case MOD:
+               case EQ:
+               case NE:
+               case LT:
+               case LE:
+               case GT:
+               case GE:
+               case LSHIFT:
+               case RSHIFT:
+               case COMMA:
+               case SAMESIGN:
+               case SFIT:
+               case UFIT:
+               case ROTATE:
+               case SAMEEXT:
+               case SAMENAM:
+                       return (sametest(e1->exp_left,e2->exp_left) &&
+                               sametest(e1->exp_right,e2->exp_right));
+               case NOT:
+               case COMP:
+               case UPLUS:
+               case UMINUS:
+                       return sametest(e1->exp_left,e2->exp_left);
+               case DEFINED:
+               case UNDEFINED:
+               case INT:
+                       return (e1->leaf_val == e2->leaf_val);
+               case PATARG:
+                        /* depends on pattern !! */
+                       if (e1->leaf_val != e2->leaf_val) return 0;
+                       return (patterns[s1].m_elems[e1->leaf_val-1]->
+                                  op_code->id_argfmt
+                            == patterns[s1].m_elems[e2->leaf_val-1]->
+                                  op_code->id_argfmt);
+               case PSIZE:
+               case WSIZE:
+                       return 1;
+
+               }
+       }
+       else return (e2==0);
+}
+
+PRIVATE int
+samerepl(s1,s2,r1,r2)
+       int s1,s2;
+       struct mnems r1,r2;
+{
+       /* return 1 if replacements are identical */
+       register int i;
+       register struct mnem_elem *m1,*m2;
+       if (r1.m_len != r2.m_len) return 0; /* different length */
+       for(i=0;i<r1.m_len;i++) {
+               m1=r1.m_elems[i];
+               m2=r2.m_elems[i];
+               if(m1->op_code!=m2->op_code) return 0;
+               if(!sametest(s1,s2,m1->arg,m2->arg)) return 0;
+       }
+       return 1;
+}
+
+PRIVATE int
+samecode(s1,s2)
+       int s1,s2;
+{
+       /* return 1 if replacement code of state s1 and s2 are identical */
+       register struct action *a1,*a2;
+       if (patterns[s1].m_len != patterns[s2].m_len) return 0;
+       a1 = actions[s1];
+       a2 = actions[s2];
+       while(a1) {
+               if(!a2) return 0; /* a2 is shorter */
+               if(!samerepl(s1,s2,a1->replacement,a2->replacement)) return 0;
+               if(!sametest(s1,s2,a1->test,a2->test)) return 0;
+               a1 = a1->next;
+               a2 = a2->next;
+       }
+       if(a2) return 0; /* a2 is longer */
+       return 1;
+}
+
 PRIVATE
 outdotrans()
 {
-       int s;
+       register int s,t;
        struct action *a;
        int seennontested;
+       int *farray;
        fprintf(ofile,"#include \"nopt.h\"\n\n");
-       /* declare all the trans functions */
-       for(s=0;s<=higheststate;s++) {
-               if(actions[s]!=(struct action *)NULL)
-                       fprintf(ofile,"static do%dtrans();\n",s);
-       }
-       /* output the array itself */
-       fprintf(ofile,"\nint (*OO_ftrans[])()=\n{\n");
-       for(s=0;s<=higheststate;s++) {
-               if(actions[s]!=(struct action *)NULL)
-                       fprintf(ofile,"\tdo%dtrans,\n",s);
-               else
-                       fprintf(ofile,"\t0,\n");
-       }
-       fprintf(ofile,"};\n\n");
-       /* now output the functions */
+       /* keep track of which procedure used for each state */
+       farray = (int *)Malloc((unsigned)(higheststate+1)*sizeof(int));
+       for(s=0;s<=higheststate;s++) farray[s] = EMPTY;
+       /* output the functions avoiding duplicates */
        for(s=0;s<=higheststate;s++) {
                if(actions[s]!=(struct action *)NULL) {
+                       /* first look for a previous identical function */
+                       for(t=0;t<s;t++) {
+                               if(actions[t]!=(struct action *)NULL &&
+                                  samecode(s,t)) {
+                                          /* use state 't' instead */
+                                          farray[s]=t;
+                                          goto next_func;
+                                  }
+                       }
+                       /* no identical function so make new one */
+                       farray[s] = s;
                        fprintf(ofile,"\nstatic do%dtrans() {\n",s);
                        fprintf(ofile,"\tregister p_instr patt = OO_patternqueue;\n");
                        fprintf(ofile,"\t/* ");
@@ -285,7 +387,18 @@ outdotrans()
                        }
                        fprintf(ofile,"}\n");
                }
+       next_func:
+               continue;
+       }
+       /* output the array itself */
+       fprintf(ofile,"\n\nint (*OO_ftrans[])()=\n{\n");
+       for(s=0;s<=higheststate;s++) {
+               if(farray[s]!=EMPTY)
+                       fprintf(ofile,"\tdo%dtrans,\n",farray[s]);
+               else
+                       fprintf(ofile,"\t0,\n");
        }
+       fprintf(ofile,"};\n");
 }
 
 PRIVATE
index 18f992e..74d6fee 100644 (file)
@@ -590,3 +590,137 @@ adp lol sti p  lol $2 loi p  adp -$1 ? p==w : dup p adp $1 lol $2 sti p
 adp ldl sti p  ldl $2 loi p  adp -$1 ? p==2*w : dup p adp $1 ldl $2 sti p
 adp loe sti p  loe $2 loi p  adp -$1 ? p==w : dup p adp $1 loe $2 sti p
 adp lde sti p  lde $2 loi p  adp -$1 ? p==2*w : dup p adp $1 lde $2 sti p
+/* dead code patterns */
+bra aar : bra $1
+bra adf : bra $1
+bra adi : bra $1
+bra adp : bra $1
+bra ads : bra $1
+bra adu : bra $1
+bra and : bra $1
+bra asp : bra $1
+bra ass : bra $1
+bra beq : bra $1
+bra bge : bra $1
+bra bgt : bra $1
+bra ble : bra $1
+bra blm : bra $1
+bra bls : bra $1
+bra blt : bra $1
+bra bne : bra $1
+bra bra : bra $1
+bra cai : bra $1
+bra cal : bra $1
+bra cff : bra $1
+bra cfi : bra $1
+bra cfu : bra $1
+bra cif : bra $1
+bra cii : bra $1
+bra ciu : bra $1
+bra cmf : bra $1
+bra cmi : bra $1
+bra cmp : bra $1
+bra cms : bra $1
+bra cmu : bra $1
+bra com : bra $1
+bra csa : bra $1
+bra csb : bra $1
+bra cuf : bra $1
+bra cui : bra $1
+bra cuu : bra $1
+bra dch : bra $1
+bra dec : bra $1
+bra dee : bra $1
+bra del : bra $1
+bra dup : bra $1
+bra dus : bra $1
+bra dvf : bra $1
+bra dvi : bra $1
+bra dvu : bra $1
+bra exg : bra $1
+bra fef : bra $1
+bra fif : bra $1
+bra fil : bra $1
+bra gto : bra $1
+bra inc : bra $1
+bra ine : bra $1
+bra inl : bra $1
+bra inn : bra $1
+bra ior : bra $1
+bra lae : bra $1
+bra lal : bra $1
+bra lar : bra $1
+bra ldc : bra $1
+bra lde : bra $1
+bra ldf : bra $1
+bra ldl : bra $1
+bra lfr : bra $1
+bra lil : bra $1
+bra lim : bra $1
+bra lin : bra $1
+bra lni : bra $1
+bra loc : bra $1
+bra loe : bra $1
+bra lof : bra $1
+bra loi : bra $1
+bra lol : bra $1
+bra lor : bra $1
+bra los : bra $1
+bra lpb : bra $1
+bra lpi : bra $1
+bra lxa : bra $1
+bra lxl : bra $1
+bra mlf : bra $1
+bra mli : bra $1
+bra mlu : bra $1
+bra mon : bra $1
+bra ngf : bra $1
+bra ngi : bra $1
+bra nop : bra $1
+bra rck : bra $1
+bra ret : bra $1
+bra rmi : bra $1
+bra rmu : bra $1
+bra rol : bra $1
+bra ror : bra $1
+bra rtt : bra $1
+bra sar : bra $1
+bra sbf : bra $1
+bra sbi : bra $1
+bra sbs : bra $1
+bra sbu : bra $1
+bra sde : bra $1
+bra sdf : bra $1
+bra sdl : bra $1
+bra set : bra $1
+bra sig : bra $1
+bra sil : bra $1
+bra sim : bra $1
+bra sli : bra $1
+bra slu : bra $1
+bra sri : bra $1
+bra sru : bra $1
+bra ste : bra $1
+bra stf : bra $1
+bra sti : bra $1
+bra stl : bra $1
+bra str : bra $1
+bra sts : bra $1
+bra teq : bra $1
+bra tge : bra $1
+bra tgt : bra $1
+bra tle : bra $1
+bra tlt : bra $1
+bra tne : bra $1
+bra trp : bra $1
+bra xor : bra $1
+bra zeq : bra $1
+bra zer : bra $1
+bra zge : bra $1
+bra zgt : bra $1
+bra zle : bra $1
+bra zlt : bra $1
+bra zne : bra $1
+bra zre : bra $1
+bra zrf : bra $1
+bra zrl : bra $1
index fecb834..9cc71ca 100644 (file)
@@ -1,9 +1,12 @@
-df_dlb | label:l       |
+insertpart     | int:id        |
        FLUSHDFA();
-       C_df_dlb(l);
-df_dnam        | char *:s      |
+       C_insertpart(id);
+beginpart      | int:id        |
        FLUSHDFA();
-       C_df_dnam(s);
+       C_beginpart(id);
+endpart        | int:id        |
+       FLUSHDFA();
+       C_endpart(id);
 pro    | char *:s arith:l      |
        FLUSHDFA();
        C_pro(s,l);
@@ -16,168 +19,111 @@ end       | arith:l       |
 end_narg       |       |
        FLUSHDFA();
        C_end_narg();
+df_dlb | label:l       |
+       C_df_dlb(l);
+df_dnam        | char *:s      |
+       C_df_dnam(s);
 exa_dnam       | char *:s      |
-       FLUSHDFA();
        C_exa_dnam(s);
 exa_dlb        | label:l       |
-       FLUSHDFA();
        C_exa_dlb(l);
 exp    | char *:s      |
-       FLUSHDFA();
        C_exp(s);
 ina_dnam       | char *:s      |
-       FLUSHDFA();
        C_ina_dnam(s);
 ina_dlb        | label:l       |
-       FLUSHDFA();
        C_ina_dlb(l);
 inp    | char *:s      |
-       FLUSHDFA();
        C_inp(s);
 bss_cst        | arith:n arith:w int:i |
-       FLUSHDFA();
        C_bss_cst(n,w,i);
 bss_icon       | arith:n char *:s arith:sz int:i       |
-       FLUSHDFA();
        C_bss_icon(n,s,sz,i);
 bss_ucon       | arith:n char *:s arith:sz int:i       |
-       FLUSHDFA();
        C_bss_ucon(n,s,sz,i);
 bss_fcon       | arith:n char *:s arith:sz int:i       |
-       FLUSHDFA();
        C_bss_fcon(n,s,sz,i);
 bss_dnam       | arith:n char *:s arith:offs int:i     |
-       FLUSHDFA();
        C_bss_dnam(n,s,offs,i);
 bss_dlb        | arith:n label:l arith:offs int:i      |
-       FLUSHDFA();
        C_bss_dlb(n,l,offs,i);
 bss_ilb        | arith:n label:l int:i |
-       FLUSHDFA();
        C_bss_ilb(n,l,i);
 bss_pnam       | arith:n char *:s int:i        |
-       FLUSHDFA();
        C_bss_pnam(n,s,i);
 hol_cst        | arith:n arith:w int:i |
-       FLUSHDFA();
        C_hol_cst(n,w,i);
 hol_icon       | arith:n char *:s arith:sz int:i       |
-       FLUSHDFA();
        C_hol_icon(n,s,sz,i);
 hol_ucon       | arith:n char *:s arith:sz int:i       |
-       FLUSHDFA();
        C_hol_ucon(n,s,sz,i);
 hol_fcon       | arith:n char *:s arith:sz int:i       |
-       FLUSHDFA();
        C_hol_fcon(n,s,sz,i);
 hol_dnam       | arith:n char *:s arith:offs int:i     |
-       FLUSHDFA();
        C_hol_dnam(n,s,offs,i);
 hol_dlb        | arith:n label:l arith:offs int:i      |
-       FLUSHDFA();
        C_hol_dlb(n,l,offs,i);
 hol_ilb        | arith:n label:l int:i |
-       FLUSHDFA();
        C_hol_ilb(n,l,i);
 hol_pnam       | arith:n char *:s int:i        |
-       FLUSHDFA();
        C_hol_pnam(n,s,i);
 con_cst        | arith:l       |
-       FLUSHDFA();
        C_con_cst(l);
 con_icon       | char *:val arith:siz  |
-       FLUSHDFA();
        C_con_icon(val,siz);
 con_ucon       | char *:val arith:siz  |
-       FLUSHDFA();
        C_con_ucon(val,siz);
 con_fcon       | char *:val arith:siz  |
-       FLUSHDFA();
        C_con_fcon(val,siz);
 con_scon       | char *:str arith:siz  |
-       FLUSHDFA();
        C_con_scon(str,siz);
 con_dnam       | char *:str arith:val  |
-       FLUSHDFA();
        C_con_dnam(str,val);
 con_dlb        | label:l arith:val     |
-       FLUSHDFA();
        C_con_dlb(l,val);
 con_ilb        | label:l       |
-       FLUSHDFA();
        C_con_ilb(l);
 con_pnam       | char *:str    |
-       FLUSHDFA();
        C_con_pnam(str);
 rom_cst        | arith:l       |
-       FLUSHDFA();
        C_rom_cst(l);
 rom_icon       | char *:val arith:siz  |
-       FLUSHDFA();
        C_rom_icon(val,siz);
 rom_ucon       | char *:val arith:siz  |
-       FLUSHDFA();
        C_rom_ucon(val,siz);
 rom_fcon       | char *:val arith:siz  |
-       FLUSHDFA();
        C_rom_fcon(val,siz);
 rom_scon       | char *:str arith:siz  |
-       FLUSHDFA();
        C_rom_scon(str,siz);
 rom_dnam       | char *:str arith:val  |
-       FLUSHDFA();
        C_rom_dnam(str,val);
 rom_dlb        | label:l arith:val     |
-       FLUSHDFA();
        C_rom_dlb(l,val);
 rom_ilb        | label:l       |
-       FLUSHDFA();
        C_rom_ilb(l);
 rom_pnam       | char *:str    |
-       FLUSHDFA();
        C_rom_pnam(str);
 cst    | arith:l       |
-       FLUSHDFA();
        C_cst(l);
 icon   | char *:val arith:siz  |
-       FLUSHDFA();
        C_icon(val,siz);
 ucon   | char *:val arith:siz  |
-       FLUSHDFA();
        C_ucon(val,siz);
 fcon   | char *:val arith:siz  |
-       FLUSHDFA();
        C_fcon(val,siz);
 scon   | char *:str arith:siz  |
-       FLUSHDFA();
        C_scon(str,siz);
 dnam   | char *:str arith:val  |
-       FLUSHDFA();
        C_dnam(str,val);
 dlb    | label:l arith:val     |
-       FLUSHDFA();
        C_dlb(l,val);
 ilb    | label:l       |
-       FLUSHDFA();
        C_ilb(l);
 pnam   | char *:str    |
-       FLUSHDFA();
        C_pnam(str);
 mes_begin      | int:ms        |
-       FLUSHDFA();
        C_mes_begin(ms);
 mes_end        |       |
-       FLUSHDFA();
        C_mes_end();
 exc    | arith:c1 arith:c2     |
-       FLUSHDFA();
        C_exc(c1,c2);
-insertpart     | int:id        |
-       FLUSHDFA();
-       C_insertpart(id);
-beginpart      | int:id        |
-       FLUSHDFA();
-       C_beginpart(id);
-endpart        | int:id        |
-       FLUSHDFA();
-       C_endpart(id);