Browse Source

changed stackheight computation to top element size computation

eck 34 years ago
parent
commit
58355b7041
15 changed files with 291 additions and 59 deletions
  1. 25 25
      util/opt/Makefile
  2. 1 1
      util/opt/alloc.c
  3. 1 1
      util/opt/backward.c
  4. 1 1
      util/opt/flow.c
  5. 2 2
      util/opt/getline.c
  6. 1 1
      util/opt/lookup.c
  7. 1 1
      util/opt/main.c
  8. 1 1
      util/opt/peephole.c
  9. 9 9
      util/opt/process.c
  10. 1 1
      util/opt/putline.c
  11. 12 14
      util/opt/reg.c
  12. 214 0
      util/opt/tes.c
  13. 20 0
      util/opt/tes.h
  14. 1 1
      util/opt/util.c
  15. 1 1
      util/opt/var.c

+ 25 - 25
util/opt/Makefile

@@ -2,11 +2,11 @@
 
 EMHOME=../..
 CFILES=main.c getline.c lookup.c var.c process.c backward.c util.c \
-	alloc.c putline.c cleanup.c peephole.c flow.c reg.c shc.c \
+	alloc.c putline.c cleanup.c peephole.c flow.c reg.c tes.c \
 	pop_push.c
 
 OFILES=main.o getline.o lookup.o var.o process.o backward.o util.o\
-	alloc.o putline.o cleanup.o peephole.o flow.o shc.o pop_push.o
+	alloc.o putline.o cleanup.o peephole.o flow.o tes.o pop_push.o
 ONOGLOB=regnoglob.o
 OGLOB=regglob.o
 LIBS=$(EMHOME)/lib/em_data.a
@@ -98,7 +98,7 @@ regglob.o:	reg.c
 main.o: alloc.h
 main.o: ext.h
 main.o: param.h
-main.o: shc.h
+main.o: tes.h
 main.o: types.h
 getline.o: alloc.h
 getline.o: ext.h
@@ -106,18 +106,18 @@ getline.o: line.h
 getline.o: lookup.h
 getline.o: param.h
 getline.o: proinf.h
-getline.o: shc.h
+getline.o: tes.h
 getline.o: types.h
 lookup.o: alloc.h
 lookup.o: lookup.h
 lookup.o: param.h
 lookup.o: proinf.h
-lookup.o: shc.h
+lookup.o: tes.h
 lookup.o: types.h
 var.o: lookup.h
 var.o: param.h
 var.o: proinf.h
-var.o: shc.h
+var.o: tes.h
 var.o: types.h
 process.o: alloc.h
 process.o: assert.h
@@ -126,7 +126,7 @@ process.o: line.h
 process.o: lookup.h
 process.o: param.h
 process.o: proinf.h
-process.o: shc.h
+process.o: tes.h
 process.o: types.h
 backward.o: alloc.h
 backward.o: assert.h
@@ -135,7 +135,7 @@ backward.o: line.h
 backward.o: lookup.h
 backward.o: param.h
 backward.o: proinf.h
-backward.o: shc.h
+backward.o: tes.h
 backward.o: types.h
 util.o: assert.h
 util.o: ext.h
@@ -143,7 +143,7 @@ util.o: lookup.h
 util.o: optim.h
 util.o: param.h
 util.o: proinf.h
-util.o: shc.h
+util.o: tes.h
 util.o: types.h
 alloc.o: alloc.h
 alloc.o: assert.h
@@ -151,7 +151,7 @@ alloc.o: line.h
 alloc.o: lookup.h
 alloc.o: param.h
 alloc.o: proinf.h
-alloc.o: shc.h
+alloc.o: tes.h
 alloc.o: types.h
 putline.o: alloc.h
 putline.o: assert.h
@@ -161,7 +161,7 @@ putline.o: lookup.h
 putline.o: optim.h
 putline.o: param.h
 putline.o: proinf.h
-putline.o: shc.h
+putline.o: tes.h
 putline.o: types.h
 cleanup.o: assert.h
 cleanup.o: ext.h
@@ -177,7 +177,7 @@ peephole.o: optim.h
 peephole.o: param.h
 peephole.o: pattern.h
 peephole.o: proinf.h
-peephole.o: shc.h
+peephole.o: tes.h
 peephole.o: types.h
 flow.o: alloc.h
 flow.o: ext.h
@@ -185,7 +185,7 @@ flow.o: line.h
 flow.o: optim.h
 flow.o: param.h
 flow.o: proinf.h
-flow.o: shc.h
+flow.o: tes.h
 flow.o: types.h
 reg.o: alloc.h
 reg.o: assert.h
@@ -193,17 +193,17 @@ reg.o: ext.h
 reg.o: line.h
 reg.o: param.h
 reg.o: proinf.h
-reg.o: shc.h
+reg.o: tes.h
 reg.o: types.h
-shc.o: alloc.h
-shc.o: assert.h
-shc.o: ext.h
-shc.o: line.h
-shc.o: param.h
-shc.o: pop_push.h
-shc.o: proinf.h
-shc.o: shc.h
-shc.o: types.h
+tes.o: alloc.h
+tes.o: assert.h
+tes.o: ext.h
+tes.o: line.h
+tes.o: param.h
+tes.o: pop_push.h
+tes.o: proinf.h
+tes.o: tes.h
+tes.o: types.h
 pop_push.o: pop_push.h
 pattern.o: param.h
 pattern.o: pattern.h
@@ -214,7 +214,7 @@ regglob.o: ext.h
 regglob.o: line.h
 regglob.o: param.h
 regglob.o: proinf.h
-regglob.o: shc.h
+regglob.o: tes.h
 regglob.o: types.h
 regnoglob.o: alloc.h
 regnoglob.o: assert.h
@@ -222,5 +222,5 @@ regnoglob.o: ext.h
 regnoglob.o: line.h
 regnoglob.o: param.h
 regnoglob.o: proinf.h
-regnoglob.o: shc.h
+regnoglob.o: tes.h
 regnoglob.o: types.h

+ 1 - 1
util/opt/alloc.c

@@ -5,7 +5,7 @@ static char rcsid[] = "$Header$";
 #include <stdio.h>
 #include "param.h"
 #include "types.h"
-#include "shc.h"
+#include "tes.h"
 #include "assert.h"
 #include "alloc.h"
 #include "line.h"

+ 1 - 1
util/opt/backward.c

@@ -4,7 +4,7 @@ static char rcsid[] = "$Header$";
 
 #include "param.h"
 #include "types.h"
-#include "shc.h"
+#include "tes.h"
 #include "assert.h"
 #include "line.h"
 #include "lookup.h"

+ 1 - 1
util/opt/flow.c

@@ -4,7 +4,7 @@ static char rcsid[] = "$Header$";
 
 #include "param.h"
 #include "types.h"
-#include "shc.h"
+#include "tes.h"
 #include <em_flag.h>
 #include <em_spec.h>
 #include <em_mnem.h>

+ 2 - 2
util/opt/getline.c

@@ -5,7 +5,7 @@ static char rcsid[] = "$Header$";
 #include <stdio.h>
 #include "param.h"
 #include "types.h"
-#include "shc.h"
+#include "tes.h"
 #include "line.h"
 #include "lookup.h"
 #include "alloc.h"
@@ -468,7 +468,7 @@ int inpseudo(n) short n; {
 			lnp=newline(OPNO);
 			n=ps_exc;	/* kludge to force out this line */
 			break;
-		case ms_sth:
+		case ms_tes:
 			tstinpro();
 			oldline(lnp);
 			lnp=newline(OPNO);

+ 1 - 1
util/opt/lookup.c

@@ -4,7 +4,7 @@ static char rcsid[] = "$Header$";
 
 #include "param.h"
 #include "types.h"
-#include "shc.h"
+#include "tes.h"
 #include "lookup.h"
 #include "alloc.h"
 #include "proinf.h"

+ 1 - 1
util/opt/main.c

@@ -5,7 +5,7 @@ static char rcsid[] = "$Header$";
 #include <stdio.h>
 #include "param.h"
 #include "types.h"
-#include "shc.h"
+#include "tes.h"
 #include "alloc.h"
 #include <em_spec.h>
 #include "ext.h"

+ 1 - 1
util/opt/peephole.c

@@ -4,7 +4,7 @@ static char rcsid[] = "$Header$";
 
 #include "param.h"
 #include "types.h"
-#include "shc.h"
+#include "tes.h"
 #include "assert.h"
 #include "line.h"
 #include "lookup.h"

+ 9 - 9
util/opt/process.c

@@ -4,7 +4,7 @@ static char rcsid[] = "$Header$";
 
 #include "param.h"
 #include "types.h"
-#include "shc.h"
+#include "tes.h"
 #include "assert.h"
 #include <em_spec.h>
 #include <em_pseu.h>
@@ -42,10 +42,10 @@ process() {
 		    } while (madeopt && ++npasses < 5000);
 		    assert(!madeopt);
 		}
-		do_shc();		/* stackheight computation phase */
+		do_tes();		/* top elt. size computation phase */
 		outpro();		/* generate PRO pseudo */
 		outregs();		/* generate MES ms_reg pseudos */
-		outsth();		/* generate MES ms_sth pseudos */
+		outtes();		/* generate MES ms_tes pseudos */
 	}
 	putlines(pseudos);		/* pseudos first */
 	if (prodepth != 0) {
@@ -190,16 +190,16 @@ symvalue() {
 	}
 }
 
-do_shc()
+do_tes()
 {
 	register line_p insptr = instrs, oldlin = NULL;
 
 	init_state();
-	shc_pseudos();
+	tes_pseudos();
 	while (insptr != NULL) {
-	    insptr->l_prev = oldlin;
-	    oldlin = insptr;
-	    shc_instr(insptr);
-	    insptr = insptr->l_next;
+		insptr->l_prev = oldlin;
+		oldlin = insptr;
+		tes_instr(insptr);
+		insptr = insptr->l_next;
 	}
 }

+ 1 - 1
util/opt/putline.c

@@ -4,7 +4,7 @@ static char rcsid[] = "$Header$";
 
 #include "param.h"
 #include "types.h"
-#include "shc.h"
+#include "tes.h"
 #include "assert.h"
 #include <em_spec.h>
 #include <em_pseu.h>

+ 12 - 14
util/opt/reg.c

@@ -6,7 +6,7 @@ static char rcsid[] = "$Header$";
 #include "param.h"
 #include "types.h"
 #include "line.h"
-#include "shc.h"
+#include "tes.h"
 #include "proinf.h"
 #include "alloc.h"
 #include <em_spec.h>
@@ -78,22 +78,20 @@ outregs() {
 	curpro.freg = (reg_p) 0;
 }
 
-/* outsth() handles the output of the stackheight messages */
-outsth() {
+/* outtes() handles the output of the top elt. messages */
+outtes() {
 	register lblst_p lp = est_list;
 
-	if (state == NO_STACK_MES) return;
-
 	while(lp != NULL) {
-	    if ((lp->ll_height != 0) && !(lp->ll_num->n_flags & NUMCOND)) {
-		outinst(ps_mes);
-		outoff((offset)ms_sth);
-		outoff((offset)lp->ll_num->n_number);
-		outoff((offset)lp->ll_height);
-		outoff((offset)lp->ll_fallthrough);
-		outinst(sp_cend);
-	    }
-	    lp = lp->ll_next;
+		if ((lp->ll_size != 0) && !(lp->ll_num->n_flags & NUMCOND)) {
+			outinst(ps_mes);
+			outoff((offset)ms_tes);
+			outoff((offset)lp->ll_num->n_number);
+			outoff((offset)lp->ll_size);
+			outoff((offset)lp->ll_fallthrough);
+			outinst(sp_cend);
+		}
+		lp = lp->ll_next;
 	}
 }
 

+ 214 - 0
util/opt/tes.c

@@ -0,0 +1,214 @@
+#ifndef NORCSID
+static char rcsid[] = "$Header$";
+#endif
+/*
+ * This file contains the main part of the top element size computation phase. 
+ *
+ * Author: Hans van Eck. 
+ */
+
+#include <stdio.h>
+#include <em_spec.h>
+#include <em_mnem.h>
+#include <em_pseu.h>
+#include "param.h"
+#include "assert.h"
+#include "types.h"
+#include "tes.h"
+#include "alloc.h"
+#include "proinf.h"
+#include "line.h"
+#include "ext.h"
+#include "pop_push.h"
+
+extern char *pop_push[];
+extern char flow_tab[];
+
+#define NON_CONTINUABLE(i)	(flow_tab[i]&JUMP)
+#define ISABRANCH(i)		(flow_tab[i]&HASLABEL)
+#define ISCONDBRANCH(i)		(flow_tab[i]&CONDBRA)
+
+lblst_p est_list = NULL;
+
+#define INSTR(lnp)      (lnp->l_instr & BMASK)
+#define TYPE(lnp)       lnp->l_optyp
+#define PREV(lnp)       lnp->l_prev
+#define SHORT(lnp)      lnp->l_a.la_short
+#define MINI(lnp)	((lnp->l_optyp & BMASK) - Z_OPMINI)
+
+#define IS_MINI(lnp)	(lnp->l_optyp >= OPMINI)
+#define IS_LOC(l)	(l!=(line_p) 0 && INSTR(l)==op_loc && IS_MINI(l))
+
+int state;
+static int stacktop = 0;
+
+init_state()
+{
+	stacktop = 0;
+	state = KNOWN;
+	est_list = NULL;
+}
+
+tes_pseudos()
+{
+	register line_p lp;
+
+	for (lp = pseudos; lp != (line_p)0; lp = lp->l_next) {
+		switch(INSTR(lp)) {
+		case ps_con:
+		case ps_rom:
+			if (lp->l_optyp == OPLIST) {
+				register arg_p ap = lp->l_a.la_arg;
+
+				while (ap != (arg_p) 0) {
+					if (ap->a_typ == ARGNUM) {
+						assign_label(ap->a_a.a_np->n_repl);
+					}
+					ap = ap->a_next;
+				}
+			} else if (lp->l_optyp == OPNUMLAB)
+				assign_label(lp->l_a.la_np->n_repl);
+		}
+	}
+}
+
+tes_instr(lnp)
+line_p lnp;
+{
+	char *s;
+	register instr = INSTR(lnp);
+	register int arg, argdef;
+	line_p x = PREV(lnp);
+	line_p y = (x == (line_p) 0 ? (line_p) 0 : PREV(x));
+
+	if (instr == op_lab) {
+		do_inst_label(lnp);
+		return;
+	}
+	if (instr < sp_fmnem || instr > sp_lmnem) {
+		return;
+	}
+
+	if (state == NOTREACHED) return;	/* What else ? */
+	s = pop_push[instr];
+
+	if (*s != '0') {
+		while (*s != '\0') {
+			 if (*s++ == '-') {		/* ignores asp -4 */
+				stacktop = 0;
+				continue;
+			 }
+
+			if (TYPE(lnp) == OPSHORT) {
+				arg = SHORT(lnp);
+				if (arg < wordsize) arg = wordsize;
+				argdef = TRUE;
+			} else if (IS_MINI(lnp)) {
+				arg = MINI(lnp);
+				if (arg > 0 && arg < wordsize) arg = wordsize;
+				if (arg < 0 && -arg < wordsize) arg = -wordsize;
+				argdef = TRUE;
+			} else {
+				argdef = FALSE;
+			}
+			switch (*s++) {
+			case 'w': stacktop = wordsize; break;
+			case 'd': stacktop = wordsize * 2; break;
+			case 'p': stacktop = pointersize; break;
+			case 'a':
+				if (argdef == FALSE || instr == op_ass) {
+					stacktop = 0;
+				} else {
+					stacktop = arg;
+				}
+				break;
+			case 'x':
+				if (IS_LOC(x)) {
+					arg = MINI(x);
+					if (arg < wordsize) arg = wordsize;
+					stacktop = arg;
+				} else {
+					stacktop = 0;
+				}
+				break;
+			case 'y':
+				if (IS_LOC(y)) {
+					arg = MINI(y);
+					if (arg < wordsize) arg = wordsize;
+					stacktop = arg;
+				} else {
+					stacktop = 0;
+				}
+				break;
+			case '?':
+				stacktop = 0;
+				break;
+			default:
+				assert(FALSE);
+			}
+		}
+	}
+
+	if (stacktop < 0) stacktop = 0;
+
+	if (ISABRANCH(instr)) do_inst_label(lnp);
+	if (NON_CONTINUABLE(instr)) {
+		state = NOTREACHED;
+		stacktop = 0;
+	}
+}
+
+delete_labels()
+{
+	register lblst_p tmp;
+
+	while ((tmp = est_list) != NULL) {
+	    est_list = est_list->ll_next;
+	    oldlblst(tmp);
+	}
+}
+
+assign_label(label)
+num_p label;
+{
+	register lblst_p lst_elt;
+
+	if (label->n_flags & NUMSET) {
+		lst_elt = label->n_lst_elt;
+		if (state == NOTREACHED || stacktop > lst_elt->ll_size) {
+			stacktop = lst_elt->ll_size;
+		} else if ( stacktop < lst_elt->ll_size) {
+			lst_elt->ll_size = stacktop;
+		}
+	} else {
+		lst_elt = newlblst();
+		lst_elt->ll_next = est_list;
+		lst_elt->ll_num = label;
+		lst_elt->ll_size = stacktop;
+
+		est_list = lst_elt;
+
+		label->n_lst_elt = lst_elt;
+		label->n_flags |= NUMSET;
+	}
+}
+
+do_inst_label(lnp)	/* (re-)install a label */
+line_p lnp;
+{
+	num_p label = lnp->l_a.la_np->n_repl;
+	int instr = INSTR(lnp);
+
+	assign_label(label);
+
+	if (instr == op_lab) {
+		if (state == NOTREACHED)  {
+			label->n_lst_elt->ll_fallthrough = FALSE;
+		} else {
+			label->n_lst_elt->ll_fallthrough = TRUE;
+		}
+	} else if (ISCONDBRANCH(instr)) {	/* conditional branch */
+		label->n_flags |= NUMCOND;
+	}
+	state = KNOWN;
+}

+ 20 - 0
util/opt/tes.h

@@ -0,0 +1,20 @@
+/*
+ * Author: Hans van Eck. 
+ */
+/* $Header$ */
+
+typedef struct label_list *lblst_p;
+
+struct label_list {
+    lblst_p	ll_next;	/* pointer to next label in the list */
+    num_p	ll_num;		/* pointer to label definition */
+    short	ll_size;	/* size of the element on top at this label */
+    char	ll_fallthrough;	/* is the label reached by fallthrough ? */
+};
+
+typedef struct label_list lblst_t;
+
+extern lblst_p est_list;
+extern int state;
+#define	KNOWN		1
+#define	NOTREACHED	2

+ 1 - 1
util/opt/util.c

@@ -5,7 +5,7 @@ static char rcsid[] = "$Header$";
 #include <stdio.h>
 #include "param.h"
 #include "types.h"
-#include "shc.h"
+#include "tes.h"
 #include "assert.h"
 #include "lookup.h"
 #include "proinf.h"

+ 1 - 1
util/opt/var.c

@@ -5,7 +5,7 @@ static char rcsid[] = "$Header$";
 #include <stdio.h>
 #include "param.h"
 #include "types.h"
-#include "shc.h"
+#include "tes.h"
 #include "lookup.h"
 #include "proinf.h"