ack/util/ego/cs/cs.c

84 lines
2 KiB
C
Raw Normal View History

1994-06-24 11:31:16 +00:00
/* $Id$ */
1987-03-09 19:15:41 +00:00
/*
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
* See the copyright notice in the ACK home directory, in the file "Copyright".
*/
1984-11-26 14:07:17 +00:00
/* 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 <stdlib.h>
1984-11-26 14:07:17 +00:00
#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 void cs_clear()
1984-11-26 14:07:17 +00:00
{
clr_avails();
clr_entities();
clr_stack();
start_valnum();
}
STATIC void cs_optimize(void *vp)
1984-11-26 14:07:17 +00:00
{
/* Optimize all basic blocks of one procedure. */
proc_p p = vp;
1984-11-26 14:07:17 +00:00
register bblock_p rbp, bdone;
1987-10-02 12:52:29 +00:00
if (IS_ENTERED_WITH_GTO(p)) return;
1984-11-26 14:07:17 +00:00
avails = (avail_p) 0;
entities = Lempty_set();
cs_clear();
rbp = p->p_start;
while (rbp != (bblock_p) 0) {
/* 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. Note that if a block is preceded
* by itself, the number of predecessors is greater than 1,
* but the previous block can still be its immediate dominator.
1984-11-26 14:07:17 +00:00
*/
do { vnm(rbp); bdone = rbp;
1984-11-26 14:07:17 +00:00
OUTTRACE("basic block %d processed", bdone->b_id);
rbp = rbp->b_next;
} while (rbp != (bblock_p) 0 && rbp->b_idom == bdone &&
Lnrelems(rbp->b_pred) == 1
);
1984-11-26 14:07:17 +00:00
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();
}
}
int main(int argc, char *argv[])
1984-11-26 14:07:17 +00:00
{
Scs = 0;
go(argc, argv, no_action, cs_optimize, cs_machinit, no_action);
report("Duplicate expressions eliminated", Scs);
exit(0);
}