mirror of
https://github.com/RPCS3/llvm.git
synced 2025-01-05 11:19:41 +00:00
* Changes to compile successfully with GCC 3.0
* Eliminated memory leak in processGraph * Pass vectors by const reference to moveDummyCode instead of by copy git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@1808 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
2d9bbfdfc4
commit
fd1717d03b
@ -1,13 +1,20 @@
|
|||||||
//===--Graph.cpp--- implements Graph class ---------------- ------*- C++ -*--=//
|
//===--Graph.cpp--- implements Graph class ---------------- ------*- C++ -*--=//
|
||||||
//
|
//
|
||||||
// This implements Graph for helping in trace generation
|
// This implements Graph for helping in trace generation
|
||||||
// This graph gets used by "PathProfile" class
|
// This graph gets used by "ProfilePaths" class
|
||||||
//
|
//
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
#include "Graph.h"
|
#include "Graph.h"
|
||||||
#include "llvm/BasicBlock.h"
|
#include "llvm/BasicBlock.h"
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
using std::list;
|
||||||
|
using std::set;
|
||||||
|
using std::map;
|
||||||
|
using std::vector;
|
||||||
|
using std::cerr;
|
||||||
|
|
||||||
static const graphListElement *findNodeInList(const Graph::nodeList &NL,
|
static const graphListElement *findNodeInList(const Graph::nodeList &NL,
|
||||||
Node *N) {
|
Node *N) {
|
||||||
@ -180,8 +187,8 @@ struct compare_nodes {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
void printNode(Node *nd){
|
static void printNode(Node *nd){
|
||||||
cerr<<"Node:"<<nd->getElement()->getName()<<endl;
|
cerr<<"Node:"<<nd->getElement()->getName()<<"\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
//Get the Maximal spanning tree (also a graph)
|
//Get the Maximal spanning tree (also a graph)
|
||||||
@ -233,7 +240,7 @@ Graph* Graph::getMaxSpanningTree(){
|
|||||||
while(!vt.empty()){
|
while(!vt.empty()){
|
||||||
Node *u=*(min_element(vt.begin(), vt.end(), compare_nodes()));
|
Node *u=*(min_element(vt.begin(), vt.end(), compare_nodes()));
|
||||||
#ifdef DEBUG_PATH_PROFILES
|
#ifdef DEBUG_PATH_PROFILES
|
||||||
cerr<<"popped wt"<<(u)->getWeight()<<endl;
|
cerr<<"popped wt"<<(u)->getWeight()<<"\n";
|
||||||
printNode(u);
|
printNode(u);
|
||||||
#endif
|
#endif
|
||||||
if(parent[u]!=NULL){ //so not root
|
if(parent[u]!=NULL){ //so not root
|
||||||
@ -270,8 +277,8 @@ Graph* Graph::getMaxSpanningTree(){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
#ifdef DEBUG_PATH_PROFILES
|
#ifdef DEBUG_PATH_PROFILES
|
||||||
cerr<<"wt:v->wt"<<weight<<":"<<v->getWeight()<<endl;
|
cerr<<"wt:v->wt"<<weight<<":"<<v->getWeight()<<"\n";
|
||||||
printNode(v);cerr<<"node wt:"<<(*v).weight<<endl;
|
printNode(v);cerr<<"node wt:"<<(*v).weight<<"\n";
|
||||||
#endif
|
#endif
|
||||||
//so if v in in vt, change wt(v) to wt(u->v)
|
//so if v in in vt, change wt(v) to wt(u->v)
|
||||||
//only if wt(u->v)<wt(v)
|
//only if wt(u->v)<wt(v)
|
||||||
|
@ -9,6 +9,12 @@
|
|||||||
#include "Graph.h"
|
#include "Graph.h"
|
||||||
#include "llvm/BasicBlock.h"
|
#include "llvm/BasicBlock.h"
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
using std::list;
|
||||||
|
using std::map;
|
||||||
|
using std::vector;
|
||||||
|
using std::cerr;
|
||||||
|
|
||||||
//check if 2 edges are equal (same endpoints and same weight)
|
//check if 2 edges are equal (same endpoints and same weight)
|
||||||
static bool edgesEqual(Edge ed1, Edge ed2);
|
static bool edgesEqual(Edge ed1, Edge ed2);
|
||||||
@ -35,17 +41,16 @@ static map<Edge, int> getEdgeIncrements(Graph& g, Graph& t);
|
|||||||
//the kind of code to be inserted along an edge
|
//the kind of code to be inserted along an edge
|
||||||
//The idea here is to minimize the computation
|
//The idea here is to minimize the computation
|
||||||
//by inserting only the needed code
|
//by inserting only the needed code
|
||||||
static map<Edge, getEdgeCode *>*
|
static void getCodeInsertions(Graph &g, map<Edge, getEdgeCode *> &Insertions,
|
||||||
getCodeInsertions(Graph &g,
|
vector<Edge > &chords,
|
||||||
vector<Edge > &chords,
|
map<Edge,int> &edIncrements);
|
||||||
map<Edge,int> &edIncrements);
|
|
||||||
|
|
||||||
//Move the incoming dummy edge code and outgoing dummy
|
//Move the incoming dummy edge code and outgoing dummy
|
||||||
//edge code over to the corresponding back edge
|
//edge code over to the corresponding back edge
|
||||||
static void moveDummyCode(vector<Edge > stDummy,
|
static void moveDummyCode(const vector<Edge> &stDummy,
|
||||||
vector<Edge > exDummy,
|
const vector<Edge> &exDummy,
|
||||||
vector<Edge > be,
|
const vector<Edge> &be,
|
||||||
map<Edge, getEdgeCode *> &insertions);
|
map<Edge, getEdgeCode *> &insertions);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -162,7 +167,7 @@ void processGraph(Graph &g,
|
|||||||
for(map<Edge, int>::iterator M_I=increment.begin(), M_E=increment.end();
|
for(map<Edge, int>::iterator M_I=increment.begin(), M_E=increment.end();
|
||||||
M_I!=M_E; ++M_I){
|
M_I!=M_E; ++M_I){
|
||||||
printEdge(M_I->first);
|
printEdge(M_I->first);
|
||||||
cerr<<"Increment for above:"<<M_I->second<<endl;
|
cerr<<"Increment for above:"<<M_I->second<<"\n";
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -172,10 +177,11 @@ void processGraph(Graph &g,
|
|||||||
//the kind of code to be inserted along an edge
|
//the kind of code to be inserted along an edge
|
||||||
//The idea here is to minimize the computation
|
//The idea here is to minimize the computation
|
||||||
//by inserting only the needed code
|
//by inserting only the needed code
|
||||||
map<Edge, getEdgeCode *>* codeInsertions;
|
vector<Edge> chords;
|
||||||
vector<Edge > chords;
|
|
||||||
getChords(chords, g, *t);
|
getChords(chords, g, *t);
|
||||||
codeInsertions=getCodeInsertions(g,chords,increment);
|
|
||||||
|
map<Edge, getEdgeCode *> codeInsertions;
|
||||||
|
getCodeInsertions(g, codeInsertions, chords,increment);
|
||||||
|
|
||||||
#ifdef DEBUG_PATH_PROFILES
|
#ifdef DEBUG_PATH_PROFILES
|
||||||
//print edges with code for debugging
|
//print edges with code for debugging
|
||||||
@ -183,7 +189,7 @@ void processGraph(Graph &g,
|
|||||||
for(map<Edge, getEdgeCode *>::iterator cd_i=codeInsertions->begin(),
|
for(map<Edge, getEdgeCode *>::iterator cd_i=codeInsertions->begin(),
|
||||||
cd_e=codeInsertions->end(); cd_i!=cd_e; ++cd_i){
|
cd_e=codeInsertions->end(); cd_i!=cd_e; ++cd_i){
|
||||||
printEdge(cd_i->first);
|
printEdge(cd_i->first);
|
||||||
cerr<<cd_i->second->getCond()<<":"<<cd_i->second->getInc()<<endl;
|
cerr<<cd_i->second->getCond()<<":"<<cd_i->second->getInc()<<"\n";
|
||||||
}
|
}
|
||||||
cerr<<"-----end insertions\n";
|
cerr<<"-----end insertions\n";
|
||||||
#endif
|
#endif
|
||||||
@ -191,24 +197,24 @@ void processGraph(Graph &g,
|
|||||||
|
|
||||||
//Move the incoming dummy edge code and outgoing dummy
|
//Move the incoming dummy edge code and outgoing dummy
|
||||||
//edge code over to the corresponding back edge
|
//edge code over to the corresponding back edge
|
||||||
moveDummyCode(stDummy, exDummy, be, *codeInsertions);
|
moveDummyCode(stDummy, exDummy, be, codeInsertions);
|
||||||
|
|
||||||
#ifdef DEBUG_PATH_PROFILES
|
#ifdef DEBUG_PATH_PROFILES
|
||||||
//debugging info
|
//debugging info
|
||||||
cerr<<"After moving dummy code\n";
|
cerr<<"After moving dummy code\n";
|
||||||
for(map<Edge, getEdgeCode *>::iterator cd_i=codeInsertions->begin(),
|
for(map<Edge, getEdgeCode *>::iterator cd_i=codeInsertions.begin(),
|
||||||
cd_e=codeInsertions->end(); cd_i!=cd_e; ++cd_i){
|
cd_e=codeInsertions.end(); cd_i != cd_e; ++cd_i){
|
||||||
printEdge(cd_i->first);
|
printEdge(cd_i->first);
|
||||||
cerr<<cd_i->second->getCond()<<":"
|
cerr<<cd_i->second->getCond()<<":"
|
||||||
<<cd_i->second->getInc()<<endl;
|
<<cd_i->second->getInc()<<"\n";
|
||||||
}
|
}
|
||||||
cerr<<"Dummy end------------\n";
|
cerr<<"Dummy end------------\n";
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
//see what it looks like...
|
//see what it looks like...
|
||||||
//now insert code along edges which have codes on them
|
//now insert code along edges which have codes on them
|
||||||
for(map<Edge, getEdgeCode *>::iterator MI=codeInsertions->begin(),
|
for(map<Edge, getEdgeCode *>::iterator MI=codeInsertions.begin(),
|
||||||
ME=codeInsertions->end(); MI!=ME; ++MI){
|
ME=codeInsertions.end(); MI!=ME; ++MI){
|
||||||
Edge ed=MI->first;
|
Edge ed=MI->first;
|
||||||
insertBB(ed, MI->second, rInst, countInst);
|
insertBB(ed, MI->second, rInst, countInst);
|
||||||
}
|
}
|
||||||
@ -406,20 +412,16 @@ static map<Edge, int> getEdgeIncrements(Graph& g, Graph& t){
|
|||||||
//the kind of code to be inserted along an edge
|
//the kind of code to be inserted along an edge
|
||||||
//The idea here is to minimize the computation
|
//The idea here is to minimize the computation
|
||||||
//by inserting only the needed code
|
//by inserting only the needed code
|
||||||
static map<Edge, getEdgeCode *>*
|
static void getCodeInsertions(Graph &g, map<Edge, getEdgeCode *> &instr,
|
||||||
getCodeInsertions(Graph &g,
|
vector<Edge > &chords,
|
||||||
vector<Edge > &chords,
|
map<Edge,int> &edIncrements){
|
||||||
map<Edge,int> &edIncrements){
|
|
||||||
//map of instrumented edges that's returned in the end
|
|
||||||
map<Edge, getEdgeCode *> *instr=
|
|
||||||
new map<Edge, getEdgeCode *>;
|
|
||||||
|
|
||||||
//Register initialization code
|
//Register initialization code
|
||||||
vector<Node *> ws;
|
vector<Node *> ws;
|
||||||
ws.push_back(g.getRoot());
|
ws.push_back(g.getRoot());
|
||||||
while(ws.size()>0){
|
while(ws.size()>0){
|
||||||
Node *v=ws[0];
|
Node *v=ws.back();
|
||||||
ws.erase(ws.begin());
|
ws.pop_back();
|
||||||
//for each edge v->w
|
//for each edge v->w
|
||||||
Graph::nodeList succs=g.getNodeList(v);
|
Graph::nodeList succs=g.getNodeList(v);
|
||||||
|
|
||||||
@ -441,7 +443,7 @@ getCodeInsertions(Graph &g,
|
|||||||
getEdgeCode *edCd=new getEdgeCode();
|
getEdgeCode *edCd=new getEdgeCode();
|
||||||
edCd->setCond(1);
|
edCd->setCond(1);
|
||||||
edCd->setInc(edIncrements[ed]);
|
edCd->setInc(edIncrements[ed]);
|
||||||
(*instr)[ed]=edCd;
|
instr[ed]=edCd;
|
||||||
}
|
}
|
||||||
else if((g.getPredNodes(w)).size()==1){
|
else if((g.getPredNodes(w)).size()==1){
|
||||||
ws.push_back(w);
|
ws.push_back(w);
|
||||||
@ -450,7 +452,7 @@ getCodeInsertions(Graph &g,
|
|||||||
getEdgeCode *edCd=new getEdgeCode();
|
getEdgeCode *edCd=new getEdgeCode();
|
||||||
edCd->setCond(2);
|
edCd->setCond(2);
|
||||||
edCd->setInc(0);
|
edCd->setInc(0);
|
||||||
(*instr)[ed]=edCd;
|
instr[ed]=edCd;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -458,9 +460,9 @@ getCodeInsertions(Graph &g,
|
|||||||
/////Memory increment code
|
/////Memory increment code
|
||||||
ws.push_back(g.getExit());
|
ws.push_back(g.getExit());
|
||||||
|
|
||||||
while(ws.size()>0){
|
while(!ws.empty()) {
|
||||||
Node *w=ws[0];
|
Node *w=ws.back();
|
||||||
ws.erase(&ws[0]);
|
ws.pop_back();
|
||||||
|
|
||||||
//for each edge v->w
|
//for each edge v->w
|
||||||
list<Node *> preds=g.getPredNodes(w);
|
list<Node *> preds=g.getPredNodes(w);
|
||||||
@ -480,13 +482,13 @@ getCodeInsertions(Graph &g,
|
|||||||
}
|
}
|
||||||
if(hasEdge){
|
if(hasEdge){
|
||||||
char str[100];
|
char str[100];
|
||||||
if((*instr)[ed]!=NULL && (*instr)[ed]->getCond()==1){
|
if(instr[ed]!=NULL && instr[ed]->getCond()==1){
|
||||||
(*instr)[ed]->setCond(4);
|
instr[ed]->setCond(4);
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
edCd->setCond(5);
|
edCd->setCond(5);
|
||||||
edCd->setInc(edIncrements[ed]);
|
edCd->setInc(edIncrements[ed]);
|
||||||
(*instr)[ed]=edCd;
|
instr[ed]=edCd;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -494,7 +496,7 @@ getCodeInsertions(Graph &g,
|
|||||||
ws.push_back(v);
|
ws.push_back(v);
|
||||||
else{
|
else{
|
||||||
edCd->setCond(6);
|
edCd->setCond(6);
|
||||||
(*instr)[ed]=edCd;
|
instr[ed]=edCd;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -502,14 +504,12 @@ getCodeInsertions(Graph &g,
|
|||||||
///// Register increment code
|
///// Register increment code
|
||||||
for(vector<Edge>::iterator CI=chords.begin(), CE=chords.end(); CI!=CE; ++CI){
|
for(vector<Edge>::iterator CI=chords.begin(), CE=chords.end(); CI!=CE; ++CI){
|
||||||
getEdgeCode *edCd=new getEdgeCode();
|
getEdgeCode *edCd=new getEdgeCode();
|
||||||
if((*instr)[*CI]==NULL){
|
if(instr[*CI]==NULL){
|
||||||
edCd->setCond(3);
|
edCd->setCond(3);
|
||||||
edCd->setInc(edIncrements[*CI]);
|
edCd->setInc(edIncrements[*CI]);
|
||||||
(*instr)[*CI]=edCd;
|
instr[*CI]=edCd;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return instr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//Add dummy edges corresponding to the back edges
|
//Add dummy edges corresponding to the back edges
|
||||||
@ -518,7 +518,7 @@ getCodeInsertions(Graph &g,
|
|||||||
//and outgoing dummy edge is a->exit
|
//and outgoing dummy edge is a->exit
|
||||||
void addDummyEdges(vector<Edge > &stDummy,
|
void addDummyEdges(vector<Edge > &stDummy,
|
||||||
vector<Edge > &exDummy,
|
vector<Edge > &exDummy,
|
||||||
Graph &g, vector<Edge > be){
|
Graph &g, vector<Edge> &be){
|
||||||
for(vector<Edge >::iterator VI=be.begin(), VE=be.end(); VI!=VE; ++VI){
|
for(vector<Edge >::iterator VI=be.begin(), VE=be.end(); VI!=VE; ++VI){
|
||||||
Edge ed=*VI;
|
Edge ed=*VI;
|
||||||
Node *first=ed.getFirst();
|
Node *first=ed.getFirst();
|
||||||
@ -529,45 +529,15 @@ void addDummyEdges(vector<Edge > &stDummy,
|
|||||||
Edge *st=new Edge(g.getRoot(), second);
|
Edge *st=new Edge(g.getRoot(), second);
|
||||||
|
|
||||||
//check if stDummy doesn't have it already
|
//check if stDummy doesn't have it already
|
||||||
bool hasIt=false;
|
if(find(stDummy.begin(), stDummy.end(), *st) == stDummy.end())
|
||||||
|
|
||||||
if(find(stDummy.begin(), stDummy.end(), *st)!=stDummy.end())
|
|
||||||
hasIt=true;
|
|
||||||
|
|
||||||
/*
|
|
||||||
for(vector<Edge>::iterator DM=stDummy.begin(), DE=stDummy.end(); DM!=DE;
|
|
||||||
++DM){
|
|
||||||
if(*DM==*st){
|
|
||||||
hasIt=true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
if(!hasIt){
|
|
||||||
stDummy.push_back(*st);
|
stDummy.push_back(*st);
|
||||||
g.addEdgeForce(*st);
|
g.addEdgeForce(*st);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!(*first==*(g.getExit()))){
|
if(!(*first==*(g.getExit()))){
|
||||||
Edge *ex=new Edge(first, g.getExit());
|
Edge *ex=new Edge(first, g.getExit());
|
||||||
|
|
||||||
bool hasIt=false;
|
if (find(exDummy.begin(), exDummy.end(), *ex) == exDummy.end()) {
|
||||||
if(find(exDummy.begin(), exDummy.end(), *ex)!=exDummy.end())
|
|
||||||
hasIt=true;
|
|
||||||
|
|
||||||
/*
|
|
||||||
for(vector<Edge>::iterator DM=exDummy.begin(), DE=exDummy.end(); DM!=DE;
|
|
||||||
++DM){
|
|
||||||
if(*DM==*ex){
|
|
||||||
hasIt=true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
if(!hasIt){
|
|
||||||
exDummy.push_back(*ex);
|
exDummy.push_back(*ex);
|
||||||
g.addEdgeForce(*ex);
|
g.addEdgeForce(*ex);
|
||||||
}
|
}
|
||||||
@ -580,16 +550,16 @@ void printEdge(Edge ed){
|
|||||||
cerr<<((ed.getFirst())->getElement())
|
cerr<<((ed.getFirst())->getElement())
|
||||||
->getName()<<"->"<<((ed.getSecond())
|
->getName()<<"->"<<((ed.getSecond())
|
||||||
->getElement())->getName()<<
|
->getElement())->getName()<<
|
||||||
":"<<ed.getWeight()<<endl;
|
":"<<ed.getWeight()<<"\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
//Move the incoming dummy edge code and outgoing dummy
|
//Move the incoming dummy edge code and outgoing dummy
|
||||||
//edge code over to the corresponding back edge
|
//edge code over to the corresponding back edge
|
||||||
static void moveDummyCode(vector<Edge > stDummy,
|
static void moveDummyCode(const vector<Edge> &stDummy,
|
||||||
vector<Edge > exDummy,
|
const vector<Edge> &exDummy,
|
||||||
vector<Edge > be,
|
const vector<Edge> &be,
|
||||||
map<Edge, getEdgeCode *> &insertions){
|
map<Edge, getEdgeCode *> &insertions){
|
||||||
typedef vector<Edge >::iterator vec_iter;
|
typedef vector<Edge >::const_iterator vec_iter;
|
||||||
|
|
||||||
#ifdef DEBUG_PATH_PROFILES
|
#ifdef DEBUG_PATH_PROFILES
|
||||||
//print all back, st and ex dummy
|
//print all back, st and ex dummy
|
||||||
@ -605,7 +575,7 @@ static void moveDummyCode(vector<Edge > stDummy,
|
|||||||
cerr<<"------end all edges\n";
|
cerr<<"------end all edges\n";
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
std::vector<Edge > toErase;
|
std::vector<Edge> toErase;
|
||||||
for(map<Edge,getEdgeCode *>::iterator MI=insertions.begin(),
|
for(map<Edge,getEdgeCode *>::iterator MI=insertions.begin(),
|
||||||
ME=insertions.end(); MI!=ME; ++MI){
|
ME=insertions.end(); MI!=ME; ++MI){
|
||||||
Edge ed=MI->first;
|
Edge ed=MI->first;
|
||||||
@ -682,7 +652,7 @@ static void moveDummyCode(vector<Edge > stDummy,
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifdef DEBUG_PATH_PROFILES
|
#ifdef DEBUG_PATH_PROFILES
|
||||||
cerr<<"size of deletions: "<<toErase.size()<<endl;
|
cerr<<"size of deletions: "<<toErase.size()<<"\n";
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
for(vector<Edge >::iterator vmi=toErase.begin(), vme=toErase.end(); vmi!=vme;
|
for(vector<Edge >::iterator vmi=toErase.begin(), vme=toErase.end(); vmi!=vme;
|
||||||
@ -690,7 +660,7 @@ static void moveDummyCode(vector<Edge > stDummy,
|
|||||||
insertions.erase(*vmi);
|
insertions.erase(*vmi);
|
||||||
|
|
||||||
#ifdef DEBUG_PATH_PROFILES
|
#ifdef DEBUG_PATH_PROFILES
|
||||||
cerr<<"SIZE OF INSERTIONS AFTER DEL "<<insertions.size()<<endl;
|
cerr<<"SIZE OF INSERTIONS AFTER DEL "<<insertions.size()<<"\n";
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,6 +9,12 @@
|
|||||||
#include "Graph.h"
|
#include "Graph.h"
|
||||||
#include "llvm/BasicBlock.h"
|
#include "llvm/BasicBlock.h"
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
using std::list;
|
||||||
|
using std::map;
|
||||||
|
using std::vector;
|
||||||
|
using std::cerr;
|
||||||
|
|
||||||
//check if 2 edges are equal (same endpoints and same weight)
|
//check if 2 edges are equal (same endpoints and same weight)
|
||||||
static bool edgesEqual(Edge ed1, Edge ed2);
|
static bool edgesEqual(Edge ed1, Edge ed2);
|
||||||
@ -35,17 +41,16 @@ static map<Edge, int> getEdgeIncrements(Graph& g, Graph& t);
|
|||||||
//the kind of code to be inserted along an edge
|
//the kind of code to be inserted along an edge
|
||||||
//The idea here is to minimize the computation
|
//The idea here is to minimize the computation
|
||||||
//by inserting only the needed code
|
//by inserting only the needed code
|
||||||
static map<Edge, getEdgeCode *>*
|
static void getCodeInsertions(Graph &g, map<Edge, getEdgeCode *> &Insertions,
|
||||||
getCodeInsertions(Graph &g,
|
vector<Edge > &chords,
|
||||||
vector<Edge > &chords,
|
map<Edge,int> &edIncrements);
|
||||||
map<Edge,int> &edIncrements);
|
|
||||||
|
|
||||||
//Move the incoming dummy edge code and outgoing dummy
|
//Move the incoming dummy edge code and outgoing dummy
|
||||||
//edge code over to the corresponding back edge
|
//edge code over to the corresponding back edge
|
||||||
static void moveDummyCode(vector<Edge > stDummy,
|
static void moveDummyCode(const vector<Edge> &stDummy,
|
||||||
vector<Edge > exDummy,
|
const vector<Edge> &exDummy,
|
||||||
vector<Edge > be,
|
const vector<Edge> &be,
|
||||||
map<Edge, getEdgeCode *> &insertions);
|
map<Edge, getEdgeCode *> &insertions);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -162,7 +167,7 @@ void processGraph(Graph &g,
|
|||||||
for(map<Edge, int>::iterator M_I=increment.begin(), M_E=increment.end();
|
for(map<Edge, int>::iterator M_I=increment.begin(), M_E=increment.end();
|
||||||
M_I!=M_E; ++M_I){
|
M_I!=M_E; ++M_I){
|
||||||
printEdge(M_I->first);
|
printEdge(M_I->first);
|
||||||
cerr<<"Increment for above:"<<M_I->second<<endl;
|
cerr<<"Increment for above:"<<M_I->second<<"\n";
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -172,10 +177,11 @@ void processGraph(Graph &g,
|
|||||||
//the kind of code to be inserted along an edge
|
//the kind of code to be inserted along an edge
|
||||||
//The idea here is to minimize the computation
|
//The idea here is to minimize the computation
|
||||||
//by inserting only the needed code
|
//by inserting only the needed code
|
||||||
map<Edge, getEdgeCode *>* codeInsertions;
|
vector<Edge> chords;
|
||||||
vector<Edge > chords;
|
|
||||||
getChords(chords, g, *t);
|
getChords(chords, g, *t);
|
||||||
codeInsertions=getCodeInsertions(g,chords,increment);
|
|
||||||
|
map<Edge, getEdgeCode *> codeInsertions;
|
||||||
|
getCodeInsertions(g, codeInsertions, chords,increment);
|
||||||
|
|
||||||
#ifdef DEBUG_PATH_PROFILES
|
#ifdef DEBUG_PATH_PROFILES
|
||||||
//print edges with code for debugging
|
//print edges with code for debugging
|
||||||
@ -183,7 +189,7 @@ void processGraph(Graph &g,
|
|||||||
for(map<Edge, getEdgeCode *>::iterator cd_i=codeInsertions->begin(),
|
for(map<Edge, getEdgeCode *>::iterator cd_i=codeInsertions->begin(),
|
||||||
cd_e=codeInsertions->end(); cd_i!=cd_e; ++cd_i){
|
cd_e=codeInsertions->end(); cd_i!=cd_e; ++cd_i){
|
||||||
printEdge(cd_i->first);
|
printEdge(cd_i->first);
|
||||||
cerr<<cd_i->second->getCond()<<":"<<cd_i->second->getInc()<<endl;
|
cerr<<cd_i->second->getCond()<<":"<<cd_i->second->getInc()<<"\n";
|
||||||
}
|
}
|
||||||
cerr<<"-----end insertions\n";
|
cerr<<"-----end insertions\n";
|
||||||
#endif
|
#endif
|
||||||
@ -191,24 +197,24 @@ void processGraph(Graph &g,
|
|||||||
|
|
||||||
//Move the incoming dummy edge code and outgoing dummy
|
//Move the incoming dummy edge code and outgoing dummy
|
||||||
//edge code over to the corresponding back edge
|
//edge code over to the corresponding back edge
|
||||||
moveDummyCode(stDummy, exDummy, be, *codeInsertions);
|
moveDummyCode(stDummy, exDummy, be, codeInsertions);
|
||||||
|
|
||||||
#ifdef DEBUG_PATH_PROFILES
|
#ifdef DEBUG_PATH_PROFILES
|
||||||
//debugging info
|
//debugging info
|
||||||
cerr<<"After moving dummy code\n";
|
cerr<<"After moving dummy code\n";
|
||||||
for(map<Edge, getEdgeCode *>::iterator cd_i=codeInsertions->begin(),
|
for(map<Edge, getEdgeCode *>::iterator cd_i=codeInsertions.begin(),
|
||||||
cd_e=codeInsertions->end(); cd_i!=cd_e; ++cd_i){
|
cd_e=codeInsertions.end(); cd_i != cd_e; ++cd_i){
|
||||||
printEdge(cd_i->first);
|
printEdge(cd_i->first);
|
||||||
cerr<<cd_i->second->getCond()<<":"
|
cerr<<cd_i->second->getCond()<<":"
|
||||||
<<cd_i->second->getInc()<<endl;
|
<<cd_i->second->getInc()<<"\n";
|
||||||
}
|
}
|
||||||
cerr<<"Dummy end------------\n";
|
cerr<<"Dummy end------------\n";
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
//see what it looks like...
|
//see what it looks like...
|
||||||
//now insert code along edges which have codes on them
|
//now insert code along edges which have codes on them
|
||||||
for(map<Edge, getEdgeCode *>::iterator MI=codeInsertions->begin(),
|
for(map<Edge, getEdgeCode *>::iterator MI=codeInsertions.begin(),
|
||||||
ME=codeInsertions->end(); MI!=ME; ++MI){
|
ME=codeInsertions.end(); MI!=ME; ++MI){
|
||||||
Edge ed=MI->first;
|
Edge ed=MI->first;
|
||||||
insertBB(ed, MI->second, rInst, countInst);
|
insertBB(ed, MI->second, rInst, countInst);
|
||||||
}
|
}
|
||||||
@ -406,20 +412,16 @@ static map<Edge, int> getEdgeIncrements(Graph& g, Graph& t){
|
|||||||
//the kind of code to be inserted along an edge
|
//the kind of code to be inserted along an edge
|
||||||
//The idea here is to minimize the computation
|
//The idea here is to minimize the computation
|
||||||
//by inserting only the needed code
|
//by inserting only the needed code
|
||||||
static map<Edge, getEdgeCode *>*
|
static void getCodeInsertions(Graph &g, map<Edge, getEdgeCode *> &instr,
|
||||||
getCodeInsertions(Graph &g,
|
vector<Edge > &chords,
|
||||||
vector<Edge > &chords,
|
map<Edge,int> &edIncrements){
|
||||||
map<Edge,int> &edIncrements){
|
|
||||||
//map of instrumented edges that's returned in the end
|
|
||||||
map<Edge, getEdgeCode *> *instr=
|
|
||||||
new map<Edge, getEdgeCode *>;
|
|
||||||
|
|
||||||
//Register initialization code
|
//Register initialization code
|
||||||
vector<Node *> ws;
|
vector<Node *> ws;
|
||||||
ws.push_back(g.getRoot());
|
ws.push_back(g.getRoot());
|
||||||
while(ws.size()>0){
|
while(ws.size()>0){
|
||||||
Node *v=ws[0];
|
Node *v=ws.back();
|
||||||
ws.erase(ws.begin());
|
ws.pop_back();
|
||||||
//for each edge v->w
|
//for each edge v->w
|
||||||
Graph::nodeList succs=g.getNodeList(v);
|
Graph::nodeList succs=g.getNodeList(v);
|
||||||
|
|
||||||
@ -441,7 +443,7 @@ getCodeInsertions(Graph &g,
|
|||||||
getEdgeCode *edCd=new getEdgeCode();
|
getEdgeCode *edCd=new getEdgeCode();
|
||||||
edCd->setCond(1);
|
edCd->setCond(1);
|
||||||
edCd->setInc(edIncrements[ed]);
|
edCd->setInc(edIncrements[ed]);
|
||||||
(*instr)[ed]=edCd;
|
instr[ed]=edCd;
|
||||||
}
|
}
|
||||||
else if((g.getPredNodes(w)).size()==1){
|
else if((g.getPredNodes(w)).size()==1){
|
||||||
ws.push_back(w);
|
ws.push_back(w);
|
||||||
@ -450,7 +452,7 @@ getCodeInsertions(Graph &g,
|
|||||||
getEdgeCode *edCd=new getEdgeCode();
|
getEdgeCode *edCd=new getEdgeCode();
|
||||||
edCd->setCond(2);
|
edCd->setCond(2);
|
||||||
edCd->setInc(0);
|
edCd->setInc(0);
|
||||||
(*instr)[ed]=edCd;
|
instr[ed]=edCd;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -458,9 +460,9 @@ getCodeInsertions(Graph &g,
|
|||||||
/////Memory increment code
|
/////Memory increment code
|
||||||
ws.push_back(g.getExit());
|
ws.push_back(g.getExit());
|
||||||
|
|
||||||
while(ws.size()>0){
|
while(!ws.empty()) {
|
||||||
Node *w=ws[0];
|
Node *w=ws.back();
|
||||||
ws.erase(&ws[0]);
|
ws.pop_back();
|
||||||
|
|
||||||
//for each edge v->w
|
//for each edge v->w
|
||||||
list<Node *> preds=g.getPredNodes(w);
|
list<Node *> preds=g.getPredNodes(w);
|
||||||
@ -480,13 +482,13 @@ getCodeInsertions(Graph &g,
|
|||||||
}
|
}
|
||||||
if(hasEdge){
|
if(hasEdge){
|
||||||
char str[100];
|
char str[100];
|
||||||
if((*instr)[ed]!=NULL && (*instr)[ed]->getCond()==1){
|
if(instr[ed]!=NULL && instr[ed]->getCond()==1){
|
||||||
(*instr)[ed]->setCond(4);
|
instr[ed]->setCond(4);
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
edCd->setCond(5);
|
edCd->setCond(5);
|
||||||
edCd->setInc(edIncrements[ed]);
|
edCd->setInc(edIncrements[ed]);
|
||||||
(*instr)[ed]=edCd;
|
instr[ed]=edCd;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -494,7 +496,7 @@ getCodeInsertions(Graph &g,
|
|||||||
ws.push_back(v);
|
ws.push_back(v);
|
||||||
else{
|
else{
|
||||||
edCd->setCond(6);
|
edCd->setCond(6);
|
||||||
(*instr)[ed]=edCd;
|
instr[ed]=edCd;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -502,14 +504,12 @@ getCodeInsertions(Graph &g,
|
|||||||
///// Register increment code
|
///// Register increment code
|
||||||
for(vector<Edge>::iterator CI=chords.begin(), CE=chords.end(); CI!=CE; ++CI){
|
for(vector<Edge>::iterator CI=chords.begin(), CE=chords.end(); CI!=CE; ++CI){
|
||||||
getEdgeCode *edCd=new getEdgeCode();
|
getEdgeCode *edCd=new getEdgeCode();
|
||||||
if((*instr)[*CI]==NULL){
|
if(instr[*CI]==NULL){
|
||||||
edCd->setCond(3);
|
edCd->setCond(3);
|
||||||
edCd->setInc(edIncrements[*CI]);
|
edCd->setInc(edIncrements[*CI]);
|
||||||
(*instr)[*CI]=edCd;
|
instr[*CI]=edCd;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return instr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//Add dummy edges corresponding to the back edges
|
//Add dummy edges corresponding to the back edges
|
||||||
@ -518,7 +518,7 @@ getCodeInsertions(Graph &g,
|
|||||||
//and outgoing dummy edge is a->exit
|
//and outgoing dummy edge is a->exit
|
||||||
void addDummyEdges(vector<Edge > &stDummy,
|
void addDummyEdges(vector<Edge > &stDummy,
|
||||||
vector<Edge > &exDummy,
|
vector<Edge > &exDummy,
|
||||||
Graph &g, vector<Edge > be){
|
Graph &g, vector<Edge> &be){
|
||||||
for(vector<Edge >::iterator VI=be.begin(), VE=be.end(); VI!=VE; ++VI){
|
for(vector<Edge >::iterator VI=be.begin(), VE=be.end(); VI!=VE; ++VI){
|
||||||
Edge ed=*VI;
|
Edge ed=*VI;
|
||||||
Node *first=ed.getFirst();
|
Node *first=ed.getFirst();
|
||||||
@ -529,45 +529,15 @@ void addDummyEdges(vector<Edge > &stDummy,
|
|||||||
Edge *st=new Edge(g.getRoot(), second);
|
Edge *st=new Edge(g.getRoot(), second);
|
||||||
|
|
||||||
//check if stDummy doesn't have it already
|
//check if stDummy doesn't have it already
|
||||||
bool hasIt=false;
|
if(find(stDummy.begin(), stDummy.end(), *st) == stDummy.end())
|
||||||
|
|
||||||
if(find(stDummy.begin(), stDummy.end(), *st)!=stDummy.end())
|
|
||||||
hasIt=true;
|
|
||||||
|
|
||||||
/*
|
|
||||||
for(vector<Edge>::iterator DM=stDummy.begin(), DE=stDummy.end(); DM!=DE;
|
|
||||||
++DM){
|
|
||||||
if(*DM==*st){
|
|
||||||
hasIt=true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
if(!hasIt){
|
|
||||||
stDummy.push_back(*st);
|
stDummy.push_back(*st);
|
||||||
g.addEdgeForce(*st);
|
g.addEdgeForce(*st);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!(*first==*(g.getExit()))){
|
if(!(*first==*(g.getExit()))){
|
||||||
Edge *ex=new Edge(first, g.getExit());
|
Edge *ex=new Edge(first, g.getExit());
|
||||||
|
|
||||||
bool hasIt=false;
|
if (find(exDummy.begin(), exDummy.end(), *ex) == exDummy.end()) {
|
||||||
if(find(exDummy.begin(), exDummy.end(), *ex)!=exDummy.end())
|
|
||||||
hasIt=true;
|
|
||||||
|
|
||||||
/*
|
|
||||||
for(vector<Edge>::iterator DM=exDummy.begin(), DE=exDummy.end(); DM!=DE;
|
|
||||||
++DM){
|
|
||||||
if(*DM==*ex){
|
|
||||||
hasIt=true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
if(!hasIt){
|
|
||||||
exDummy.push_back(*ex);
|
exDummy.push_back(*ex);
|
||||||
g.addEdgeForce(*ex);
|
g.addEdgeForce(*ex);
|
||||||
}
|
}
|
||||||
@ -580,16 +550,16 @@ void printEdge(Edge ed){
|
|||||||
cerr<<((ed.getFirst())->getElement())
|
cerr<<((ed.getFirst())->getElement())
|
||||||
->getName()<<"->"<<((ed.getSecond())
|
->getName()<<"->"<<((ed.getSecond())
|
||||||
->getElement())->getName()<<
|
->getElement())->getName()<<
|
||||||
":"<<ed.getWeight()<<endl;
|
":"<<ed.getWeight()<<"\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
//Move the incoming dummy edge code and outgoing dummy
|
//Move the incoming dummy edge code and outgoing dummy
|
||||||
//edge code over to the corresponding back edge
|
//edge code over to the corresponding back edge
|
||||||
static void moveDummyCode(vector<Edge > stDummy,
|
static void moveDummyCode(const vector<Edge> &stDummy,
|
||||||
vector<Edge > exDummy,
|
const vector<Edge> &exDummy,
|
||||||
vector<Edge > be,
|
const vector<Edge> &be,
|
||||||
map<Edge, getEdgeCode *> &insertions){
|
map<Edge, getEdgeCode *> &insertions){
|
||||||
typedef vector<Edge >::iterator vec_iter;
|
typedef vector<Edge >::const_iterator vec_iter;
|
||||||
|
|
||||||
#ifdef DEBUG_PATH_PROFILES
|
#ifdef DEBUG_PATH_PROFILES
|
||||||
//print all back, st and ex dummy
|
//print all back, st and ex dummy
|
||||||
@ -605,7 +575,7 @@ static void moveDummyCode(vector<Edge > stDummy,
|
|||||||
cerr<<"------end all edges\n";
|
cerr<<"------end all edges\n";
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
std::vector<Edge > toErase;
|
std::vector<Edge> toErase;
|
||||||
for(map<Edge,getEdgeCode *>::iterator MI=insertions.begin(),
|
for(map<Edge,getEdgeCode *>::iterator MI=insertions.begin(),
|
||||||
ME=insertions.end(); MI!=ME; ++MI){
|
ME=insertions.end(); MI!=ME; ++MI){
|
||||||
Edge ed=MI->first;
|
Edge ed=MI->first;
|
||||||
@ -682,7 +652,7 @@ static void moveDummyCode(vector<Edge > stDummy,
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifdef DEBUG_PATH_PROFILES
|
#ifdef DEBUG_PATH_PROFILES
|
||||||
cerr<<"size of deletions: "<<toErase.size()<<endl;
|
cerr<<"size of deletions: "<<toErase.size()<<"\n";
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
for(vector<Edge >::iterator vmi=toErase.begin(), vme=toErase.end(); vmi!=vme;
|
for(vector<Edge >::iterator vmi=toErase.begin(), vme=toErase.end(); vmi!=vme;
|
||||||
@ -690,7 +660,7 @@ static void moveDummyCode(vector<Edge > stDummy,
|
|||||||
insertions.erase(*vmi);
|
insertions.erase(*vmi);
|
||||||
|
|
||||||
#ifdef DEBUG_PATH_PROFILES
|
#ifdef DEBUG_PATH_PROFILES
|
||||||
cerr<<"SIZE OF INSERTIONS AFTER DEL "<<insertions.size()<<endl;
|
cerr<<"SIZE OF INSERTIONS AFTER DEL "<<insertions.size()<<"\n";
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,8 +36,8 @@
|
|||||||
|
|
||||||
using std::vector;
|
using std::vector;
|
||||||
|
|
||||||
static Node *findBB(set<Node *> &st, BasicBlock *BB){
|
static Node *findBB(std::set<Node *> &st, BasicBlock *BB){
|
||||||
for(set<Node *>::iterator si=st.begin(); si!=st.end(); ++si){
|
for(std::set<Node *>::iterator si=st.begin(); si!=st.end(); ++si){
|
||||||
if(((*si)->getElement())==BB){
|
if(((*si)->getElement())==BB){
|
||||||
return *si;
|
return *si;
|
||||||
}
|
}
|
||||||
@ -95,7 +95,7 @@ bool ProfilePaths::runOnMethod(Method *M){
|
|||||||
if (M->getBasicBlocks().size() == 1) {
|
if (M->getBasicBlocks().size() == 1) {
|
||||||
//The graph is made acyclic: this is done
|
//The graph is made acyclic: this is done
|
||||||
//by removing back edges for now, and adding them later on
|
//by removing back edges for now, and adding them later on
|
||||||
vector<Edge > be;
|
vector<Edge> be;
|
||||||
g.getBackEdges(be);
|
g.getBackEdges(be);
|
||||||
#ifdef DEBUG_PATH_PROFILES
|
#ifdef DEBUG_PATH_PROFILES
|
||||||
cerr<<"Backedges:"<<be.size()<<endl;
|
cerr<<"Backedges:"<<be.size()<<endl;
|
||||||
@ -106,8 +106,8 @@ bool ProfilePaths::runOnMethod(Method *M){
|
|||||||
//Then we add 2 back edges for it:
|
//Then we add 2 back edges for it:
|
||||||
//1. from root->b (in vector stDummy)
|
//1. from root->b (in vector stDummy)
|
||||||
//and 2. from a->exit (in vector exDummy)
|
//and 2. from a->exit (in vector exDummy)
|
||||||
vector<Edge > stDummy;
|
vector<Edge> stDummy;
|
||||||
vector<Edge > exDummy;
|
vector<Edge> exDummy;
|
||||||
addDummyEdges(stDummy, exDummy, g, be);
|
addDummyEdges(stDummy, exDummy, g, be);
|
||||||
|
|
||||||
//Now, every edge in the graph is assigned a weight
|
//Now, every edge in the graph is assigned a weight
|
||||||
|
Loading…
Reference in New Issue
Block a user