1 /* $Id: sr_expr.c,v 1.5 1994/06/24 10:32:16 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
15 #include "../share/types.h"
17 #include "../share/debug.h"
18 #include "../share/global.h"
19 #include "../share/aux.h"
21 #include "../share/lset.h"
29 #define ME_LOOPCONST 3
36 STATIC lset ivars, loopvars;
38 STATIC bool is_loadiv(lnp)
41 /* See if lnp is a LOL iv instruction, where iv is an
42 * induction variable of the set ivars. If so, set the
43 * the global variable last_iv to its descriptor.
50 if (INSTR(lnp) == op_lol) {
52 for (i = Lfirst(ivars); i != (Lindex) 0; i = Lnext(i,ivars)) {
54 if (iv->iv_off == off) {
66 #define size_ok(l) (TYPE(l) == OPSHORT && SHORT(l) == ws)
69 STATIC int me_kind(l,sign_in,sign_out)
71 int sign_in, *sign_out;
73 if (l != (line_p) 0) {
85 *sign_out = - sign_in;
91 *sign_out = - sign_in;
106 if (is_loopconst(l,loopvars)) return ME_LOOPCONST;
114 STATIC bool match_expr(l,iv_allowed,lbegin,iv_seen,sign)
116 bool iv_allowed, *iv_seen;
119 /* This routine is a top down parser for simple
120 * EM expressions. It recognizes expressions that
121 * have as operators + and - (unary - is also allowed)
122 * and that have as operands a number of loop constants
123 * (either a constant or a variable that is not
124 * changed within the loop) and at most one induction
126 * The parameter iv_allowed is propagated downwards
127 * in the expression tree, indicating whether the
128 * subexpression may use an induction variable as
129 * operand. The parameter iv_seen is propagated
130 * upwards, indicating if the subexpression has used
131 * an induction variable. The parameter sign is
132 * propagated downwards; it indicates the sign of
133 * the subexpression. lbegin will point to the
134 * beginning of the recognized subexpression
135 * (it is an out parameter). Note that we scan the
136 * EM text from right to left (i.e. top down).
143 switch(me_kind(l,sign,&sign2)) {
145 /* unairy operator, match one subexpression */
146 if (match_expr(PREV(l),iv_allowed,&l1,&iv_insubexpr,sign2)) {
148 *iv_seen = iv_insubexpr;
153 /* binairy operator, match two subexpressions */
154 if (match_expr(PREV(l), iv_allowed, &l1, &iv_insubexpr,sign2)) {
156 iv_allowed = iv_allowed && !iv_insubexpr;
157 if (match_expr(l,iv_allowed,&l1,
158 &iv_insubexpr,sign)) {
160 *iv_seen = !iv_allowed || iv_insubexpr;
164 return FALSE; /* subexpression not recognized */
166 *lbegin = l; /* expression is a loop constant */
175 /* fall through ... */
182 bool is_ivexpr(l,ivs,vars,lbegin_out,iv_out,sign_out)
183 line_p l, *lbegin_out;
194 if (match_expr(l,TRUE,&l2,&iv_seen,1)) {
196 /* recognized a correct expression */