Initial revision
authorbal <none@none>
Mon, 26 Nov 1984 14:07:17 +0000 (14:07 +0000)
committerbal <none@none>
Mon, 26 Nov 1984 14:07:17 +0000 (14:07 +0000)
util/ego/cs/Makefile [new file with mode: 0644]
util/ego/cs/cs.c [new file with mode: 0644]
util/ego/cs/cs_getent.h [new file with mode: 0644]

diff --git a/util/ego/cs/Makefile b/util/ego/cs/Makefile
new file mode 100644 (file)
index 0000000..294efce
--- /dev/null
@@ -0,0 +1,175 @@
+# CPPFLAGS=-DVERBOSE -DTRACE
+CPPFLAGS=-DVERBOSE
+CFLAGS=-O $(CPPFLAGS)
+LDFLAGS=-i
+LINTFLAGS=-phbac $(CPPFLAGS)
+
+EMH=../../../h
+EMLIB=../../../lib
+SHR=../share
+
+CFILES=\
+cs.c cs_alloc.c cs_aux.c cs_avail.c cs_debug.c cs_elim.c \
+cs_entity.c cs_kill.c cs_partit.c cs_profit.c cs_getent.c \
+cs_stack.c cs_vnm.c
+
+OFILES=\
+cs.o cs_alloc.o cs_aux.o cs_avail.o cs_debug.o cs_elim.o \
+cs_entity.o cs_kill.o cs_partit.o cs_profit.o cs_getent.o \
+cs_stack.o cs_vnm.o
+
+HFILES=\
+cs.h cs_alloc.h cs_aux.h cs_avail.h cs_debug.h cs_elim.h \
+cs_entity.h cs_kill.h cs_partit.h cs_profit.h cs_getent.h \
+cs_stack.h cs_vnm.h
+
+PRFILES=\
+$(CFILES) $(HFILES) Makefile
+
+SHARE_OFILES=\
+$(SHR)/get.o $(SHR)/put.o $(SHR)/alloc.o $(SHR)/global.o $(SHR)/debug.o\
+$(SHR)/files.o $(SHR)/map.o $(SHR)/lset.o $(SHR)/cset.o $(SHR)/aux.o\
+$(SHR)/go.o
+
+cs:    $(OFILES)
+       $(CC) -o cs $(LDFLAGS) $(OFILES) $(SHARE_OFILES) $(EMLIB)/em_data.a
+
+lint:
+       lint $(LINTFLAGS) $(CFILES)
+
+pr:    $(PRFILES)
+       @pr $?
+       @touch pr
+
+depend:
+       $(SHR)/makedepend
+
+# the next lines are generated automatically
+# AUTOAUTOAUTOAUTOAUTOAUTO
+cs.o:  ../share/debug.h
+cs.o:  ../share/go.h
+cs.o:  ../share/types.h
+cs.o:  cs.h
+cs.o:  cs_aux.h
+cs.o:  cs_avail.h
+cs.o:  cs_debug.h
+cs.o:  cs_elim.h
+cs.o:  cs_entity.h
+cs.o:  cs_profit.h
+cs.o:  cs_stack.h
+cs.o:  cs_vnm.h
+cs_alloc.o:    ../share/alloc.h
+cs_alloc.o:    ../share/types.h
+cs_alloc.o:    cs.h
+cs_aux.o:      ../share/aux.h
+cs_aux.o:      ../share/debug.h
+cs_aux.o:      ../share/global.h
+cs_aux.o:      ../share/lset.h
+cs_aux.o:      ../share/types.h
+cs_aux.o:      cs.h
+cs_aux.o:      cs_entity.h
+cs_avail.o:    ../../../h/em_mnem.h
+cs_avail.o:    ../share/aux.h
+cs_avail.o:    ../share/debug.h
+cs_avail.o:    ../share/global.h
+cs_avail.o:    ../share/lset.h
+cs_avail.o:    ../share/types.h
+cs_avail.o:    cs.h
+cs_avail.o:    cs_alloc.h
+cs_avail.o:    cs_aux.h
+cs_avail.o:    cs_getent.h
+cs_debug.o:    ../../../h/em_spec.h
+cs_debug.o:    ../share/debug.h
+cs_debug.o:    ../share/lset.h
+cs_debug.o:    ../share/types.h
+cs_debug.o:    cs.h
+cs_debug.o:    cs_aux.h
+cs_debug.o:    cs_avail.h
+cs_debug.o:    cs_entity.h
+cs_elim.o:     ../../../h/em_mnem.h
+cs_elim.o:     ../../../h/em_reg.h
+cs_elim.o:     ../share/alloc.h
+cs_elim.o:     ../share/aux.h
+cs_elim.o:     ../share/debug.h
+cs_elim.o:     ../share/global.h
+cs_elim.o:     ../share/lset.h
+cs_elim.o:     ../share/types.h
+cs_elim.o:     cs.h
+cs_elim.o:     cs_alloc.h
+cs_elim.o:     cs_aux.h
+cs_elim.o:     cs_avail.h
+cs_elim.o:     cs_debug.h
+cs_elim.o:     cs_partit.h
+cs_elim.o:     cs_profit.h
+cs_entity.o:   ../share/debug.h
+cs_entity.o:   ../share/global.h
+cs_entity.o:   ../share/lset.h
+cs_entity.o:   ../share/types.h
+cs_entity.o:   cs.h
+cs_entity.o:   cs_aux.h
+cs_getent.o:   ../../../h/em_mnem.h
+cs_getent.o:   ../share/aux.h
+cs_getent.o:   ../share/debug.h
+cs_getent.o:   ../share/global.h
+cs_getent.o:   ../share/types.h
+cs_getent.o:   cs.h
+cs_getent.o:   cs_aux.h
+cs_getent.o:   cs_entity.h
+cs_getent.o:   cs_stack.h
+cs_kill.o:     ../../../h/em_mnem.h
+cs_kill.o:     ../share/aux.h
+cs_kill.o:     ../share/cset.h
+cs_kill.o:     ../share/debug.h
+cs_kill.o:     ../share/global.h
+cs_kill.o:     ../share/lset.h
+cs_kill.o:     ../share/types.h
+cs_kill.o:     cs.h
+cs_kill.o:     cs_aux.h
+cs_kill.o:     cs_avail.h
+cs_kill.o:     cs_debug.h
+cs_kill.o:     cs_entity.h
+cs_partit.o:   ../../../h/em_mnem.h
+cs_partit.o:   ../../../h/em_pseu.h
+cs_partit.o:   ../../../h/em_reg.h
+cs_partit.o:   ../../../h/em_spec.h
+cs_partit.o:   ../share/aux.h
+cs_partit.o:   ../share/debug.h
+cs_partit.o:   ../share/global.h
+cs_partit.o:   ../share/types.h
+cs_partit.o:   cs.h
+cs_partit.o:   cs_stack.h
+cs_profit.o:   ../../../h/em_mnem.h
+cs_profit.o:   ../../../h/em_spec.h
+cs_profit.o:   ../share/aux.h
+cs_profit.o:   ../share/cset.h
+cs_profit.o:   ../share/debug.h
+cs_profit.o:   ../share/global.h
+cs_profit.o:   ../share/lset.h
+cs_profit.o:   ../share/types.h
+cs_profit.o:   cs.h
+cs_profit.o:   cs_aux.h
+cs_profit.o:   cs_avail.h
+cs_profit.o:   cs_partit.h
+cs_stack.o:    ../share/aux.h
+cs_stack.o:    ../share/debug.h
+cs_stack.o:    ../share/global.h
+cs_stack.o:    ../share/types.h
+cs_stack.o:    cs.h
+cs_stack.o:    cs_aux.h
+cs_valno.o:    ../share/debug.h
+cs_valno.o:    ../share/types.h
+cs_valno.o:    cs.h
+cs_vnm.o:      ../../../h/em_mnem.h
+cs_vnm.o:      ../share/aux.h
+cs_vnm.o:      ../share/debug.h
+cs_vnm.o:      ../share/global.h
+cs_vnm.o:      ../share/types.h
+cs_vnm.o:      cs.h
+cs_vnm.o:      cs_alloc.h
+cs_vnm.o:      cs_aux.h
+cs_vnm.o:      cs_avail.h
+cs_vnm.o:      cs_entity.h
+cs_vnm.o:      cs_getent.h
+cs_vnm.o:      cs_kill.h
+cs_vnm.o:      cs_partit.h
+cs_vnm.o:      cs_stack.h
diff --git a/util/ego/cs/cs.c b/util/ego/cs/cs.c
new file mode 100644 (file)
index 0000000..502e143
--- /dev/null
@@ -0,0 +1,75 @@
+/* C O M M O N   S U B E X P R E S S I O N   E L I M I N A T I O N */
+
+
+#include <stdio.h>
+#include "../share/types.h"
+#include "../share/lset.h"
+#include "../share/debug.h"
+#include "../share/go.h"
+#include "cs.h"
+#include "cs_aux.h"
+#include "cs_avail.h"
+#include "cs_debug.h"
+#include "cs_elim.h"
+#include "cs_entity.h"
+#include "cs_profit.h"
+#include "cs_stack.h"
+#include "cs_vnm.h"
+
+int Scs; /* Number of optimizations found. */
+
+STATIC cs_clear()
+{
+       clr_avails();
+       clr_entities();
+       clr_stack();
+
+       start_valnum();
+}
+
+STATIC cs_optimize(p)
+       proc_p p;
+{
+       /* Optimize all basic blocks of one procedure. */
+
+       register bblock_p rbp, bdone;
+
+       avails = (avail_p) 0;
+       entities = Lempty_set();
+       cs_clear();
+
+       rbp = p->p_start;
+
+       while (rbp != (bblock_p) 0) {
+               bdone = rbp->b_idom;
+               /* First we build a list of common expressions with the
+                * value numbering algorithm. We take blocks in textual order
+                * as long as the next block can only be reached through the
+                * block we have just done.
+                */
+               while (rbp != (bblock_p) 0 && rbp->b_idom == bdone) {
+                       vnm(rbp); bdone = rbp;
+                       OUTTRACE("basic block %d processed", bdone->b_id);
+                       rbp = rbp->b_next;
+               }
+               OUTTRACE("value numbering completed", 0);
+               OUTAVAILS(); OUTENTITIES();
+
+               /* Now we put out the instructions without common
+                * subexpressions but with the use of temporaries,
+                * which will be local variables of procedure p.
+                */
+               eliminate(p);
+               cs_clear();
+       }
+}
+
+main(argc, argv)
+       int     argc;
+       char    *argv[];
+{
+       Scs = 0;
+       go(argc, argv, no_action, cs_optimize, cs_machinit, no_action);
+       report("Duplicate expressions eliminated", Scs);
+       exit(0);
+}
diff --git a/util/ego/cs/cs_getent.h b/util/ego/cs/cs_getent.h
new file mode 100644 (file)
index 0000000..53eb5ea
--- /dev/null
@@ -0,0 +1,8 @@
+extern entity_p getentity();   /* (line_p lnp, *l_out)
+                                * Extract the entity lnp refers and enter it
+                                * in the table of entities. The main entity
+                                * lnp refers to is returned; sometimes there
+                                * is more than one entity. The first line that
+                                * was involved in pushing it is returned
+                                * through l_out.
+                                */