1 /* $Id: cs_avail.c,v 1.6 1994/06/24 10:21:57 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 /* M O D U L E F O R A C C E S S S I N G T H E L I S T
8 * O F A V A I L A B L E E X P R E S S I O N S
12 #include "../share/types.h"
13 #include "../share/debug.h"
14 #include "../share/aux.h"
15 #include "../share/lset.h"
16 #include "../share/global.h"
21 #include "cs_getent.h"
23 avail_p avails; /* The list of available expressions. */
25 STATIC bool commutative(instr)
28 /* Is instr a commutative operator? */
31 case op_adf: case op_adi: case op_adu: case op_and:
32 case op_cms: case op_ior: case op_mlf: case op_mli:
40 STATIC bool same_avail(kind, avp1, avp2)
44 /* Two expressions are the same if they have the same operator,
45 * the same size, and their operand(s) have the same value.
46 * Only if the operator is commutative, the order of the operands
49 if (avp1->av_instr != avp2->av_instr) return FALSE;
50 if (avp1->av_size != avp2->av_size) return FALSE;
58 return avp1->av_operand == avp2->av_operand;
60 if (commutative(avp1->av_instr & BMASK))
61 return avp1->av_oleft == avp2->av_oleft &&
62 avp1->av_oright == avp2->av_oright
64 avp1->av_oleft == avp2->av_oright &&
65 avp1->av_oright == avp2->av_oleft
68 return avp1->av_oleft == avp2->av_oleft &&
69 avp1->av_oright == avp2->av_oright;
71 return avp1->av_ofirst == avp2->av_ofirst &&
72 avp1->av_osecond == avp2->av_osecond &&
73 avp1->av_othird == avp2->av_othird;
78 STATIC check_local(avp)
81 /* Check if the local in which the result of avp was stored,
82 * still holds this result. Update if not.
84 if (avp->av_saveloc == (entity_p) 0) return; /* Nothing to check. */
86 if (avp->av_saveloc->en_vn != avp->av_result) {
87 OUTTRACE("save local changed value", 0);
88 avp->av_saveloc = (entity_p) 0;
92 STATIC entity_p result_local(size, l)
96 /* If the result of an expression of size bytes is stored into a
97 * local for which a registermessage was generated, return a pointer
106 if (INSTR(l)==op_stl && size==ws || INSTR(l)==op_sdl && size==2*ws) {
107 enp = getentity(l, &dummy);
108 if (is_regvar(enp->en_loc)) {
109 OUTTRACE("save local found, %ld(LB)", enp->en_loc);
117 STATIC copy_avail(kind, src, dst)
121 /* Copy some attributes from src to dst. */
123 dst->av_instr = src->av_instr;
124 dst->av_size = src->av_size;
132 dst->av_operand = src->av_operand;
135 dst->av_oleft = src->av_oleft;
136 dst->av_oright = src->av_oright;
139 dst->av_ofirst = src->av_ofirst;
140 dst->av_osecond = src->av_osecond;
141 dst->av_othird = src->av_othird;
146 avail_p av_enter(avp, ocp, kind)
151 /* Put the available expression avp in the list,
152 * if it is not already there.
153 * Add ocp to the set of occurrences of this expression.
155 register avail_p ravp;
156 line_p last = ocp->oc_llast;
158 for (ravp = avails; ravp != (avail_p) 0; ravp = ravp->av_before) {
159 if (same_avail(kind, ravp, avp)) { /* It was there. */
160 Ladd(ocp, &ravp->av_occurs);
161 /* Can we still use the local in which
162 * the result was stored?
168 /* A new available axpression. */
171 /* Remember local, if any, that holds result. */
172 if (avp->av_instr != (byte) INSTR(last)) {
173 /* Only possible when instr is the implicit AAR in
176 ravp->av_saveloc = (entity_p) 0;
178 ravp->av_saveloc = result_local(avp->av_size, last->l_next);
180 ravp->av_found = last;
181 ravp->av_result = kind == EXPENSIVE_LOAD? avp->av_operand: newvalnum();
182 copy_avail(kind, avp, ravp);
184 ravp->av_before = avails;
191 /* Throw away the information about the available expressions. */
193 register avail_p ravp, next;
197 for (ravp = avails; ravp != (avail_p) 0; ravp = next) {
198 next = ravp->av_before;
201 for (i = Lfirst(s); i != (Lindex) 0; i = Lnext(i, s)) {
202 oldoccur(occ_elem(i));
207 avails = (avail_p) 0;