2002-09-10 17:03:06 +00:00
|
|
|
//===-- EdgeCode.cpp - generate LLVM instrumentation code -----------------===//
|
2003-10-20 19:43:21 +00:00
|
|
|
//
|
|
|
|
// 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.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
2002-02-26 18:59:46 +00:00
|
|
|
//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
|
|
|
|
//top block of cfg
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2003-01-14 22:33:56 +00:00
|
|
|
#include "Graph.h"
|
2002-04-28 19:55:58 +00:00
|
|
|
#include "llvm/Constants.h"
|
2002-02-26 18:59:46 +00:00
|
|
|
#include "llvm/DerivedTypes.h"
|
|
|
|
#include "llvm/iMemory.h"
|
|
|
|
#include "llvm/iTerminators.h"
|
|
|
|
#include "llvm/iOther.h"
|
|
|
|
#include "llvm/iOperators.h"
|
|
|
|
#include "llvm/iPHINode.h"
|
2002-06-25 21:14:58 +00:00
|
|
|
#include "llvm/Module.h"
|
|
|
|
|
|
|
|
#define INSERT_LOAD_COUNT
|
|
|
|
#define INSERT_STORE
|
2002-02-26 18:59:46 +00:00
|
|
|
|
2003-11-11 22:41:34 +00:00
|
|
|
|
2002-02-26 18:59:46 +00:00
|
|
|
using std::vector;
|
|
|
|
|
2003-11-11 22:41:34 +00:00
|
|
|
namespace llvm {
|
2002-06-25 21:14:58 +00:00
|
|
|
|
2002-09-10 17:03:06 +00:00
|
|
|
static void getTriggerCode(Module *M, BasicBlock *BB, int MethNo, Value *pathNo,
|
2003-02-14 20:41:53 +00:00
|
|
|
Value *cnt, Instruction *rInst){
|
2002-09-16 05:26:51 +00:00
|
|
|
|
2003-02-14 20:41:53 +00:00
|
|
|
vector<Value *> tmpVec;
|
|
|
|
tmpVec.push_back(Constant::getNullValue(Type::LongTy));
|
|
|
|
tmpVec.push_back(Constant::getNullValue(Type::LongTy));
|
|
|
|
Instruction *Idx = new GetElementPtrInst(cnt, tmpVec, "");//,
|
|
|
|
BB->getInstList().push_back(Idx);
|
|
|
|
|
2003-08-31 00:21:05 +00:00
|
|
|
const Type *PIntTy = PointerType::get(Type::IntTy);
|
|
|
|
Function *trigMeth = M->getOrInsertFunction("trigger", Type::VoidTy,
|
|
|
|
Type::IntTy, Type::IntTy,
|
|
|
|
PIntTy, PIntTy, 0);
|
2002-06-25 21:14:58 +00:00
|
|
|
assert(trigMeth && "trigger method could not be inserted!");
|
|
|
|
|
2002-09-16 05:26:51 +00:00
|
|
|
vector<Value *> trargs;
|
2002-07-08 19:36:39 +00:00
|
|
|
|
2002-06-25 21:14:58 +00:00
|
|
|
trargs.push_back(ConstantSInt::get(Type::IntTy,MethNo));
|
|
|
|
trargs.push_back(pathNo);
|
2003-02-14 20:41:53 +00:00
|
|
|
trargs.push_back(Idx);
|
|
|
|
trargs.push_back(rInst);
|
2002-09-16 05:26:51 +00:00
|
|
|
|
2002-09-20 16:44:35 +00:00
|
|
|
Instruction *callInst=new CallInst(trigMeth, trargs, "");//, BB->begin());
|
|
|
|
BB->getInstList().push_back(callInst);
|
|
|
|
//triggerInst = new CallInst(trigMeth, trargs, "");//, InsertPos);
|
2002-06-25 21:14:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-02-26 18:59:46 +00:00
|
|
|
//get the code to be inserted on the edge
|
|
|
|
//This is determined from cond (1-6)
|
2003-02-14 20:41:53 +00:00
|
|
|
void getEdgeCode::getCode(Instruction *rInst, Value *countInst,
|
2002-09-20 16:44:35 +00:00
|
|
|
Function *M, BasicBlock *BB,
|
|
|
|
vector<Value *> &retVec){
|
2002-02-26 18:59:46 +00:00
|
|
|
|
2002-09-20 16:44:35 +00:00
|
|
|
//Instruction *InsertPos = BB->getInstList().begin();
|
2002-02-26 18:59:46 +00:00
|
|
|
|
2002-09-20 16:44:35 +00:00
|
|
|
//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);
|
|
|
|
}
|
|
|
|
|
2002-02-26 18:59:46 +00:00
|
|
|
//case: r=k code to be inserted
|
|
|
|
switch(cond){
|
|
|
|
case 1:{
|
|
|
|
Value *val=ConstantSInt::get(Type::IntTy,inc);
|
2002-06-25 21:14:58 +00:00
|
|
|
#ifdef INSERT_STORE
|
2002-09-20 16:44:35 +00:00
|
|
|
Instruction *stInst=new StoreInst(val, rInst);//, InsertPos);
|
|
|
|
BB->getInstList().push_back(stInst);
|
2002-06-25 21:14:58 +00:00
|
|
|
#endif
|
2002-02-26 18:59:46 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
//case: r=0 to be inserted
|
2002-09-20 16:44:35 +00:00
|
|
|
case 2:{
|
2002-06-25 21:14:58 +00:00
|
|
|
#ifdef INSERT_STORE
|
2002-09-20 16:44:35 +00:00
|
|
|
Instruction *stInst = new StoreInst(ConstantSInt::getNullValue(Type::IntTy), rInst);//, InsertPos);
|
|
|
|
BB->getInstList().push_back(stInst);
|
2002-06-25 21:14:58 +00:00
|
|
|
#endif
|
2002-02-26 18:59:46 +00:00
|
|
|
break;
|
2002-09-20 16:44:35 +00:00
|
|
|
}
|
2002-02-26 18:59:46 +00:00
|
|
|
|
|
|
|
//r+=k
|
|
|
|
case 3:{
|
2002-09-20 16:44:35 +00:00
|
|
|
Instruction *ldInst = new LoadInst(rInst, "ti1");//, InsertPos);
|
|
|
|
BB->getInstList().push_back(ldInst);
|
2002-09-10 17:03:06 +00:00
|
|
|
Value *val = ConstantSInt::get(Type::IntTy,inc);
|
2002-09-20 16:44:35 +00:00
|
|
|
Instruction *addIn = BinaryOperator::create(Instruction::Add, ldInst, val,
|
|
|
|
"ti2");//, InsertPos);
|
|
|
|
BB->getInstList().push_back(addIn);
|
2002-06-25 21:14:58 +00:00
|
|
|
#ifdef INSERT_STORE
|
2002-09-20 16:44:35 +00:00
|
|
|
Instruction *stInst = new StoreInst(addIn, rInst);//, InsertPos);
|
|
|
|
BB->getInstList().push_back(stInst);
|
2002-06-25 21:14:58 +00:00
|
|
|
#endif
|
2002-02-26 18:59:46 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
//count[inc]++
|
|
|
|
case 4:{
|
2003-02-14 20:41:53 +00:00
|
|
|
vector<Value *> tmpVec;
|
|
|
|
tmpVec.push_back(Constant::getNullValue(Type::LongTy));
|
|
|
|
tmpVec.push_back(ConstantSInt::get(Type::LongTy, inc));
|
|
|
|
Instruction *Idx = new GetElementPtrInst(countInst, tmpVec, "");//,
|
|
|
|
|
|
|
|
//Instruction *Idx = new GetElementPtrInst(countInst,
|
|
|
|
// vector<Value*>(1,ConstantSInt::get(Type::LongTy, inc)),
|
|
|
|
// "");//, InsertPos);
|
2002-09-20 16:44:35 +00:00
|
|
|
BB->getInstList().push_back(Idx);
|
2002-08-21 22:11:33 +00:00
|
|
|
|
2002-09-20 16:44:35 +00:00
|
|
|
Instruction *ldInst=new LoadInst(Idx, "ti1");//, InsertPos);
|
|
|
|
BB->getInstList().push_back(ldInst);
|
2002-08-21 22:11:33 +00:00
|
|
|
|
|
|
|
Value *val = ConstantSInt::get(Type::IntTy, 1);
|
2002-09-20 16:44:35 +00:00
|
|
|
//Instruction *addIn =
|
|
|
|
Instruction *newCount =
|
|
|
|
BinaryOperator::create(Instruction::Add, ldInst, val,"ti2");
|
|
|
|
BB->getInstList().push_back(newCount);
|
|
|
|
|
2002-09-10 17:03:06 +00:00
|
|
|
|
|
|
|
#ifdef INSERT_STORE
|
2002-09-20 16:44:35 +00:00
|
|
|
//Instruction *stInst=new StoreInst(addIn, Idx, InsertPos);
|
|
|
|
Instruction *stInst=new StoreInst(newCount, Idx);//, InsertPos);
|
|
|
|
BB->getInstList().push_back(stInst);
|
2002-09-10 17:03:06 +00:00
|
|
|
#endif
|
2002-09-20 16:44:35 +00:00
|
|
|
|
|
|
|
Value *trAddIndex = ConstantSInt::get(Type::IntTy,inc);
|
2002-02-26 18:59:46 +00:00
|
|
|
|
2002-09-20 16:44:35 +00:00
|
|
|
retVec.push_back(newCount);
|
|
|
|
retVec.push_back(trAddIndex);
|
2002-06-25 21:14:58 +00:00
|
|
|
//insert trigger
|
2002-09-20 16:44:35 +00:00
|
|
|
//getTriggerCode(M->getParent(), BB, MethNo,
|
|
|
|
// ConstantSInt::get(Type::IntTy,inc), newCount, triggerInst);
|
2002-06-25 21:14:58 +00:00
|
|
|
//end trigger code
|
|
|
|
|
2002-02-26 18:59:46 +00:00
|
|
|
assert(inc>=0 && "IT MUST BE POSITIVE NOW");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
//case: count[r+inc]++
|
|
|
|
case 5:{
|
2002-09-10 17:03:06 +00:00
|
|
|
|
2002-02-26 18:59:46 +00:00
|
|
|
//ti1=inc+r
|
2002-09-20 16:44:35 +00:00
|
|
|
Instruction *ldIndex=new LoadInst(rInst, "ti1");//, InsertPos);
|
|
|
|
BB->getInstList().push_back(ldIndex);
|
|
|
|
|
2002-02-26 18:59:46 +00:00
|
|
|
Value *val=ConstantSInt::get(Type::IntTy,inc);
|
|
|
|
Instruction *addIndex=BinaryOperator::
|
2002-09-20 16:44:35 +00:00
|
|
|
create(Instruction::Add, ldIndex, val,"ti2");//, InsertPos);
|
|
|
|
BB->getInstList().push_back(addIndex);
|
2002-06-25 21:14:58 +00:00
|
|
|
|
2002-09-16 05:26:51 +00:00
|
|
|
//now load count[addIndex]
|
2002-02-26 18:59:46 +00:00
|
|
|
Instruction *castInst=new CastInst(addIndex,
|
2002-09-20 16:44:35 +00:00
|
|
|
Type::LongTy,"ctin");//, InsertPos);
|
|
|
|
BB->getInstList().push_back(castInst);
|
|
|
|
|
2003-02-14 20:41:53 +00:00
|
|
|
vector<Value *> tmpVec;
|
|
|
|
tmpVec.push_back(Constant::getNullValue(Type::LongTy));
|
|
|
|
tmpVec.push_back(castInst);
|
|
|
|
Instruction *Idx = new GetElementPtrInst(countInst, tmpVec, "");//,
|
2002-09-20 16:44:35 +00:00
|
|
|
// InsertPos);
|
|
|
|
BB->getInstList().push_back(Idx);
|
|
|
|
|
|
|
|
Instruction *ldInst=new LoadInst(Idx, "ti3");//, InsertPos);
|
|
|
|
BB->getInstList().push_back(ldInst);
|
2002-08-21 22:11:33 +00:00
|
|
|
|
2002-02-26 18:59:46 +00:00
|
|
|
Value *cons=ConstantSInt::get(Type::IntTy,1);
|
|
|
|
//count[addIndex]++
|
2003-02-14 20:41:53 +00:00
|
|
|
//std::cerr<<"Type ldInst:"<<ldInst->getType()<<"\t cons:"<<cons->getType()<<"\n";
|
2002-09-20 16:44:35 +00:00
|
|
|
Instruction *newCount = BinaryOperator::create(Instruction::Add, ldInst,
|
|
|
|
cons,"");
|
|
|
|
BB->getInstList().push_back(newCount);
|
2002-06-25 21:14:58 +00:00
|
|
|
|
|
|
|
#ifdef INSERT_STORE
|
2002-09-20 16:44:35 +00:00
|
|
|
Instruction *stInst = new StoreInst(newCount, Idx);//, InsertPos);
|
|
|
|
BB->getInstList().push_back(stInst);
|
2002-06-25 21:14:58 +00:00
|
|
|
#endif
|
2002-09-10 17:03:06 +00:00
|
|
|
|
2002-09-20 16:44:35 +00:00
|
|
|
retVec.push_back(newCount);
|
|
|
|
retVec.push_back(addIndex);
|
2002-09-10 17:03:06 +00:00
|
|
|
//insert trigger
|
2002-09-20 16:44:35 +00:00
|
|
|
//getTriggerCode(M->getParent(), BB, MethNo, addIndex, newCount, triggerInst);
|
2002-09-10 17:03:06 +00:00
|
|
|
//end trigger code
|
|
|
|
|
2002-02-26 18:59:46 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
//case: count[r]+
|
|
|
|
case 6:{
|
|
|
|
//ti1=inc+r
|
2002-09-20 16:44:35 +00:00
|
|
|
Instruction *ldIndex=new LoadInst(rInst, "ti1");//, InsertPos);
|
|
|
|
BB->getInstList().push_back(ldIndex);
|
|
|
|
|
2002-02-26 18:59:46 +00:00
|
|
|
//now load count[addIndex]
|
2002-09-20 16:44:35 +00:00
|
|
|
Instruction *castInst2=new CastInst(ldIndex, Type::LongTy,"ctin");
|
|
|
|
BB->getInstList().push_back(castInst2);
|
|
|
|
|
2003-02-14 20:41:53 +00:00
|
|
|
vector<Value *> tmpVec;
|
|
|
|
tmpVec.push_back(Constant::getNullValue(Type::LongTy));
|
|
|
|
tmpVec.push_back(castInst2);
|
|
|
|
Instruction *Idx = new GetElementPtrInst(countInst, tmpVec, "");//,
|
|
|
|
|
|
|
|
//Instruction *Idx = new GetElementPtrInst(countInst,
|
|
|
|
// vector<Value*>(1,castInst2), "");
|
|
|
|
|
2002-09-20 16:44:35 +00:00
|
|
|
BB->getInstList().push_back(Idx);
|
2002-08-21 22:11:33 +00:00
|
|
|
|
2002-09-20 16:44:35 +00:00
|
|
|
Instruction *ldInst=new LoadInst(Idx, "ti2");//, InsertPos);
|
|
|
|
BB->getInstList().push_back(ldInst);
|
|
|
|
|
2002-02-26 18:59:46 +00:00
|
|
|
Value *cons=ConstantSInt::get(Type::IntTy,1);
|
|
|
|
|
|
|
|
//count[addIndex]++
|
2002-09-20 16:44:35 +00:00
|
|
|
Instruction *newCount = BinaryOperator::create(Instruction::Add, ldInst,
|
|
|
|
cons,"ti3");
|
|
|
|
BB->getInstList().push_back(newCount);
|
2002-06-25 21:14:58 +00:00
|
|
|
|
|
|
|
#ifdef INSERT_STORE
|
2002-09-20 16:44:35 +00:00
|
|
|
Instruction *stInst = new StoreInst(newCount, Idx);//, InsertPos);
|
|
|
|
BB->getInstList().push_back(stInst);
|
2002-06-25 21:14:58 +00:00
|
|
|
#endif
|
2002-09-20 16:44:35 +00:00
|
|
|
|
|
|
|
retVec.push_back(newCount);
|
|
|
|
retVec.push_back(ldIndex);
|
2002-02-26 18:59:46 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Insert the initialization code in the top BB
|
|
|
|
//this includes initializing r, and count
|
|
|
|
//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,
|
2003-02-14 20:41:53 +00:00
|
|
|
Instruction *rVar, Value *threshold){
|
2002-02-26 18:59:46 +00:00
|
|
|
//rVar is variable r,
|
2003-02-14 20:41:53 +00:00
|
|
|
//countVar is count[]
|
2002-08-21 22:11:33 +00:00
|
|
|
|
|
|
|
Value *Int0 = ConstantInt::get(Type::IntTy, 0);
|
2002-02-26 18:59:46 +00:00
|
|
|
|
|
|
|
//now push all instructions in front of the BB
|
2002-09-10 17:03:06 +00:00
|
|
|
BasicBlock::iterator here=front->begin();
|
|
|
|
front->getInstList().insert(here, rVar);
|
2003-02-14 20:41:53 +00:00
|
|
|
//front->getInstList().insert(here,countVar);
|
2002-02-26 18:59:46 +00:00
|
|
|
|
|
|
|
//Initialize Count[...] with 0
|
2002-06-25 21:14:58 +00:00
|
|
|
|
2002-09-20 16:44:35 +00:00
|
|
|
//for (int i=0;i<k; i++){
|
|
|
|
//Value *GEP2 = new GetElementPtrInst(countVar,
|
|
|
|
// vector<Value *>(1,ConstantSInt::get(Type::LongTy, i)),
|
|
|
|
// "", here);
|
|
|
|
//new StoreInst(Int0, GEP2, here);
|
|
|
|
//}
|
2002-06-25 21:14:58 +00:00
|
|
|
|
2002-09-11 01:21:29 +00:00
|
|
|
//store uint 0, uint *%R
|
|
|
|
new StoreInst(Int0, rVar, here);
|
2002-02-26 18:59:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//insert a basic block with appropriate code
|
|
|
|
//along a given edge
|
|
|
|
void insertBB(Edge ed,
|
|
|
|
getEdgeCode *edgeCode,
|
|
|
|
Instruction *rInst,
|
2003-02-14 20:41:53 +00:00
|
|
|
Value *countInst,
|
2002-09-20 16:44:35 +00:00
|
|
|
int numPaths, int Methno, Value *threshold){
|
2002-09-16 05:26:51 +00:00
|
|
|
|
2002-02-26 18:59:46 +00:00
|
|
|
BasicBlock* BB1=ed.getFirst()->getElement();
|
|
|
|
BasicBlock* BB2=ed.getSecond()->getElement();
|
|
|
|
|
2002-06-25 21:14:58 +00:00
|
|
|
#ifdef DEBUG_PATH_PROFILES
|
|
|
|
//debugging info
|
|
|
|
cerr<<"Edges with codes ######################\n";
|
|
|
|
cerr<<BB1->getName()<<"->"<<BB2->getName()<<"\n";
|
|
|
|
cerr<<"########################\n";
|
|
|
|
#endif
|
|
|
|
|
2002-02-26 18:59:46 +00:00
|
|
|
//We need to insert a BB between BB1 and BB2
|
|
|
|
TerminatorInst *TI=BB1->getTerminator();
|
2002-09-16 05:26:51 +00:00
|
|
|
BasicBlock *newBB=new BasicBlock("counter", BB1->getParent());
|
2002-02-26 18:59:46 +00:00
|
|
|
|
2002-09-20 16:44:35 +00:00
|
|
|
//get code for the new BB
|
|
|
|
vector<Value *> retVec;
|
|
|
|
|
|
|
|
edgeCode->getCode(rInst, countInst, BB1->getParent(), newBB, retVec);
|
2002-02-26 18:59:46 +00:00
|
|
|
|
2002-07-08 19:36:39 +00:00
|
|
|
BranchInst *BI = cast<BranchInst>(TI);
|
|
|
|
|
2002-09-20 16:44:35 +00:00
|
|
|
//Is terminator a branch instruction?
|
|
|
|
//then we need to change branch destinations to include new BB
|
|
|
|
|
2002-02-26 18:59:46 +00:00
|
|
|
if(BI->isUnconditional()){
|
|
|
|
BI->setUnconditionalDest(newBB);
|
|
|
|
}
|
|
|
|
else{
|
2002-06-25 21:14:58 +00:00
|
|
|
if(BI->getSuccessor(0)==BB2)
|
|
|
|
BI->setSuccessor(0, newBB);
|
|
|
|
|
|
|
|
if(BI->getSuccessor(1)==BB2)
|
|
|
|
BI->setSuccessor(1, newBB);
|
2002-09-20 16:44:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
BasicBlock *triggerBB = NULL;
|
|
|
|
if(retVec.size()>0){
|
|
|
|
triggerBB = new BasicBlock("trigger", BB1->getParent());
|
|
|
|
getTriggerCode(BB1->getParent()->getParent(), triggerBB, Methno,
|
2003-02-14 20:41:53 +00:00
|
|
|
retVec[1], countInst, rInst);//retVec[0]);
|
2002-06-25 21:14:58 +00:00
|
|
|
|
2002-09-20 16:44:35 +00:00
|
|
|
//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,
|
|
|
|
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);
|
2003-11-20 18:25:24 +00:00
|
|
|
new BranchInst(BB2, 0, 0, triggerBB);
|
2002-09-20 16:44:35 +00:00
|
|
|
}
|
|
|
|
else{
|
2003-11-20 18:25:24 +00:00
|
|
|
new BranchInst(BB2, 0, 0, newBB);
|
2002-02-26 18:59:46 +00:00
|
|
|
}
|
2002-09-14 19:33:16 +00:00
|
|
|
|
2002-09-16 05:26:51 +00:00
|
|
|
//now iterate over BB2, and set its Phi nodes right
|
2002-06-25 16:13:21 +00:00
|
|
|
for(BasicBlock::iterator BB2Inst = BB2->begin(), BBend = BB2->end();
|
|
|
|
BB2Inst != BBend; ++BB2Inst){
|
2002-02-26 18:59:46 +00:00
|
|
|
|
2003-04-23 16:37:45 +00:00
|
|
|
if(PHINode *phiInst=dyn_cast<PHINode>(BB2Inst)){
|
2002-02-26 18:59:46 +00:00
|
|
|
int bbIndex=phiInst->getBasicBlockIndex(BB1);
|
2002-06-25 21:14:58 +00:00
|
|
|
assert(bbIndex>=0);
|
|
|
|
phiInst->setIncomingBlock(bbIndex, newBB);
|
2002-09-20 16:44:35 +00:00
|
|
|
|
|
|
|
///check if trigger!=null, then add value corresponding to it too!
|
|
|
|
if(retVec.size()>0){
|
|
|
|
assert(triggerBB && "BasicBlock with trigger should not be null!");
|
|
|
|
Value *vl = phiInst->getIncomingValue((unsigned int)bbIndex);
|
|
|
|
phiInst->addIncoming(vl, triggerBB);
|
|
|
|
}
|
2002-02-26 18:59:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2002-06-25 21:14:58 +00:00
|
|
|
|
2003-11-11 22:41:34 +00:00
|
|
|
} // End llvm namespace
|