[llvm-commits] CVS: llvm/lib/Reoptimizer/Trigger/Trigger.cpp
Anand Shukla
ashukla at cs.uiuc.edu
Sun Sep 15 15:36:01 PDT 2002
Changes in directory llvm/lib/Reoptimizer/Trigger:
Trigger.cpp updated: 1.6 -> 1.7
---
Log message:
Updated trigger function: it removes fall through branches and modifies other branches appropriately!
---
Diffs of the changes:
Index: llvm/lib/Reoptimizer/Trigger/Trigger.cpp
diff -u llvm/lib/Reoptimizer/Trigger/Trigger.cpp:1.6 llvm/lib/Reoptimizer/Trigger/Trigger.cpp:1.7
--- llvm/lib/Reoptimizer/Trigger/Trigger.cpp:1.6 Thu Aug 1 03:00:11 2002
+++ llvm/lib/Reoptimizer/Trigger/Trigger.cpp Sun Sep 15 15:35:05 2002
@@ -7,8 +7,9 @@
//
//===----------------------------------------------------------------------===//
-#include "llvm/Transforms/Instrumentation/Graph.h"
#include "llvm/Reoptimizer/TraceCache.h"
+#include "llvm/Reoptimizer/VirtualMem.h"
+#include "llvm/Reoptimizer/InstrUtils.h"
#include "llvm/Reoptimizer/Mapping/LLVMinfo.h"
#include "llvm/Bytecode/Reader.h"
#include "llvm/Module.h"
@@ -20,14 +21,23 @@
#include <vector>
#include <map>
+using std::vector;
+
extern int llvm_length;
extern const unsigned char LLVMBytecode[];
extern void** llvmFunctionTable[];
-uint64_t getBranchAddr(TraceCache &tempTrace, uint64_t n){
-
- return tempTrace.getBranchAddr(std::make_pair(n,n));
+
+void getBBtrace(vector<BasicBlock *> &vBB, int pathNo, Function *M);
+
+void printTrace(vector<BasicBlock *> &vBB, int pn){
+ std::cerr<<"Path no:"<<pn<<" ---------\n";
+ for(vector<BasicBlock *>::iterator VVI = vBB.begin(), VVE = vBB.end();
+ VVI!=VVE; ++VVI)
+ std::cerr<<*VVI;
+ std::cerr<<"End of path----\n";
}
+
extern "C" void trigger(int mn, int pn, int cnt){
static bool initialized = false; //so module is read just once
static Module *M;
@@ -57,299 +67,367 @@
assert(M && "Module unparsed!");
assert(funcList[mn] && "Function not parsed!");
-
-
- /* for(Module::iterator FI=M->begin(), FE=M->end(); FI!=FE; ++FI){
- for(Function::iterator BI=FI->begin(), BE=FI->end(); BI!=BE; ++BI){
- for( BasicBlock::iterator II=BI->begin(), IE=BI->end(); II!=IE; ++II){
- std::cerr<<"I:\t"<<II<<"\n";
- vector<unsigned *> check = getLLVMInstrInfo(II);
- for(unsigned i=0; i<check.size(); ++i){
- std::cerr<<"MI:\t"<<(void *)check[i]<<"\n";
- }
- }
- }
- }*/
-
-
- //std::cerr<<*funcList[mn];
-
+
// ******* SET THE count THRESHOLD HERE ***********
- //if(cnt < 30 || cnt%30!=0) return;
+ //if(cnt < 39 || cnt%39!=0) return;
+
+ std::cerr<<"Meth: "<<mn<<"\t path"<<pn<<"\t count:"<<cnt<<std::endl;
+ //for(int ppn = 0; ppn<8; ppn++){
+ //getBBtrace(vBB, pn, funcList[mn]);
std::vector<BasicBlock *> vBB;
-
- //std::cerr<<"Meth: "<<mn<<"\t path"<<pn<<"\t count:"<<cnt<<std::endl;
-
getBBtrace(vBB, pn, funcList[mn]);
- // ******* Now vBB is a vector of basic blocks that form the trace!
- //Forming a trace[] of instructions (uint [])
- //-for each basic block
- // -get the address of machine instruction at the start of
- // basic block (say startAddr), and instruction at the end of
- // basic block (say endAddr). Add all instructions in the
- // range [startAddr, endAddr] to the trace.
- //
- //-locate the branch/call instructions in the trace[]
- //-locate the branch/call instructions in the function
- // that have target startAddr
- //-call addTrace()
- //std::cerr<<"function add:"<<(void *)llvmFunctionTable[mn]<<"\n";
- //So we have vector of BBs. Now do things with it!
- //Using this vec: pass it on to trace
- TraceCache newTrace;
- //std::cerr<<"calling addTrace\n";
- //std::cerr<<"arguments:\n";
- uint64_t firstInstructionAdd=(uint64_t)getBasicBlockInfo(vBB[0]).first;
- //std::cerr<<"firstInstructionAdd: "<<(void *)firstInstructionAdd<<"\n";
-
- vector<unsigned> traceInstructions;
- std::vector<std::pair<uint64_t, uint64_t> > outB;
- unsigned count=0;
- //std::cerr<<"traceInstructions and outB\n";
- for(std::vector<BasicBlock *>::iterator VBI=vBB.begin(); VBI!=vBB.end(); ++VBI){
- std::pair<unsigned *, unsigned *> BBinfo=getBasicBlockInfo(*VBI);
- //std::cerr<<"BB start and end: "<<BBinfo.first<<" "<<BBinfo.second<<"\n";
- traceInstructions.insert(traceInstructions.end(), BBinfo.first, BBinfo.second);
- for(unsigned *i=BBinfo.first; i<=BBinfo.second; ++i, ++count){
- //std::cerr<<"InstructionAdd: "<<i<<"\n";
- if(isBranchInstr(*i)){
- outB.push_back(std::make_pair((uint64_t)i,(uint64_t)(&traceInstructions[count])));
- //std::cerr<<"branch Add: "<<i<<"\n";
- }
- }
- }
-
-
- std::vector<uint64_t> inB;
- //std::cerr<<"inB\n";
- for(BasicBlock::pred_iterator inBI = pred_begin(vBB[0]), inBE=pred_end(vBB[0]);
- inBI!=inBE; ++inBI){
- //std::cerr<<"gets here\n";
- vector<unsigned *> inBMI =
- getLLVMInstrInfo((Instruction *)((*inBI)->getTerminator()));
- //std::cerr<<"gets here2\n";
- for(unsigned i=0; i<inBMI.size(); ++i){
- //std::cerr<<"instruction "<<inBMI[i]<<"\n";
- if(isBranchInstr(*inBMI[i]) &&
- getBranchAddr(newTrace, *inBMI[i])==firstInstructionAdd){
- inB.push_back((uint64_t)inBMI[i]);
- //std::cerr<<"branch Add: "<<inBMI[i]<<"\n";
- }
- }
+ if(vBB[0] == &funcList[mn]->front() ||
+ isa<ReturnInst>(vBB[vBB.size()-1]->getTerminator())){
+ //std::cerr<<"Found a path starting with root!\n";
+ return;
}
- newTrace.addTrace(firstInstructionAdd , &traceInstructions[0],
- traceInstructions.size(), inB , outB ,pn);
-
-
- //std::cerr<<"------------------------------------ path --------\n";
- //for(std::vector<BasicBlock *>::iterator VBI=vBB.begin(); VBI!=vBB.end();
- //++VBI){
- //BasicBlock *BB=*VBI;
- //std::cerr<<*BB;
-
- //TerminatorInst *tti = BB->getTerminator();
- //std::cerr<<*tti;
- //std::vector<uint64_t> vt = getLLVMInstrInfo(tti);
- //for(vector<uint64_t>::iterator VI = vt.begin(), VE = vt.end();
- //VI!=VE; ++VI){
- //unsigned int a = *VI;//(unsigned int *)*VI;
- //std::cerr<<"add:"<<(void *)*VI<<"\n";//a<<"\n";//<<" inst:"<<*a<<"\n";
- //}
-
- // std::cerr<<"--------- BB end\n";
- //}
- //std::cerr<<"\n--------------\n";
-
-}
-
-using std::vector;
-
-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);
- int maxCount=-9999999;
- bool isStart=false;
-
- if(*n==*g.getRoot())//its root: so first node of path
- isStart=true;
-
- double edgeRnd=0;
- Node *nextRoot=n;
- for(Graph::nodeList::iterator NLI=nlist.begin(), NLE=nlist.end(); NLI!=NLE;
- ++NLI){
- if(NLI->weight>maxCount && NLI->weight<=pathNo){
- maxCount=NLI->weight;
- nextRoot=NLI->element;
- edgeRnd=NLI->randId;
- if(isStart)
- strand=NLI->randId;
+ //check if loop is not formed
+ TerminatorInst *Tcheck = vBB[vBB.size()-1]->getTerminator();
+ BranchInst *Bcheck = cast<BranchInst>(Tcheck);
+ if(Bcheck->isConditional()){
+ if((vBB[0] != Bcheck->getSuccessor(0)) &&
+ (vBB[0] != Bcheck->getSuccessor(1))){
+ std::cerr<<"Not a loop!\n";
+ return;
}
}
-
- if(!isStart)
- 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");
-
- //std::cerr<<"inserting############ \n";
- //std::cerr<<*(n->getElement());
- vBB.push_back(n->getElement());
-
- if(pathNo-maxCount==0 && *nextRoot==*g.getExit()){
-
- //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;
- ++VI){
- if(VI->getRandId()==edgeRnd){
- has2=true;
- break;
- }
+ else{
+ if(vBB[0] != Bcheck->getSuccessor(0)){
+ std::cerr<<"Not a loop!\n";
+ return;
}
+ }
+
+ static VirtualMem *vm = new VirtualMem();
+ static TraceCache *tr = new TraceCache();
- //check if start has it
- for(vector<Edge>::iterator VI=stDummy.begin(), VE=stDummy.end(); VI!=VE;
- ++VI){
- if(VI->getRandId()==strand){
- has1=true;
- break;
- }
- }
+ std::pair<uint64_t, uint64_t> firtBBLimits = getBasicBlockInfo(*(vBB.begin()));
+ uint64_t startAddr = firtBBLimits.first;
- if(has1){
- //find backedge with endpoint vBB[1]
- for(vector<Edge>::iterator VI=be.begin(), VE=be.end(); VI!=VE; ++VI){
- assert(vBB.size()>0 && "vector too small");
- if( VI->getSecond()->getElement() == vBB[1] ){
- //vBB[0]=VI->getFirst()->getElement();
- vBB.erase(vBB.begin());
- break;
- }
- }
- }
+ assert(startAddr && "startAddr should have been defined!");
- if(has2){
- //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] &&
- VI->getSecond()->getElement() == vBB[0]){
- //vBB.push_back(VI->getSecond()->getElement());
- break;
- }
- }
- }
- else
- vBB.push_back(nextRoot->getElement());
-
+ //return if SAME trace already there!
+ if(tr->hasTraceAddr(startAddr) && tr->hasTraceId(pn)){
+ std::cerr<<"Trace exists!!!\n";
return;
}
- assert(pathNo-maxCount>=0);
-
- return getPathFrmNode(nextRoot, vBB, pathNo-maxCount, g, stDummy,
- exDummy, be, strand);
-}
-
-
-static Node *findBB(std::vector<Node *> &st, BasicBlock *BB){
- for(std::vector<Node *>::iterator si=st.begin(); si!=st.end(); ++si){
- if(((*si)->getElement())==BB){
- return *si;
- }
+ if(tr->hasTraceAddr(startAddr)){
+ std::cerr<<"Removing old trace!\n";
+ tr->removeTrace(startAddr);
}
- return NULL;
-}
-void getBBtrace(vector<BasicBlock *> &vBB, int pathNo, Function *M){
- //step 1: create graph
- //Transform the cfg s.t. we have just one exit node
+ //the trace of instructions
+ vector<unsigned int> trace;
- //std::cerr<< "Inside bbtrace! path:"<<pathNo<<std::endl;
- //std::cerr<< "function:\n";
- //M->dump();
-
- std::vector<Node *> nodes;
- std::vector<Edge> edges;
- Node *tmp;
- Node *exitNode=0, *startNode=0;
- static std::map<Function *, Graph *> graphMap;
- static std::map<Function *, vector<Edge> > stMap, exMap, beMap;
-
- if(!graphMap[M]){
- BasicBlock *ExitNode = 0;
- for (Function::iterator I = M->begin(), E = M->end(); I != E; ++I){
- if (isa<ReturnInst>(I->getTerminator())) {
- ExitNode = I;
- break;
- }
- }
+ //map of call instructions
+ std::map<int, uint64_t> callMap;
- assert(ExitNode!=0 && "exitnode not found");
-
- //iterating over BBs and making graph
- //The nodes must be uniquely identified:
- //That is, no two nodes must hav same BB*
+ //map of branches
+ std::map<int, uint64_t> branchMap; //branch at index, was located at PC
- //First enter just nodes: later enter edges
- for(Function::iterator BB = M->begin(), BE=M->end(); BB != BE; ++BB){
- Node *nd=new Node(BB);
- nodes.push_back(nd);
- if(&*BB==ExitNode)
- exitNode=nd;
- if(&*BB==&M->front())
- startNode=nd;
- }
-
- assert(exitNode!=0 && startNode!=0 && "Start or exit not found!");
-
- for (Function::iterator BB = M->begin(), BE=M->end(); BB != BE; ++BB){
- Node *nd=findBB(nodes, BB);
- assert(nd && "No node for this edge!");
-
- for(BasicBlock::succ_iterator s=succ_begin(&*BB), se=succ_end(&*BB);
- s!=se; ++s){
- Node *nd2=findBB(nodes,*s);
- assert(nd2 && "No node for this edge!");
- Edge ed(nd,nd2,0);
- edges.push_back(ed);
+ int instIndex = 0;
+
+ //Now iterate ove trace of BBs, and insert them into the cache
+ for(vector<BasicBlock *>::iterator VBI = vBB.begin(), VBE = vBB.end();
+ VBI!=VBE; ++VBI){
+
+ //Take the first instr of the basic block, and insert
+ //all instructions uptil the end of basic block in the trace
+ std::pair<uint64_t, uint64_t> bbInst = getBasicBlockInfo(*VBI);
+
+ //set various flags
+ bool isCondBranch = false;
+ bool hasNextBB = false;
+ bool hasTrueIndex = false;
+
+ //see if terminator is a conditional branch
+ TerminatorInst *TI = (*VBI)->getTerminator();
+ if(isa<BranchInst>(TI)){
+ BranchInst *BI = cast<BranchInst>(TI);
+ if(BI->isConditional()){
+ isCondBranch = true;
+
+ //see if next BB is in vBB
+ if(VBI != vBB.end()-1 && BI->getSuccessor(0) == *(VBI+1) ){
+ hasNextBB = true;
+ hasTrueIndex = true;
+ }
+ else if(VBI != vBB.end()-1 && BI->getSuccessor(1) == *(VBI+1) )
+ hasNextBB = true;
+ }
+ else{//is unconditional branch
+ assert(BI->isUnconditional() && "Ought to be unconditional branch!");
+ if(VBI != vBB.end()-1 && BI->getSuccessor(0) == *(VBI+1) ){
+ hasNextBB = true;
+ }
+ }
+ }
+
+ if(VBI != vBB.end()-1){//so its NOT last BB
+ assert(hasNextBB && "Next BB not in sequence!");
+ }
+
+ //Now, the last inst corresponding to the BB MAY or MAY NOT be included
+ //in the returned addresses. So leave last two instructions
+ //Now if unconditional branch, then read until last 2,
+ //if unconditional branch
+ //then read until last 4
+ int skipIndex = (isCondBranch ? 4:2);
+
+ std::cerr<<"From->to"<<(void *)bbInst.first<<"->"<<(void *)(bbInst.second-4*skipIndex)<<"\n";
+
+ for(uint64_t addr = bbInst.first, endAddr = bbInst.second;
+ addr<=endAddr-4*skipIndex; addr+=4, instIndex++){
+ unsigned inst = vm->readInstrFrmVm(addr);
+
+ trace.push_back(inst);
+ //handle call instructions later!
+ if(isCallInstr(inst)){
+ callMap[instIndex] = addr;
+ std::cerr<<(void *)inst;
+ std::cerr<<"\t\tcall is index:"<<instIndex<<"\t address: "<<addr<<"\n";
+ }
+
+ std::cerr<< "address: "<<(void *)addr<<" inst: "<<(void *)inst<<"\n";
+ assert(!isBranchInstr(inst) &&
+ "No branch instruction should occur in middle of BasicBlock!");
+ }
+ std::cerr<<"---------------\n";
+
+ if(isCondBranch){//skipped last 4!
+ //if 4th last is a branch, then no probs!!!
+ unsigned int instrCheck = vm->readInstrFrmVm(bbInst.second-12);
+ unsigned int br1, ds1, br2, ds2;
+ uint64_t addrbr1, addrbr2;
+ if(isBranchInstr(instrCheck)){
+ br1 = instrCheck;
+ addrbr1 = bbInst.second-12;
+ ds1 = vm->readInstrFrmVm(bbInst.second-8);
+ br2 = vm->readInstrFrmVm(bbInst.second-4);
+ addrbr2 = bbInst.second-4;
+ ds2 = vm->readInstrFrmVm(bbInst.second);
+ }
+ else{
+ trace.push_back(instrCheck);
+
+ if(isCallInstr(instrCheck)){
+ callMap[instIndex] = bbInst.second - 12;
+ std::cerr<<(void *)instrCheck;
+ std::cerr<<"\t\tcall is index:"<<instIndex<<"\t address: "<<bbInst.second-12<<"\n";
+ }
+
+ instIndex++;
+
+ br1 = vm->readInstrFrmVm(bbInst.second-8);
+ addrbr1 = bbInst.second-8;
+ ds1 = vm->readInstrFrmVm(bbInst.second-4);
+ br2 = vm->readInstrFrmVm(bbInst.second);
+ addrbr2 = bbInst.second;
+ ds2 = vm->readInstrFrmVm(bbInst.second+4);
+ }
+
+ assert(isBranchInstr(br1) && isBranchInstr(br2) && "Not a branch!");
+
+ if(hasNextBB){
+ //eliminate one of the branches!
+ std::vector<BasicBlock *>::iterator VBNext = VBI+1;
+ std::pair<uint64_t, uint64_t> bbDest = getBasicBlockInfo(*VBNext);
+ //get branch br1 and br2 targets to check if any matches bbDest
+ uint64_t tar1, tar2;
+ if(isNonDepJump(br1))
+ tar1 = getNonDepJmpTarget(br1, addrbr1);
+ else if(isDepJump(br1))
+ tar1 = getDepJmpTarget(br1, addrbr1);
+ else if(isBPR(br1))
+ tar1 = getBPRTarget(br1, addrbr1);
+ else{
+ std::cerr<<(void *)br1<<"\n";
+ assert(false && "Branch not handled 1!");
+ }
+
+ if(isNonDepJump(br2))
+ tar2 = getNonDepJmpTarget(br2, addrbr2);
+ else if(isDepJump(br2))
+ tar2 = getDepJmpTarget(br2, addrbr2);
+ else
+ assert(false && "Branch not handled!");
+
+ assert( (tar1 == bbDest.first || tar2 == bbDest.first) &&
+ "No destination matched for consecutive BBs");
+
+ if(tar1 == bbDest.first){
+ //check that second branch is ba, or bn
+ assert( (isBranchAlways(br2) || isBranchNever(br2) ) &&
+ "Branch 2 should have been branch always, or branch never!");
+
+ //so invert branch condition, make it second branch,
+ //and eliminate first branch!
+
+ //take the target of br2 and inverted condition of br1
+ std::pair<unsigned int, unsigned int> invertedBranch =
+ vm->getInvertedBranch(br1, br2);
+
+ //insert ds1, br2, ds2 in the trace (in that order)
+ //store branches and PCs for later correction in branchMap
+
+ trace.push_back(ds1);
+ instIndex++;
+ if(invertedBranch.first != 0){
+ trace.push_back(invertedBranch.first);
+ instIndex++;
+ }
+ trace.push_back(invertedBranch.second);
+ branchMap[instIndex] = addrbr2;
+ trace.push_back(ds2);
+ //trace.push_back(ds1);
+ instIndex += 2;
+ }
+ else{
+ //erase second branch
+ //insert into trace br1, ds1, ds2
+
+ trace.push_back(br1);
+ //store branch index and PC for later correction in branchMap
+ branchMap[instIndex] = addrbr1;
+ if(isBPR(br1)){
+ trace.push_back(0);
+ instIndex++;
+ }
+ trace.push_back(ds1);
+ trace.push_back(ds2);
+
+ instIndex += 3;
+ }
+ }
+ else{//So it must be last BB in sequence!
+
+ //check that it points to first BB
+ std::pair<uint64_t, uint64_t> bbDest = getBasicBlockInfo(*(vBB.begin()));
+ //get branch br1 and br2 targets to check if any matches bbDest
+ uint64_t tar1, tar2;
+ if(isNonDepJump(br1))
+ tar1 = getNonDepJmpTarget(br1, addrbr1);
+ else if(isDepJump(br1))
+ tar1 = getDepJmpTarget(br1, addrbr1);
+ else
+ assert(false && "Branch not handled!");
+
+ if(isNonDepJump(br2))
+ tar2 = getNonDepJmpTarget(br2, addrbr2);
+ else if(isDepJump(br2))
+ tar2 = getDepJmpTarget(br2, addrbr2);
+ else
+ assert(false && "Branch not handled!");
+
+ assert( (tar1 == bbDest.first || tar2 == bbDest.first) &&
+ "Last BB must point to first BB");
+
+ //insert code
+ trace.push_back(br1);
+ branchMap[instIndex] = addrbr1;
+ if(isBPR(br1)){
+ trace.push_back(0);
+ instIndex++;
+ }
+
+ trace.push_back(ds1);
+
+ trace.push_back(br2);
+ branchMap[instIndex+2] = addrbr2;
+ if(isBPR(br2)){
+ trace.push_back(0);
+ instIndex++;
+ }
+
+ trace.push_back(ds2);
+ instIndex += 4;
+ }
+ }
+ //is unconditional branch
+ else{
+ unsigned int instrCheck = vm->readInstrFrmVm(bbInst.second-4);
+ unsigned int br1, ds1;
+ uint64_t addrbr1;
+ if(isBranchInstr(instrCheck)){
+ br1 = instrCheck;
+ addrbr1 = bbInst.second-4;
+ ds1 = vm->readInstrFrmVm(bbInst.second);
+ }
+ else{
+ trace.push_back(instrCheck);
+
+ if(isCallInstr(instrCheck)){
+ callMap[instIndex] = bbInst.second - 4;
+ std::cerr<<(void *)instrCheck;
+ std::cerr<<"\t\tcall is index:"<<instIndex<<"\t address: "<<bbInst.second-4<<"\n";
+ }
+
+ instIndex++;
+
+ br1 = vm->readInstrFrmVm(bbInst.second);
+ addrbr1 = bbInst.second;
+ ds1 = vm->readInstrFrmVm(bbInst.second+4);
+ }
+
+ std::cerr<<"Branch: "<<(void *)br1<<"\n";
+ assert( (isBranchAlways(br1) || isBranchNever(br1) ) &&
+ "Unconditional branch: should be branch always, or branch never!");
+
+ //now do fancy stuff!
+ //if branch points to the next BB, then erase it
+ if(hasNextBB){
+ std::pair<uint64_t, uint64_t> bbDest = getBasicBlockInfo(*(VBI+1));
+
+ //get branch br1 target to check if it matches bbDest
+ uint64_t tar1, tar2;
+
+ if(isNonDepJump(br1))
+ tar1 = getNonDepJmpTarget(br1, addrbr1);
+ else if(isDepJump(br1))
+ tar1 = getDepJmpTarget(br1, addrbr1);
+ else if(isBPR(br1))
+ tar1 = getBPRTarget(br1, addrbr1);
+ else{
+ std::cerr<<(void *)br1<<"\n";
+ assert(false && "Branch not handled!");
+ }
+
+ //copy ds1, and tht's all
+ trace.push_back(ds1);
+ instIndex++;
+ }
+ else{
+ //Must be last BB. check for coninuity!
+ std::pair<uint64_t, uint64_t> bbDest =
+ getBasicBlockInfo(*(vBB.begin()));
+
+ uint64_t tar1;
+ if(isNonDepJump(br1))
+ tar1 = getNonDepJmpTarget(br1, addrbr1);
+ else if(isDepJump(br1))
+ tar1 = getDepJmpTarget(br1, addrbr1);
+ else if(isBPR(br1))
+ tar1 = getBPRTarget(br1, addrbr1);
+ else{
+ std::cerr<<(void *)br1<<"\n";
+ assert(false && "Branch not handled!");
+ }
+
+ assert(tar1 == bbDest.first && "Last BB must point to first BB");
+ trace.push_back(br1);
+ branchMap[instIndex] = addrbr1;
+ trace.push_back(ds1);
+
+ instIndex += 2;
}
}
-
- graphMap[M]= new Graph(nodes,edges, startNode, exitNode);
-
- Graph *g = graphMap[M];
-
- 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);
- //printGraph(*g);
}
-
- //print graph
- //printGraph(g);
-
- //step 5: now travel from root, select max(edge) < pathNo,
- //and go on until reach the exit
- return getPathFrmNode(graphMap[M]->getRoot(), vBB, pathNo, *graphMap[M], stMap[M], exMap[M], beMap[M], -1);
+
+ //Now add trace to cache, and we are all set!
+ if(!tr->addTrace(startAddr, trace, pn, callMap, branchMap))
+ std::cerr<<"^^^^^^^^^^************** Trace could not be added!!!\n";
}
More information about the llvm-commits
mailing list