[llvm-commits] CVS: llvm/lib/Reoptimizer/Trigger/Trigger.cpp

Anand Shukla ashukla at cs.uiuc.edu
Tue Oct 8 11:30:01 PDT 2002


Changes in directory llvm/lib/Reoptimizer/Trigger:

Trigger.cpp updated: 1.12 -> 1.13

---
Log message:

Added functions to time execution inside trace cache


---
Diffs of the changes:

Index: llvm/lib/Reoptimizer/Trigger/Trigger.cpp
diff -u llvm/lib/Reoptimizer/Trigger/Trigger.cpp:1.12 llvm/lib/Reoptimizer/Trigger/Trigger.cpp:1.13
--- llvm/lib/Reoptimizer/Trigger/Trigger.cpp:1.12	Mon Oct  7 03:21:07 2002
+++ llvm/lib/Reoptimizer/Trigger/Trigger.cpp	Tue Oct  8 11:29:48 2002
@@ -10,6 +10,7 @@
 #include "llvm/Reoptimizer/TraceCache.h"
 #include "llvm/Reoptimizer/VirtualMem.h"
 #include "llvm/Reoptimizer/InstrUtils.h"
+#include "llvm/Reoptimizer/GetTraceTime.h"
 #include "llvm/Reoptimizer/Mapping/LLVMinfo.h"
 #include "llvm/Bytecode/Reader.h"
 #include "llvm/Module.h"
@@ -17,6 +18,10 @@
 #include "llvm/Support/CFG.h"
 #include <map>
 
+#include <sys/time.h>
+#include <iostream>
+#include <fstream>
+
 using std::vector;
 using std::map;
 
@@ -24,11 +29,34 @@
 extern const unsigned char LLVMBytecode[];
 extern void** llvmFunctionTable[];
 
+#ifdef GET_TRACE_TIME
+
+static struct timeval llvm_trace_time;
+
+extern "C" void llvm_time_start(){
+  gettimeofday(&llvm_trace_time, (void *)0);
+}
+
+extern "C" void llvm_time_end(){
+  static std::ofstream f_out("llvm_last_run");
+
+  struct timeval time_end;
+  gettimeofday(&time_end, (void *)0);
+  
+  long time = (time_end.tv_sec - llvm_trace_time.tv_sec)*1000000 + 
+    (time_end.tv_usec - llvm_trace_time.tv_usec);
+  
+  f_out<<time<<"\n";
+}
+#endif
+
+
 void getBBtrace(vector<BasicBlock *> &vBB, int pathNo, Function *M);
 
 void getBranchExitCode(vector<unsigned int> &instVec, 
                        map<int, int> &branchMap, 
-                       map<int, uint64_t> &targetMap);
+                       map<int, uint64_t> &targetMap,
+                       map<int, uint64_t> &callMap);
 
 extern "C" void llvmInitializeCounter(int *cnt, int k){
   for(int i=0; i<k; i++)
@@ -52,6 +80,8 @@
 }
 
 
+
+
 extern "C" void trigger(int mn, int pn, int *cnt){
   static bool initialized = false; //so module is read just once
   static Module *M;
@@ -399,7 +429,7 @@
   }
   
   //insert exit code!
-  getBranchExitCode(trace, branchMap, targetMap);
+  getBranchExitCode(trace, branchMap, targetMap, callMap);
   //Now add trace to cache, and we are all set!
   if(!tr->addTrace(startAddr, trace, pn, callMap, branchMap))
     std::cerr<<"^^^^^^^^^^************** Trace could not be added!!!\n";
@@ -408,7 +438,8 @@
 
 void getBranchExitCode(vector<unsigned int> &instVec, 
                        map<int, int> &branchMap, 
-                       map<int, uint64_t> &targetMap){
+                       map<int, uint64_t> &targetMap, 
+                       map<int, uint64_t> &callMap){
 
   //for each branch, insert code!
   int instIndex = instVec.size();
@@ -418,6 +449,18 @@
     unsigned int instr = instVec[MI->first];
     uint64_t pc = MI->second;
     
+#ifdef GET_TRACE_TIME
+    instVec.push_back(0);//just dummy, so we can use its adress
+
+    //call llvm_time_end
+    unsigned int call_inst = getCallInstr((uint64_t)&llvm_time_end, 
+                                          (uint64_t)&instVec[instIndex]); 
+    instVec[instIndex] = call_inst;
+
+    callMap[instIndex] = (uint64_t)&instVec[instIndex];
+    //end call_inst!
+#endif
+
     //save %io, ad1
     unsigned int stx1 = 0xf077a000|0x7f7; //stx %i0, %fp+offset-8
       unsigned int stx2 = 0xf277a000|0x7ef; //stx %i1, offset-16
@@ -475,5 +518,9 @@
     branchMap[MI->first] = instIndex; 
 
     instIndex += 11;
+
+#ifdef GET_TRACE_TIME
+    instIndex++;
+#endif
   }
 }





More information about the llvm-commits mailing list