[llvm-commits] CVS: llvm/lib/Reoptimizer/TraceCache/TraceCache.cpp
Anand Shukla
ashukla at cs.uiuc.edu
Tue Oct 8 11:31:02 PDT 2002
Changes in directory llvm/lib/Reoptimizer/TraceCache:
TraceCache.cpp updated: 1.7 -> 1.8
---
Log message:
Added functions to time execution inside trace cache
---
Diffs of the changes:
Index: llvm/lib/Reoptimizer/TraceCache/TraceCache.cpp
diff -u llvm/lib/Reoptimizer/TraceCache/TraceCache.cpp:1.7 llvm/lib/Reoptimizer/TraceCache/TraceCache.cpp:1.8
--- llvm/lib/Reoptimizer/TraceCache/TraceCache.cpp:1.7 Sat Sep 21 00:04:09 2002
+++ llvm/lib/Reoptimizer/TraceCache/TraceCache.cpp Tue Oct 8 11:30:13 2002
@@ -21,6 +21,7 @@
#include "llvm/Reoptimizer/TraceCache.h"
#include "llvm/Reoptimizer/VirtualMem.h"
#include "llvm/Reoptimizer/InstrUtils.h"
+#include "llvm/Reoptimizer/GetTraceTime.h"
#include <assert.h>
#include <algorithm>
#include <iostream>
@@ -103,16 +104,28 @@
//add instAddr to queue
allocationOrder.push_back(instAddr);
- //copy the first instruction of the trace in the original code
+ //copy the first few instructions of the trace in the original code
//and write a jump instruction in its place
- tracesFirstInstruction[instAddr] =
- std::make_pair(vm->readInstrFrmVm(instAddr),
- vm->readInstrFrmVm(instAddr+4));
+ 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, traceStartAddr);
+ vm->writeBranchInstruction(instAddr+8, traceStartAddr);
+#endif
+#ifndef GET_TRACE_TIME
+ vm->writeBranchInstruction(instAddr, traceStartAddr);
+#endif
+
//now set correctly all branches
vm->setBranches(branchMap, traceStartAddr);
@@ -122,58 +135,13 @@
doFlush(traceStartAddr, traceStartAddr+4*sz);
doFlush(instAddr, instAddr+4);
- return true;
-}
-/*
-bool TraceCache::addTrace(uint64_t instAddr, unsigned int trace[],
- int sz, std::vector<uint64_t> &inBranches,
- std::vector<std::pair<uint64_t, uint64_t> > &outBranches, int traceUniqId){
-
- //remove trace if its already there
- if(hasTraceAddr(instAddr))
- removeTrace(instAddr);
-
- 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(sz);
-
- if(traceStartAddr == 0) return false; //could not allocate space!
-
- //copy trace to the memory
- vm->copyToVM(trace, traceStartAddr, sz);
-
- 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);
+#ifdef GET_TRACE_TIME
+ doFlush(instAddr+8, instAddr+12);
+#endif
- //copy the first instruction of the trace in the original code
- //and write a jump instruction in its place
- tracesFirstInstruction[instAddr] =
- std::make_pair(vm->readInstrFrmVm(instAddr),
- vm->readInstrFrmVm(instAddr+4));
-
- //Now write branch instruction with target as
- //traceStartAddr at the address instAddr
- vm->writeBranchInstruction(instAddr, traceStartAddr);
-
return true;
}
-*/
+
void TraceCache::removeTrace(uint64_t n){
//if no trace, do nothing
if(traces.find(n) == traces.end())
@@ -182,12 +150,17 @@
uint64_t toRemove = traces[n];
//put back the original instruction at n
- assert(tracesFirstInstruction.find(n) != tracesFirstInstruction.end() &&
+ assert(traceInstructions.find(n) != traceInstructions.end() &&
"Starting instruction not found!");
- vm->writeInstToVM(n, tracesFirstInstruction[n].first);
- vm->writeInstToVM(n+4, tracesFirstInstruction[n].second);
+
+ int removeSize = traceInstructions[n].size();
+ for(int i=0; i < removeSize; 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);
+ doFlush(n, n+4*(removeSize-1));
//remove n from queue
std::list<uint64_t>::iterator LI = std::find(allocationOrder.begin(),
@@ -206,88 +179,10 @@
traceSize.erase(n);
reverseMap.erase(toRemove);
- tracesFirstInstruction.erase(n);
-
-}
-
-#undef ANAND_TRACE_CACHE_TEST_CODE
-#ifdef ANAND_TRACE_CACHE_TEST_CODE
-
-int f_trial(int a);
-
-int main(void){
- std::cerr<<"in main "<<f_trial(6)<<"\n";
- std::cerr<<(void *)&f_trial<<"\n";
- unsigned int arr[29];
-
- //open file pointer
- char ctr[25];
- int pid = getpid();
- sprintf(ctr, "/proc/%d/as",pid);
- int fp = open(ctr, O_RDWR);
-
- lseek(fp, (uint64_t)&f_trial+12, SEEK_SET);
-
- unsigned int instr=0;
-
- for(int i=0; i<29; i++){
- read(fp, &instr, 4);
- arr[i]=instr;
- std::cerr<<(void *)instr<<"\n";
- }
-
- std::cerr<< (0xc0000000&arr[27]) <<"multiplied\n";
- std::cerr<< isBranchInstr(arr[27]) <<" wow!\n";
- if(isBranchInstr(arr[27])){
- std::cerr<<"Branch target"<<"\n";
- std::cerr<<(void *)getNonDepJmpTarget(arr[27], 0x10002cff0)<<"\n";
- std::cerr<<(void *)((uint64_t)&f_trial+(uint64_t)30*4)<<" was add\n";
- std::cerr<<(void *)getUndepJumpInstr(arr[27], 0x10002cf84, 0x10002cff0);
- }
+ traceInstructions.erase(n);
- TraceCache tr(100);
-
- const uint64_t k = (uint64_t)0x0000000000000004;
- std::vector<uint64_t> inBranches;
- uint64_t inAddr = (uint64_t)&f_trial+30*k;
- inBranches.push_back(inAddr);
- std::cerr<<" Incoming add: "<<(void *)inAddr<<"\n";
-
- std::vector<std::pair<uint64_t, uint64_t> > outBranches;
- outBranches.push_back(std::make_pair((uint64_t)&f_trial+5*k, (uint64_t)&arr[2]));
- outBranches.push_back(std::make_pair((uint64_t)&f_trial+10*k, (uint64_t)&arr[7]));
- outBranches.push_back(std::make_pair((uint64_t)&f_trial+15*k, (uint64_t)&arr[12]));
- outBranches.push_back(std::make_pair((uint64_t)&f_trial+22*k, (uint64_t)&arr[19]));
- outBranches.push_back(std::make_pair((uint64_t)&f_trial+26*k, (uint64_t)&arr[23]));
- outBranches.push_back(std::make_pair((uint64_t)&f_trial+30*k, (uint64_t)&arr[27]));
-
- uint64_t traceStartAddr = (uint64_t)&f_trial+k*3;
- std::cerr<<(void *)(traceStartAddr)<<" address\n";
- //tr.addTrace((uint64_t)0x10002dbec, arr, 28, inBranches, outBranches, 3);
- tr.addTrace(traceStartAddr, arr, 29, inBranches, outBranches, 3);
-
- int nn = f_trial(6);
- std::cerr<<nn<<" before f()\n";
-
- tr.removeTrace(traceStartAddr);
- nn=f_trial(6);
- std::cerr<<nn<<" after f()\n";
-
- close(fp);
- //std::cerr<<"Dummy addr: "<<(void *)&dummyFunction<<"\n";
- //return (uint64_t)&dummyFunction;
}
-
-/// Trial functions!
-int f_trial(int a){
- for(int i=0; i<10; i++)
- for(int j=0; j<10; j++)
- for(int k=0; k<10; k++)
- a++;
- return a;
-}
-#endif
More information about the llvm-commits
mailing list