Commit a56dbf14 authored by Ballabriga Clément's avatar Ballabriga Clément
Browse files

qq bugfixs

parent af6415de
......@@ -11,7 +11,7 @@
#include "MyHTable.h"
//#define POLY_DEBUG 1
// #define POLY_DEBUG 1
namespace otawa {
namespace poly {
......
......@@ -73,6 +73,7 @@ class WLinExpr {
inline coef_t inhomogeneous_term() const { return cst; }
inline coef_t coefficient(const WVar &v) const { return coefs.at(v.guid()); }
inline bool has_var(const WVar &v) const { return coefs.find(v.guid()) != coefs.end(); }
void print(output_t &out) const;
......@@ -124,6 +125,7 @@ class WCons {
}
inline coef_t inhomogeneous_term() const { return expr.inhomogeneous_term(); }
inline coef_t coefficient(const WVar &v) const { return expr.coefficient(v); }
inline bool has_var(const WVar &v) const { return expr.has_var(v); }
inline const WLinExpr& getLE() const { return expr; }
inline ctype_t getType() const { return ctype; }
inline bool is_equality() const { return ctype == CONS_EQ; }
......
......@@ -2255,9 +2255,11 @@ void PPLDomain::_doUnify(PPLDomain &l1, PPLDomain &r1, bool noPtr) const {
WPoly::ConsIterator it2(temp);
for (; it2 && !(*it2).is_equality(); it2++);
if (!it2)
if (!it2) {
if (v.guid() < 20)
indepVars.insert(*it);
}
}
#ifdef POLY_DEBUG
cout << "Independant common vars: ";
......@@ -2599,8 +2601,14 @@ void PPLDomain::_doBinaryOp(int op, WVar *v, WVar *vs1, WVar *vs2) {
void PPLDomain::_identifyPolyVars(const PPLDomain &d, const std::set<guid_t> &vars, const std::set<guid_t> &indep, MyHTable<guid_t, Vector<PPL::Coefficient> > &vmap) const {
const WPoly &poly = d.poly;
#ifdef POLY_DEBUG
cout << "Begin _identifyPolyVars" << endl;
#endif
for (std::set<guid_t>::const_iterator it = vars.begin(); it != vars.end(); it++) {
WVar v(*it);
#ifdef POLY_DEBUG
cout << "trying for: " << v << endl;
#endif
if (!d.isVarMapped(v) || d.getIdent(v).getType() != Ident::ID_MEM_ADDR)
continue;
WPoly temp = poly;
......@@ -2609,7 +2617,10 @@ void PPLDomain::_identifyPolyVars(const PPLDomain &d, const std::set<guid_t> &va
});
WPoly::ConsIterator it2(temp);
for (; it2 && !(*it2).is_equality(); it2++);
for (; it2 && !((*it2).is_equality() && (*it2).has_var(v)); it2++);
#ifdef POLY_DEBUG
cout << "Found equality: " << (*it2) << endl;
#endif
if (it2) {
WCons c = *it2;
......@@ -2617,20 +2628,30 @@ void PPLDomain::_identifyPolyVars(const PPLDomain &d, const std::set<guid_t> &va
vect.setLength(indep.size() + 2); /* vector format: [Indep. vars coefs, Current var (v) coef, Constant] */
for (int i = 0; i < vect.length(); i++)
vect[i] = 0;
PPL::Coefficient curVarCoef = c.coefficient(v);
PPL::Coefficient constant = c.inhomogeneous_term();
ASSERT(curVarCoef); // curVarCoef==0 would imply that the indep set contains non-independant variables
bool normalizeSign = curVarCoef < 0;
vect[vect.length() - 2] = normalizeSign ? -curVarCoef : curVarCoef;
vect[vect.length() - 1] = normalizeSign ? -constant : constant;
bool seen_v = false;
for (WCons::TermIterator it3(c); it3; it3++) {
WVar v2(*it3);
if ((v2.guid() != v.guid()) && (c.coefficient(v2) != 0)) {
ASSERT(indep.find(v2.guid()) != indep.end()); // must be true because of projection, and because v2!=v
PPL::Coefficient coef = c.coefficient(v2);
vect[std::distance(indep.begin(), indep.find(v2.guid()))] = normalizeSign ? -coef : coef;
vect[std::distance(indep.begin(), indep.find(v2.guid()))] = coef;
}
if (v2.guid() == v.guid()) {
seen_v = true;
vect[vect.length() - 2] = c.coefficient(v);
ASSERT(c.coefficient(v) != 0);
}
}
if (!seen_v) {
ASSERT(false);
#ifdef POLY_DEBUG
cout << "nvm. " << endl;
#endif
continue;
}
vect[vect.length() - 1] = c.inhomogeneous_term();
PPL::Coefficient pgcd = vect[vect.length() - 1];
for (int i = 0; i < vect.length() - 1; i++) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment