[llvm-commits] CVS: llvm/lib/Reoptimizer/LightWtProfiling/Trigger/SecondTrigger.cpp
Brian Gaeke
gaeke at cs.uiuc.edu
Mon Aug 18 15:35:08 PDT 2003
Changes in directory llvm/lib/Reoptimizer/LightWtProfiling/Trigger:
SecondTrigger.cpp updated: 1.14 -> 1.15
---
Log message:
Include Support/Debug.h.
Turn #ifdef GET_ALL_INFO...#endif into DEBUG(...).
Spiff up the debug messages.
Refactor one of the bits of code copied and pasted all over the place
to support GET_COVERAGE.
I tried to understand some of the hex constants that get inserted into
the code, but couldn't really add any useful documentation (yet).
---
Diffs of the changes:
Index: llvm/lib/Reoptimizer/LightWtProfiling/Trigger/SecondTrigger.cpp
diff -u llvm/lib/Reoptimizer/LightWtProfiling/Trigger/SecondTrigger.cpp:1.14 llvm/lib/Reoptimizer/LightWtProfiling/Trigger/SecondTrigger.cpp:1.15
--- llvm/lib/Reoptimizer/LightWtProfiling/Trigger/SecondTrigger.cpp:1.14 Tue Aug 12 22:31:53 2003
+++ llvm/lib/Reoptimizer/LightWtProfiling/Trigger/SecondTrigger.cpp Mon Aug 18 15:34:20 2003
@@ -14,6 +14,7 @@
#include "Globals.h"
#include "scheduler.h"
#include "Timer.h"
+#include "Support/Debug.h"
#include "llvm/Reoptimizer/Mapping/LLVMinfo.h"
#include "llvm/Reoptimizer/VirtualMem.h"
#include "llvm/Reoptimizer/InstrUtils.h"
@@ -80,13 +81,11 @@
// If we've exited the trace more than LEVEL_TWO_EXITS times, then...
if(accumulate > LEVEL_TWO_EXITS){
-
-#ifdef GET_ALL_INFO
- std::cerr<<"Rejected-too-many-exits\t"<<
- (void *)tr->getOriginalAddress(tr->getAddrLessThan(brAddr))<<
- "\t"<<(void *)tr->getEndAddress(tr->getOriginalAddress(tr->getAddrLessThan(brAddr)))
- <<"\n";
-#endif
+ DEBUG(std::cerr << "Rejected trace; exit counters exceeded threshold: "
+ << (void *)tr->getOriginalAddress(tr->getAddrLessThan(brAddr))
+ << ", " << (void *)
+ tr->getEndAddress(tr->getOriginalAddress(tr->getAddrLessThan(brAddr)))
+ << "\n");
exitCounter[reverseAddr] = 0;
delete pathCounter[reverseAddr];
@@ -215,11 +214,10 @@
if(pathCounter.find(pcAddr) != pathCounter.end()){
std::map<uint64_t, int> *oldMap = pathCounter[pcAddr];
if(oldMap->size() > MAX_PATH_HISTORIES){
-
-#ifdef GET_ALL_INFO
- std::cerr<<"Removed-SLI-too-many\t"<<(void *)tr->getOriginalAddress(startAddr)<<"\t"<<(void *)endAddr<<"\t"<<oldMap->size()<<"\n";
-#endif
-
+ DEBUG(std::cerr << "Removing SLI because there is too much path data: "
+ << (void *)tr->getOriginalAddress(startAddr) << ", end addr = "
+ << (void *)endAddr << ", size = " << oldMap->size() << "\n");
+
//flush-everything, and do not cache!
assert(tr);
@@ -278,11 +276,9 @@
tempVec, startAddr);
else{
//write a branch to the top
-#ifdef GET_ALL_INFO
- std::cerr<<"Trace-exists\t"<<
- (void *)tr->getOriginalAddress(startAddr)<<
- "\t"<<(void *)endAddr<<"\n";
-#endif
+ DEBUG(std::cerr << "Trace already exists in countPath(): "
+ << (void *)tr->getOriginalAddress(startAddr) << ", "
+ << (void *)endAddr << "\n");
uint64_t startAddrforTrace = tr->getOriginalAddress(startAddr);
vm->writeBranchInstruction(startAddrforTrace,
@@ -296,13 +292,21 @@
exitCounter[reverseAddr] = 0;
}
else{
-#ifdef GET_ALL_INFO
- std::cerr<<"No-trace-generated\t"
- <<(void *)tr->getOriginalAddress(startAddr)<<
- "\t"<<(void *)endAddr<<"\t"<<exitCounter[reverseAddr]<<"\t"<<
- totalCount[pcAddr]<<"\t"<<THRESHOLD_LEVEL_2<<"\n";
+ DEBUG(std::cerr << "Trace not generated in countPath(): "
+ << (void *)tr->getOriginalAddress(startAddr) << ", "
+ << (void *)endAddr);
+#ifndef NDEBUG
+ if (exitCounter[reverseAddr] >= (totalCount[pcAddr]*30)/100)
+ DEBUG(std::cerr << " because exitCounter == "
+ << exitCounter[reverseAddr] << " >= "
+ << " 30% of totalCount == "
+ << (totalCount[pcAddr]*30)/100);
+ if (totalCount[pcAddr] <= THRESHOLD_LEVEL_2)
+ DEBUG(std::cerr << " because totalCount == "
+ << totalCount[pcAddr] << " <= level 2 threshold == "
+ << THRESHOLD_LEVEL_2);
#endif
-
+
uint64_t startAddrforTrace = tr->getOriginalAddress(startAddr);
vm->writeBranchInstruction(startAddr, startAddrforTrace);
doFlush(startAddr-8, startAddr+8);
@@ -471,30 +475,44 @@
} while (bb != vBB[0]);
}
+void addCall(std::vector<unsigned int> &traces,
+ std::map<int, uint64_t> &callMap, int &index,
+ uint64_t addressOfCall)
+{
+ traces.push_back(0xde77a7ef); // save o7
+ traces.push_back(CALL);
+ traces.push_back(NOP);
+ traces.push_back(0xde5fa7ef); // restore o7
+ callMap[index+1] = addressOfCall;
+ index += 4;
+}
+
+
//Create traces, stich them together, and add them to tracecache
void generateTraces(uint64_t start, uint64_t end,
std::vector<uint64_t> &paths,
uint64_t firstLevelTraceStartAddr){
-
- if(paths.size() > MAX_ALLOWED_PATHS){
-#ifdef GET_ALL_INFO
- std::cerr<<"More-than-allowed-paths\t"<<(void *)start<<"\t"<<(void *)(tr->getEndAddress(start))
- <<"\t"<<paths.size()<<"\n";
-#endif
-
+ DEBUG(std::cerr << "In generateTraces (start = " << (void *)start
+ << ", end = " << (void *)end << ", firstLevelTraceStartAddr = "
+ << firstLevelTraceStartAddr << "), paths:\n");
+
+ // If we have more paths than our configuration allows, bail out
+ // early.
+ if(paths.size() > MAX_ALLOWED_PATHS) {
+ DEBUG(std::cerr << "Too many paths (" << paths.size () << ", more than "
+ << MAX_ALLOWED_PATHS << "); EndAddress = " <<
+ (void *)(tr->getEndAddress(start)) << "\n");
tr->patchTrace(firstLevelTraceStartAddr);
return;
}
-#ifdef GET_ALL_INFO
- std::cerr<<"Start: "<<(void *)start<<"\t End: "<<(void *)end<<"\n";
- std::cerr<<"Paths------\n";
+#ifndef NDEBUG
+ // Print the paths when in debug mode.
for(std::vector<uint64_t>::iterator VI = paths.begin(), VE = paths.end();
VI != VE; ++VI)
- printBinary(*VI);
- std::cerr<<"-----------\n";
-#endif
-
+ DEBUG(printBinary (*VI));
+#endif // NDEBUG
+
//branch map and call map
//map of call instructions
std::map<int, uint64_t> callMap;
@@ -518,37 +536,30 @@
//if (!vBB.empty()) { optimizeTrace (vBB, firstLevelTraceStartAddr); }
//return;
-#ifdef GET_ALL_INFO
- std::cerr<<"Path Intersections------\n";
+#ifndef NDEBUG
for(std::map<int, std::map<int, int> >::iterator MI =
pathIntersections.begin(), ME = pathIntersections.end(); MI != ME;
- ++MI){
- std::cerr<<"From path:\t"<<MI->first<<"\n";
+ ++MI) {
+ DEBUG(std::cerr << "Path intersections from path: " << MI->first << "\n");
std::map<int, int> &toMap = MI->second;
for(std::map<int, int>::iterator MMI = toMap.begin(), MME = toMap.end();
MMI != MME; ++MMI)
- std::cerr<<"Branch number: "<<MMI->first<<"\t Trace: "<<MMI->second<<"\n";
+ DEBUG(std::cerr << "\tBranch number: " << MMI->first
+ << "\tTrace: " << MMI->second << "\n");
}
- std::cerr<<"------------------------\n";
#endif
//do not include the backward branch yet!
//do it for the first element of the vector
std::vector<unsigned int> traces;
+ // FIXME: index should go; we should be able to recover this from traces.size()
int index = 0;
-#ifdef GET_ALL_INFO
- int numberOfFunctions = 0;
-#endif
+ int numberOfFunctions = 0; // only used in DEBUG output.
#ifdef GET_COVERAGE
- traces.push_back(0xde77a7ef);//save o7
- traces.push_back(CALL);
- traces.push_back(NOP);
- traces.push_back(0xde5fa7ef);//restore o7
- callMap[index+1] = (uint64_t)(intptr_t)&llvm_time_start;
- index += 4;
+ addCall(traces, callMap, index, (uint64_t)(intptr_t)&llvm_time_start);
#endif
uint64_t pc = start;
@@ -590,9 +601,7 @@
seenStartPC = true;
sawUnconditional = false;
-#ifdef GET_ALL_INFO
- std::cerr<<"PC:\t"<<(void *)pc<<"\n";
-#endif
+ DEBUG(std::cerr << "Generating trace, PC = " << (void *)pc << "\n");
if(!insertCode && indexToStart == pathIndex-1){
insertCode = true;
@@ -637,9 +646,7 @@
assert(0 && "Call stack empty and return instruction found!");
return;
}
-#ifdef GET_ALL_INFO
numberOfFunctions++;
-#endif
if(insertCode){
// Copy the instruction in the return's delay slot.
traces.push_back(vm->readInstrFrmVm(pc+4, tr, tr2));
@@ -656,23 +663,13 @@
else if(isIndirectCall(instr)){
if(insertCode){
#ifdef GET_COVERAGE
- traces.push_back(0xde77a7ef);//save o7
- traces.push_back(CALL);
- traces.push_back(NOP);
- traces.push_back(0xde5fa7ef);//restore o7
- callMap[index+1] = (uint64_t)(intptr_t)&llvm_time_end2;
- index += 4;
+ addCall(traces, callMap, index, (uint64_t)(intptr_t)&llvm_time_end2);
#endif
traces.push_back(instr);
traces.push_back(vm->readInstrFrmVm(pc+4, tr, tr2));
index += 2;
#ifdef GET_COVERAGE
- traces.push_back(0xde77a7ef);//save o7
- traces.push_back(CALL);
- traces.push_back(NOP);
- traces.push_back(0xde5fa7ef);//restore o7
- callMap[index+1] = (uint64_t)(intptr_t)&llvm_time_start;
- index += 4;
+ addCall(traces, callMap, index, (uint64_t)(intptr_t)&llvm_time_start);
#endif
}
pc += 8;
@@ -716,12 +713,8 @@
// call map.
if(insertCode){
#ifdef GET_COVERAGE
- traces.push_back(0xde77a7ef);//save o7
- traces.push_back(CALL);
- traces.push_back(NOP);
- traces.push_back(0xde5fa7ef);//restore o7
- callMap[index+1] = (uint64_t)(intptr_t)&llvm_time_end2;
- index += 4;
+ addCall(traces, callMap, index,
+ (uint64_t)(intptr_t)&llvm_time_end2);
#endif
traces.push_back(instr);
callMap[index] = getCallTarget(instr, pc);
@@ -729,12 +722,8 @@
index += 2;
#ifdef GET_COVERAGE
- traces.push_back(0xde77a7ef);//save o7
- traces.push_back(CALL);
- traces.push_back(NOP);
- traces.push_back(0xde5fa7ef);//restore o7
- callMap[index+1] = (uint64_t)(intptr_t)&llvm_time_start;
- index += 4;
+ addCall(traces, callMap, index,
+ (uint64_t)(intptr_t)&llvm_time_start);
#endif
}
}
@@ -764,9 +753,7 @@
// Check bit number pathIndex of firstPath to see whether the
// branch was taken.
if(firstPath & (1ULL << pathIndex)){
-#ifdef GET_ALL_INFO
- std::cerr<<" taken \t";
-#endif
+ DEBUG(std::cerr << "Found a taken branch.\n");
if(insertCode){
// Invert the branch, and use the fall-through as the target.
assert(!(instr & 0x20000000));
@@ -844,7 +831,6 @@
}
#ifdef GET_COVERAGE
- // std::cerr<<"YYYYYYYYYYYYYYY\n";
traces[index-1] = getBranchInst(br, (uint64_t)(&traces[4]),
(uint64_t)(&traces[index-1]));
#else
@@ -878,20 +864,14 @@
assert(tr->getEndAddress(start));
- //tr->patchTrace(firstLevelTraceStartAddr);
-
if(!tr2->addTrace(start, tr->getEndAddress(start), traces, paths[0], callMap,
myBranchMap, branchMap, firstLevelTraceStartAddr, tr)){
-
- std::cerr<<"^^^^^^^^^^************** Trace could not be added!!!\n";
+ DEBUG(std::cerr << "Trace could not be added in generateTraces()!\n");
}
-#ifdef GET_ALL_INFO
- std::cerr<<"Added-trace\t"<<(void *)start<<"\t"
- <<(void *)(tr->getEndAddress(start))
- <<"\t"<<traces.size()<<"\t"<<paths.size()<<"\t"
- <<numberOfFunctions<<"\n";
-#endif
-
+ DEBUG(std::cerr << "Added final trace in generateTraces(): start = "
+ << (void *)start << ", end = " << (void *)(tr->getEndAddress(start))
+ << ", #insns = " << traces.size() << ", #paths = " << paths.size()
+ << ", #functions = " << numberOfFunctions << "\n");
}
void getBranchExitCode(std::vector<unsigned int> &instVec,
@@ -909,14 +889,9 @@
uint64_t pc = MI->second;
#ifdef GET_COVERAGE
- instVec.push_back(0xde77a7ef);//save o7
- instVec.push_back(CALL);
- callMap[instIndex+1] = (uint64_t)&llvm_time_end2;
- instVec.push_back(NOP);
- instVec.push_back(0xde77a7ef);//restore o7
- //end call_inst!
+ addCall(instVec, callMap, instIndex, (uint64_t)(intptr_t)&llvm_time_end2);
#endif
-
+
uint64_t target = targetMap[MI->first];
instVec.push_back(0x10800000);//BA
@@ -939,26 +914,26 @@
}
void getReturnCode(std::vector<unsigned int> &traces, int &index, uint64_t ret){
- //sethi1
+ // sethi (?), %g1
unsigned int r1 = ((ret>>32)&(0xfffff000))>>10;
- unsigned int r2 = (ret>>32)&(0xfff);
unsigned int sethi1 = 0x03000000 | r1;
- //or %g1, r2, %g1
+ // or %g1, r2, %g1
+ unsigned int r2 = (ret>>32)&(0xfff);
unsigned int or1 = 0x82106000|r2;
- //sllx %g1, 32, %g5
+ // sllx %g1, 32, %g5 (?)
unsigned int sllx = 0x8b287020;
- //sethi2
+ // sethi (?), %g1
unsigned int r11 = ((ret)&(0xfffff000))>>10;
- unsigned int r22 = (ret)&(0xfff);
unsigned int sethi2 = 0x03000000 | r11;
- //or %g1, r22, %g1
+ // or %g1, r22, %g1
+ unsigned int r22 = (ret)&(0xfff);
unsigned int or2 = 0x82106000|r22;
- //add %g1, %g5, %07
+ // add %g1, %g5, %o7
unsigned int add = 0x9e014001;
traces.push_back(sethi1);
More information about the llvm-commits
mailing list