[llvm-commits] CVS: reopt/lib/LightWtProfiling/SecondTrigger.cpp
Brian Gaeke
gaeke at cs.uiuc.edu
Thu Oct 30 13:57:02 PST 2003
Changes in directory reopt/lib/LightWtProfiling:
SecondTrigger.cpp updated: 1.20 -> 1.21
---
Log message:
Refactor the resetCounters stuff.
Fix some style issues; get rid of some commented-out code.
---
Diffs of the changes: (+28 -56)
Index: reopt/lib/LightWtProfiling/SecondTrigger.cpp
diff -u reopt/lib/LightWtProfiling/SecondTrigger.cpp:1.20 reopt/lib/LightWtProfiling/SecondTrigger.cpp:1.21
--- reopt/lib/LightWtProfiling/SecondTrigger.cpp:1.20 Mon Oct 6 13:15:26 2003
+++ reopt/lib/LightWtProfiling/SecondTrigger.cpp Thu Oct 30 13:56:13 2003
@@ -121,13 +121,11 @@
for(std::map<uint64_t, int>::iterator MI = mMap->begin(),
ME = mMap->end(); MI != ME; ++MI){
mulMap.insert(std::make_pair(MI->second, MI->first));
- //std::cerr<<MI->first<<"\n";
}
int sum = 0;
for(std::multimap<int, uint64_t>::reverse_iterator RMI = mulMap.rbegin(),
RME = mulMap.rend(); RMI != RME; ++RMI){
sum += RMI->first;
- //std::cerr<<(void *)RMI->second<<"\n";
paths.push_back(RMI->second);
if((sum*100)/total > THRESHOLD_PERCENTAGE)
break;
@@ -146,7 +144,6 @@
for(int x = 0; x<j; x++)
fin |= ((((1ULL << (j-x-1))&temp)>>(j-x-1))<<(x));
- //std::cerr<<"Fin: "<<(void *)fin<<"\n";
paths[i] = fin;
}
}
@@ -168,6 +165,13 @@
return instr;
}
+static void resetCounters (uint64_t pcAddr, uint64_t reverseAddr) {
+ delete pathCounter[pcAddr];
+ pathCounter.erase(pcAddr);
+ totalCount[pcAddr] = 0;
+ exitCounter[reverseAddr] = 0;
+}
+
void countPath () {
uint64_t branchHist;
uint64_t i_reg_save[6];
@@ -224,49 +228,33 @@
vm->writeBranchInstruction(startAddr, startAddrforTrace);
doFlush(startAddr-8, startAddr+8);
- delete pathCounter[pcAddr];
- pathCounter.erase(pcAddr);
- totalCount[pcAddr] = 0;
- exitCounter[reverseAddr] = 0;
+ resetCounters (pcAddr, reverseAddr);
tr->patchTrace(startAddr);
if(!backOffCounters[reverseAddr].second)
backOffCounters[reverseAddr].second = 1;
-
backOffCounters[reverseAddr].second *= 2;
+
assert(firstTriggerAddr.find(reverseAddr) != firstTriggerAddr.end());
insert_address_at(llvm_interval_counter +
backOffCounters[reverseAddr].second,
firstTriggerAddr[reverseAddr]);
- }
- else{
+ } else{
if(oldMap->find(branchHist) != oldMap->end()){
- //std::cerr<<(void *)pcAddr<<"\t"<<branchHist<<"\n";
(*oldMap)[branchHist]++;
if(totalCount[pcAddr] > THRESHOLD_LEVEL_2){
- //|| exitCounter[reverseAddr] > totalCount[pcAddr]){
-
- if(exitCounter[reverseAddr] < (totalCount[pcAddr]*30)/100 &&
- totalCount[pcAddr] > THRESHOLD_LEVEL_2){
-
+ if(exitCounter[reverseAddr] < ((totalCount[pcAddr]*30)/100)){
int total = totalCount[pcAddr];
- exitCounter[reverseAddr] = 0;
if(!backOffCounters[reverseAddr].first)
backOffCounters[reverseAddr].first = 1;
-
backOffCounters[reverseAddr].first *= 2;
- //insert into queue with interval set
+
assert(firstTriggerAddr.find(reverseAddr) != firstTriggerAddr.end());
//DO NOT insert trace address if already optimized
- //insert_address_at(llvm_interval_counter +
- //backOffCounters[reverseAddr].first,
- // firstTriggerAddr[reverseAddr]);
-
std::vector<uint64_t> tempVec;
-
getPaths(tempVec, oldMap, total);
uint64_t startAddrforTrace = tr->getOriginalAddress(startAddr);
assert(startAddr);
@@ -284,13 +272,9 @@
tr2->getAddr(startAddrforTrace));
doFlush(startAddrforTrace-8, startAddrforTrace+8);
}
-
- delete pathCounter[pcAddr];
- pathCounter.erase(pcAddr);
- totalCount[pcAddr] = 0;
- exitCounter[reverseAddr] = 0;
- }
- else{
+
+ resetCounters (pcAddr, reverseAddr);
+ } else {
DEBUG(std::cerr << "Trace not generated in countPath(): "
<< (void *)tr->getOriginalAddress(startAddr) << ", "
<< (void *)endAddr);
@@ -310,16 +294,13 @@
vm->writeBranchInstruction(startAddr, startAddrforTrace);
doFlush(startAddr-8, startAddr+8);
- delete pathCounter[pcAddr];
- pathCounter.erase(pcAddr);
- totalCount[pcAddr] = 0;
- exitCounter[reverseAddr] = 0;
+ resetCounters (pcAddr, reverseAddr);
tr->patchTrace(startAddr);
if(!backOffCounters[reverseAddr].second)
backOffCounters[reverseAddr].second = 1;
-
backOffCounters[reverseAddr].second *= 2;
+
assert(firstTriggerAddr.find(reverseAddr) != firstTriggerAddr.end());
insert_address_at(llvm_interval_counter +
@@ -333,8 +314,7 @@
(*oldMap)[branchHist] = 1;
}
//increment counter!
- }
- else{
+ } else {
std::map<uint64_t, int> *newMap = new std::map<uint64_t, int>();
(*newMap)[branchHist]=1;
pathCounter[pcAddr] = newMap;
@@ -378,8 +358,8 @@
}
}
- prtoret.first = toRet;//x;//toRet
- prtoret.second = pathChosen;//0;//pathChosen;
+ prtoret.first = toRet;
+ prtoret.second = pathChosen;
}
//Note: end addr is superfluous. The *only* way to work is to form loops,
@@ -571,7 +551,6 @@
std::vector<uint64_t> callStack;
std::vector<uint64_t> calledStack;
- //int pathCounter = 0;
int pathNumber = 0;
for(std::vector<uint64_t>::iterator PI = paths.begin(), PE = paths.end();
PI != PE; ++PI, pathNumber++){
@@ -696,18 +675,15 @@
== calledStack.end()){
//push DS, and set PC to new target
if(insertCode){
- //std::cerr<<"Inlining function\n";
- //std::cerr<<callFunc;
+ DEBUG (std::cerr<<"Inlining function: " << callFunc << "\n");
traces.push_back(vm->readInstrFrmVm(pc+4, tr, tr2));
index++;
- //if(callFunc->size() > 1)
getReturnCode(traces, index, pc);
}
callStack.push_back(pc+8); //return address
calledStack.push_back(callTarget);
pc = callTarget;
- }
- else{
+ } else{
// Can't inline the called function
if(callTarget != (uint64_t)llvm_first_trigger && callTarget !=
(uint64_t)countPath){
@@ -729,8 +705,7 @@
addCall(traces, callMap, index,
(uint64_t)(intptr_t)&llvm_time_start);
}
- }
- else{
+ } else{
// Reoptimizer entry point being called; skip the call,
// but copy its delay slot instruction.
if(insertCode){
@@ -766,8 +741,8 @@
traces.push_back(brInstr);
if(nextTrace < 0){
targetMap[index] = pc+8;
- }
- else{//make it point to next trace
+ } else{
+ // make it point to next trace
assert(targetTraceMap.find(nextTrace) == targetTraceMap.end()
&& "a given trace can have only one entry");
targetTraceMap[nextTrace] = index;
@@ -787,8 +762,7 @@
traces.push_back(instr);
if(nextTrace < 0){
targetMap[index] = getBranchTarget(instr, pc);
- }
- else{
+ } else{
targetTraceMap[nextTrace] = index;
}
traces.push_back(vm->readInstrFrmVm(pc+4, tr, tr2));
@@ -842,16 +816,14 @@
}
traces.push_back(ds);
index++;
- }
- else if(pc == start){
+ } else if(pc == start){
//insert branch back to top!
unsigned int br = vm->readInstrFrmVm(lastPC, tr, tr2);
unsigned int ds = vm->readInstrFrmVm(lastPC+4, tr, tr2);
traces[index-2] = getBranchInst(br, (uint64_t)(&traces[0]),
(uint64_t)(&traces[index-2]));
traces[index-1] = ds;
- }
- else{
+ } else{
//insert branch back to top!
unsigned int br = vm->readInstrFrmVm(pc, tr, tr2);
unsigned int ds = vm->readInstrFrmVm(pc+4, tr, tr2);
More information about the llvm-commits
mailing list