[llvm-commits] CVS: llvm/lib/Reoptimizer/TraceCache/TraceCache2.cpp
Anand Shukla
ashukla at cs.uiuc.edu
Sat May 31 21:34:24 PDT 2003
Changes in directory llvm/lib/Reoptimizer/TraceCache:
TraceCache2.cpp updated: 1.1 -> 1.2
---
Log message:
Simple additions to the runtime API
---
Diffs of the changes:
Index: llvm/lib/Reoptimizer/TraceCache/TraceCache2.cpp
diff -u llvm/lib/Reoptimizer/TraceCache/TraceCache2.cpp:1.1 llvm/lib/Reoptimizer/TraceCache/TraceCache2.cpp:1.2
--- llvm/lib/Reoptimizer/TraceCache/TraceCache2.cpp:1.1 Mon Feb 17 13:50:37 2003
+++ llvm/lib/Reoptimizer/TraceCache/TraceCache2.cpp Sat May 31 21:33:11 2003
@@ -18,6 +18,7 @@
//===----------------------------------------------------------------------===//
#include "MemoryManager2.h"
+#include "llvm/Reoptimizer/TraceCache.h"
#include "llvm/Reoptimizer/TraceCache2.h"
#include "llvm/Reoptimizer/VirtualMem.h"
#include "llvm/Reoptimizer/InstrUtils.h"
@@ -41,13 +42,13 @@
unsigned int TraceCache2::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-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];
+ //else if(hasTraceInstructions(addr-8))
+ // return traceInstructions[addr-8][2];
#endif
return 0;
}
@@ -75,6 +76,17 @@
vm = new VirtualMem();
}
+TraceCache2::TraceCache2(VirtualMem *vmem){
+
+ mm = new MemoryManager2();
+
+ isLimitSet = true; //making limit as the size of memory
+ currSize = 0;
+ limit = mm->getMemSize();
+
+ vm = vmem;
+}
+
void TraceCache2::setLimit(int n) {
assert(isLimitSet && "can't chage limit, if not set initially");
assert(currSize < n && "trying to set to a smaller limit than current size");
@@ -165,8 +177,102 @@
#endif
//now write branch in the level 1 tracecache
- vm->writeBranchInstruction(firstLevelTraceStartAddr, traceStartAddr);
- doFlush(firstLevelTraceStartAddr, firstLevelTraceStartAddr+16);
+ vm->writeBranchInstruction(firstLevelTraceStartAddr+4, traceStartAddr);
+ doFlush(firstLevelTraceStartAddr+4, firstLevelTraceStartAddr+20);
+
+ return true;
+}
+
+//Do the following:
+//1. Insert a jump at location instrAddr with target as new trace
+bool TraceCache2::addTrace(uint64_t instAddr,
+ std::vector<unsigned int> &trace,
+ int traceUniqId,
+ std::map<int, uint64_t> &callMap,
+ std::map<int, uint64_t> &branchMap,
+ uint64_t firstLevelTraceStartAddr){
+
+ //remove trace if its already there
+ //if(hasTraceAddr(instAddr))
+ //removeTrace(instAddr);
+
+ int sz = trace.size();
+
+ while(isLimitSet && currSize+sz>limit){
+
+ assert(0 && "out of memory");
+
+ 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);
+
+ if(!hasTraceInstructions(instAddr)){
+ traceInstructions[instAddr].clear();
+ //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!
+ if(!hasTraceInstructions(instAddr)){
+ traceInstructions[instAddr].push_back(vm->readInstrFrmVm(instAddr+8));
+ traceInstructions[instAddr].push_back(vm->readInstrFrmVm(instAddr+12));
+ }
+ //write call instruction!
+
+ //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
+
+ //now write branch in the level 1 tracecache
+ vm->writeBranchInstruction(firstLevelTraceStartAddr+4, traceStartAddr);
+ doFlush(firstLevelTraceStartAddr+4, firstLevelTraceStartAddr+20);
return true;
}
@@ -294,6 +400,106 @@
}
+//Do the following:
+//1. Insert a jump at location instrAddr with target as new trace
+bool TraceCache2::addTrace(uint64_t instAddr,
+ std::vector<unsigned int> &trace,
+ int traceUniqId,
+ std::map<int, uint64_t> &callMap,
+ std::map<int, uint64_t> &myBranchMap,
+ std::map<int, int> &branchMap,
+ uint64_t firstLevelTraceStartAddr, TraceCache *tr){
+
+ //remove trace if its already there
+ //if(hasTraceAddr(instAddr))// && uniqueID(instAddrtraceUniqId))
+ //removeTrace(instAddr);
+
+ int sz = trace.size();
+
+ if(sz%8){
+ sz = sz - (sz % 8);
+ sz = sz + 8;
+ }
+
+ while(isLimitSet && currSize+sz>limit){
+
+ assert(0 && "Can't allocate more mem!");
+
+ 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(sz);
+
+ 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);
+ bool ifPushed = false;
+ if(!hasTraceInstructions(instAddr)){
+ //traceInstructions[instAddr].clear();
+ //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, tr));
+ //traceInstructions[instAddr].push_back(vm->readInstrFrmVm(instAddr+4));
+ ifPushed = true;
+ }
+#ifdef GET_TRACE_TIME
+ if(ifPushed){
+ //two more: to accomodate call instruction and get time!
+ traceInstructions[instAddr].push_back(vm->readInstrFrmVm(instAddr+4, tr));
+ traceInstructions[instAddr].push_back(vm->readInstrFrmVm(instAddr+8, tr));
+ ifPushed = false;
+ }
+ //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);
+
+ //now set correctly all branches
+ vm->setBranches(myBranchMap, traceStartAddr);
+
+ //set correctly all calls
+ vm->setCalls(callMap, traceStartAddr);
+
+ doFlush(traceStartAddr, traceStartAddr+4*sz+4);
+ doFlush(instAddr, instAddr+4);
+
+#ifdef GET_TRACE_TIME
+ doFlush(instAddr+8, instAddr+12);
+#endif
+
+ //now write branch in the level 1 tracecache
+ vm->writeBranchInstruction(firstLevelTraceStartAddr+4, traceStartAddr);
+ doFlush(firstLevelTraceStartAddr+4, firstLevelTraceStartAddr+20);
+
+ return true;
+}
More information about the llvm-commits
mailing list