ack/util/ego/cs/cs.c
1984-11-26 14:07:17 +00:00

76 lines
1.6 KiB
C

/* 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);
}