summaryrefslogtreecommitdiff
path: root/lib/Transforms/Instrumentation
diff options
context:
space:
mode:
authorMisha Brukman <brukman+llvm@gmail.com>2005-04-21 23:48:37 +0000
committerMisha Brukman <brukman+llvm@gmail.com>2005-04-21 23:48:37 +0000
commitfd93908ae8b9684fe71c239e3c6cfe13ff6a2663 (patch)
tree4d0726d997a629d08765d11a705a42c4f48690af /lib/Transforms/Instrumentation
parent0e0a7a45d3d0a8c865a078459d2e1c6d8967a100 (diff)
downloadllvm-fd93908ae8b9684fe71c239e3c6cfe13ff6a2663.tar.gz
llvm-fd93908ae8b9684fe71c239e3c6cfe13ff6a2663.tar.bz2
llvm-fd93908ae8b9684fe71c239e3c6cfe13ff6a2663.tar.xz
Remove trailing whitespace
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21427 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/Instrumentation')
-rw-r--r--lib/Transforms/Instrumentation/BlockProfiling.cpp12
-rw-r--r--lib/Transforms/Instrumentation/EdgeProfiling.cpp4
-rw-r--r--lib/Transforms/Instrumentation/EmitFunctions.cpp34
-rw-r--r--lib/Transforms/Instrumentation/ProfilePaths/CombineBranch.cpp40
-rw-r--r--lib/Transforms/Instrumentation/ProfilePaths/EdgeCode.cpp94
-rw-r--r--lib/Transforms/Instrumentation/ProfilePaths/Graph.cpp74
-rw-r--r--lib/Transforms/Instrumentation/ProfilePaths/Graph.h84
-rw-r--r--lib/Transforms/Instrumentation/ProfilePaths/GraphAuxiliary.cpp186
-rw-r--r--lib/Transforms/Instrumentation/ProfilePaths/InstLoops.cpp24
-rw-r--r--lib/Transforms/Instrumentation/ProfilePaths/ProfilePaths.cpp58
-rw-r--r--lib/Transforms/Instrumentation/ProfilePaths/RetracePath.cpp88
-rw-r--r--lib/Transforms/Instrumentation/ProfilingUtils.cpp8
-rw-r--r--lib/Transforms/Instrumentation/ProfilingUtils.h4
-rw-r--r--lib/Transforms/Instrumentation/TraceBasicBlocks.cpp4
-rw-r--r--lib/Transforms/Instrumentation/TraceValues.cpp72
15 files changed, 393 insertions, 393 deletions
diff --git a/lib/Transforms/Instrumentation/BlockProfiling.cpp b/lib/Transforms/Instrumentation/BlockProfiling.cpp
index 476a9e8c53..f92f0ef6f0 100644
--- a/lib/Transforms/Instrumentation/BlockProfiling.cpp
+++ b/lib/Transforms/Instrumentation/BlockProfiling.cpp
@@ -1,10 +1,10 @@
//===- BlockProfiling.cpp - Insert counters for block profiling -----------===//
-//
+//
// The LLVM Compiler Infrastructure
//
// This file was developed by the LLVM research group and is distributed under
// the University of Illinois Open Source License. See LICENSE.TXT for details.
-//
+//
//===----------------------------------------------------------------------===//
//
// This pass instruments the specified program with counters for basic block or
@@ -51,7 +51,7 @@ bool FunctionProfiler::runOnModule(Module &M) {
}
unsigned NumFunctions = 0;
- for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I)
+ for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I)
if (!I->isExternal())
++NumFunctions;
@@ -62,7 +62,7 @@ bool FunctionProfiler::runOnModule(Module &M) {
// Instrument all of the functions...
unsigned i = 0;
- for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I)
+ for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I)
if (!I->isExternal())
// Insert counter at the start of the function
IncrementCounterInBlock(I->begin(), i++, Counters);
@@ -93,7 +93,7 @@ bool BlockProfiler::runOnModule(Module &M) {
}
unsigned NumBlocks = 0;
- for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I)
+ for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I)
NumBlocks += I->size();
const Type *ATy = ArrayType::get(Type::UIntTy, NumBlocks);
@@ -103,7 +103,7 @@ bool BlockProfiler::runOnModule(Module &M) {
// Instrument all of the blocks...
unsigned i = 0;
- for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I)
+ for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I)
for (Function::iterator BB = I->begin(), E = I->end(); BB != E; ++BB)
// Insert counter at the start of the block
IncrementCounterInBlock(BB, i++, Counters);
diff --git a/lib/Transforms/Instrumentation/EdgeProfiling.cpp b/lib/Transforms/Instrumentation/EdgeProfiling.cpp
index c453554236..2ac6cc87de 100644
--- a/lib/Transforms/Instrumentation/EdgeProfiling.cpp
+++ b/lib/Transforms/Instrumentation/EdgeProfiling.cpp
@@ -1,10 +1,10 @@
//===- EdgeProfiling.cpp - Insert counters for edge profiling -------------===//
-//
+//
// The LLVM Compiler Infrastructure
//
// This file was developed by the LLVM research group and is distributed under
// the University of Illinois Open Source License. See LICENSE.TXT for details.
-//
+//
//===----------------------------------------------------------------------===//
//
// This pass instruments the specified program with counters for edge profiling.
diff --git a/lib/Transforms/Instrumentation/EmitFunctions.cpp b/lib/Transforms/Instrumentation/EmitFunctions.cpp
index 16d3687fb1..369a784a4e 100644
--- a/lib/Transforms/Instrumentation/EmitFunctions.cpp
+++ b/lib/Transforms/Instrumentation/EmitFunctions.cpp
@@ -1,10 +1,10 @@
//===-- EmitFunctions.cpp - interface to insert instrumentation -----------===//
-//
+//
// The LLVM Compiler Infrastructure
//
// This file was developed by the LLVM research group and is distributed under
// the University of Illinois Open Source License. See LICENSE.TXT for details.
-//
+//
//===----------------------------------------------------------------------===//
//
// This inserts into the input module three new global constants containing
@@ -27,7 +27,7 @@
#include "llvm/Transforms/Instrumentation.h"
using namespace llvm;
-namespace llvm {
+namespace llvm {
namespace {
enum Color{
@@ -35,11 +35,11 @@ namespace {
GREY,
BLACK
};
-
+
struct EmitFunctionTable : public ModulePass {
bool runOnModule(Module &M);
};
-
+
RegisterOpt<EmitFunctionTable>
X("emitfuncs", "Emit a function table for the reoptimizer");
}
@@ -48,9 +48,9 @@ static char doDFS(BasicBlock * node,std::map<BasicBlock *, Color > &color){
color[node] = GREY;
for(succ_iterator vl = succ_begin(node), ve = succ_end(node); vl != ve; ++vl){
-
- BasicBlock *BB = *vl;
-
+
+ BasicBlock *BB = *vl;
+
if(color[BB]!=GREY && color[BB]!=BLACK){
if(!doDFS(BB, color)){
return 0;
@@ -75,7 +75,7 @@ static char hasBackEdge(Function *F){
// Per Module pass for inserting function table
bool EmitFunctionTable::runOnModule(Module &M){
std::vector<const Type*> vType;
-
+
std::vector<Constant *> vConsts;
std::vector<Constant *> sBCons;
@@ -83,24 +83,24 @@ bool EmitFunctionTable::runOnModule(Module &M){
for(Module::iterator MI = M.begin(), ME = M.end(); MI != ME; ++MI)
if (!MI->isExternal()) {
vType.push_back(MI->getType());
-
+
//std::cerr<<MI;
vConsts.push_back(MI);
sBCons.push_back(ConstantInt::get(Type::SByteTy, hasBackEdge(MI)));
-
+
counter++;
}
-
+
StructType *sttype = StructType::get(vType);
Constant *cstruct = ConstantStruct::get(sttype, vConsts);
GlobalVariable *gb = new GlobalVariable(cstruct->getType(), true,
- GlobalValue::ExternalLinkage,
+ GlobalValue::ExternalLinkage,
cstruct, "llvmFunctionTable");
M.getGlobalList().push_back(gb);
- Constant *constArray = ConstantArray::get(ArrayType::get(Type::SByteTy,
+ Constant *constArray = ConstantArray::get(ArrayType::get(Type::SByteTy,
sBCons.size()),
sBCons);
@@ -110,9 +110,9 @@ bool EmitFunctionTable::runOnModule(Module &M){
M.getGlobalList().push_back(funcArray);
- ConstantInt *cnst = ConstantSInt::get(Type::IntTy, counter);
- GlobalVariable *fnCount = new GlobalVariable(Type::IntTy, true,
- GlobalValue::ExternalLinkage,
+ ConstantInt *cnst = ConstantSInt::get(Type::IntTy, counter);
+ GlobalVariable *fnCount = new GlobalVariable(Type::IntTy, true,
+ GlobalValue::ExternalLinkage,
cnst, "llvmFunctionCount");
M.getGlobalList().push_back(fnCount);
return true; // Always modifies program
diff --git a/lib/Transforms/Instrumentation/ProfilePaths/CombineBranch.cpp b/lib/Transforms/Instrumentation/ProfilePaths/CombineBranch.cpp
index 1a7b77387d..e592d28653 100644
--- a/lib/Transforms/Instrumentation/ProfilePaths/CombineBranch.cpp
+++ b/lib/Transforms/Instrumentation/ProfilePaths/CombineBranch.cpp
@@ -1,10 +1,10 @@
//===-- CombineBranch.cpp -------------------------------------------------===//
-//
+//
// The LLVM Compiler Infrastructure
//
// This file was developed by the LLVM research group and is distributed under
// the University of Illinois Open Source License. See LICENSE.TXT for details.
-//
+//
//===----------------------------------------------------------------------===//
//
// Combine multiple back-edges going to the same sink into a single
@@ -31,14 +31,14 @@ namespace {
void getBackEdgesVisit(BasicBlock *u,
std::map<BasicBlock *, Color > &color,
- std::map<BasicBlock *, int > &d,
+ std::map<BasicBlock *, int > &d,
int &time,
std::map<BasicBlock *, BasicBlock *> &be);
void removeRedundant(std::map<BasicBlock *, BasicBlock *> &be);
public:
bool runOnFunction(Function &F);
};
-
+
RegisterOpt<CombineBranches>
X("branch-combine", "Multiple backedges going to same target are merged");
}
@@ -53,10 +53,10 @@ namespace {
///
void CombineBranches::getBackEdgesVisit(BasicBlock *u,
std::map<BasicBlock *, Color > &color,
- std::map<BasicBlock *, int > &d,
+ std::map<BasicBlock *, int > &d,
int &time,
std::map<BasicBlock *, BasicBlock *> &be) {
-
+
color[u]=GREY;
time++;
d[u]=time;
@@ -66,7 +66,7 @@ void CombineBranches::getBackEdgesVisit(BasicBlock *u,
if(color[BB]!=GREY && color[BB]!=BLACK)
getBackEdgesVisit(BB, color, d, time, be);
-
+
//now checking for d and f vals
else if(color[BB]==GREY){
//so v is ancestor of u if time of u > time of v
@@ -83,29 +83,29 @@ void CombineBranches::getBackEdgesVisit(BasicBlock *u,
void CombineBranches::removeRedundant(std::map<BasicBlock *, BasicBlock *> &be){
std::vector<BasicBlock *> toDelete;
std::map<BasicBlock *, int> seenBB;
-
- for(std::map<BasicBlock *, BasicBlock *>::iterator MI = be.begin(),
+
+ for(std::map<BasicBlock *, BasicBlock *>::iterator MI = be.begin(),
ME = be.end(); MI != ME; ++MI){
-
+
if(seenBB[MI->second])
continue;
-
+
seenBB[MI->second] = 1;
std::vector<BasicBlock *> sameTarget;
sameTarget.clear();
-
- for(std::map<BasicBlock *, BasicBlock *>::iterator MMI = be.begin(),
+
+ for(std::map<BasicBlock *, BasicBlock *>::iterator MMI = be.begin(),
MME = be.end(); MMI != MME; ++MMI){
-
+
if(MMI->first == MI->first)
continue;
-
+
if(MMI->second == MI->second)
sameTarget.push_back(MMI->first);
-
+
}
-
+
//so more than one branch to same target
if(sameTarget.size()){
@@ -126,9 +126,9 @@ void CombineBranches::removeRedundant(std::map<BasicBlock *, BasicBlock *> &be){
ti->setSuccessor(index, newBB);
- for(BasicBlock::iterator BB2Inst = MI->second->begin(),
+ for(BasicBlock::iterator BB2Inst = MI->second->begin(),
BBend = MI->second->end(); BB2Inst != BBend; ++BB2Inst){
-
+
if (PHINode *phiInst = dyn_cast<PHINode>(BB2Inst)){
int bbIndex;
bbIndex = phiInst->getBasicBlockIndex(*VBI);
@@ -178,7 +178,7 @@ bool CombineBranches::runOnFunction(Function &F){
int time = 0;
getBackEdgesVisit (F.begin (), color, d, time, be);
removeRedundant (be);
-
+
return true; // FIXME: assumes a modification was always made.
}
diff --git a/lib/Transforms/Instrumentation/ProfilePaths/EdgeCode.cpp b/lib/Transforms/Instrumentation/ProfilePaths/EdgeCode.cpp
index 8e7bd78958..aef4681f30 100644
--- a/lib/Transforms/Instrumentation/ProfilePaths/EdgeCode.cpp
+++ b/lib/Transforms/Instrumentation/ProfilePaths/EdgeCode.cpp
@@ -1,16 +1,16 @@
//===-- EdgeCode.cpp - generate LLVM instrumentation code -----------------===//
-//
+//
// The LLVM Compiler Infrastructure
//
// This file was developed by the LLVM research group and is distributed under
// the University of Illinois Open Source License. See LICENSE.TXT for details.
-//
+//
//===----------------------------------------------------------------------===//
-//It implements the class EdgeCode: which provides
+//It implements the class EdgeCode: which provides
//support for inserting "appropriate" instrumentation at
//designated points in the graph
//
-//It also has methods to insert initialization code in
+//It also has methods to insert initialization code in
//top block of cfg
//===----------------------------------------------------------------------===//
@@ -29,8 +29,8 @@ using std::vector;
namespace llvm {
static void getTriggerCode(Module *M, BasicBlock *BB, int MethNo, Value *pathNo,
- Value *cnt, Instruction *rInst){
-
+ Value *cnt, Instruction *rInst){
+
vector<Value *> tmpVec;
tmpVec.push_back(Constant::getNullValue(Type::LongTy));
tmpVec.push_back(Constant::getNullValue(Type::LongTy));
@@ -38,7 +38,7 @@ static void getTriggerCode(Module *M, BasicBlock *BB, int MethNo, Value *pathNo,
BB->getInstList().push_back(Idx);
const Type *PIntTy = PointerType::get(Type::IntTy);
- Function *trigMeth = M->getOrInsertFunction("trigger", Type::VoidTy,
+ Function *trigMeth = M->getOrInsertFunction("trigger", Type::VoidTy,
Type::IntTy, Type::IntTy,
PIntTy, PIntTy, 0);
assert(trigMeth && "trigger method could not be inserted!");
@@ -58,18 +58,18 @@ static void getTriggerCode(Module *M, BasicBlock *BB, int MethNo, Value *pathNo,
//get the code to be inserted on the edge
//This is determined from cond (1-6)
-void getEdgeCode::getCode(Instruction *rInst, Value *countInst,
- Function *M, BasicBlock *BB,
+void getEdgeCode::getCode(Instruction *rInst, Value *countInst,
+ Function *M, BasicBlock *BB,
vector<Value *> &retVec){
-
+
//Instruction *InsertPos = BB->getInstList().begin();
-
+
//now check for cdIn and cdOut
//first put cdOut
if(cdOut!=NULL){
cdOut->getCode(rInst, countInst, M, BB, retVec);
}
-
+
if(cdIn!=NULL){
cdIn->getCode(rInst, countInst, M, BB, retVec);
}
@@ -93,7 +93,7 @@ void getEdgeCode::getCode(Instruction *rInst, Value *countInst,
#endif
break;
}
-
+
//r+=k
case 3:{
Instruction *ldInst = new LoadInst(rInst, "ti1");//, InsertPos);
@@ -116,33 +116,33 @@ void getEdgeCode::getCode(Instruction *rInst, Value *countInst,
tmpVec.push_back(ConstantSInt::get(Type::LongTy, inc));
Instruction *Idx = new GetElementPtrInst(countInst, tmpVec, "");//,
- //Instruction *Idx = new GetElementPtrInst(countInst,
+ //Instruction *Idx = new GetElementPtrInst(countInst,
// vector<Value*>(1,ConstantSInt::get(Type::LongTy, inc)),
// "");//, InsertPos);
BB->getInstList().push_back(Idx);
Instruction *ldInst=new LoadInst(Idx, "ti1");//, InsertPos);
BB->getInstList().push_back(ldInst);
-
+
Value *val = ConstantSInt::get(Type::IntTy, 1);
//Instruction *addIn =
Instruction *newCount =
BinaryOperator::create(Instruction::Add, ldInst, val,"ti2");
BB->getInstList().push_back(newCount);
-
+
#ifdef INSERT_STORE
//Instruction *stInst=new StoreInst(addIn, Idx, InsertPos);
Instruction *stInst=new StoreInst(newCount, Idx);//, InsertPos);
BB->getInstList().push_back(stInst);
#endif
-
+
Value *trAddIndex = ConstantSInt::get(Type::IntTy,inc);
retVec.push_back(newCount);
retVec.push_back(trAddIndex);
//insert trigger
- //getTriggerCode(M->getParent(), BB, MethNo,
+ //getTriggerCode(M->getParent(), BB, MethNo,
// ConstantSInt::get(Type::IntTy,inc), newCount, triggerInst);
//end trigger code
@@ -152,7 +152,7 @@ void getEdgeCode::getCode(Instruction *rInst, Value *countInst,
//case: count[r+inc]++
case 5:{
-
+
//ti1=inc+r
Instruction *ldIndex=new LoadInst(rInst, "ti1");//, InsertPos);
BB->getInstList().push_back(ldIndex);
@@ -161,9 +161,9 @@ void getEdgeCode::getCode(Instruction *rInst, Value *countInst,
Instruction *addIndex=BinaryOperator::
create(Instruction::Add, ldIndex, val,"ti2");//, InsertPos);
BB->getInstList().push_back(addIndex);
-
+
//now load count[addIndex]
- Instruction *castInst=new CastInst(addIndex,
+ Instruction *castInst=new CastInst(addIndex,
Type::LongTy,"ctin");//, InsertPos);
BB->getInstList().push_back(castInst);
@@ -180,10 +180,10 @@ void getEdgeCode::getCode(Instruction *rInst, Value *countInst,
Value *cons=ConstantSInt::get(Type::IntTy,1);
//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,"");
BB->getInstList().push_back(newCount);
-
+
#ifdef INSERT_STORE
Instruction *stInst = new StoreInst(newCount, Idx);//, InsertPos);
BB->getInstList().push_back(stInst);
@@ -213,11 +213,11 @@ void getEdgeCode::getCode(Instruction *rInst, Value *countInst,
tmpVec.push_back(castInst2);
Instruction *Idx = new GetElementPtrInst(countInst, tmpVec, "");//,
- //Instruction *Idx = new GetElementPtrInst(countInst,
+ //Instruction *Idx = new GetElementPtrInst(countInst,
// vector<Value*>(1,castInst2), "");
-
+
BB->getInstList().push_back(Idx);
-
+
Instruction *ldInst=new LoadInst(Idx, "ti2");//, InsertPos);
BB->getInstList().push_back(ldInst);
@@ -237,7 +237,7 @@ void getEdgeCode::getCode(Instruction *rInst, Value *countInst,
retVec.push_back(ldIndex);
break;
}
-
+
}
}
@@ -245,25 +245,25 @@ void getEdgeCode::getCode(Instruction *rInst, Value *countInst,
//Insert the initialization code in the top BB
//this includes initializing r, and count
-//r is like an accumulator, that
+//r is like an accumulator, that
//keeps on adding increments as we traverse along a path
//and at the end of the path, r contains the path
//number of that path
//Count is an array, where Count[k] represents
//the number of executions of path k
-void insertInTopBB(BasicBlock *front,
- int k,
+void insertInTopBB(BasicBlock *front,
+ int k,
Instruction *rVar, Value *threshold){
- //rVar is variable r,
+ //rVar is variable r,
//countVar is count[]
Value *Int0 = ConstantInt::get(Type::IntTy, 0);
-
+
//now push all instructions in front of the BB
BasicBlock::iterator here=front->begin();
front->getInstList().insert(here, rVar);
//front->getInstList().insert(here,countVar);
-
+
//Initialize Count[...] with 0
//for (int i=0;i<k; i++){
@@ -281,22 +281,22 @@ void insertInTopBB(BasicBlock *front,
//insert a basic block with appropriate code
//along a given edge
void insertBB(Edge ed,
- getEdgeCode *edgeCode,
- Instruction *rInst,
- Value *countInst,
+ getEdgeCode *edgeCode,
+ Instruction *rInst,
+ Value *countInst,
int numPaths, int Methno, Value *threshold){
BasicBlock* BB1=ed.getFirst()->getElement();
BasicBlock* BB2=ed.getSecond()->getElement();
-
+
#ifdef DEBUG_PATH_PROFILES
//debugging info
cerr<<"Edges with codes ######################\n";
cerr<<BB1->getName()<<"->"<<BB2->getName()<<"\n";
cerr<<"########################\n";
#endif
-
- //We need to insert a BB between BB1 and BB2
+
+ //We need to insert a BB between BB1 and BB2
TerminatorInst *TI=BB1->getTerminator();
BasicBlock *newBB=new BasicBlock("counter", BB1->getParent());
@@ -316,7 +316,7 @@ void insertBB(Edge ed,
else{
if(BI->getSuccessor(0)==BB2)
BI->setSuccessor(0, newBB);
-
+
if(BI->getSuccessor(1)==BB2)
BI->setSuccessor(1, newBB);
}
@@ -324,21 +324,21 @@ void insertBB(Edge ed,
BasicBlock *triggerBB = NULL;
if(retVec.size()>0){
triggerBB = new BasicBlock("trigger", BB1->getParent());
- getTriggerCode(BB1->getParent()->getParent(), triggerBB, Methno,
+ getTriggerCode(BB1->getParent()->getParent(), triggerBB, Methno,
retVec[1], countInst, rInst);//retVec[0]);
//Instruction *castInst = new CastInst(retVec[0], Type::IntTy, "");
Instruction *etr = new LoadInst(threshold, "threshold");
-
- //std::cerr<<"type1: "<<etr->getType()<<" type2: "<<retVec[0]->getType()<<"\n";
- Instruction *cmpInst = new SetCondInst(Instruction::SetLE, etr,
+
+ //std::cerr<<"type1: "<<etr->getType()<<" type2: "<<retVec[0]->getType()<<"\n";
+ Instruction *cmpInst = new SetCondInst(Instruction::SetLE, etr,
retVec[0], "");
Instruction *newBI2 = new BranchInst(triggerBB, BB2, cmpInst);
//newBB->getInstList().push_back(castInst);
newBB->getInstList().push_back(etr);
newBB->getInstList().push_back(cmpInst);
newBB->getInstList().push_back(newBI2);
-
+
//triggerBB->getInstList().push_back(triggerInst);
new BranchInst(BB2, 0, 0, triggerBB);
}
@@ -347,9 +347,9 @@ void insertBB(Edge ed,
}
//now iterate over BB2, and set its Phi nodes right
- for(BasicBlock::iterator BB2Inst = BB2->begin(), BBend = BB2->end();
+ for(BasicBlock::iterator BB2Inst = BB2->begin(), BBend = BB2->end();
BB2Inst != BBend; ++BB2Inst){
-
+
if(PHINode *phiInst=dyn_cast<PHINode>(BB2Inst)){
int bbIndex=phiInst->getBasicBlockIndex(BB1);
assert(bbIndex>=0);
diff --git a/lib/Transforms/Instrumentation/ProfilePaths/Graph.cpp b/lib/Transforms/Instrumentation/ProfilePaths/Graph.cpp
index 21a6e93e04..21883c41b0 100644
--- a/lib/Transforms/Instrumentation/ProfilePaths/Graph.cpp
+++ b/lib/Transforms/Instrumentation/ProfilePaths/Graph.cpp
@@ -1,10 +1,10 @@
//===-- Graph.cpp - Implements Graph class --------------------------------===//
-//
+//
// The LLVM Compiler Infrastructure
//
// This file was developed by the LLVM research group and is distributed under
// the University of Illinois Open Source License. See LICENSE.TXT for details.
-//
+//
//===----------------------------------------------------------------------===//
//
// This implements Graph for helping in trace generation This graph gets used by
@@ -23,7 +23,7 @@ namespace llvm {
const graphListElement *findNodeInList(const Graph::nodeList &NL,
Node *N) {
- for(Graph::nodeList::const_iterator NI = NL.begin(), NE=NL.end(); NI != NE;
+ for(Graph::nodeList::const_iterator NI = NL.begin(), NE=NL.end(); NI != NE;
++NI)
if (*NI->element== *N)
return &*NI;
@@ -38,7 +38,7 @@ graphListElement *findNodeInList(Graph::nodeList &NL, Node *N) {
}
//graph constructor with root and exit specified
-Graph::Graph(std::vector<Node*> n, std::vector<Edge> e,
+Graph::Graph(std::vector<Node*> n, std::vector<Edge> e,
Node *rt, Node *lt){
strt=rt;
ext=lt;
@@ -49,17 +49,17 @@ Graph::Graph(std::vector<Node*> n, std::vector<Edge> e,
for(vector<Edge >::iterator x=e.begin(), en=e.end(); x!=en; ++x){
Edge ee=*x;
int w=ee.getWeight();
- //nodes[ee.getFirst()].push_front(graphListElement(ee.getSecond(),w, ee.getRandId()));
+ //nodes[ee.getFirst()].push_front(graphListElement(ee.getSecond(),w, ee.getRandId()));
nodes[ee.getFirst()].push_back(graphListElement(ee.getSecond(),w, ee.getRandId()));
}
-
+
}
//sorting edgelist, called by backEdgeVist ONLY!!!
Graph::nodeList &Graph::sortNodeList(Node *par, nodeList &nl, vector<Edge> &be){
assert(par && "null node pointer");
BasicBlock *bbPar = par->getElement();
-
+
if(nl.size()<=1) return nl;
if(getExit() == par) return nl;
@@ -79,7 +79,7 @@ Graph::nodeList &Graph::sortNodeList(Node *par, nodeList &nl, vector<Edge> &be){
assert(ti && "not a branch");
assert(ti->getNumSuccessors()==2 && "less successors!");
-
+
BasicBlock *tB = ti->getSuccessor(0);
BasicBlock *fB = ti->getSuccessor(1);
//so one of LI or min must be back edge!
@@ -109,24 +109,24 @@ Graph::nodeList &Graph::sortNodeList(Node *par, nodeList &nl, vector<Edge> &be){
}
}
}
-
+
else if (min->element->getElement() != LI->element->getElement()){
TerminatorInst *tti = par->getElement()->getTerminator();
BranchInst *ti = cast<BranchInst>(tti);
assert(ti && "not a branch");
if(ti->getNumSuccessors()<=1) continue;
-
+
assert(ti->getNumSuccessors()==2 && "less successors!");
-
+
BasicBlock *tB = ti->getSuccessor(0);
BasicBlock *fB = ti->getSuccessor(1);
-
+
if(tB == LI->element->getElement() || fB == min->element->getElement())
min = LI;
}
}
-
+
graphListElement tmpElmnt = *min;
*min = *NLI;
*NLI = tmpElmnt;
@@ -159,11 +159,11 @@ bool Graph::hasEdgeAndWt(Edge ed){
Node *nd2=ed.getSecond();
nodeList &nli = nodes[ed.getFirst()];//getNodeList(ed.getFirst());
-
+
for(nodeList::iterator NI=nli.begin(), NE=nli.end(); NI!=NE; ++NI)
if(*NI->element == *nd2 && ed.getWeight()==NI->weight)
return true;
-
+
return false;
}
@@ -180,9 +180,9 @@ void Graph::addNode(Node *nd){
}
//add an edge
-//this adds an edge ONLY when
+//this adds an edge ONLY when
//the edge to be added does not already exist
-//we "equate" two edges here only with their
+//we "equate" two edges here only with their
//end points
void Graph::addEdge(Edge ed, int w){
nodeList &ndList = nodes[ed.getFirst()];
@@ -190,7 +190,7 @@ void Graph::addEdge(Edge ed, int w){
if(findNodeInList(nodes[ed.getFirst()], nd2))
return;
-
+
//ndList.push_front(graphListElement(nd2,w, ed.getRandId()));
ndList.push_back(graphListElement(nd2,w, ed.getRandId()));//chng
//sortNodeList(ed.getFirst(), ndList);
@@ -296,7 +296,7 @@ int Graph::getNumberOfIncomingEdges(Node *nd){
for(nodeMapTy::const_iterator EI=nodes.begin(), EE=nodes.end(); EI!=EE ;++EI){
Node *lnode=EI->first;
const nodeList &nl = getNodeList(lnode);
- for(Graph::nodeList::const_iterator NI = nl.begin(), NE=nl.end(); NI != NE;
+ for(Graph::nodeList::const_iterator NI = nl.begin(), NE=nl.end(); NI != NE;
++NI)
if (*NI->element== *nd)
count++;
@@ -340,19 +340,19 @@ static void printNode(Node *nd){
//of the graph
Graph* Graph::getMaxSpanningTree(){
//assume connected graph
-
+
Graph *st=new Graph();//max spanning tree, undirected edges
int inf=9999999;//largest key
vector<Node *> lt = getAllNodes();
-
+
//initially put all vertices in vector vt
//assign wt(root)=0
//wt(others)=infinity
//
//now:
//pull out u: a vertex frm vt of min wt
- //for all vertices w in vt,
- //if wt(w) greater than
+ //for all vertices w in vt,
+ //if wt(w) greater than
//the wt(u->w), then assign
//wt(w) to be wt(u->w).
//
@@ -360,7 +360,7 @@ Graph* Graph::getMaxSpanningTree(){
//keep pulling out vertices from vt till it is empty
vector<Node *> vt;
-
+
std::map<Node*, Node* > parent;
std::map<Node*, int > ed_weight;
@@ -373,7 +373,7 @@ Graph* Graph::getMaxSpanningTree(){
parent[thisNode]=NULL;
ed_weight[thisNode]=0;
}
- else{
+ else{
thisNode->setWeight(inf);
}
st->addNode(thisNode);//add all nodes to spanning tree
@@ -396,7 +396,7 @@ Graph* Graph::getMaxSpanningTree(){
}
//vt.erase(u);
-
+
//remove u frm vt
for(vector<Node *>::iterator VI=vt.begin(), VE=vt.end(); VI!=VE; ++VI){
if(**VI==*u){
@@ -404,7 +404,7 @@ Graph* Graph::getMaxSpanningTree(){
break;
}
}
-
+
//assign wt(v) to all adjacent vertices v of u
//only if v is in vt
Graph::nodeList &nl = getNodeList(u);
@@ -438,7 +438,7 @@ Graph* Graph::getMaxSpanningTree(){
return st;
}
-//print the graph (for debugging)
+//print the graph (for debugging)
void Graph::printGraph(){
vector<Node *> lt=getAllNodes();
std::cerr<<"Graph---------------------\n";
@@ -469,7 +469,7 @@ vector<Node *> Graph::reverseTopologicalSort(){
}
//a private method for doing DFS traversal of graph
-//this is used in determining the reverse topological sort
+//this is used in determining the reverse topological sort
//of the graph
void Graph::DFS_Visit(Node *nd, vector<Node *> &toReturn){
nd->setWeight(GREY);
@@ -482,13 +482,13 @@ void Graph::DFS_Visit(Node *nd, vector<Node *> &toReturn){
}
//Ordinarily, the graph is directional
-//this converts the graph into an
+//this converts the graph into an
//undirectional graph
//This is done by adding an edge
//v->u for all existing edges u->v
void Graph::makeUnDirectional(){
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) {
nodeList &nl = getNodeList(*NI);
for(nodeList::iterator NLI=nl.begin(), NLE=nl.end(); NLI!=NLE; ++NLI){
@@ -507,10 +507,10 @@ void Graph::makeUnDirectional(){
//using min-spanning tree, and vice versa
void Graph::reverseWts(){
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) {
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->weight=-NLI->weight;
}
@@ -535,7 +535,7 @@ void Graph::getBackEdges(vector<Edge > &be, std::map<Node *, int> &d){
getBackEdgesVisit(getRoot(), be, color, d, time);
}
-//helper function to get back edges: it is called by
+//helper function to get back edges: it is called by
//the "getBackEdges" function above
void Graph::getBackEdgesVisit(Node *u, vector<Edge > &be,
std::map<Node *, Color > &color,
@@ -545,14 +545,14 @@ void Graph::getBackEdgesVisit(Node *u, vector<Edge > &be,
d[u]=time;
vector<graphListElement> &succ_list = getNodeList(u);
-
- for(vector<graphListElement>::iterator vl=succ_list.begin(),
+
+ for(vector<graphListElement>::iterator vl=succ_list.begin(),
ve=succ_list.end(); vl!=ve; ++vl){
Node *v=vl->element;
if(color[v]!=GREY && color[v]!=BLACK){
getBackEdgesVisit(v, be, color, d, time);
}
-
+
//now checking for d and f vals
if(color[v]==GREY){
//so v is ancestor of u if time of u > time of v
diff --git a/lib/Transforms/Instrumentation/ProfilePaths/Graph.h b/lib/Transforms/Instrumentation/ProfilePaths/Graph.h
index 44b63a91ea..203948454c 100644
--- a/lib/Transforms/Instrumentation/ProfilePaths/Graph.h
+++ b/lib/Transforms/Instrumentation/ProfilePaths/Graph.h
@@ -1,10 +1,10 @@
//===-- Graph.h -------------------------------------------------*- C++ -*-===//
-//
+//
// The LLVM Compiler Infrastructure
//
// This file was developed by the LLVM research group and is distributed under
// the University of Illinois Open Source License. See LICENSE.TXT for details.
-//
+//
//===----------------------------------------------------------------------===//
//
// Header file for Graph: This Graph is used by PathProfiles class, and is used
@@ -58,13 +58,13 @@ public:
randId=rand();
isnull=false;
}
-
+
inline Edge(Node *f,Node *s, int wt, double rd){
first=f;
second=s;
weight=wt;
randId=rd;
- isnull=false;
+ isnull=false;
}
inline Edge() { isnull = true; }
@@ -73,22 +73,22 @@ public:
inline Node* const getFirst() const { assert(!isNull()); return first; }
inline Node* getSecond() { assert(!isNull()); return second; }
inline Node* const getSecond() const { assert(!isNull()); return second; }
-
+
inline int getWeight() { assert(!isNull()); return weight; }
inline void setWeight(int n) { assert(!isNull()); weight=n; }
-
+
inline void setFirst(Node *&f) { assert(!isNull()); first=f; }
inline void setSecond(Node *&s) { assert(!isNull()); second=s; }
-
-
- inline bool isNull() const { return isnull;}
-
+
+
+ inline bool isNull() const { return isnull;}
+
inline bool operator<(const Edge& ed) const{
// Can't be the same if one is null and the other isn't
if (isNull() != ed.isNull())
return true;
- return (*first<*(ed.getFirst()))||
+ return (*first<*(ed.getFirst()))||
(*first==*(ed.getFirst()) && *second<*(ed.getSecond()));
}
@@ -96,19 +96,19 @@ public:
return !(*this<ed) && !(ed<*this);
}
- inline bool operator!=(const Edge& ed) const{return !(*this==ed);}
+ inline bool operator!=(const Edge& ed) const{return !(*this==ed);}
};
//graphListElement
-//This forms the "adjacency list element" of a
+//This forms the "adjacency list element" of a
//vertex adjacency list in graph
struct graphListElement{
Node *element;
int weight;
double randId;
- inline graphListElement(Node *n, int w, double rand){
- element=n;
+ inline graphListElement(Node *n, int w, double rand){
+ element=n;
weight=w;
randId=rand;
}
@@ -127,12 +127,12 @@ using namespace llvm;
return n1->getElement() < n2->getElement();
}
};
-
+
template<>
struct less<Edge> : public binary_function<Edge,Edge,bool> {
bool operator()(Edge e1, Edge e2) const {
assert(!e1.isNull() && !e2.isNull());
-
+
Node *x1=e1.getFirst();
Node *x2=e1.getSecond();
Node *y1=e2.getFirst();
@@ -210,7 +210,7 @@ public:
private:
//the adjacency list of a vertex or node
nodeMapTy nodes;
-
+
//the start or root node
Node *strt;
@@ -218,7 +218,7 @@ private:
Node *ext;
//a private method for doing DFS traversal of graph
- //this is used in determining the reverse topological sort
+ //this is used in determining the reverse topological sort
//of the graph
void DFS_Visit(Node *nd, std::vector<Node *> &toReturn);
@@ -232,10 +232,10 @@ private:
//have been visited
//So we have a back edge when we meet a successor of
//a node with smaller time, and GREY color
- void getBackEdgesVisit(Node *u,
+ void getBackEdgesVisit(Node *u,
std::vector<Edge > &be,
std::map<Node *, Color> &clr,
- std::map<Node *, int> &d,
+ std::map<Node *, int> &d,
int &time);
public:
@@ -248,18 +248,18 @@ public:
//empty constructor: then add edges and nodes later on
Graph() {}
-
+
//constructor with root and exit node specified
- Graph(std::vector<Node*> n,
+ Graph(std::vector<Node*> n,
std::vector<Edge> e, Node *rt, Node *lt);
//add a node
void addNode(Node *nd);
//add an edge
- //this adds an edge ONLY when
+ //this adds an edge ONLY when
//the edge to be added doesn not already exist
- //we "equate" two edges here only with their
+ //we "equate" two edges here only with their
//end points
void addEdge(Edge ed, int w);
@@ -310,14 +310,14 @@ public:
//in r-topological sorted order
//note that we assumed graph to be connected
std::vector<Node *> reverseTopologicalSort();
-
+
//reverse the sign of weights on edges
//this way, max-spanning tree could be obtained
//usin min-spanning tree, and vice versa
void reverseWts();
//Ordinarily, the graph is directional
- //this converts the graph into an
+ //this converts the graph into an
//undirectional graph
//This is done by adding an edge
//v->u for all existing edges u->v
@@ -325,31 +325,31 @@ public:
//print graph: for debugging
void printGraph();
-
+
//get a vector of back edges in the graph
void getBackEdges(std::vector<Edge> &be, std::map<Node *, int> &d);
nodeList &sortNodeList(Node *par, nodeList &nl, std::vector<Edge> &be);
-
+
//Get the Maximal spanning tree (also a graph)
//of the graph
Graph* getMaxSpanningTree();
-
+
//get the nodeList adjacent to a node
- //a nodeList element contains a node, and the weight
+ //a nodeList element contains a node, and the weight
//corresponding to the edge for that element
inline nodeList &getNodeList(Node *nd) {
elementIterator nli = nodes.find(nd);
assert(nli != nodes.end() && "Node must be in nodes map");
return nodes[nd];//sortNodeList(nd, nli->second);
}
-
+
nodeList &getSortedNodeList(Node *nd, std::vector<Edge> &be) {
elementIterator nli = nodes.find(nd);
assert(nli != nodes.end() && "Node must be in nodes map");
return sortNodeList(nd, nodes[nd], be);
}
-
+
//get the root of the graph
inline Node *getRoot() {return strt; }
inline Node * const getRoot() const {return strt; }
@@ -365,7 +365,7 @@ public:
inline bool isLeaf(Node *n) const {return (*n==*ext); }
};
-//This class is used to generate
+//This class is used to generate
//"appropriate" code to be inserted
//along an edge
//The code to be inserted can be of six different types
@@ -378,13 +378,13 @@ public:
//6: Count[r]++
class getEdgeCode{
private:
- //cond implies which
+ //cond implies which
//"kind" of code is to be inserted
//(from 1-6 above)
int cond;
//inc is the increment: eg k, or 0
int inc;
-
+
//A backedge must carry the code
//of both incoming "dummy" edge
//and outgoing "dummy" edge
@@ -420,23 +420,23 @@ public:
//set CdIn (only used for backedges)
inline void setCdIn(getEdgeCode *gd){ cdIn=gd;}
-
+
//set CdOut (only used for backedges)
inline void setCdOut(getEdgeCode *gd){ cdOut=gd;}
//get the code to be inserted on the edge
//This is determined from cond (1-6)
- void getCode(Instruction *a, Value *b, Function *M, BasicBlock *BB,
+ void getCode(Instruction *a, Value *b, Function *M, BasicBlock *BB,
std::vector<Value *> &retVec);
};
//auxillary functions on graph
-//print a given edge in the form BB1Label->BB2Label
+//print a given edge in the form BB1Label->BB2Label
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 locations
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);
@@ -452,7 +452,7 @@ void insertBB(Edge ed, getEdgeCode *edgeCode, Instruction *rInst, Value *countIn
//Insert the initialization code in the top BB
//this includes initializing r, and count
-//r is like an accumulator, that
+//r is like an accumulator, that
//keeps on adding increments as we traverse along a path
//and at the end of the path, r contains the path
//number of that path
@@ -470,7 +470,7 @@ void addDummyEdges(std::vector<Edge> &stDummy, std::vector<Edge> &exDummy, Graph
//such that if we traverse along any path from root to exit, and
//add up the edge values, we get a path number that uniquely
//refers to the path we travelled
-int valueAssignmentToEdges(Graph& g, std::map<Node *, int> nodePriority,
+int valueAssignmentToEdges(Graph& g, std::map<Node *, int> nodePriority,
std::vector<Edge> &be);
void getBBtrace(std::vector<BasicBlock *> &vBB, int pathNo, Function *M);
diff --git a/lib/Transforms/Instrumentation/ProfilePaths/GraphAuxiliary.cpp b/lib/Transforms/Instrumentation/ProfilePaths/GraphAuxiliary.cpp
index bd1fa51621..bd7bf4fe9e 100644
--- a/lib/Transforms/Instrumentation/ProfilePaths/GraphAuxiliary.cpp
+++ b/lib/Transforms/Instrumentation/ProfilePaths/GraphAuxiliary.cpp
@@ -1,10 +1,10 @@
//===- GraphAuxiliary.cpp - Auxiliary functions on graph ------------------===//
-//
+//
// The LLVM Compiler Infrastructure
//
// This file was developed by the LLVM research group and is distributed under
// the University of Illinois Open Source License. See LICENSE.TXT for details.
-//
+//
//===----------------------------------------------------------------------===//
//
// auxiliary function associated with graph: they all operate on graph, and help
@@ -36,10 +36,10 @@ static void getChords(vector<Edge > &chords, Graph &g, Graph st){
//make sure the spanning tree is directional
//iterate over ALL the edges of the graph
vector<Node *> allNodes=g.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){
Graph::nodeList node_list=g.getNodeList(*NI);
- for(Graph::nodeList::iterator NLI=node_list.begin(), NLE=node_list.end();
+ for(Graph::nodeList::iterator NLI=node_list.begin(), NLE=node_list.end();
NLI!=NLE; ++NLI){
Edge f(*NI, NLI->element,NLI->weight, NLI->randId);
if(!(st.hasEdgeAndWt(f)))//addnl
@@ -51,13 +51,13 @@ static void getChords(vector<Edge > &chords, Graph &g, Graph st){
//Given a tree t, and a "directed graph" g
//replace the edges in the tree t with edges that exist in graph
//The tree is formed from "undirectional" copy of graph
-//So whatever edges the tree has, the undirectional graph
-//would have too. This function corrects some of the directions in
+//So whatever edges the tree has, the undirectional graph
+//would have too. This function corrects some of the directions in
//the tree so that now, all edge directions in the tree match
//the edge directions of corresponding edges in the directed graph
static void removeTreeEdges(Graph &g, Graph& t){
vector<Node* > allNodes=t.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){
Graph::nodeList nl=t.getNodeList(*NI);
for(Graph::nodeList::iterator NLI=nl.begin(), NLE=nl.end(); NLI!=NLE;++NLI){
@@ -72,11 +72,11 @@ static void removeTreeEdges(Graph &g, Graph& t){
//such that if we traverse along any path from root to exit, and
//add up the edge values, we get a path number that uniquely
//refers to the path we travelled
-int valueAssignmentToEdges(Graph& g, map<Node *, int> nodePriority,
+int valueAssignmentToEdges(Graph& g, map<Node *, int> nodePriority,
vector<Edge> &be){
vector<Node *> revtop=g.reverseTopologicalSort();
map<Node *,int > NumPaths;
- for(vector<Node *>::iterator RI=revtop.begin(), RE=revtop.end();
+ for(vector<Node *>::iterator RI=revtop.begin(), RE=revtop.end();
RI!=RE; ++RI){
if(g.isLeaf(*RI))
NumPaths[*RI]=1;
@@ -87,47 +87,47 @@ int valueAssignmentToEdges(Graph& g, map<Node *, int> nodePriority,
Graph::nodeList &nlist=g.getSortedNodeList(*RI, be);
//sort nodelist by increasing order of numpaths
-
+
int sz=nlist.size();
-
+
for(int i=0;i<sz-1; i++){
int min=i;
for(int j=i+1; j<sz; j++){
BasicBlock *bb1 = nlist[j].element->getElement();
BasicBlock *bb2 = nlist[min].element->getElement();
-
+
if(bb1 == bb2) continue;
-
+
if(*RI == g.getRoot()){
- assert(nodePriority[nlist[min].element]!=
- nodePriority[nlist[j].element]
+ assert(nodePriority[nlist[min].element]!=
+ nodePriority[nlist[j].element]
&& "priorities can't be same!");
-
- if(nodePriority[nlist[j].element] <
+
+ if(nodePriority[nlist[j].element] <
nodePriority[nlist[min].element])
- min = j;
+ min = j;
}
else{
TerminatorInst *tti = (*RI)->getElement()->getTerminator();
-
+
BranchInst *ti = cast<BranchInst>(tti);
assert(ti && "not a branch");
assert(ti->getNumSuccessors()==2 && "less successors!");
-
+
BasicBlock *tB = ti->getSuccessor(0);
BasicBlock *fB = ti->getSuccessor(1);
-
+
if(tB == bb1 || fB == bb2)
min = j;
}
-
+
}
graphListElement tempEl=nlist[min];
nlist[min]=nlist[i];
nlist[i]=tempEl;
}
-
+
//sorted now!
for(Graph::nodeList::iterator GLI=nlist.begin(), GLE=nlist.end();
GLI!=GLE; ++GLI){
@@ -148,35 +148,35 @@ int valueAssignmentToEdges(Graph& g, map<Node *, int> nodePriority,
//refers to the path we travelled
//inc_Dir tells whether 2 edges are in same, or in different directions
//if same direction, return 1, else -1
-static int inc_Dir(Edge e, Edge f){
- if(e.isNull())
+static int inc_Dir(Edge e, Edge f){
+ if(e.isNull())
return 1;
-
+
//check that the edges must have at least one common endpoint
assert(*(e.getFirst())==*(f.getFirst()) ||
- *(e.getFirst())==*(f.getSecond()) ||
+ *(e.getFirst())==*(f.getSecond()) ||
*(e.getSecond())==*(f.getFirst()) ||
*(e.getSecond())==*(f.getSecond()));
- if(*(e.getFirst())==*(f.getSecond()) ||
+ if(*(e.getFirst())==*(f.getSecond()) ||
*(e.getSecond())==*(f.getFirst()))
return 1;
-
+
return -1;
}
//used for getting edge increments (read comments above in inc_Dir)
-//inc_DFS is a modification of DFS
-static void inc_DFS(Graph& g,Graph& t,map<Edge, int, EdgeCompare2>& Increment,
+//inc_DFS is a modification of DFS
+static void inc_DFS(Graph& g,Graph& t,map<Edge, int, EdgeCompare2>& Increment,
int events, Node *v, Edge e){
-
+
vector<Node *> allNodes=t.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){
Graph::nodeList node_list=t.getNodeList(*NI);
- for(Graph::nodeList::iterator NLI=node_list.begin(), NLE=node_list.end();
+ for(Graph::nodeList::iterator NLI=node_list.begin(), NLE=node_list.end();
NLI!= NLE; ++NLI){
Edge f(*NI, NLI->element,NLI->weight, NLI->randId);
if(!edgesEqual(f,e) && *v==*(f.getSecond())){
@@ -187,29 +187,29 @@ static void inc_DFS(Graph& g,Graph& t,map<Edge, int, EdgeCompare2>& Increment,
}
}
- 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){
Graph::nodeList node_list=t.getNodeList(*NI);
- for(Graph::nodeList::iterator NLI=node_list.begin(), NLE=node_list.end();
+ for(Graph::nodeList::iterator NLI=node_list.begin(), NLE=node_list.end();
NLI!=NLE; ++NLI){
Edge f(*NI, NLI->element,NLI->weight, NLI->randId);
if(!edgesEqual(f,e) && *v==*(f.getFirst())){
int dir_count=inc_Dir(e,f);
int wt=f.getWeight();
- inc_DFS(g,t, Increment, dir_count*events+wt,
+ inc_DFS(g,t, Increment, dir_count*events+wt,
f.getSecond(), f);
}
}
}
allNodes=g.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){
Graph::nodeList node_list=g.getNodeList(*NI);
- for(Graph::nodeList::iterator NLI=node_list.begin(), NLE=node_list.end();
+ for(Graph::nodeList::iterator NLI=node_list.begin(), NLE=node_list.end();
NLI!=NLE; ++NLI){
Edge f(*NI, NLI->element,NLI->weight, NLI->randId);
- if(!(t.hasEdgeAndWt(f)) && (*v==*(f.getSecond()) ||
+ if(!(t.hasEdgeAndWt(f)) && (*v==*(f.getSecond()) ||
*v==*(f.getFirst()))){
int dir_count=inc_Dir(e,f);
Increment[f]+=dir_count*events;
@@ -219,21 +219,21 @@ static void inc_DFS(Graph& g,Graph& t,map<Edge, int, EdgeCompare2>& Increment,
}
//Now we select a subset of all edges
-//and assign them some values such that
+//and assign them some values such that
//if we consider just this subset, it still represents
//the path sum along any path in the graph
-static map<Edge, int, EdgeCompare2> getEdgeIncrements(Graph& g, Graph& t,
+static map<Edge, int, EdgeCompare2> getEdgeIncrements(Graph& g, Graph& t,
vector<Edge> &be){
//get all edges in g-t
map<Edge, int, EdgeCompare2> Increment;
vector<Node *> allNodes=g.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){
Graph::nodeList node_list=g.getSortedNodeList(*NI, be);
//modified g.getNodeList(*NI);
- for(Graph::nodeList::iterator NLI=node_list.begin(), NLE=node_list.end();
+ for(Graph::nodeList::iterator NLI=node_list.begin(), NLE=node_list.end();
NLI!=NLE; ++NLI){
Edge ed(*NI, NLI->element,NLI->weight,NLI->randId);
if(!(t.hasEdgeAndWt(ed))){
@@ -245,11 +245,11 @@ static map<Edge, int, EdgeCompare2> getEdgeIncrements(Graph& g, Graph& t,
Edge *ed=new Edge();
inc_DFS(g,t,Increment, 0, g.getRoot(), *ed);
- 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){
Graph::nodeList node_list=g.getSortedNodeList(*NI, be);
//modified g.getNodeList(*NI);
- for(Graph::nodeList::iterator NLI=node_list.begin(), NLE=node_list.end();
+ for(Graph::nodeList::iterator NLI=node_list.begin(), NLE=node_list.end();
NLI!=NLE; ++NLI){
Edge ed(*NI, NLI->element,NLI->weight, NLI->randId);
if(!(t.hasEdgeAndWt(ed))){
@@ -274,7 +274,7 @@ graphListElement *findNodeInList(Graph::nodeList &NL, Node *N);
//The idea here is to minimize the computation
//by inserting only the needed code
static void getCodeInsertions(Graph &g, map<Edge, getEdgeCode *, EdgeCompare2> &instr,
- vector<Edge > &chords,
+ vector<Edge > &chords,
map<Edge,int, EdgeCompare2> &edIncrements){
//Register initialization code
@@ -285,7 +285,7 @@ static void getCodeInsertions(Graph &g, map<Edge, getEdgeCode *, EdgeCompare2> &
ws.pop_back();
//for each edge v->w
Graph::nodeList succs=g.getNodeList(v);
-
+
for(Graph::nodeList::iterator nl=succs.begin(), ne=succs.end();
nl!=ne; ++nl){
int edgeWt=nl->weight;
@@ -320,7 +320,7 @@ static void getCodeInsertions(Graph &g, map<Edge, getEdgeCode *, EdgeCompare2> &
/////Memory increment code
ws.push_back(g.getExit());
-
+
while(!ws.empty()) {
Node *w=ws.back();
ws.pop_back();
@@ -333,11 +333,11 @@ static void getCodeInsertions(Graph &g, map<Edge, getEdgeCode *, EdgeCompare2> &
Node *lnode=*EII;
Graph::nodeList &nl = g.getNodeList(lnode);
//graphListElement *N = findNodeInList(nl, w);
- for(Graph::nodeList::const_iterator N = nl.begin(),
+ for(Graph::nodeList::const_iterator N = nl.begin(),
NNEN = nl.end(); N!= NNEN; ++N){
if (*N->element == *w){
Node *v=lnode;
-
+
//if chords has v->w
Edge ed(v,w, N->weight, N->randId);
getEdgeCode *edCd=new getEdgeCode();
@@ -359,7 +359,7 @@ static void getCodeInsertions(Graph &g, map<Edge, getEdgeCode *, EdgeCompare2> &
edCd->setInc(edIncrements[ed]);
instr[ed]=edCd;
}
-
+
}
else if(g.getNumberOfOutgoingEdges(v)==1)
ws.push_back(v);
@@ -387,8 +387,8 @@ static void getCodeInsertions(Graph &g, map<Edge, getEdgeCode *, EdgeCompare2> &
//then incoming dummy edge is root->b
//and outgoing dummy edge is a->exit
//changed
-void addDummyEdges(vector<Edge > &stDummy,
- vector<Edge > &exDummy,
+void addDummyEdges(vector<Edge > &stDummy,
+ vector<Edge > &exDummy,
Graph &g, vector<Edge> &be){
for(vector<Edge >::iterator VI=be.begin(), VE=be.end(); VI!=VE; ++VI){
Edge ed=*VI;
@@ -420,17 +420,17 @@ void printEdge(Edge ed){
//Move the incoming dummy edge code and outgoing dummy
//edge code over to the corresponding back edge
-static void moveDummyCode(vector<Edge> &stDummy,
- vector<Edge> &exDummy,
- vector<Edge> &be,
- map<Edge, getEdgeCode *, EdgeCompare2> &insertions,
+static void moveDummyCode(vector<Edge> &stDummy,
+ vector<Edge> &exDummy,
+ vector<Edge> &be,
+ map<Edge, getEdgeCode *, EdgeCompare2> &insertions,
Graph &g){
typedef vector<Edge >::iterator vec_iter;
-
+
map<Edge,getEdgeCode *, EdgeCompare2> temp;
//iterate over edges with code
std::vector<Edge> toErase;
- for(map<Edge,getEdgeCode *, EdgeCompare2>::iterator MI=insertions.begin(),
+ for(map<Edge,getEdgeCode *, EdgeCompare2>::iterator MI=insertions.begin(),
ME=insertions.end(); MI!=ME; ++MI){
Edge ed=MI->first;
getEdgeCode *edCd=MI->second;
@@ -462,18 +462,18 @@ static void moveDummyCode(vector<Edge> &stDummy,
}
}
}
-
- for(vector<Edge >::iterator vmi=toErase.begin(), vme=toErase.end(); vmi!=vme;
+
+ for(vector<Edge >::iterator vmi=toErase.begin(), vme=toErase.end(); vmi!=vme;
++vmi){
insertions.erase(*vmi);
g.removeEdgeWithWt(*vmi);
}
-
- for(map<Edge,getEdgeCode *, EdgeCompare2>::iterator MI=temp.begin(),
+
+ for(map<Edge,getEdgeCode *, EdgeCompare2>::iterator MI=temp.begin(),
ME=temp.end(); MI!=ME; ++MI){
insertions[MI->first]=MI->second;
}
-
+
#ifdef DEBUG_PATH_PROFILES
cerr<<"size of deletions: "<<toErase.size()<<"\n";
cerr<<"SIZE OF INSERTIONS AFTER DEL "<<insertions.size()<<"\n";
@@ -481,16 +481,16 @@ static void moveDummyCode(vector<Edge> &stDummy,
}
-//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 locations
-void processGraph(Graph &g,
- Instruction *rInst,
- Value *countInst,
- vector<Edge >& be,
- vector<Edge >& stDummy,
- vector<Edge >& exDummy,
- int numPaths, int MethNo,
+void processGraph(Graph &g,
+ Instruction *rInst,
+ Value *countInst,
+ vector<Edge >& be,
+ vector<Edge >& stDummy,
+ vector<Edge >& exDummy,
+ int numPaths, int MethNo,
Value *threshold){
//Given a graph: with exit->root edge, do the following in seq:
@@ -505,11 +505,11 @@ void processGraph(Graph &g,
//5. Get edge increments
//6. Get code insertions
//7. move code on dummy edges over to the back edges
-
- //This is used as maximum "weight" for
+
+ //This is used as maximum "weight" for
//priority queue
- //This would hold all
+ //This would hold all
//right as long as number of paths in the graph
//is less than this
const int Infinity=99999999;
@@ -524,7 +524,7 @@ void processGraph(Graph &g,
//if its there earlier, remove it!
//assign it weight Infinity
//so that this edge IS ALWAYS IN spanning tree
- //Note than edges in spanning tree do not get
+ //Note than edges in spanning tree do not get
//instrumented: and we do not want the
//edge exit->root to get instrumented
//as it MAY BE a dummy edge
@@ -544,13 +544,13 @@ void processGraph(Graph &g,
#endif
//now edges of tree t have weights reversed
//(negative) because the algorithm used
- //to find max spanning tree is
+ //to find max spanning tree is
//actually for finding min spanning tree
//so get back the original weights
t->reverseWts();
//Ordinarily, the graph is directional
- //lets converts the graph into an
+ //lets converts the graph into an
//undirectional graph
//This is done by adding an edge
//v->u for all existing edges u->v
@@ -559,8 +559,8 @@ void processGraph(Graph &g,
//Given a tree t, and a "directed graph" g
//replace the edges in the tree t with edges that exist in graph
//The tree is formed from "undirectional" copy of graph
- //So whatever edges the tree has, the undirectional graph
- //would have too. This function corrects some of the directions in
+ //So whatever edges the tree has, the undirectional graph
+ //would have too. This function corrects some of the directions in
//the tree so that now, all edge directions in the tree match
//the edge directions of corresponding edges in the directed graph
removeTreeEdges(g, *t);
@@ -588,7 +588,7 @@ void processGraph(Graph &g,
//step 5: Get edge increments
//Now we select a subset of all edges
- //and assign them some values such that
+ //and assign them some values such that
//if we consider just this subset, it still represents
//the path sum along any path in the graph
@@ -603,9 +603,9 @@ void processGraph(Graph &g,
std::cerr<<"-------end of edge increments\n";
#endif
-
+
//step 6: Get code insertions
-
+
//Based on edgeIncrements (above), now obtain
//the kind of code to be inserted along an edge
//The idea here is to minimize the computation
@@ -616,11 +616,11 @@ void processGraph(Graph &g,
map<Edge, getEdgeCode *, EdgeCompare2> codeInsertions;
getCodeInsertions(g, codeInsertions, chords,increment);
-
+
#ifdef DEBUG_PATH_PROFILES
//print edges with code for debugging
cerr<<"Code inserted in following---------------\n";
- for(map<Edge, getEdgeCode *, EdgeCompare2>::iterator cd_i=codeInsertions.begin(),
+ for(map<Edge, getEdgeCode *, EdgeCompare2>::iterator cd_i=codeInsertions.begin(),
cd_e=codeInsertions.end(); cd_i!=cd_e; ++cd_i){
printEdge(cd_i->first);
cerr<<cd_i->second->getCond()<<":"<<cd_i->second->getInc()<<"\n";
@@ -634,11 +634,11 @@ void processGraph(Graph &g,
//edge code over to the corresponding back edge
moveDummyCode(stDummy, exDummy, be, codeInsertions, g);
-
+
#ifdef DEBUG_PATH_PROFILES
//debugging info
cerr<<"After moving dummy code\n";
- for(map<Edge, getEdgeCode *,EdgeCompare2>::iterator cd_i=codeInsertions.begin(),
+ for(map<Edge, getEdgeCode *,EdgeCompare2>::iterator cd_i=codeInsertions.begin(),
cd_e=codeInsertions.end(); cd_i != cd_e; ++cd_i){
printEdge(cd_i->first);
cerr<<cd_i->second->getCond()<<":"
@@ -650,22 +650,22 @@ void processGraph(Graph &g,
//see what it looks like...
//now insert code along edges which have codes on them
- for(map<Edge, getEdgeCode *,EdgeCompare2>::iterator MI=codeInsertions.begin(),
+ for(map<Edge, getEdgeCode *,EdgeCompare2>::iterator MI=codeInsertions.begin(),
ME=codeInsertions.end(); MI!=ME; ++MI){
Edge ed=MI->first;
insertBB(ed, MI->second, rInst, countInst, numPaths, MethNo, threshold);
- }
+ }
}
//print the graph (for debugging)
void printGraph(Graph &g){
vector<Node *> lt=g.getAllNodes();
cerr<<"Graph---------------------\n";
- for(vector<Node *>::iterator LI=lt.begin();
+ for(vector<Node *>::iterator LI=lt.begin();
LI!=lt.end(); ++LI){
cerr<<((*LI)->getElement())->getName()<<"->";
Graph::nodeList nl=g.getNodeList(*LI);
- for(Graph::nodeList::iterator NI=nl.begin();
+ for(Graph::nodeList::iterator NI=nl.begin();
NI!=nl.end(); ++NI){
cerr<<":"<<"("<<(NI->element->getElement())
->getName()<<":"<<NI->element->getWeight()<<","<<NI->weight<<","
diff --git a/lib/Transforms/Instrumentation/ProfilePaths/InstLoops.cpp b/lib/Transforms/Instrumentation/ProfilePaths/InstLoops.cpp
index 500208756a..fc828977f6 100644
--- a/lib/Transforms/Instrumentation/ProfilePaths/InstLoops.cpp
+++ b/lib/Transforms/Instrumentation/ProfilePaths/InstLoops.cpp
@@ -1,10 +1,10 @@
//===-- InstLoops.cpp -----------------------------------------------------===//
-//
+//
// The LLVM Compiler Infrastructure
//
// This file was developed by the LLVM research group and is distributed under
// the University of Illinois Open Source License. See LICENSE.TXT for details.
-//
+//
//===----------------------------------------------------------------------===//
//
// This is the first-level instrumentation pass for the Reoptimizer. It
@@ -46,7 +46,7 @@ namespace {
DominatorSet *DS;
void getBackEdgesVisit(BasicBlock *u,
std::map<BasicBlock *, Color > &color,
- std::map<BasicBlock *, int > &d,
+ std::map<BasicBlock *, int > &d,
int &time, BBMap &be);
void removeRedundant(BBMap &be);
void findAndInstrumentBackEdges(Function &F);
@@ -54,15 +54,15 @@ namespace {
bool doInitialization(Module &M);
bool runOnFunction(Function &F);
};
-
+
RegisterOpt<InstLoops> X("instloops", "Instrument backedges for profiling");
}
-//helper function to get back edges: it is called by
+//helper function to get back edges: it is called by
//the "getBackEdges" function below
void InstLoops::getBackEdgesVisit(BasicBlock *u,
std::map<BasicBlock *, Color > &color,
- std::map<BasicBlock *, int > &d,
+ std::map<BasicBlock *, int > &d,
int &time, BBMap &be) {
color[u]=GREY;
time++;
@@ -74,7 +74,7 @@ void InstLoops::getBackEdgesVisit(BasicBlock *u,
if(color[BB]!=GREY && color[BB]!=BLACK){
getBackEdgesVisit(BB, color, d, time, be);
}
-
+
//now checking for d and f vals
else if(color[BB]==GREY){
//so v is ancestor of u if time of u > time of v
@@ -91,13 +91,13 @@ void InstLoops::getBackEdgesVisit(BasicBlock *u,
//set
void InstLoops::removeRedundant(BBMap &be) {
std::vector<BasicBlock *> toDelete;
- for(std::map<BasicBlock *, BasicBlock *>::iterator MI = be.begin(),
+ for(std::map<BasicBlock *, BasicBlock *>::iterator MI = be.begin(),
ME = be.end(); MI != ME; ++MI)
for(BBMap::iterator MMI = be.begin(), MME = be.end(); MMI != MME; ++MMI)
if(DS->properlyDominates(MI->first, MMI->first))
toDelete.push_back(MMI->first);
// Remove all the back-edges we found from be.
- for(std::vector<BasicBlock *>::iterator VI = toDelete.begin(),
+ for(std::vector<BasicBlock *>::iterator VI = toDelete.begin(),
VE = toDelete.end(); VI != VE; ++VI)
be.erase(*VI);
}
@@ -137,14 +137,14 @@ void InstLoops::findAndInstrumentBackEdges(Function &F){
assert(ti->getNumSuccessors() > index && "Not enough successors!");
ti->setSuccessor(index, newBB);
-
+
BasicBlock::InstListType &lt = newBB->getInstList();
lt.push_back(new CallInst(inCountMth));
new BranchInst(BB, newBB);
-
+
// Now, set the sources of Phi nodes corresponding to the back-edge
// in BB to come from the instrumentation block instead.
- for(BasicBlock::iterator BB2Inst = BB->begin(), BBend = BB->end();
+ for(BasicBlock::iterator BB2Inst = BB->begin(), BBend = BB->end();
BB2Inst != BBend; ++BB2Inst) {
if (PHINode *phiInst = dyn_cast<PHINode>(BB2Inst)) {
int bbIndex = phiInst->getBasicBlockIndex(u);
diff --git a/lib/Transforms/Instrumentation/ProfilePaths/ProfilePaths.cpp b/lib/Transforms/Instrumentation/ProfilePaths/ProfilePaths.cpp
index cc14c268e0..d0d0f550fe 100644
--- a/lib/Transforms/Instrumentation/ProfilePaths/ProfilePaths.cpp
+++ b/lib/Transforms/Instrumentation/ProfilePaths/ProfilePaths.cpp
@@ -1,17 +1,17 @@
//===-- ProfilePaths.cpp - interface to insert instrumentation --*- C++ -*-===//
-//
+//
// The LLVM Compiler Infrastructure
//
// This file was developed by the LLVM research group and is distributed under
// the University of Illinois Open Source License. See LICENSE.TXT for details.
-//
+//
//===----------------------------------------------------------------------===//
//
// This inserts instrumentation for counting execution of paths though a given
// function Its implemented as a "Function" Pass, and called using opt
//
-// This pass is implemented by using algorithms similar to
-// 1."Efficient Path Profiling": Ball, T. and Larus, J. R.,
+// This pass is implemented by using algorithms similar to
+// 1."Efficient Path Profiling": Ball, T. and Larus, J. R.,
// Proceedings of Micro-29, Dec 1996, Paris, France.
// 2."Efficiently Counting Program events with support for on-line
// "queries": Ball T., ACM Transactions on Programming Languages
@@ -22,7 +22,7 @@
// (implementation in Graph.cpp and GraphAuxiliary.cpp) and finally, appropriate
// instrumentation is placed over suitable edges. (code inserted through
// EdgeCode.cpp).
-//
+//
// The algorithm inserts code such that every acyclic path in the CFG of a
// function is identified through a unique number. the code insertion is optimal
// in the sense that its inserted over a minimal set of edges. Also, the
@@ -47,7 +47,7 @@ namespace llvm {
struct ProfilePaths : public FunctionPass {
bool runOnFunction(Function &F);
- // Before this pass, make sure that there is only one
+ // Before this pass, make sure that there is only one
// entry and only one exit node for the function in the CFG of the function
//
void getAnalysisUsage(AnalysisUsage &AU) const {
@@ -76,13 +76,13 @@ bool ProfilePaths::runOnFunction(Function &F){
if(F.isExternal()) {
return false;
}
-
+
//increment counter for instrumented functions. mn is now function#
mn++;
-
+
// Transform the cfg s.t. we have just one exit node
- BasicBlock *ExitNode =
- getAnalysis<UnifyFunctionExitNodes>().getReturnBlock();
+ BasicBlock *ExitNode =
+ getAnalysis<UnifyFunctionExitNodes>().getReturnBlock();
//iterating over BBs and making graph
std::vector<Node *> nodes;
@@ -92,10 +92,10 @@ bool ProfilePaths::runOnFunction(Function &F){
// The nodes must be uniquely identified:
// That is, no two nodes must hav same BB*
-
+
for (Function::iterator BB = F.begin(), BE = F.end(); BB != BE; ++BB) {
Node *nd=new Node(BB);
- nodes.push_back(nd);
+ nodes.push_back(nd);
if(&*BB == ExitNode)
exitNode=nd;
if(BB==F.begin())
@@ -114,22 +114,22 @@ bool ProfilePaths::runOnFunction(Function &F){
edges.push_back(ed);
}
}
-
+
Graph g(nodes,edges, startNode, exitNode);
-#ifdef DEBUG_PATH_PROFILES
+#ifdef DEBUG_PATH_PROFILES
std::cerr<<"Original graph\n";
printGraph(g);
#endif
BasicBlock *fr = &F.front();
-
+
// The graph is made acyclic: this is done
// by removing back edges for now, and adding them later on
std::vector<Edge> be;
std::map<Node *, int> nodePriority; //it ranks nodes in depth first order traversal
g.getBackEdges(be, nodePriority);
-
+
#ifdef DEBUG_PATH_PROFILES
std::cerr<<"BackEdges-------------\n";
for (std::vector<Edge>::iterator VI=be.begin(); VI!=be.end(); ++VI){
@@ -190,7 +190,7 @@ bool ProfilePaths::runOnFunction(Function &F){
Function *initialize =
F.getParent()->getOrInsertFunction("reoptimizerInitialize", Type::VoidTy,
PointerType::get(Type::IntTy), 0);
-
+
std::vector<Value *> trargs;
trargs.push_back(threshold);
new CallInst(initialize, trargs, "", fr->begin());
@@ -198,8 +198,8 @@ bool ProfilePaths::runOnFunction(Function &F){
if(numPaths<=1 || numPaths >5000) return false;
-
-#ifdef DEBUG_PATH_PROFILES
+
+#ifdef DEBUG_PATH_PROFILES
printGraph(g);
#endif
@@ -210,12 +210,12 @@ bool ProfilePaths::runOnFunction(Function &F){
//count is an array: count[x] would store
//the number of executions of path numbered x
- Instruction *rVar=new
- AllocaInst(Type::IntTy,
+ Instruction *rVar=new
+ AllocaInst(Type::IntTy,
ConstantUInt::get(Type::UIntTy,1),"R");
- //Instruction *countVar=new
- //AllocaInst(Type::IntTy,
+ //Instruction *countVar=new
+ //AllocaInst(Type::IntTy,
// ConstantUInt::get(Type::UIntTy, numPaths), "Count");
//initialize counter array!
@@ -230,21 +230,21 @@ bool ProfilePaths::runOnFunction(Function &F){
CountCounter++;
std::string countStr = tempChar;
GlobalVariable *countVar = new GlobalVariable(ATy, false,
- GlobalValue::InternalLinkage,
+ GlobalValue::InternalLinkage,
initializer, countStr,
F.getParent());
-
+
// insert initialization code in first (entry) BB
// this includes initializing r and count
insertInTopBB(&F.getEntryBlock(), numPaths, rVar, threshold);
-
+
//now process the graph: get path numbers,
//get increments along different paths,
//and assign "increments" and "updates" (to r and count)
//"optimally". Finally, insert llvm code along various edges
- processGraph(g, rVar, countVar, be, stDummy, exDummy, numPaths, mn,
- threshold);
-
+ processGraph(g, rVar, countVar, be, stDummy, exDummy, numPaths, mn,
+ threshold);
+
return true; // Always modifies function
}
diff --git a/lib/Transforms/Instrumentation/ProfilePaths/RetracePath.cpp b/lib/Transforms/Instrumentation/ProfilePaths/RetracePath.cpp
index 4954723685..c92094015d 100644
--- a/lib/Transforms/Instrumentation/ProfilePaths/RetracePath.cpp
+++ b/lib/Transforms/Instrumentation/ProfilePaths/RetracePath.cpp
@@ -1,10 +1,10 @@
//===- RetracePath.cpp ----------------------------------------------------===//
-//
+//
// The LLVM Compiler Infrastructure
//
// This file was developed by the LLVM research group and is distributed under
// the University of Illinois Open Source License. See LICENSE.TXT for details.
-//
+//
//===----------------------------------------------------------------------===//
//
// Retraces a path of BasicBlock, given a path number and a graph!
@@ -25,12 +25,12 @@ namespace llvm {
//Routines to get the path trace!
-void getPathFrmNode(Node *n, vector<BasicBlock*> &vBB, int pathNo, Graph &g,
- vector<Edge> &stDummy, vector<Edge> &exDummy,
+void getPathFrmNode(Node *n, vector<BasicBlock*> &vBB, int pathNo, Graph &g,
+ vector<Edge> &stDummy, vector<Edge> &exDummy,
vector<Edge> &be,
double strand){
Graph::nodeList &nlist = g.getNodeList(n);
-
+
//printGraph(g);
//std::cerr<<"Path No: "<<pathNo<<"\n";
int maxCount=-9999999;
@@ -53,7 +53,7 @@ void getPathFrmNode(Node *n, vector<BasicBlock*> &vBB, int pathNo, Graph &g,
}
if(!isStart)
- assert(strand!=-1 && "strand not assigned!");
+ assert(strand!=-1 && "strand not assigned!");
assert(!(*nextRoot==*n && pathNo>0) && "No more BBs to go");
assert(!(*nextRoot==*g.getExit() && pathNo-maxCount!=0) && "Reached exit");
@@ -65,7 +65,7 @@ void getPathFrmNode(Node *n, vector<BasicBlock*> &vBB, int pathNo, Graph &g,
//look for strnd and edgeRnd now:
bool has1=false, has2=false;
//check if exit has it
- for(vector<Edge>::iterator VI=exDummy.begin(), VE=exDummy.end(); VI!=VE;
+ for(vector<Edge>::iterator VI=exDummy.begin(), VE=exDummy.end(); VI!=VE;
++VI){
if(VI->getRandId()==edgeRnd){
has2=true;
@@ -74,7 +74,7 @@ void getPathFrmNode(Node *n, vector<BasicBlock*> &vBB, int pathNo, Graph &g,
}
//check if start has it
- for(vector<Edge>::iterator VI=stDummy.begin(), VE=stDummy.end(); VI!=VE;
+ for(vector<Edge>::iterator VI=stDummy.begin(), VE=stDummy.end(); VI!=VE;
++VI){
if(VI->getRandId()==strand){
has1=true;
@@ -98,22 +98,22 @@ void getPathFrmNode(Node *n, vector<BasicBlock*> &vBB, int pathNo, Graph &g,
//find backedge with startpoint vBB[vBB.size()-1]
for(vector<Edge>::iterator VI=be.begin(), VE=be.end(); VI!=VE; ++VI){
assert(vBB.size()>0 && "vector too small");
- if( VI->getFirst()->getElement() == vBB[vBB.size()-1] &&
+ if( VI->getFirst()->getElement() == vBB[vBB.size()-1] &&
VI->getSecond()->getElement() == vBB[0]){
//vBB.push_back(VI->getSecond()->getElement());
break;
}
}
}
- else
+ else
vBB.push_back(nextRoot->getElement());
-
+
return;
}
assert(pathNo-maxCount>=0);
- return getPathFrmNode(nextRoot, vBB, pathNo-maxCount, g, stDummy,
+ return getPathFrmNode(nextRoot, vBB, pathNo-maxCount, g, stDummy,
exDummy, be, strand);
}
@@ -131,16 +131,16 @@ void getBBtrace(vector<BasicBlock *> &vBB, int pathNo, Function *M){//,
// vector<Instruction *> &instToErase){
//step 1: create graph
//Transform the cfg s.t. we have just one exit node
-
+
std::vector<Node *> nodes;
std::vector<Edge> edges;
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
@@ -152,19 +152,19 @@ void getBBtrace(vector<BasicBlock *> &vBB, int pathNo, Function *M){//,
break;
}
}
-
+
assert(ExitNode!=0 && "exitnode not found");
- //iterating over BBs and making graph
+ //iterating over BBs and making graph
//The nodes must be uniquely identified:
//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
for(Function::iterator BB = M->begin(), BE=M->end(); BB != BE; ++BB){
bool cont = false;
-
+
if(BB->size()==3 || BB->size() ==2){
for(BasicBlock::iterator II = BB->begin(), IE = BB->end();
II != IE; ++II){
@@ -180,10 +180,10 @@ void getBBtrace(vector<BasicBlock *> &vBB, int pathNo, Function *M){//,
}
}
}
-
+
if(cont)
continue;
-
+
// const Instruction *inst = BB->getInstList().begin();
// if(isa<CallInst>(inst)){
// Instruction *ii1 = BB->getInstList().begin();
@@ -191,9 +191,9 @@ void getBBtrace(vector<BasicBlock *> &vBB, int pathNo, Function *M){//,
// if(callInst->getCalledFunction()->getName()=="trigger")
// continue;
// }
-
+
Node *nd=new Node(BB);
- nodes.push_back(nd);
+ nodes.push_back(nd);
if(&*BB==ExitNode)
exitNode=nd;
if(&*BB==&M->front())
@@ -201,16 +201,16 @@ void getBBtrace(vector<BasicBlock *> &vBB, int pathNo, Function *M){//,
}
assert(exitNode!=0 && startNode!=0 && "Start or exit not found!");
-
+
for (Function::iterator BB = M->begin(), BE=M->end(); BB != BE; ++BB){
- if(triggerBBs[BB] == 9)
+ if(triggerBBs[BB] == 9)
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)){
@@ -220,12 +220,12 @@ void getBBtrace(vector<BasicBlock *> &vBB, int pathNo, Function *M){//,
// continue;
// }
// }
-
+
Node *nd=findBB(nodes, BB);
assert(nd && "No node for this edge!");
-
+
for(succ_iterator s=succ_begin(BB), se=succ_end(BB); s!=se; ++s){
-
+
if(triggerBBs[*s] == 9){
//if(!pathReg[M]){ //Get the path register for this!
//if(BB->size()>8)
@@ -235,11 +235,11 @@ void getBBtrace(vector<BasicBlock *> &vBB, int pathNo, Function *M){//,
continue;
}
//if((*s)->size()==3)
- //if(CallInst *callInst =
+ //if(CallInst *callInst =
// dyn_cast<CallInst>((*s)->getInstList().begin()))
// if(callInst->getCalledFunction()->getName() == "trigger")
// continue;
-
+
// if((*s)->size()==2){
// const Instruction *inst = (*s)->getInstList().begin();
// if(isa<CallInst>(inst)){
@@ -249,40 +249,40 @@ void getBBtrace(vector<BasicBlock *> &vBB, int pathNo, Function *M){//,
// continue;
// }
// }
-
+
Node *nd2 = findBB(nodes,*s);
assert(nd2 && "No node for this edge!");
Edge ed(nd,nd2,0);
edges.push_back(ed);
}
}
-
+
graphMap[M]= new Graph(nodes,edges, startNode, exitNode);
-
+
Graph *g = graphMap[M];
- if (M->size() <= 1) return; //uninstrumented
-
+ if (M->size() <= 1) return; //uninstrumented
+
//step 2: getBackEdges
//vector<Edge> be;
std::map<Node *, int> nodePriority;
g->getBackEdges(beMap[M], nodePriority);
-
+
//step 3: add dummy edges
//vector<Edge> stDummy;
//vector<Edge> exDummy;
addDummyEdges(stMap[M], exMap[M], *g, beMap[M]);
-
+
//step 4: value assgn to edges
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
- getPathFrmNode(graphMap[M]->getRoot(), vBB, pathNo, *graphMap[M],
+ getPathFrmNode(graphMap[M]->getRoot(), vBB, pathNo, *graphMap[M],
stMap[M], exMap[M], beMap[M], -1);
-
+
//post process vBB to locate instructions to be erased
/*
diff --git a/lib/Transforms/Instrumentation/ProfilingUtils.cpp b/lib/Transforms/Instrumentation/ProfilingUtils.cpp
index 5ce0142716..4093759e4d 100644
--- a/lib/Transforms/Instrumentation/ProfilingUtils.cpp
+++ b/lib/Transforms/Instrumentation/ProfilingUtils.cpp
@@ -1,10 +1,10 @@
//===- ProfilingUtils.cpp - Helper functions shared by profilers ----------===//
-//
+//
// The LLVM Compiler Infrastructure
//
// This file was developed by the LLVM research group and is distributed under
// the University of Illinois Open Source License. See LICENSE.TXT for details.
-//
+//
//===----------------------------------------------------------------------===//
//
// This files implements a few helper functions which are used by profile
@@ -51,7 +51,7 @@ void llvm::InsertProfilingInitCall(Function *MainFn, const char *FnName,
Args[2] = ConstantPointerNull::get(UIntPtr);
}
Args[3] = ConstantUInt::get(Type::UIntTy, NumElements);
-
+
Instruction *InitCall = new CallInst(InitFn, Args, "newargc", InsertPos);
// If argc or argv are not available in main, just pass null values in.
@@ -80,7 +80,7 @@ void llvm::InsertProfilingInitCall(Function *MainFn, const char *FnName,
AI->replaceAllUsesWith(InitCall);
InitCall->setOperand(1, AI);
}
-
+
case 0: break;
}
}
diff --git a/lib/Transforms/Instrumentation/ProfilingUtils.h b/lib/Transforms/Instrumentation/ProfilingUtils.h
index cf1bbce540..52c6e049c6 100644
--- a/lib/Transforms/Instrumentation/ProfilingUtils.h
+++ b/lib/Transforms/Instrumentation/ProfilingUtils.h
@@ -1,10 +1,10 @@
//===- ProfilingUtils.h - Helper functions shared by profilers --*- C++ -*-===//
-//
+//
// The LLVM Compiler Infrastructure
//
// This file was developed by the LLVM research group and is distributed under
// the University of Illinois Open Source License. See LICENSE.TXT for details.
-//
+//
//===----------------------------------------------------------------------===//
//
// This files defines a few helper functions which are used by profile
diff --git a/lib/Transforms/Instrumentation/TraceBasicBlocks.cpp b/lib/Transforms/Instrumentation/TraceBasicBlocks.cpp
index 68d50ae559..ae8a8bdb73 100644
--- a/lib/Transforms/Instrumentation/TraceBasicBlocks.cpp
+++ b/lib/Transforms/Instrumentation/TraceBasicBlocks.cpp
@@ -1,10 +1,10 @@
//===- TraceBasicBlocks.cpp - Insert basic-block trace instrumentation ----===//
-//
+//
// The LLVM Compiler Infrastructure
//
// This file was developed by the LLVM research group and is distributed under
// the University of Illinois Open Source License. See LICENSE.TXT for details.
-//
+//
//===----------------------------------------------------------------------===//
//
// This pass instruments the specified program with calls into a runtime
diff --git a/lib/Transforms/Instrumentation/TraceValues.cpp b/lib/Transforms/Instrumentation/TraceValues.cpp
index 5be8637a20..586c923077 100644
--- a/lib/Transforms/Instrumentation/TraceValues.cpp
+++ b/lib/Transforms/Instrumentation/TraceValues.cpp
@@ -1,10 +1,10 @@
//===- TraceValues.cpp - Value Tracing for debugging ----------------------===//
-//
+//
// The LLVM Compiler Infrastructure
//
// This file was developed by the LLVM research group and is distributed under
// the University of Illinois Open Source License. See LICENSE.TXT for details.
-//
+//
//===----------------------------------------------------------------------===//
//
// Support for inserting LLVM code to print values at basic block and function
@@ -41,7 +41,7 @@ static void TraceValuesAtBBExit(BasicBlock *BB,
// We trace a particular function if no functions to trace were specified
// or if the function is in the specified list.
-//
+//
inline static bool
TraceThisFunction(Function &F)
{
@@ -58,19 +58,19 @@ namespace {
Function *RecordPtrFunc, *PushOnEntryFunc, *ReleaseOnReturnFunc;
void doInitialization(Module &M); // Add prototypes for external functions
};
-
+
class InsertTraceCode : public FunctionPass {
protected:
ExternalFuncs externalFuncs;
public:
-
+
// Add a prototype for runtime functions not already in the program.
//
bool doInitialization(Module &M);
-
+
//--------------------------------------------------------------------------
// Function InsertCodeToTraceValues
- //
+ //
// Inserts tracing code for all live values at basic block and/or function
// exits as specified by `traceBasicBlockExits' and `traceFunctionExits'.
//
@@ -131,13 +131,13 @@ void ExternalFuncs::doInitialization(Module &M) {
// uint (sbyte*)
HashPtrFunc = M.getOrInsertFunction("HashPointerToSeqNum", Type::UIntTy, SBP,
0);
-
+
// void (sbyte*)
- ReleasePtrFunc = M.getOrInsertFunction("ReleasePointerSeqNum",
+ ReleasePtrFunc = M.getOrInsertFunction("ReleasePointerSeqNum",
Type::VoidTy, SBP, 0);
RecordPtrFunc = M.getOrInsertFunction("RecordPointer",
Type::VoidTy, SBP, 0);
-
+
PushOnEntryFunc = M.getOrInsertFunction("PushPointerSet", Type::VoidTy, 0);
ReleaseOnReturnFunc = M.getOrInsertFunction("ReleasePointersPopSet",
Type::VoidTy, 0);
@@ -158,7 +158,7 @@ static inline GlobalVariable *getStringRef(Module *M, const std::string &str) {
// Create the global variable and record it in the module
// The GV will be renamed to a unique name if needed.
- GlobalVariable *GV = new GlobalVariable(Init->getType(), true,
+ GlobalVariable *GV = new GlobalVariable(Init->getType(), true,
GlobalValue::InternalLinkage, Init,
"trstr");
M->getGlobalList().push_back(GV);
@@ -166,12 +166,12 @@ static inline GlobalVariable *getStringRef(Module *M, const std::string &str) {
}
-//
+//
// Check if this instruction has any uses outside its basic block,
// or if it used by either a Call or Return instruction (ditto).
// (Values stored to memory within this BB are live at end of BB but are
// traced at the store instruction, not where they are computed.)
-//
+//
static inline bool LiveAtBBExit(const Instruction* I) {
const BasicBlock *BB = I->getParent();
for (Value::use_const_iterator U = I->use_begin(); U != I->use_end(); ++U)
@@ -186,7 +186,7 @@ static inline bool LiveAtBBExit(const Instruction* I) {
static inline bool TraceThisOpCode(unsigned opCode) {
// Explicitly test for opCodes *not* to trace so that any new opcodes will
// be traced by default (VoidTy's are already excluded)
- //
+ //
return (opCode < Instruction::OtherOpsBegin &&
opCode != Instruction::Alloca &&
opCode != Instruction::PHI &&
@@ -198,7 +198,7 @@ static inline bool TraceThisOpCode(unsigned opCode) {
// by a real computation, not just a copy (see TraceThisOpCode), and
// -- it is a load instruction: we want to check values read from memory
// -- or it is live at exit from the basic block (i.e., ignore local temps)
-//
+//
static bool ShouldTraceValue(const Instruction *I) {
return
I->getType() != Type::VoidTy &&
@@ -216,7 +216,7 @@ static std::string getPrintfCodeFor(const Value *V) {
return DisablePtrHashing ? "0x%p" : "%d";
else if (V->getType()->isIntegral())
return "%d";
-
+
assert(0 && "Illegal value to print out...");
return "";
}
@@ -245,7 +245,7 @@ static void InsertPrintInst(Value *V, BasicBlock *BB, Instruction *InsertBefore,
// Turn the format string into an sbyte *
Constant *GEP=ConstantExpr::getGetElementPtr(fmtVal,
std::vector<Constant*>(2,Constant::getNullValue(Type::LongTy)));
-
+
// Insert a call to the hash function if this is a pointer value
if (V && isa<PointerType>(V->getType()) && !DisablePtrHashing) {
const Type *SBP = PointerType::get(Type::SByteTy);
@@ -255,14 +255,14 @@ static void InsertPrintInst(Value *V, BasicBlock *BB, Instruction *InsertBefore,
std::vector<Value*> HashArgs(1, V);
V = new CallInst(HashPtrToSeqNum, HashArgs, "ptrSeqNum", InsertBefore);
}
-
+
// Insert the first print instruction to print the string flag:
std::vector<Value*> PrintArgs;
PrintArgs.push_back(GEP);
if (V) PrintArgs.push_back(V);
new CallInst(Printf, PrintArgs, "trace", InsertBefore);
}
-
+
static void InsertVerbosePrintInst(Value *V, BasicBlock *BB,
Instruction *InsertBefore,
@@ -274,11 +274,11 @@ static void InsertVerbosePrintInst(Value *V, BasicBlock *BB,
Printf, HashPtrToSeqNum);
}
-static void
+static void
InsertReleaseInst(Value *V, BasicBlock *BB,
Instruction *InsertBefore,
Function* ReleasePtrFunc) {
-
+
const Type *SBP = PointerType::get(Type::SByteTy);
if (V->getType() != SBP) // Cast pointer to be sbyte*
V = new CastInst(V, SBP, "RPSN_cast", InsertBefore);
@@ -287,7 +287,7 @@ InsertReleaseInst(Value *V, BasicBlock *BB,
new CallInst(ReleasePtrFunc, releaseArgs, "", InsertBefore);
}
-static void
+static void
InsertRecordInst(Value *V, BasicBlock *BB,
Instruction *InsertBefore,
Function* RecordPtrFunc) {
@@ -302,17 +302,17 @@ InsertRecordInst(Value *V, BasicBlock *BB,
// Look for alloca and free instructions. These are the ptrs to release.
// Release the free'd pointers immediately. Record the alloca'd pointers
// to be released on return from the current function.
-//
+//
static void
ReleasePtrSeqNumbers(BasicBlock *BB,
ExternalFuncs& externalFuncs) {
-
+
for (BasicBlock::iterator II=BB->begin(), IE = BB->end(); II != IE; ++II)
if (FreeInst *FI = dyn_cast<FreeInst>(II))
InsertReleaseInst(FI->getOperand(0), BB, FI,externalFuncs.ReleasePtrFunc);
else if (AllocaInst *AI = dyn_cast<AllocaInst>(II))
InsertRecordInst(AI, BB, AI->getNext(), externalFuncs.RecordPtrFunc);
-}
+}
// Insert print instructions at the end of basic block BB for each value
@@ -323,15 +323,15 @@ ReleasePtrSeqNumbers(BasicBlock *BB,
// for printing at the exit from the function. (Note that in each invocation
// of the function, this will only get the last value stored for each static
// store instruction).
-//
+//
static void TraceValuesAtBBExit(BasicBlock *BB,
Function *Printf, Function* HashPtrToSeqNum,
std::vector<Instruction*> *valuesStoredInFunction) {
// Get an iterator to point to the insertion location, which is
// just before the terminator instruction.
- //
+ //
TerminatorInst *InsertPos = BB->getTerminator();
-
+
std::ostringstream OutStr;
WriteAsOperand(OutStr, BB, false);
InsertPrintInst(0, BB, InsertPos, "LEAVING BB:" + OutStr.str(),
@@ -340,7 +340,7 @@ static void TraceValuesAtBBExit(BasicBlock *BB,
// Insert a print instruction for each instruction preceding InsertPos.
// The print instructions must go before InsertPos, so we use the
// instruction *preceding* InsertPos to check when to terminate the loop.
- //
+ //
for (BasicBlock::iterator II = BB->begin(); &*II != InsertPos; ++II) {
if (StoreInst *SI = dyn_cast<StoreInst>(II)) {
// Trace the stored value and address
@@ -380,12 +380,12 @@ static inline void InsertCodeToShowFunctionExit(BasicBlock *BB,
Function* HashPtrToSeqNum) {
// Get an iterator to point to the insertion location
ReturnInst *Ret = cast<ReturnInst>(BB->getTerminator());
-
+
std::ostringstream OutStr;
WriteAsOperand(OutStr, BB->getParent(), true);
InsertPrintInst(0, BB, Ret, "LEAVING FUNCTION: " + OutStr.str(),
Printf, HashPtrToSeqNum);
-
+
// print the return value, if any
if (BB->getParent()->getReturnType() != Type::VoidTy)
InsertPrintInst(Ret->getReturnValue(), BB, Ret, " Returning: ",
@@ -396,14 +396,14 @@ static inline void InsertCodeToShowFunctionExit(BasicBlock *BB,
bool InsertTraceCode::runOnFunction(Function &F) {
if (!TraceThisFunction(F))
return false;
-
+
std::vector<Instruction*> valuesStoredInFunction;
std::vector<BasicBlock*> exitBlocks;
// Insert code to trace values at function entry
InsertCodeToShowFunctionEntry(F, externalFuncs.PrintfFunc,
externalFuncs.HashPtrFunc);
-
+
// Push a pointer set for recording alloca'd pointers at entry.
if (!DisablePtrHashing)
new CallInst(externalFuncs.PushOnEntryFunc, std::vector<Value*>(), "",
@@ -419,18 +419,18 @@ bool InsertTraceCode::runOnFunction(Function &F) {
if (!DisablePtrHashing) // release seq. numbers on free/ret
ReleasePtrSeqNumbers(BB, externalFuncs);
}
-
+
for (unsigned i=0; i != exitBlocks.size(); ++i)
{
// Insert code to trace values at function exit
InsertCodeToShowFunctionExit(exitBlocks[i], externalFuncs.PrintfFunc,
externalFuncs.HashPtrFunc);
-
+
// Release all recorded pointers before RETURN. Do this LAST!
if (!DisablePtrHashing)
new CallInst(externalFuncs.ReleaseOnReturnFunc, std::vector<Value*>(),
"", exitBlocks[i]->getTerminator());
}
-
+
return true;
}