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

le join marche mais j ai pas teste le widening

parent ab6d331c
......@@ -275,6 +275,20 @@ private:
* Partial mapping function accoring to passed hashtable.
* Needs to be wrapped with MapHelper before usage with PPL.
*/
class MapGuid {
public:
inline explicit MapGuid(MyHTable<guid_t, guid_t> &map) : _map(map) {}
inline bool maps(guid_t i, guid_t &j) const {
if (_map.hasKey(i)) {
j = _map[i];
return true;
}
{ return false; }
}
private:
MyHTable<guid_t, guid_t> &_map;
};
class MapWithHash {
public:
inline explicit MapWithHash(MyHTable<int, int> &map) : _map(map) {}
......
......@@ -148,8 +148,9 @@ class WPoly {
inline bool maps(PPL::dimension_type i, PPL::dimension_type &j) const {
PPL::dimension_type k = 0;
for (std::vector<PPL::dimension_type>::const_iterator it = _victims.begin(); it != _victims.end(); it++) {
if ((*it) == i)
if ((*it) == i) {
return false;
}
if ((*it) < i)
k++;
}
......@@ -252,6 +253,10 @@ class WPoly {
if (adapter.find(g) == adapter.end()) {
// std::cout << "v" << g << " does not exists\n";
adapter[g] = next;
if (g == 26)
{
int k = 26;
}
next++;
}
return PPL::Variable(adapter[g]);
......@@ -398,7 +403,10 @@ class WPoly {
template <class F> inline void map_with_dim(F pfunc) {
poly.map_space_dimensions(pfunc);
next = pfunc.max_in_codomain() + 1;
assert(next == poly.space_dimension());
if (next != poly.space_dimension()) {
print(elm::cout);
abort();
}
map_adapter_dim(pfunc);
}
......@@ -440,10 +448,10 @@ template <class F> void WPoly::map_vars(F pfunc) {
guid_t j = i;
bool b = pfunc.maps(i, j);
if (b) {
std::cout << "v" << i << " mapped to " << "v" << j << "\n";
//std::cout << "v" << i << " mapped to " << "v" << j << "\n";
new_adapter[j] = it->second;
} else {
std::cout << "v" << i << " removed\n";
//std::cout << "v" << i << " removed\n";
victims.push_back(it->second);
}
}
......
......@@ -118,13 +118,15 @@ void PPLDomain::print(io::Output &out) const {
int ncons = 0;
if (!is_loop_bound)
if (!is_loop_bound) {
out << "Constraints: ";
} else out << "Bound: " ;
out << poly << endl;
for (WPoly::ConsIterator it(poly); it; it++) {
const WCons &c = *it;
ncons++;
bool firstTerm = true;
for (WCons::TermIterator it2(*it); it2; it2++) {
......@@ -639,7 +641,8 @@ PPLDomain PPLDomain::onBranch(bool taken) const {
default:
break;
};
res.victims.add(res.getVar(res.compare_reg).guid());
//res.victims.add(res.getVar(res.compare_reg).guid());
res.varKill(res.compare_reg);
res.compare_reg = Ident();
if (res.isBottom()) {
#ifdef POLY_DEBUG
......@@ -1106,12 +1109,12 @@ PPLDomain PPLDomain::onMerge(const PPLDomain &r, bool widen) const {
return r;
}
cout << "not implemented" << endl; abort();
#ifdef TODO
/*
ASSERT(!trash.countOnes());
ASSERT(!r.trash.countOnes());
ASSERT(compare_reg.getType() == Ident::ID_INVALID);
ASSERT(r.compare_reg.getType() == Ident::ID_INVALID);
*/
#ifdef POLY_DEBUG
cout << "Non-trivial merge, type=" << (widen ? "widening" : "convex-hull") << endl;
......@@ -1122,7 +1125,8 @@ PPLDomain PPLDomain::onMerge(const PPLDomain &r, bool widen) const {
PPLDomain r1 = r;
_doUnify(l1, r1);
exit(0);
#ifdef TODO
// cout << "before " << (widen ? "widening" : "join") << ", l= " << l1.getConsCount() << " r=" << r1.getConsCount() << endl;
for (int i = 0; i < r1.bounds.length(); i++)
l1.setBound(i, r1.getBound(i));
......@@ -2161,8 +2165,6 @@ void PPLDomain::_doMatchGlobals(PPLDomain &l1, PPLDomain &r1, unsigned int& axis
// TODO unifier le summary aussi ici
// TODO faire la projection sur le damaged
void PPLDomain::_doUnify(PPLDomain &l1, PPLDomain &r1, bool noPtr) const {
cout << "not implemented" << endl; abort();
#ifdef TODO
unsigned int axis = 0;
#ifdef POLY_DEBUG
......@@ -2173,7 +2175,82 @@ void PPLDomain::_doUnify(PPLDomain &l1, PPLDomain &r1, bool noPtr) const {
cout << "Right state: " << endl;
cout << r1;
#endif
WPoly inter = l1.poly;
inter.intersection_assign(r1.poly);
MyHTable<guid_t,guid_t> rename;
for (MyHTable<Ident, guid_t, HashIdent>::PairIterator it = l1.idmap.getPairIter(); it; it++) {
for (MyHTable<Ident, guid_t, HashIdent>::PairIterator it2 = r1.idmap.getPairIter(); it2; it2++) {
// Memory variables substitution
if (((*it).fst.getType() == Ident::ID_MEM_ADDR) && ((*it2).fst.getType() == Ident::ID_MEM_ADDR)) {
WVar x1((*it).snd);
WVar x2((*it2).snd);
if ((x1.guid() == x2.guid()) ||
inter.relation_with(x1 == x2).implies(PPL::Poly_Con_Relation::is_included())) {
cout << "Identified " << x1 << " with " << x2 << endl;
WVar x1v = l1.getVar(Ident((*it).fst.getId(), Ident::ID_MEM_VAL));
WVar x2v = r1.getVar(Ident((*it2).fst.getId(), Ident::ID_MEM_VAL));
rename.add(x1.guid(), x2.guid());
rename.add(x1v.guid(), x2v.guid());
cout << "[A] mapping " << x1.guid() << " to " << x2.guid() << endl;
cout << "[V] mapping " << x1v.guid() << " to " << x2v.guid() << endl;
}
}
}
if (((*it).fst.getType() != Ident::ID_MEM_ADDR) && ((*it).fst.getType() != Ident::ID_MEM_VAL))
if (r1.idmap.has1((*it).fst)) {
rename.add((*it).snd, r1.idmap.find1((*it).fst));
cout << "[R] mapping " << (*it).snd << " to " << r1.idmap.find1((*it).fst) << endl;
}
}
MapGuid mg(rename);
l1.doMap(mg);
#ifdef POLY_DEBUG
cout << "Unified, pre-remove:" << endl;
cout << "Left state: " << endl;
cout << l1;
fflush(stdout);
cout << "Right state: " << endl;
cout << r1;
#endif
l1.poly.poly_hull_assign(r1.poly);
#ifdef POLY_DEBUG
cout << "Joined state:" << endl;
cout << l1;
fflush(stdout);
#endif
exit(0);
for (MyHTable<Ident, guid_t, HashIdent>::PairIterator it = l1.idmap.getPairIter(); it; it++) {
if ((*it).fst.getType() == Ident::ID_MEM_ADDR) {
if (!r1.idmap.has2((*it).snd)) {
cout << "Removing unmatched memory: " << (*it).fst << endl;
l1.victims.add((*it).snd);
l1.victims.add(l1.getVar(Ident((*it).fst.getId(), Ident::ID_MEM_VAL)).guid());
}
} else if ((*it).fst.getType() != Ident::ID_MEM_VAL) {
if (r1.idmap.has1((*it).fst)) {
ASSERT((*it).snd == r1.idmap.find1((*it).fst));
} else {
l1.victims.add((*it).snd);
cout << "Removing unmatched register: " << (*it).fst << endl;
}
}
}
exit(0);
#ifdef TODO
/*
* These hashtables will represent the substitution to perform in the two input states.
*
......
......@@ -52,12 +52,26 @@ void WLinExpr::print(output_t &out) const {
}
void WPoly::print(output_t &out) const {
out << "\nRaw poly: [";
fflush(stdout);
poly.print();
out << endl;
fflush(stdout);
out << "]\n" << endl;
out << "Map: [";
for (std::map<guid_t,dim_t>::const_iterator it=adapter.begin(); it != adapter.end(); it++) {
out << it->first << " -> " << it->second << endl;
PPL::Variable pv(it->second);
char letter = (pv.id() % 26) + 'A';
int number = pv.id() / 26;
char name[32];
if (number != 0) {
snprintf(name, sizeof(name), "%c%u", letter, number);
} else {
snprintf(name, sizeof(name), "%c", letter);
}
out << "v" << it->first << " -> " << name << "; ";
}
out << "[";
out << "] " << endl << endl;
out << "WPoly: ";
for (WPoly::ConsIterator it(*this); it; it++) {
out << (*it) << "; ";
}
......
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