/// \brief Resolves the strongly connected components from the graph void OffsetBasedAliasAnalysis::resolveSCCs (std::map<int,std::pair<OffsetPointer*, int> > sccs) { std::deque<OffsetPointer*> dq; for(auto i : offset_pointers) i.second->color = 0; for(auto i : sccs) { dq.clear(); DFS_visit_t_scc(i.second.first, &dq); while(!dq.empty()) { OffsetPointer* rp = dq.front(); dq.pop_front(); std::deque<Address*> ad; std::set<Address*> fn; //it expanded itself std::pair<OffsetPointer*, Offset> p = std::pair<OffsetPointer*, Offset>(rp, Offset()); for(auto j = rp->addr_begin(), je = rp->addr_end(); j != je; j++) { ad.push_front(*j); (*j)->expanded.insert(p); } while(!ad.empty()) { Address* addr = ad.front(); ad.pop_front(); if ( (addr->getBase()->scc == rp->scc) and ( (addr->getBase()->getPointerType() == OffsetPointer::Phi) or (addr->getBase()->getPointerType() == OffsetPointer::Cont) ) ) { // if its in the same scc we must expand addr->Expand(ad, fn); } else { // if its not from the same scc there's nothing more to be done fn.insert(addr); } } } } }
/// \brief Function that finds the pointer's path to the root of it's local /// tree. /// TODO: Optimize function to take advantage of topological ordering. void OffsetPointer::getPathToRoot() { OffsetPointer* current = this; int index = 0; Offset offset; while(true) { path_to_root[current] = std::pair<int, Offset>(index, offset); if(current->addresses.size() == 1) { Address* addr = *(current->addresses.begin()); current = addr->getBase(); if(path_to_root.count(current)) { //This means that the local tree is actually a lonely loop // so the local tree's root will be the pointer with the highest address OffsetPointer* root = NULL; for(auto i : path_to_root){ if(root < i.first) root = i.first; } local_root = root; break; } index++; offset = offset + addr->getOffset(); } else { local_root = current; break; } } }
// Resolves the sccs in the dependence graph void RangeBasedPointerAnalysis::resolveSCCs (std::map<int,std::pair<RangedPointer*, int> > sccs) { std::deque<RangedPointer*> dq; for(auto i : RangedPointers) i.second->color = 0; for(auto i : sccs) { //std::cout << i.first << "/" << scc << "\n"; // if the scc has more then one pointer than there is a loop //if(i.second.second > 1) { dq.clear(); SCC_DFS_visit(i.second.first, &dq); while(!dq.empty()) { RangedPointer* rp = dq.front(); dq.pop_front(); //std::cout << rp << "\n"; std::deque<Address*> ad; std::set<Address*> fn; std::pair<RangedPointer*, Range> p = std::pair<RangedPointer*, Range>(rp, Range(Expr(*SI, 0))); for(auto j = rp->addr_begin(), je = rp->addr_end(); j != je; j++) { ad.push_front(*j); (*j)->expanded.insert(p); } while(!ad.empty()) { //std::cout << "ad: " << ad.size() << "\n"; Address* addr = ad.front(); ad.pop_front(); if(addr->getBase()->scc == rp->scc) { //std::cout << "expand\n"; addr->Expand(ad, fn); } else { //std::cout << "insert\n"; fn.insert(addr); } } } } } }
/// \brief Resolves the whole graph void OffsetBasedAliasAnalysis::resolveWholeGraph() { std::deque<OffsetPointer*> dq; for(auto i : offset_pointers) i.second->color = 0; for(auto i : offset_pointers) { if(i.second->getPointerType() != OffsetPointer::Cont and i.second->color == 0) { DFS_visit_t(i.second, &dq); } } while(!dq.empty()) { OffsetPointer* rp = dq.front(); dq.pop_front(); std::deque<Address*> ad; std::set<Address*> fn; for(auto j = rp->addr_begin(), je = rp->addr_end(); j != je; j++) ad.push_front(*j); while(!ad.empty()) { Address* addr = ad.front(); ad.pop_front(); if(addr->getBase() == addr->getAddressee()) { //if the base is the very addressee, then we have a meaningless loop delete addr; } else if(addr->getBase()->getPointerType() == OffsetPointer::Phi or addr->getBase()->getPointerType() == OffsetPointer::Cont) { //if its a phi or a continuous pointer there must be expansion addr->Expand(ad, fn); } else { //if its not a phi or a continuous pointer there's nothing more to // be done fn.insert(addr); } } } }
// Resolves the whole graph void RangeBasedPointerAnalysis::resolveWholeGraph() { std::deque<RangedPointer*> dq; for(auto i : RangedPointers) i.second->color = 0; for(auto i : RangedPointers) { if(i.second->getPointerType() != RangedPointer::Cont and i.second->color == 0) { DFS_visit(i.second, &dq); } } /*std::cout << "Expanded sizes:\n"; for(auto i : RangedPointers) { for(auto j : i.second->Addresses) { std::cout << j->expanded.size(); if(j->expanded.find(i.second) != j->expanded.end()) std::cout << "SIM "; else std::cout << "NAO "; } std::cout << "\n"; } int n; std::cin >> n; */ while(!dq.empty()) { RangedPointer* rp = dq.front(); dq.pop_front(); std::deque<Address*> ad; std::set<Address*> fn; for(auto j = rp->addr_begin(), je = rp->addr_end(); j != je; j++) ad.push_front(*j); while(!ad.empty()) { Address* addr = ad.front(); ad.pop_front(); if(addr->getBase() == addr->getAddressee()) { delete addr; } else if(addr->getBase()->getPointerType() == RangedPointer::Phi or addr->getBase()->getPointerType() == RangedPointer::Cont) { //std::cout << "expand "; addr->Expand(ad, fn); } else { //std::cout << "insert\n"; fn.insert(addr); } } } }