[llvm-commits] CVS: llvm/lib/Reoptimizer/Trigger/Trigger.cpp
Anand Shukla
ashukla at cs.uiuc.edu
Thu Sep 19 18:02:01 PDT 2002
Changes in directory llvm/lib/Reoptimizer/Trigger:
Trigger.cpp updated: 1.8 -> 1.9
---
Log message:
Recent Trigger file
---
Diffs of the changes:
Index: llvm/lib/Reoptimizer/Trigger/Trigger.cpp
diff -u llvm/lib/Reoptimizer/Trigger/Trigger.cpp:1.8 llvm/lib/Reoptimizer/Trigger/Trigger.cpp:1.9
--- llvm/lib/Reoptimizer/Trigger/Trigger.cpp:1.8 Sun Sep 15 21:14:33 2002
+++ llvm/lib/Reoptimizer/Trigger/Trigger.cpp Thu Sep 19 18:00:45 2002
@@ -25,6 +25,17 @@
void getBBtrace(vector<BasicBlock *> &vBB, int pathNo, Function *M);
+extern "C" void llvmInitializeCounter(int *cnt, int k){
+ for(int i=0; i<k; i++)
+ cnt[i]=0;
+}
+
+extern "C" void reoptimizerInitialize(int *t){
+ char *a = getenv("LLVM_THRESHOLD");
+ assert(a && "LLVM_THRESHOLD not exported as a shell variable!");
+ *t = atoi(a);
+}
+
void printTrace(vector<BasicBlock *> &vBB, int pn){
std::cerr<<"Path no:"<<pn<<" ---------\n";
for(vector<BasicBlock *>::iterator VVI = vBB.begin(), VVE = vBB.end();
@@ -34,17 +45,22 @@
}
-extern "C" void trigger(int mn, int pn, int cnt){
+extern "C" void trigger(int mn, int pn, int *cnt){
static bool initialized = false; //so module is read just once
static Module *M;
static std::vector<Function *> funcList; //map of functions
+ //std::cerr<<"Meth: "<<mn<<"\t path"<<pn<<"\t count:"<<cnt[pn]<<std::endl;
+
+ //intialize counter!
+ cnt[pn]=0;
+
if(!initialized){
//BytecodeParser Parser;
M = ParseBytecodeBuffer(LLVMBytecode, llvm_length);
assert(M && "Module parsing failed!");
- std::cerr<<M;
+ //std::cerr<<M;
initialized = true;
//read in pointers to functions
int mmn = -1;
@@ -67,12 +83,21 @@
// ******* SET THE count THRESHOLD HERE ***********
//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;
+
+ //for(int ppn =0; ppn<8; ppn++){
+ //std::vector<BasicBlock *> vBB;
+ //getBBtrace(vBB, ppn, funcList[mn]);
+ //printTrace(vBB, ppn);
+ //}
+
+ //exit(0);
+
getBBtrace(vBB, pn, funcList[mn]);
+
+ //return;//just measure time to retrace!
if(vBB[0] == &funcList[mn]->front() ||
isa<ReturnInst>(vBB[vBB.size()-1]->getTerminator())){
@@ -174,7 +199,7 @@
//then read until last 4
int skipIndex = (isCondBranch ? 4:2);
- std::cerr<<"From->to"<<(void *)bbInst.first<<"->"<<(void *)(bbInst.second-4*skipIndex)<<"\n";
+ //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++){
@@ -184,15 +209,15 @@
//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<<(void *)inst;
+ //std::cerr<<"\t\tcall is index:"<<instIndex<<"\t address: "<<addr<<"\n";
}
- std::cerr<< "address: "<<(void *)addr<<" inst: "<<(void *)inst<<"\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";
+ //std::cerr<<"---------------\n";
if(isCondBranch){//skipped last 4!
//if 4th last is a branch, then no probs!!!
@@ -212,8 +237,8 @@
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";
+ //std::cerr<<(void *)instrCheck;
+ //std::cerr<<"\t\tcall is index:"<<instIndex<<"\t address: "<<bbInst.second-12<<"\n";
}
instIndex++;
@@ -241,7 +266,7 @@
else if(isBPR(br1))
tar1 = getBPRTarget(br1, addrbr1);
else{
- std::cerr<<(void *)br1<<"\n";
+ //std::cerr<<(void *)br1<<"\n";
assert(false && "Branch not handled 1!");
}
@@ -267,10 +292,17 @@
std::pair<unsigned int, unsigned int> invertedBranch =
vm->getInvertedBranch(br1, br2);
- //insert ds1, br2, ds2 in the trace (in that order)
+ //insert (del cmp) ds1, cmp, br2, ds2 in the trace (in that order)
//store branches and PCs for later correction in branchMap
- trace.push_back(ds1);
+ unsigned int last_inst = trace[instIndex-1];
+ if(invertedBranch.first == 0){
+ trace[instIndex-1] = ds1;
+ trace.push_back(last_inst);
+ }
+ else
+ trace.push_back(ds1);
+
instIndex++;
if(invertedBranch.first != 0){
trace.push_back(invertedBranch.first);
@@ -319,28 +351,30 @@
else
assert(false && "Branch not handled!");
- assert( (tar1 == bbDest.first || tar2 == bbDest.first) &&
- "Last BB must point to first BB");
+ //assert( (tar1 == bbDest.first || tar2 == bbDest.first) &&
+ // "Last BB must point to first BB");
+ assert(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(br1);
+ //branchMap[instIndex] = addrbr1;
+ //if(isBPR(br1)){
+ //trace.push_back(0);
+ //instIndex++;
+ //}
trace.push_back(ds1);
trace.push_back(br2);
- branchMap[instIndex+2] = addrbr2;
+ branchMap[instIndex+1] = addrbr2;
if(isBPR(br2)){
trace.push_back(0);
instIndex++;
}
trace.push_back(ds2);
- instIndex += 4;
+ instIndex += 3;
}
}
//is unconditional branch
@@ -351,15 +385,15 @@
if(isBranchInstr(instrCheck)){
br1 = instrCheck;
addrbr1 = bbInst.second-4;
- ds1 = vm->readInstrFrmVm(bbInst.second);
+ 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";
+ //std::cerr<<(void *)instrCheck;
+ //std::cerr<<"\t\tcall is index:"<<instIndex<<"\t address: "<<bbInst.second-4<<"\n";
}
instIndex++;
@@ -369,7 +403,7 @@
ds1 = vm->readInstrFrmVm(bbInst.second+4);
}
- std::cerr<<"Branch: "<<(void *)br1<<"\n";
+ //std::cerr<<"Branch: "<<(void *)br1<<"\n";
assert( (isBranchAlways(br1) || isBranchNever(br1) ) &&
"Unconditional branch: should be branch always, or branch never!");
@@ -388,7 +422,7 @@
else if(isBPR(br1))
tar1 = getBPRTarget(br1, addrbr1);
else{
- std::cerr<<(void *)br1<<"\n";
+ //std::cerr<<(void *)br1<<"\n";
assert(false && "Branch not handled!");
}
@@ -409,7 +443,7 @@
else if(isBPR(br1))
tar1 = getBPRTarget(br1, addrbr1);
else{
- std::cerr<<(void *)br1<<"\n";
+ //std::cerr<<(void *)br1<<"\n";
assert(false && "Branch not handled!");
}
More information about the llvm-commits
mailing list