From a9c17b85692354f08944954333bcbdde99907035 Mon Sep 17 00:00:00 2001 From: Sven Verdoolaege Date: Sun, 24 Aug 2008 16:25:06 +0200 Subject: [PATCH] Partial support for integer divisions in access vectors An outermost integer division can easily be represented in the current framework by simply keeping a global denominator as in this commit. Note that there may be other places that use access_vectors that still need to be update. Also, before this commit, an expression like "2*(i/2)" would be treated as "i", which is clearly incorrect, so we consider such expressions too messy now. --- src/baseparsuif/dependence/access_vector.cc | 45 ++++++++++++++------------ src/baseparsuif/dependence/access_vector.h | 1 + src/baseparsuif/dependence/named_array_func.cc | 7 ++-- 3 files changed, 31 insertions(+), 22 deletions(-) diff --git a/src/baseparsuif/dependence/access_vector.cc b/src/baseparsuif/dependence/access_vector.cc index 0f44b5c..4fb290f 100644 --- a/src/baseparsuif/dependence/access_vector.cc +++ b/src/baseparsuif/dependence/access_vector.cc @@ -195,7 +195,8 @@ tree_for * is_index(var_sym * v, tree_node *tn) static void put_index_info(tree_for * fn, /* deepest for node */ const operand & op, /* expression */ access_vector *av, - int factor) + int factor, + int outermost) { assert(av); @@ -243,7 +244,7 @@ static void put_index_info(tree_for * fn, /* deepest for node */ // Saman 12/1/94: // io_cvt is needed in SGI64 format, so here we go. case io_cvt: { - put_index_info(fn, i3r->src1_op(), av, factor); + put_index_info(fn, i3r->src1_op(), av, factor, outermost); break; } @@ -277,23 +278,23 @@ static void put_index_info(tree_for * fn, /* deepest for node */ break; } case io_neg: - put_index_info(fn, i3r->src1_op(), av, -factor); + put_index_info(fn, i3r->src1_op(), av, -factor, 0); break; case io_add: - put_index_info(fn, i3r->src1_op(), av, factor); - put_index_info(fn, i3r->src2_op(), av, factor); + put_index_info(fn, i3r->src1_op(), av, factor, 0); + put_index_info(fn, i3r->src2_op(), av, factor, 0); break; case io_sub: - put_index_info(fn, i3r->src1_op(), av, factor); - put_index_info(fn, i3r->src2_op(), av, -factor); + put_index_info(fn, i3r->src1_op(), av, factor, 0); + put_index_info(fn, i3r->src2_op(), av, -factor, 0); break; case io_mul: { int val; // var*const or const*var if(is_const(i3r->src1_op(), &val)) - put_index_info(fn, i3r->src2_op(), av, factor * val); + put_index_info(fn, i3r->src2_op(), av, factor * val, 0); else if(is_const(i3r->src2_op(), &val)) - put_index_info(fn, i3r->src1_op(), av, factor * val); + put_index_info(fn, i3r->src1_op(), av, factor * val, 0); else av->too_messy++; } @@ -303,10 +304,12 @@ static void put_index_info(tree_for * fn, /* deepest for node */ case io_divceil: { int val; // var/const - if(!is_const(i3r->src2_op(),&val) || (val == 0) || factor % val) + if(!is_const(i3r->src2_op(),&val) || (val == 0) || !outermost) av->too_messy++; - else - put_index_info(fn, i3r->src1_op(), av, factor / val); + else { + av->denom = val; + put_index_info(fn, i3r->src1_op(), av, factor, 0); + } } break; case io_lsl: { @@ -314,11 +317,11 @@ static void put_index_info(tree_for * fn, /* deepest for node */ if(!is_const(i3r->src2_op(), &val) || val < 0) av->too_messy++; else - put_index_info(fn, i3r->src1_op(), av, factor<src1_op(), av, factor<src1_op(), av, factor); + put_index_info(fn, i3r->src1_op(), av, factor, outermost); break; } } @@ -350,6 +353,7 @@ access_vector::access_vector(const access_vector *a): glist_e() too_messy = a -> too_messy; mod_this = forget_about_mod_this ? 0 : a->mod_this; + denom = a->denom; con = a->con; if (a->min) { min = new int; @@ -369,6 +373,7 @@ access_vector::access_vector(const access_vector &a): glist_e() too_messy = a.too_messy; mod_this = forget_about_mod_this ? 0 : a.mod_this; + denom = a.denom; con = a.con; if (a.min) { min = new int; @@ -384,12 +389,12 @@ access_vector::access_vector(const access_vector &a): glist_e() access_vector::access_vector(tree_instr *n, int fancy): - glist_e(), too_messy(0), con(0) + glist_e(), too_messy(0), con(0), denom(1) { min = max = 0; mod_this = 0; tree_for * tf = (tree_for *)next_further_out(n, TREE_FOR); - put_index_info(tf, operand(n->instr()), this, 1); + put_index_info(tf, operand(n->instr()), this, 1, 1); if(fancy == 0 && !(conregs.is_empty() && memregs.is_empty())) @@ -403,14 +408,14 @@ access_vector::access_vector(tree_instr *n, int fancy): } access_vector::access_vector(operand op, tree_node * tn, int fancy): - glist_e(), too_messy(0), con(0) + glist_e(), too_messy(0), con(0), denom(1) { min = max = 0; mod_this = 0; tree_for * tf = (tree_for *)next_further_out(tn, TREE_FOR, TRUE); - put_index_info(tf, op, this, 1); + put_index_info(tf, op, this, 1, 1); if(!fancy && !(conregs.is_empty() && memregs.is_empty())) @@ -425,7 +430,7 @@ access_vector::access_vector(operand op, tree_node * tn, int fancy): } access_vector::access_vector(instruction * inst, int fancy): - glist_e(), too_messy(0), con(0) + glist_e(), too_messy(0), con(0), denom(1) { min = max = 0; mod_this = 0; @@ -433,7 +438,7 @@ access_vector::access_vector(instruction * inst, int fancy): assert(inst); tree_for * tf = (tree_for *)next_further_out(inst->parent(), TREE_FOR, TRUE); - put_index_info(tf, operand(inst), this, 1); + put_index_info(tf, operand(inst), this, 1, 1); if(!fancy && !(conregs.is_empty() && memregs.is_empty())) diff --git a/src/baseparsuif/dependence/access_vector.h b/src/baseparsuif/dependence/access_vector.h index e1e8391..9602b0a 100644 --- a/src/baseparsuif/dependence/access_vector.h +++ b/src/baseparsuif/dependence/access_vector.h @@ -85,6 +85,7 @@ public: access_list conregs; // access vector for non-induction registers access_list memregs; // access vector for indirections thru regs int con; // constant to add to vector + int denom; // denominator tree_for *mod_this; // innermost for which defines a variable in // this access vector (may make conserv assump) // nil means this is completely loop constant diff --git a/src/baseparsuif/dependence/named_array_func.cc b/src/baseparsuif/dependence/named_array_func.cc index 89de721..45b56e1 100644 --- a/src/baseparsuif/dependence/named_array_func.cc +++ b/src/baseparsuif/dependence/named_array_func.cc @@ -126,10 +126,13 @@ named_lin_ineq * named_lin_ineq::mk_named_lin_ineq(access_vector & av, ret->nt[cnt++].mark_sym(); } - ret->lq[0][cnt] = -1; + ret->lq[0][cnt] = -av.denom; ret->nt[cnt].init(ind); ret->nt[cnt].mark_sym(); - if(lb) ret->lq[0] *= -1; + if(lb) { + ret->lq[0] *= -1; + ret->lq[0][0] += av.denom-1; + } convert_const(ret); if (ret && (ret->m()==0)) { -- 2.11.4.GIT