1 /* $Id: cs.c,v 1.6 1994/06/24 10:21:40 ceriel Exp $ */
3 * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
4 * See the copyright notice in the ACK home directory, in the file "Copyright".
7 /* 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 */
11 #include "../share/types.h"
12 #include "../share/lset.h"
13 #include "../share/debug.h"
14 #include "../share/go.h"
20 #include "cs_entity.h"
21 #include "cs_profit.h"
25 int Scs; /* Number of optimizations found. */
39 /* Optimize all basic blocks of one procedure. */
41 register bblock_p rbp, bdone;
43 if (IS_ENTERED_WITH_GTO(p)) return;
45 entities = Lempty_set();
50 while (rbp != (bblock_p) 0) {
51 /* First we build a list of common expressions with the
52 * value numbering algorithm. We take blocks in textual order
53 * as long as the next block can only be reached through the
54 * block we have just done. Note that if a block is preceded
55 * by itself, the number of predecessors is greater than 1,
56 * but the previous block can still be its immediate dominator.
58 do { vnm(rbp); bdone = rbp;
59 OUTTRACE("basic block %d processed", bdone->b_id);
61 } while (rbp != (bblock_p) 0 && rbp->b_idom == bdone &&
62 Lnrelems(rbp->b_pred) == 1
64 OUTTRACE("value numbering completed", 0);
65 OUTAVAILS(); OUTENTITIES();
67 /* Now we put out the instructions without common
68 * subexpressions but with the use of temporaries,
69 * which will be local variables of procedure p.
81 go(argc, argv, no_action, cs_optimize, cs_machinit, no_action);
82 report("Duplicate expressions eliminated", Scs);