1 /* $Id: sr_cand.c,v 1.5 1994/06/24 10:32:10 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".
6 /* S T R E N G T H R E D U C T I O N
14 #include "../share/types.h"
15 #include "../share/lset.h"
16 #include "../share/cset.h"
17 #include "../share/debug.h"
18 #include "../share/global.h"
19 #include "../share/map.h"
20 #include "../share/aux.h"
26 /* A candidate induction variable of a loop (hereafter called candidate) is a
27 * local variable (of the current procedure) that is assigned a value
28 * precisely once within the loop. Furthermore, this assignment must
29 * take place in a firm block of the loop.
30 * We determine those locals that are assigned precisely once, within
33 * We represent a local variable via an instruction that references it,
34 * e.g. LOL -6 represents the local variable at offset -6 with size=wordsize.
35 * We keep track of two sets:
36 * cand - the set of all candidate variables
37 * dismiss - a set of variables that may not be made a candidate
38 * (because they are assigned more than once, or because
39 * they are assigned outside a firm block).
40 * Only local variables for which a register message is given are considered.
44 STATIC lset cand, /* set of candidates */
45 dism; /* set of dismissed variables */
48 #define ALL_LINES(lnp,list) lnp = list; lnp != (line_p) 0; lnp = lnp->l_next
55 /* remove the variable stored into by lnp from the list of
56 * candidates (if it was there anyway).
61 for (i = Lfirst(cand); i != (Lindex) 0; i = next) {
63 if (same_local(lnp,Lelem(i))) {
64 OUTTRACE("remove candidate",0);
65 Lremove(Lelem(i), &cand);
71 STATIC bool is_cand(lnp)
74 /* see if the variable stored into by lnp is a candate */
78 for (i = Lfirst(cand); i != (Lindex) 0; i = Lnext(i,cand)) {
79 if (same_local(lnp,Lelem(i))) {
90 /* make the variable stored into by lnp a candidate */
93 OUTTRACE("add a new candidate",0);
99 STATIC do_dismiss(lnp)
109 /* The variable referenced by lnp is turned definitely into
113 un_cand(lnp); /* remove it from the candidate set,
114 * if it was there in the first place.
116 do_dismiss(lnp); /* add it to the set of dismissed variables */
120 STATIC bool not_dismissed(lnp)
125 for (i = Lfirst(dism); i != (Lindex) 0; i = Lnext(i,dism)) {
126 if (same_local(Lelem(i),lnp)) {
127 return FALSE; /* variable was dismissed */
134 STATIC try_cand(lnp,b)
138 /* If the variable stored into by lnp was not already a candidate
139 * and was not dismissed, then it is made a candidate
140 * (unless the assignment takes places in a block that is not firm).
143 if (!is_regvar(off_set(lnp))) return;
144 if (is_cand(lnp) || !IS_FIRM(b)) {
147 if (not_dismissed(lnp)) {
154 candidates(lp,cand_out,vars_out)
156 lset *cand_out, *vars_out;
158 /* Find the candidate induction variables.
165 OUTTRACE("find candidates of loop %d",lp->lp_id);
169 for (i = Lfirst(lp->LP_BLOCKS); i != (Lindex) 0;
170 i = Lnext(i,lp->LP_BLOCKS)) {
171 b = (bblock_p) Lelem(i);
172 for ( ALL_LINES(lnp, b->b_start)) {
173 OUTTRACE("inspect instruction %d",INSTR(lnp));
178 OUTTRACE("it's a store local",0);
182 OUTTRACE("it's a destroy local",0);
183 if (is_regvar(off_set(lnp))) {