[llvm-commits] CVS: llvm/lib/Reoptimizer/TraceCache/TraceCache.cpp
Anand Shukla
ashukla at cs.uiuc.edu
Fri Feb 14 14:46:02 PST 2003
Changes in directory llvm/lib/Reoptimizer/TraceCache:
TraceCache.cpp updated: 1.8 -> 1.9
---
Log message:
Changes to runtime framework
---
Diffs of the changes:
Index: llvm/lib/Reoptimizer/TraceCache/TraceCache.cpp
diff -u llvm/lib/Reoptimizer/TraceCache/TraceCache.cpp:1.8 llvm/lib/Reoptimizer/TraceCache/TraceCache.cpp:1.9
--- llvm/lib/Reoptimizer/TraceCache/TraceCache.cpp:1.8 Tue Oct 8 11:30:13 2002
+++ llvm/lib/Reoptimizer/TraceCache/TraceCache.cpp Fri Feb 14 14:45:35 2003
@@ -142,6 +142,110 @@
return true;
}
+bool TraceCache::hasTraceInstructions(uint64_t addr){
+ return (traceInstructions.find(addr) != traceInstructions.end());
+}
+
+unsigned int TraceCache::getAddr(uint64_t addr){
+ if(hasTraceInstructions(addr))
+ return traceInstructions[addr][0];
+ else if(hasTraceInstructions(addr-4))
+ return traceInstructions[addr-4][1];
+#ifdef GET_TRACE_TIME
+ else if(hasTraceInstructions(addr-8))
+ return traceInstructions[addr-8][2];
+ else if(hasTraceInstructions(addr-12))
+ return traceInstructions[addr-12][3];
+#endif
+ return 0;
+}
+
+std::vector<unsigned int> &TraceCache::getTraceInstructions(uint64_t addr){
+ assert(traceInstructions.find(addr) != traceInstructions.end());
+
+ return traceInstructions[addr];
+}
+
+//Do the following:
+//1. Insert a jump at location instrAddr with target as new trace
+bool TraceCache::addTrace(uint64_t instAddr,
+ std::vector<unsigned int> &trace,
+ int traceUniqId,
+ std::map<int, uint64_t> &callMap,
+ std::map<int, uint64_t> &branchMap){
+
+ //remove trace if its already there
+ if(hasTraceAddr(instAddr))
+ removeTrace(instAddr);
+
+ int sz = trace.size();
+
+ while(isLimitSet && currSize+sz>limit){
+ if(currSize == 0)
+ return false;
+
+ //erase first addr from queue
+ assert(allocationOrder.size()>0 && "No entries in trace!");
+ uint64_t addr = allocationOrder.front();
+ allocationOrder.pop_front();
+ removeTrace(addr);
+ }
+
+ uint64_t traceStartAddr = mm->getMemory(trace.size());
+
+ if(traceStartAddr == 0) return false; //could not allocate space!
+
+ //copy trace to the memory
+ vm->copyToVM(trace, traceStartAddr);
+
+ traces[instAddr] = traceStartAddr;
+ traceId[traceUniqId] = traceStartAddr;
+ reverseTraceId[instAddr] = traceUniqId;
+ traceSize[instAddr] = sz;
+ reverseMap[traceStartAddr] = instAddr;
+ currSize += sz;
+
+ //add instAddr to queue
+ allocationOrder.push_back(instAddr);
+
+ //copy the first few instructions of the trace in the original code
+ //and write a jump instruction in its place
+ traceInstructions[instAddr].push_back(vm->readInstrFrmVm(instAddr));
+ traceInstructions[instAddr].push_back(vm->readInstrFrmVm(instAddr+4));
+
+#ifdef GET_TRACE_TIME
+ //two more: to accomodate call instruction and get time!
+ traceInstructions[instAddr].push_back(vm->readInstrFrmVm(instAddr+8));
+ traceInstructions[instAddr].push_back(vm->readInstrFrmVm(instAddr+12));
+
+ //write call instruction!
+ vm->writeCallLLVMTime(instAddr);
+
+ //Now write branch instruction with target as
+ //traceStartAddr at the address instAddr
+ vm->writeBranchInstruction(instAddr+8, traceStartAddr);
+#endif
+
+#ifndef GET_TRACE_TIME
+ vm->writeBranchInstruction(instAddr, traceStartAddr);
+#endif
+
+ //now set correctly all branches
+ vm->setBranches(branchMap, traceStartAddr);
+
+ //set correctly all calls
+ vm->setCalls(callMap, traceStartAddr);
+
+ doFlush(traceStartAddr, traceStartAddr+4*sz);
+ doFlush(instAddr, instAddr+4);
+
+#ifdef GET_TRACE_TIME
+ doFlush(instAddr+8, instAddr+12);
+#endif
+
+ return true;
+}
+
void TraceCache::removeTrace(uint64_t n){
//if no trace, do nothing
if(traces.find(n) == traces.end())
@@ -154,12 +258,10 @@
"Starting instruction not found!");
int removeSize = traceInstructions[n].size();
+
for(int i=0; i < removeSize; i++)
- vm->writeInstToVM(n+4*i, (traceInstructions[n])[i]);
+ vm->writeInstToVM(n+4*i, (traceInstructions[n])[i]);
- //vm->writeInstToVM(n, tracesFirstInstruction[n].first);
- //vm->writeInstToVM(n+4, tracesFirstInstruction[n].second);
-
doFlush(n, n+4*(removeSize-1));
//remove n from queue
@@ -183,6 +285,86 @@
}
+bool TraceCache::addTrace(uint64_t instAddr,
+ std::vector<unsigned int> &trace,
+ int traceUniqId,
+ std::map<int, uint64_t> &callMap,
+ std::map<int, int> &branchMap,
+ std::vector<unsigned int> *exitStubs){
+
+ //remove trace if its already there
+ if(hasTraceAddr(instAddr))
+ removeTrace(instAddr);
+
+ int sz = trace.size();
+
+ while(isLimitSet && currSize+sz>limit){
+ if(currSize == 0)
+ return false;
+
+ //erase first addr from queue
+ assert(allocationOrder.size()>0 && "No entries in trace!");
+ uint64_t addr = allocationOrder.front();
+ allocationOrder.pop_front();
+ removeTrace(addr);
+ }
+
+ uint64_t traceStartAddr = mm->getMemory(trace.size());
+
+ if(traceStartAddr == 0) return false; //could not allocate space!
+
+ //copy trace to the memory
+ vm->copyToVM(*exitStubs, traceStartAddr);
+ vm->copyToVM(trace, traceStartAddr+exitStubs->size()*4);
+
+ traces[instAddr] = traceStartAddr;
+ traceId[traceUniqId] = traceStartAddr;
+ reverseTraceId[instAddr] = traceUniqId;
+ traceSize[instAddr] = sz;
+ reverseMap[traceStartAddr] = instAddr;
+ currSize += sz;
+ uint64_t actualTraceStartAddr = traceStartAddr+4*exitStubs->size();
+
+ //add instAddr to queue
+ allocationOrder.push_back(instAddr);
+
+ //copy the first few instructions of the trace in the original code
+ //and write a jump instruction in its place
+ traceInstructions[instAddr].push_back(vm->readInstrFrmVm(instAddr));
+ traceInstructions[instAddr].push_back(vm->readInstrFrmVm(instAddr+4));
+
+#ifdef GET_TRACE_TIME
+ //two more: to accomodate call instruction and get time!
+ traceInstructions[instAddr].push_back(vm->readInstrFrmVm(instAddr+8));
+ traceInstructions[instAddr].push_back(vm->readInstrFrmVm(instAddr+12));
+
+ //write call instruction!
+ vm->writeCallLLVMTime(instAddr);
+
+ //Now write branch instruction with target as
+ //traceStartAddr at the address instAddr
+ vm->writeBranchInstruction(instAddr+8, traceStartAddr);
+#endif
+
+#ifndef GET_TRACE_TIME
+ vm->writeBranchInstruction(instAddr, traceStartAddr);
+#endif
+
+ //now set correctly all branches
+ vm->setBranches(branchMap, actualTraceStartAddr);
+
+ //set correctly all calls
+ vm->setCalls(callMap, actualTraceStartAddr);
+
+ doFlush(traceStartAddr, traceStartAddr+4*(sz+exitStubs->size()));
+ doFlush(instAddr, instAddr+4);
+
+#ifdef GET_TRACE_TIME
+ doFlush(instAddr+8, instAddr+12);
+#endif
+
+ return true;
+}
More information about the llvm-commits
mailing list