mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-08-19 19:29:31 +00:00
Changes to runtime framework
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@5572 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
f1c283859b
commit
92d5e30e76
@ -25,7 +25,7 @@ using std::vector;
|
|||||||
|
|
||||||
|
|
||||||
static void getTriggerCode(Module *M, BasicBlock *BB, int MethNo, Value *pathNo,
|
static void getTriggerCode(Module *M, BasicBlock *BB, int MethNo, Value *pathNo,
|
||||||
Value *cnt){
|
Value *cnt, Instruction *rInst){
|
||||||
|
|
||||||
vector<const Type*> args;
|
vector<const Type*> args;
|
||||||
//args.push_back(PointerType::get(Type::SByteTy));
|
//args.push_back(PointerType::get(Type::SByteTy));
|
||||||
@ -33,8 +33,15 @@ static void getTriggerCode(Module *M, BasicBlock *BB, int MethNo, Value *pathNo,
|
|||||||
args.push_back(Type::IntTy);
|
args.push_back(Type::IntTy);
|
||||||
//args.push_back(Type::IntTy);
|
//args.push_back(Type::IntTy);
|
||||||
args.push_back(PointerType::get(Type::IntTy));
|
args.push_back(PointerType::get(Type::IntTy));
|
||||||
|
args.push_back(PointerType::get(Type::IntTy));
|
||||||
const FunctionType *MTy = FunctionType::get(Type::VoidTy, args, false);
|
const FunctionType *MTy = FunctionType::get(Type::VoidTy, args, false);
|
||||||
|
|
||||||
|
vector<Value *> tmpVec;
|
||||||
|
tmpVec.push_back(Constant::getNullValue(Type::LongTy));
|
||||||
|
tmpVec.push_back(Constant::getNullValue(Type::LongTy));
|
||||||
|
Instruction *Idx = new GetElementPtrInst(cnt, tmpVec, "");//,
|
||||||
|
BB->getInstList().push_back(Idx);
|
||||||
|
|
||||||
Function *trigMeth = M->getOrInsertFunction("trigger", MTy);
|
Function *trigMeth = M->getOrInsertFunction("trigger", MTy);
|
||||||
assert(trigMeth && "trigger method could not be inserted!");
|
assert(trigMeth && "trigger method could not be inserted!");
|
||||||
|
|
||||||
@ -42,7 +49,8 @@ static void getTriggerCode(Module *M, BasicBlock *BB, int MethNo, Value *pathNo,
|
|||||||
|
|
||||||
trargs.push_back(ConstantSInt::get(Type::IntTy,MethNo));
|
trargs.push_back(ConstantSInt::get(Type::IntTy,MethNo));
|
||||||
trargs.push_back(pathNo);
|
trargs.push_back(pathNo);
|
||||||
trargs.push_back(cnt);
|
trargs.push_back(Idx);
|
||||||
|
trargs.push_back(rInst);
|
||||||
|
|
||||||
Instruction *callInst=new CallInst(trigMeth, trargs, "");//, BB->begin());
|
Instruction *callInst=new CallInst(trigMeth, trargs, "");//, BB->begin());
|
||||||
BB->getInstList().push_back(callInst);
|
BB->getInstList().push_back(callInst);
|
||||||
@ -52,7 +60,7 @@ static void getTriggerCode(Module *M, BasicBlock *BB, int MethNo, Value *pathNo,
|
|||||||
|
|
||||||
//get the code to be inserted on the edge
|
//get the code to be inserted on the edge
|
||||||
//This is determined from cond (1-6)
|
//This is determined from cond (1-6)
|
||||||
void getEdgeCode::getCode(Instruction *rInst, Instruction *countInst,
|
void getEdgeCode::getCode(Instruction *rInst, Value *countInst,
|
||||||
Function *M, BasicBlock *BB,
|
Function *M, BasicBlock *BB,
|
||||||
vector<Value *> &retVec){
|
vector<Value *> &retVec){
|
||||||
|
|
||||||
@ -105,9 +113,14 @@ void getEdgeCode::getCode(Instruction *rInst, Instruction *countInst,
|
|||||||
|
|
||||||
//count[inc]++
|
//count[inc]++
|
||||||
case 4:{
|
case 4:{
|
||||||
Instruction *Idx = new GetElementPtrInst(countInst,
|
vector<Value *> tmpVec;
|
||||||
vector<Value*>(1,ConstantSInt::get(Type::LongTy, inc)),
|
tmpVec.push_back(Constant::getNullValue(Type::LongTy));
|
||||||
"");//, InsertPos);
|
tmpVec.push_back(ConstantSInt::get(Type::LongTy, inc));
|
||||||
|
Instruction *Idx = new GetElementPtrInst(countInst, tmpVec, "");//,
|
||||||
|
|
||||||
|
//Instruction *Idx = new GetElementPtrInst(countInst,
|
||||||
|
// vector<Value*>(1,ConstantSInt::get(Type::LongTy, inc)),
|
||||||
|
// "");//, InsertPos);
|
||||||
BB->getInstList().push_back(Idx);
|
BB->getInstList().push_back(Idx);
|
||||||
|
|
||||||
Instruction *ldInst=new LoadInst(Idx, "ti1");//, InsertPos);
|
Instruction *ldInst=new LoadInst(Idx, "ti1");//, InsertPos);
|
||||||
@ -156,8 +169,10 @@ void getEdgeCode::getCode(Instruction *rInst, Instruction *countInst,
|
|||||||
Type::LongTy,"ctin");//, InsertPos);
|
Type::LongTy,"ctin");//, InsertPos);
|
||||||
BB->getInstList().push_back(castInst);
|
BB->getInstList().push_back(castInst);
|
||||||
|
|
||||||
Instruction *Idx = new GetElementPtrInst(countInst,
|
vector<Value *> tmpVec;
|
||||||
vector<Value*>(1,castInst), "");//,
|
tmpVec.push_back(Constant::getNullValue(Type::LongTy));
|
||||||
|
tmpVec.push_back(castInst);
|
||||||
|
Instruction *Idx = new GetElementPtrInst(countInst, tmpVec, "");//,
|
||||||
// InsertPos);
|
// InsertPos);
|
||||||
BB->getInstList().push_back(Idx);
|
BB->getInstList().push_back(Idx);
|
||||||
|
|
||||||
@ -166,6 +181,7 @@ void getEdgeCode::getCode(Instruction *rInst, Instruction *countInst,
|
|||||||
|
|
||||||
Value *cons=ConstantSInt::get(Type::IntTy,1);
|
Value *cons=ConstantSInt::get(Type::IntTy,1);
|
||||||
//count[addIndex]++
|
//count[addIndex]++
|
||||||
|
//std::cerr<<"Type ldInst:"<<ldInst->getType()<<"\t cons:"<<cons->getType()<<"\n";
|
||||||
Instruction *newCount = BinaryOperator::create(Instruction::Add, ldInst,
|
Instruction *newCount = BinaryOperator::create(Instruction::Add, ldInst,
|
||||||
cons,"");
|
cons,"");
|
||||||
BB->getInstList().push_back(newCount);
|
BB->getInstList().push_back(newCount);
|
||||||
@ -194,8 +210,14 @@ void getEdgeCode::getCode(Instruction *rInst, Instruction *countInst,
|
|||||||
Instruction *castInst2=new CastInst(ldIndex, Type::LongTy,"ctin");
|
Instruction *castInst2=new CastInst(ldIndex, Type::LongTy,"ctin");
|
||||||
BB->getInstList().push_back(castInst2);
|
BB->getInstList().push_back(castInst2);
|
||||||
|
|
||||||
Instruction *Idx = new GetElementPtrInst(countInst,
|
vector<Value *> tmpVec;
|
||||||
vector<Value*>(1,castInst2), "");
|
tmpVec.push_back(Constant::getNullValue(Type::LongTy));
|
||||||
|
tmpVec.push_back(castInst2);
|
||||||
|
Instruction *Idx = new GetElementPtrInst(countInst, tmpVec, "");//,
|
||||||
|
|
||||||
|
//Instruction *Idx = new GetElementPtrInst(countInst,
|
||||||
|
// vector<Value*>(1,castInst2), "");
|
||||||
|
|
||||||
BB->getInstList().push_back(Idx);
|
BB->getInstList().push_back(Idx);
|
||||||
|
|
||||||
Instruction *ldInst=new LoadInst(Idx, "ti2");//, InsertPos);
|
Instruction *ldInst=new LoadInst(Idx, "ti2");//, InsertPos);
|
||||||
@ -233,17 +255,16 @@ void getEdgeCode::getCode(Instruction *rInst, Instruction *countInst,
|
|||||||
//the number of executions of path k
|
//the number of executions of path k
|
||||||
void insertInTopBB(BasicBlock *front,
|
void insertInTopBB(BasicBlock *front,
|
||||||
int k,
|
int k,
|
||||||
Instruction *rVar,
|
Instruction *rVar, Value *threshold){
|
||||||
Instruction *countVar, Value *threshold){
|
|
||||||
//rVar is variable r,
|
//rVar is variable r,
|
||||||
//countVar is array Count, and these are allocatted outside
|
//countVar is count[]
|
||||||
|
|
||||||
Value *Int0 = ConstantInt::get(Type::IntTy, 0);
|
Value *Int0 = ConstantInt::get(Type::IntTy, 0);
|
||||||
|
|
||||||
//now push all instructions in front of the BB
|
//now push all instructions in front of the BB
|
||||||
BasicBlock::iterator here=front->begin();
|
BasicBlock::iterator here=front->begin();
|
||||||
front->getInstList().insert(here, rVar);
|
front->getInstList().insert(here, rVar);
|
||||||
front->getInstList().insert(here,countVar);
|
//front->getInstList().insert(here,countVar);
|
||||||
|
|
||||||
//Initialize Count[...] with 0
|
//Initialize Count[...] with 0
|
||||||
|
|
||||||
@ -258,19 +279,19 @@ void insertInTopBB(BasicBlock *front,
|
|||||||
new StoreInst(Int0, rVar, here);
|
new StoreInst(Int0, rVar, here);
|
||||||
|
|
||||||
//insert initialize function for initializing
|
//insert initialize function for initializing
|
||||||
vector<const Type*> inCountArgs;
|
//vector<const Type*> inCountArgs;
|
||||||
inCountArgs.push_back(PointerType::get(Type::IntTy));
|
//inCountArgs.push_back(PointerType::get(Type::IntTy));
|
||||||
inCountArgs.push_back(Type::IntTy);
|
//inCountArgs.push_back(Type::IntTy);
|
||||||
|
|
||||||
const FunctionType *cFty = FunctionType::get(Type::VoidTy, inCountArgs,
|
//const FunctionType *cFty = FunctionType::get(Type::VoidTy, inCountArgs,
|
||||||
false);
|
// false);
|
||||||
Function *inCountMth = front->getParent()->getParent()->getOrInsertFunction("llvmInitializeCounter", cFty);
|
//Function *inCountMth = front->getParent()->getParent()->getOrInsertFunction("llvmInitializeCounter", cFty);
|
||||||
assert(inCountMth && "Initialize method could not be inserted!");
|
//assert(inCountMth && "Initialize method could not be inserted!");
|
||||||
|
|
||||||
vector<Value *> iniArgs;
|
//vector<Value *> iniArgs;
|
||||||
iniArgs.push_back(countVar);
|
//iniArgs.push_back(countVar);
|
||||||
iniArgs.push_back(ConstantSInt::get(Type::IntTy, k));
|
//iniArgs.push_back(ConstantSInt::get(Type::IntTy, k));
|
||||||
new CallInst(inCountMth, iniArgs, "", here);
|
//new CallInst(inCountMth, iniArgs, "", here);
|
||||||
|
|
||||||
|
|
||||||
if(front->getParent()->getName() == "main"){
|
if(front->getParent()->getName() == "main"){
|
||||||
@ -296,7 +317,7 @@ void insertInTopBB(BasicBlock *front,
|
|||||||
void insertBB(Edge ed,
|
void insertBB(Edge ed,
|
||||||
getEdgeCode *edgeCode,
|
getEdgeCode *edgeCode,
|
||||||
Instruction *rInst,
|
Instruction *rInst,
|
||||||
Instruction *countInst,
|
Value *countInst,
|
||||||
int numPaths, int Methno, Value *threshold){
|
int numPaths, int Methno, Value *threshold){
|
||||||
|
|
||||||
BasicBlock* BB1=ed.getFirst()->getElement();
|
BasicBlock* BB1=ed.getFirst()->getElement();
|
||||||
@ -338,7 +359,7 @@ void insertBB(Edge ed,
|
|||||||
if(retVec.size()>0){
|
if(retVec.size()>0){
|
||||||
triggerBB = new BasicBlock("trigger", BB1->getParent());
|
triggerBB = new BasicBlock("trigger", BB1->getParent());
|
||||||
getTriggerCode(BB1->getParent()->getParent(), triggerBB, Methno,
|
getTriggerCode(BB1->getParent()->getParent(), triggerBB, Methno,
|
||||||
retVec[1], countInst);//retVec[0]);
|
retVec[1], countInst, rInst);//retVec[0]);
|
||||||
|
|
||||||
//Instruction *castInst = new CastInst(retVec[0], Type::IntTy, "");
|
//Instruction *castInst = new CastInst(retVec[0], Type::IntTy, "");
|
||||||
Instruction *etr = new LoadInst(threshold, "threshold");
|
Instruction *etr = new LoadInst(threshold, "threshold");
|
||||||
|
@ -151,7 +151,7 @@ bool Graph::hasEdgeAndWt(Edge ed){
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
Node *nd2=ed.getSecond();
|
Node *nd2=ed.getSecond();
|
||||||
nodeList nli = nodes[ed.getFirst()];//getNodeList(ed.getFirst());
|
nodeList &nli = nodes[ed.getFirst()];//getNodeList(ed.getFirst());
|
||||||
|
|
||||||
for(nodeList::iterator NI=nli.begin(), NE=nli.end(); NI!=NE; ++NI)
|
for(nodeList::iterator NI=nli.begin(), NE=nli.end(); NI!=NE; ++NI)
|
||||||
if(*NI->element == *nd2 && ed.getWeight()==NI->weight)
|
if(*NI->element == *nd2 && ed.getWeight()==NI->weight)
|
||||||
@ -400,7 +400,7 @@ Graph* Graph::getMaxSpanningTree(){
|
|||||||
|
|
||||||
//assign wt(v) to all adjacent vertices v of u
|
//assign wt(v) to all adjacent vertices v of u
|
||||||
//only if v is in vt
|
//only if v is in vt
|
||||||
Graph::nodeList nl=getNodeList(u);
|
Graph::nodeList &nl = getNodeList(u);
|
||||||
for(nodeList::iterator NI=nl.begin(), NE=nl.end(); NI!=NE; ++NI){
|
for(nodeList::iterator NI=nl.begin(), NE=nl.end(); NI!=NE; ++NI){
|
||||||
Node *v=NI->element;
|
Node *v=NI->element;
|
||||||
int weight=-NI->weight;
|
int weight=-NI->weight;
|
||||||
@ -437,7 +437,7 @@ void Graph::printGraph(){
|
|||||||
cerr<<"Graph---------------------\n";
|
cerr<<"Graph---------------------\n";
|
||||||
for(vector<Node *>::iterator LI=lt.begin(), LE=lt.end(); LI!=LE; ++LI){
|
for(vector<Node *>::iterator LI=lt.begin(), LE=lt.end(); LI!=LE; ++LI){
|
||||||
cerr<<((*LI)->getElement())->getName()<<"->";
|
cerr<<((*LI)->getElement())->getName()<<"->";
|
||||||
Graph::nodeList nl=getNodeList(*LI);
|
Graph::nodeList &nl = getNodeList(*LI);
|
||||||
for(Graph::nodeList::iterator NI=nl.begin(), NE=nl.end(); NI!=NE; ++NI){
|
for(Graph::nodeList::iterator NI=nl.begin(), NE=nl.end(); NI!=NE; ++NI){
|
||||||
cerr<<":"<<"("<<(NI->element->getElement())
|
cerr<<":"<<"("<<(NI->element->getElement())
|
||||||
->getName()<<":"<<NI->element->getWeight()<<","<<NI->weight<<")";
|
->getName()<<":"<<NI->element->getWeight()<<","<<NI->weight<<")";
|
||||||
@ -483,7 +483,7 @@ void Graph::makeUnDirectional(){
|
|||||||
vector<Node* > allNodes=getAllNodes();
|
vector<Node* > allNodes=getAllNodes();
|
||||||
for(vector<Node *>::iterator NI=allNodes.begin(), NE=allNodes.end(); NI!=NE;
|
for(vector<Node *>::iterator NI=allNodes.begin(), NE=allNodes.end(); NI!=NE;
|
||||||
++NI) {
|
++NI) {
|
||||||
nodeList nl=getNodeList(*NI);
|
nodeList &nl = getNodeList(*NI);
|
||||||
for(nodeList::iterator NLI=nl.begin(), NLE=nl.end(); NLI!=NLE; ++NLI){
|
for(nodeList::iterator NLI=nl.begin(), NLE=nl.end(); NLI!=NLE; ++NLI){
|
||||||
Edge ed(NLI->element, *NI, NLI->weight);
|
Edge ed(NLI->element, *NI, NLI->weight);
|
||||||
if(!hasEdgeAndWt(ed)){
|
if(!hasEdgeAndWt(ed)){
|
||||||
@ -502,7 +502,7 @@ void Graph::reverseWts(){
|
|||||||
vector<Node *> allNodes=getAllNodes();
|
vector<Node *> allNodes=getAllNodes();
|
||||||
for(vector<Node *>::iterator NI=allNodes.begin(), NE=allNodes.end(); NI!=NE;
|
for(vector<Node *>::iterator NI=allNodes.begin(), NE=allNodes.end(); NI!=NE;
|
||||||
++NI) {
|
++NI) {
|
||||||
nodeList node_list=getNodeList(*NI);
|
nodeList &node_list = getNodeList(*NI);
|
||||||
for(nodeList::iterator NLI=nodes[*NI].begin(), NLE=nodes[*NI].end();
|
for(nodeList::iterator NLI=nodes[*NI].begin(), NLE=nodes[*NI].end();
|
||||||
NLI!=NLE; ++NLI)
|
NLI!=NLE; ++NLI)
|
||||||
NLI->weight=-NLI->weight;
|
NLI->weight=-NLI->weight;
|
||||||
|
@ -33,7 +33,6 @@ public:
|
|||||||
inline bool operator==(Node& nd) const { return element==nd.element; }
|
inline bool operator==(Node& nd) const { return element==nd.element; }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
//Class Edge
|
//Class Edge
|
||||||
//Denotes an edge in the graph
|
//Denotes an edge in the graph
|
||||||
class Edge{
|
class Edge{
|
||||||
@ -410,7 +409,7 @@ public:
|
|||||||
|
|
||||||
//get the code to be inserted on the edge
|
//get the code to be inserted on the edge
|
||||||
//This is determined from cond (1-6)
|
//This is determined from cond (1-6)
|
||||||
void getCode(Instruction *a, Instruction *b, Function *M, BasicBlock *BB,
|
void getCode(Instruction *a, Value *b, Function *M, BasicBlock *BB,
|
||||||
std::vector<Value *> &retVec);
|
std::vector<Value *> &retVec);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -423,7 +422,7 @@ void printEdge(Edge ed);
|
|||||||
//Do graph processing: to determine minimal edge increments,
|
//Do graph processing: to determine minimal edge increments,
|
||||||
//appropriate code insertions etc and insert the code at
|
//appropriate code insertions etc and insert the code at
|
||||||
//appropriate locations
|
//appropriate locations
|
||||||
void processGraph(Graph &g, Instruction *rInst, Instruction *countInst, std::vector<Edge> &be, std::vector<Edge> &stDummy, std::vector<Edge> &exDummy, int n, int MethNo, Value *threshold);
|
void processGraph(Graph &g, Instruction *rInst, Value *countInst, std::vector<Edge> &be, std::vector<Edge> &stDummy, std::vector<Edge> &exDummy, int n, int MethNo, Value *threshold);
|
||||||
|
|
||||||
//print the graph (for debugging)
|
//print the graph (for debugging)
|
||||||
void printGraph(Graph &g);
|
void printGraph(Graph &g);
|
||||||
@ -432,7 +431,7 @@ void printGraph(Graph &g);
|
|||||||
//void printGraph(const Graph g);
|
//void printGraph(const Graph g);
|
||||||
//insert a basic block with appropriate code
|
//insert a basic block with appropriate code
|
||||||
//along a given edge
|
//along a given edge
|
||||||
void insertBB(Edge ed, getEdgeCode *edgeCode, Instruction *rInst, Instruction *countInst, int n, int Methno, Value *threshold);
|
void insertBB(Edge ed, getEdgeCode *edgeCode, Instruction *rInst, Value *countInst, int n, int Methno, Value *threshold);
|
||||||
|
|
||||||
//Insert the initialization code in the top BB
|
//Insert the initialization code in the top BB
|
||||||
//this includes initializing r, and count
|
//this includes initializing r, and count
|
||||||
@ -442,7 +441,7 @@ void insertBB(Edge ed, getEdgeCode *edgeCode, Instruction *rInst, Instruction *c
|
|||||||
//number of that path
|
//number of that path
|
||||||
//Count is an array, where Count[k] represents
|
//Count is an array, where Count[k] represents
|
||||||
//the number of executions of path k
|
//the number of executions of path k
|
||||||
void insertInTopBB(BasicBlock *front, int k, Instruction *rVar, Instruction *countVar, Value *threshold);
|
void insertInTopBB(BasicBlock *front, int k, Instruction *rVar, Value *threshold);
|
||||||
|
|
||||||
//Add dummy edges corresponding to the back edges
|
//Add dummy edges corresponding to the back edges
|
||||||
//If a->b is a backedge
|
//If a->b is a backedge
|
||||||
|
@ -479,7 +479,7 @@ static void moveDummyCode(vector<Edge> &stDummy,
|
|||||||
//appropriate locations
|
//appropriate locations
|
||||||
void processGraph(Graph &g,
|
void processGraph(Graph &g,
|
||||||
Instruction *rInst,
|
Instruction *rInst,
|
||||||
Instruction *countInst,
|
Value *countInst,
|
||||||
vector<Edge >& be,
|
vector<Edge >& be,
|
||||||
vector<Edge >& stDummy,
|
vector<Edge >& stDummy,
|
||||||
vector<Edge >& exDummy,
|
vector<Edge >& exDummy,
|
||||||
|
@ -479,7 +479,7 @@ static void moveDummyCode(vector<Edge> &stDummy,
|
|||||||
//appropriate locations
|
//appropriate locations
|
||||||
void processGraph(Graph &g,
|
void processGraph(Graph &g,
|
||||||
Instruction *rInst,
|
Instruction *rInst,
|
||||||
Instruction *countInst,
|
Value *countInst,
|
||||||
vector<Edge >& be,
|
vector<Edge >& be,
|
||||||
vector<Edge >& stDummy,
|
vector<Edge >& stDummy,
|
||||||
vector<Edge >& exDummy,
|
vector<Edge >& exDummy,
|
||||||
|
@ -155,6 +155,8 @@ bool ProfilePaths::runOnFunction(Function &F){
|
|||||||
// numPaths is the number of acyclic paths in the graph
|
// numPaths is the number of acyclic paths in the graph
|
||||||
int numPaths=valueAssignmentToEdges(g, nodePriority, be);
|
int numPaths=valueAssignmentToEdges(g, nodePriority, be);
|
||||||
|
|
||||||
|
//if(numPaths<=1) return false;
|
||||||
|
|
||||||
if(numPaths<=1 || numPaths >5000) return false;
|
if(numPaths<=1 || numPaths >5000) return false;
|
||||||
|
|
||||||
#ifdef DEBUG_PATH_PROFILES
|
#ifdef DEBUG_PATH_PROFILES
|
||||||
@ -172,10 +174,17 @@ bool ProfilePaths::runOnFunction(Function &F){
|
|||||||
AllocaInst(Type::IntTy,
|
AllocaInst(Type::IntTy,
|
||||||
ConstantUInt::get(Type::UIntTy,1),"R");
|
ConstantUInt::get(Type::UIntTy,1),"R");
|
||||||
|
|
||||||
Instruction *countVar=new
|
//Instruction *countVar=new
|
||||||
AllocaInst(Type::IntTy,
|
//AllocaInst(Type::IntTy,
|
||||||
ConstantUInt::get(Type::UIntTy, numPaths), "Count");
|
// ConstantUInt::get(Type::UIntTy, numPaths), "Count");
|
||||||
|
|
||||||
|
//initialize counter array!
|
||||||
|
std::vector<Constant*> arrayInitialize;
|
||||||
|
for(int xi=0; xi<numPaths; xi++)
|
||||||
|
arrayInitialize.push_back(ConstantSInt::get(Type::IntTy, 0));
|
||||||
|
|
||||||
|
Constant *initializer = ConstantArray::get(ArrayType::get(Type::IntTy, numPaths), arrayInitialize);
|
||||||
|
GlobalVariable *countVar = new GlobalVariable(ArrayType::get(Type::IntTy, numPaths), false, true, initializer, "Count", F.getParent());
|
||||||
static GlobalVariable *threshold = NULL;
|
static GlobalVariable *threshold = NULL;
|
||||||
static bool insertedThreshold = false;
|
static bool insertedThreshold = false;
|
||||||
|
|
||||||
@ -191,7 +200,7 @@ bool ProfilePaths::runOnFunction(Function &F){
|
|||||||
|
|
||||||
// insert initialization code in first (entry) BB
|
// insert initialization code in first (entry) BB
|
||||||
// this includes initializing r and count
|
// this includes initializing r and count
|
||||||
insertInTopBB(&F.getEntryNode(),numPaths, rVar, countVar, threshold);
|
insertInTopBB(&F.getEntryNode(),numPaths, rVar, threshold);
|
||||||
|
|
||||||
//now process the graph: get path numbers,
|
//now process the graph: get path numbers,
|
||||||
//get increments along different paths,
|
//get increments along different paths,
|
||||||
|
@ -16,12 +16,14 @@ using std::cerr;
|
|||||||
|
|
||||||
//Routines to get the path trace!
|
//Routines to get the path trace!
|
||||||
|
|
||||||
void getPathFrmNode(Node *n, vector<BasicBlock*> &vBB, int pathNo, Graph g,
|
void getPathFrmNode(Node *n, vector<BasicBlock*> &vBB, int pathNo, Graph &g,
|
||||||
vector<Edge> &stDummy, vector<Edge> &exDummy,
|
vector<Edge> &stDummy, vector<Edge> &exDummy,
|
||||||
vector<Edge> &be,
|
vector<Edge> &be,
|
||||||
double strand){
|
double strand){
|
||||||
Graph::nodeList nlist=g.getNodeList(n);
|
Graph::nodeList &nlist = g.getNodeList(n);
|
||||||
|
|
||||||
|
//printGraph(g);
|
||||||
|
//std::cerr<<"Path No: "<<pathNo<<"\n";
|
||||||
int maxCount=-9999999;
|
int maxCount=-9999999;
|
||||||
bool isStart=false;
|
bool isStart=false;
|
||||||
|
|
||||||
@ -30,7 +32,7 @@ void getPathFrmNode(Node *n, vector<BasicBlock*> &vBB, int pathNo, Graph g,
|
|||||||
|
|
||||||
double edgeRnd=0;
|
double edgeRnd=0;
|
||||||
Node *nextRoot=n;
|
Node *nextRoot=n;
|
||||||
for(Graph::nodeList::iterator NLI=nlist.begin(), NLE=nlist.end(); NLI!=NLE;
|
for(Graph::nodeList::iterator NLI = nlist.begin(), NLE=nlist.end(); NLI!=NLE;
|
||||||
++NLI){
|
++NLI){
|
||||||
if(NLI->weight>maxCount && NLI->weight<=pathNo){
|
if(NLI->weight>maxCount && NLI->weight<=pathNo){
|
||||||
maxCount=NLI->weight;
|
maxCount=NLI->weight;
|
||||||
@ -116,7 +118,8 @@ static Node *findBB(std::vector<Node *> &st, BasicBlock *BB){
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void getBBtrace(vector<BasicBlock *> &vBB, int pathNo, Function *M){
|
void getBBtrace(vector<BasicBlock *> &vBB, int pathNo, Function *M){//,
|
||||||
|
// vector<Instruction *> &instToErase){
|
||||||
//step 1: create graph
|
//step 1: create graph
|
||||||
//Transform the cfg s.t. we have just one exit node
|
//Transform the cfg s.t. we have just one exit node
|
||||||
|
|
||||||
@ -124,8 +127,14 @@ void getBBtrace(vector<BasicBlock *> &vBB, int pathNo, Function *M){
|
|||||||
std::vector<Edge> edges;
|
std::vector<Edge> edges;
|
||||||
Node *tmp;
|
Node *tmp;
|
||||||
Node *exitNode=0, *startNode=0;
|
Node *exitNode=0, *startNode=0;
|
||||||
|
|
||||||
|
//Creat cfg just once for each function!
|
||||||
static std::map<Function *, Graph *> graphMap;
|
static std::map<Function *, Graph *> graphMap;
|
||||||
|
|
||||||
|
//get backedges, exit and start edges for the graphs and store them
|
||||||
static std::map<Function *, vector<Edge> > stMap, exMap, beMap;
|
static std::map<Function *, vector<Edge> > stMap, exMap, beMap;
|
||||||
|
static std::map<Function *, Value *> pathReg; //path register
|
||||||
|
|
||||||
|
|
||||||
if(!graphMap[M]){
|
if(!graphMap[M]){
|
||||||
BasicBlock *ExitNode = 0;
|
BasicBlock *ExitNode = 0;
|
||||||
@ -142,17 +151,39 @@ void getBBtrace(vector<BasicBlock *> &vBB, int pathNo, Function *M){
|
|||||||
//The nodes must be uniquely identified:
|
//The nodes must be uniquely identified:
|
||||||
//That is, no two nodes must hav same BB*
|
//That is, no two nodes must hav same BB*
|
||||||
|
|
||||||
|
//keep a map for trigger basicblocks!
|
||||||
|
std::map<BasicBlock *, unsigned char> triggerBBs;
|
||||||
//First enter just nodes: later enter edges
|
//First enter just nodes: later enter edges
|
||||||
for(Function::iterator BB = M->begin(), BE=M->end(); BB != BE; ++BB){
|
for(Function::iterator BB = M->begin(), BE=M->end(); BB != BE; ++BB){
|
||||||
if(BB->size()==2){
|
bool cont = false;
|
||||||
const Instruction *inst = BB->getInstList().begin();
|
|
||||||
if(isa<CallInst>(inst)){
|
if(BB->size()==3 || BB->size() ==2){
|
||||||
Instruction *ii1 = BB->getInstList().begin();
|
for(BasicBlock::iterator II = BB->begin(), IE = BB->end();
|
||||||
CallInst *callInst = dyn_cast<CallInst>(ii1);
|
II != IE; ++II){
|
||||||
if(callInst->getCalledFunction()->getName()=="trigger")
|
if(CallInst *callInst = dyn_cast<CallInst>(&*II)){
|
||||||
|
//std::cerr<<*callInst;
|
||||||
|
Function *calledFunction = callInst->getCalledFunction();
|
||||||
|
if(calledFunction && calledFunction->getName() == "trigger"){
|
||||||
|
triggerBBs[BB] = 9;
|
||||||
|
cont = true;
|
||||||
|
//std::cerr<<"Found trigger!\n";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(cont)
|
||||||
continue;
|
continue;
|
||||||
}
|
|
||||||
}
|
// const Instruction *inst = BB->getInstList().begin();
|
||||||
|
// if(isa<CallInst>(inst)){
|
||||||
|
// Instruction *ii1 = BB->getInstList().begin();
|
||||||
|
// CallInst *callInst = dyn_cast<CallInst>(ii1);
|
||||||
|
// if(callInst->getCalledFunction()->getName()=="trigger")
|
||||||
|
// continue;
|
||||||
|
// }
|
||||||
|
|
||||||
Node *nd=new Node(BB);
|
Node *nd=new Node(BB);
|
||||||
nodes.push_back(nd);
|
nodes.push_back(nd);
|
||||||
if(&*BB==ExitNode)
|
if(&*BB==ExitNode)
|
||||||
@ -164,32 +195,55 @@ void getBBtrace(vector<BasicBlock *> &vBB, int pathNo, Function *M){
|
|||||||
assert(exitNode!=0 && startNode!=0 && "Start or exit not found!");
|
assert(exitNode!=0 && startNode!=0 && "Start or exit not found!");
|
||||||
|
|
||||||
for (Function::iterator BB = M->begin(), BE=M->end(); BB != BE; ++BB){
|
for (Function::iterator BB = M->begin(), BE=M->end(); BB != BE; ++BB){
|
||||||
if(BB->size()==2){
|
if(triggerBBs[BB] == 9)
|
||||||
const Instruction *inst = BB->getInstList().begin();
|
|
||||||
if(isa<CallInst>(inst)){
|
|
||||||
Instruction *ii1 = BB->getInstList().begin();
|
|
||||||
CallInst *callInst = dyn_cast<CallInst>(ii1);
|
|
||||||
if(callInst->getCalledFunction()->getName()=="trigger")
|
|
||||||
continue;
|
continue;
|
||||||
}
|
|
||||||
}
|
//if(BB->size()==3)
|
||||||
|
//if(CallInst *callInst = dyn_cast<CallInst>(&*BB->getInstList().begin()))
|
||||||
|
//if(callInst->getCalledFunction()->getName() == "trigger")
|
||||||
|
//continue;
|
||||||
|
|
||||||
|
// if(BB->size()==2){
|
||||||
|
// const Instruction *inst = BB->getInstList().begin();
|
||||||
|
// if(isa<CallInst>(inst)){
|
||||||
|
// Instruction *ii1 = BB->getInstList().begin();
|
||||||
|
// CallInst *callInst = dyn_cast<CallInst>(ii1);
|
||||||
|
// if(callInst->getCalledFunction()->getName()=="trigger")
|
||||||
|
// continue;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
Node *nd=findBB(nodes, BB);
|
Node *nd=findBB(nodes, BB);
|
||||||
assert(nd && "No node for this edge!");
|
assert(nd && "No node for this edge!");
|
||||||
|
|
||||||
for(BasicBlock::succ_iterator s=succ_begin(&*BB), se=succ_end(&*BB);
|
for(BasicBlock::succ_iterator s=succ_begin(&*BB), se=succ_end(&*BB);
|
||||||
s!=se; ++s){
|
s!=se; ++s){
|
||||||
if((*s)->size()==2){
|
|
||||||
const Instruction *inst = (*s)->getInstList().begin();
|
if(triggerBBs[*s] == 9){
|
||||||
if(isa<CallInst>(inst)){
|
//if(!pathReg[M]){ //Get the path register for this!
|
||||||
Instruction *ii1 = (*s)->getInstList().begin();
|
//if(BB->size()>8)
|
||||||
CallInst *callInst = dyn_cast<CallInst>(ii1);
|
// if(LoadInst *ldInst = dyn_cast<LoadInst>(&*BB->getInstList().begin()))
|
||||||
if(callInst->getCalledFunction()->getName()=="trigger")
|
// pathReg[M] = ldInst->getPointerOperand();
|
||||||
|
//}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
//if((*s)->size()==3)
|
||||||
|
//if(CallInst *callInst =
|
||||||
|
// dyn_cast<CallInst>(&*(*s)->getInstList().begin()))
|
||||||
|
// if(callInst->getCalledFunction()->getName() == "trigger")
|
||||||
|
// continue;
|
||||||
|
|
||||||
Node *nd2=findBB(nodes,*s);
|
// if((*s)->size()==2){
|
||||||
|
// const Instruction *inst = (*s)->getInstList().begin();
|
||||||
|
// if(isa<CallInst>(inst)){
|
||||||
|
// Instruction *ii1 = (*s)->getInstList().begin();
|
||||||
|
// CallInst *callInst = dyn_cast<CallInst>(ii1);
|
||||||
|
// if(callInst->getCalledFunction()->getName()=="trigger")
|
||||||
|
// continue;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
Node *nd2 = findBB(nodes,*s);
|
||||||
assert(nd2 && "No node for this edge!");
|
assert(nd2 && "No node for this edge!");
|
||||||
Edge ed(nd,nd2,0);
|
Edge ed(nd,nd2,0);
|
||||||
edges.push_back(ed);
|
edges.push_back(ed);
|
||||||
@ -216,8 +270,30 @@ void getBBtrace(vector<BasicBlock *> &vBB, int pathNo, Function *M){
|
|||||||
int numPaths = valueAssignmentToEdges(*g, nodePriority, beMap[M]);
|
int numPaths = valueAssignmentToEdges(*g, nodePriority, beMap[M]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//step 5: now travel from root, select max(edge) < pathNo,
|
//step 5: now travel from root, select max(edge) < pathNo,
|
||||||
//and go on until reach the exit
|
//and go on until reach the exit
|
||||||
return getPathFrmNode(graphMap[M]->getRoot(), vBB, pathNo, *graphMap[M],
|
getPathFrmNode(graphMap[M]->getRoot(), vBB, pathNo, *graphMap[M],
|
||||||
stMap[M], exMap[M], beMap[M], -1);
|
stMap[M], exMap[M], beMap[M], -1);
|
||||||
|
|
||||||
|
|
||||||
|
//post process vBB to locate instructions to be erased
|
||||||
|
/*
|
||||||
|
if(pathReg[M]){
|
||||||
|
for(vector<BasicBlock *>::iterator VBI = vBB.begin(), VBE = vBB.end();
|
||||||
|
VBI != VBE; ++VBI){
|
||||||
|
for(BasicBlock::iterator BBI = (*VBI)->begin(), BBE = (*VBI)->end();
|
||||||
|
BBI != BBE; ++BBI){
|
||||||
|
if(LoadInst *ldInst = dyn_cast<LoadInst>(&*BBI)){
|
||||||
|
if(pathReg[M] == ldInst->getPointerOperand())
|
||||||
|
instToErase.push_back(ldInst);
|
||||||
|
}
|
||||||
|
else if(StoreInst *stInst = dyn_cast<StoreInst>(&*BBI)){
|
||||||
|
if(pathReg[M] == stInst->getPointerOperand())
|
||||||
|
instToErase.push_back(stInst);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user