[llvm-commits] CVS: reopt/lib/LightWtProfiling/RuntimeOptimizations.cpp

Brian Gaeke gaeke at cs.uiuc.edu
Tue Apr 27 13:35:03 PDT 2004


Changes in directory reopt/lib/LightWtProfiling:

RuntimeOptimizations.cpp updated: 1.29 -> 1.30

---
Log message:

Get rid of commented-out debug emitter.
Wrap long lines.
Include reopt/VirtualMem.h and reopt/InstrUtils.h.
Steal some code from the generic ExecutionEngine to use for keeping track of
where TraceFns get their code generated to (like the JIT does).
Try to add a branch from the instrumented code to the freshly-emitted 
reoptimized code.


---
Diffs of the changes:  (+34 -5)

Index: reopt/lib/LightWtProfiling/RuntimeOptimizations.cpp
diff -u reopt/lib/LightWtProfiling/RuntimeOptimizations.cpp:1.29 reopt/lib/LightWtProfiling/RuntimeOptimizations.cpp:1.30
--- reopt/lib/LightWtProfiling/RuntimeOptimizations.cpp:1.29	Fri Apr 23 15:35:53 2004
+++ reopt/lib/LightWtProfiling/RuntimeOptimizations.cpp	Tue Apr 27 13:34:44 2004
@@ -15,6 +15,8 @@
 
 #include "ReoptimizerInternal.h"
 #include "TraceToFunction.h"
+#include "reopt/VirtualMem.h"
+#include "reopt/InstrUtils.h"
 #include "Support/Debug.h"
 #include "Support/StringExtras.h"
 #include "llvm/Analysis/Verifier.h"
@@ -39,6 +41,30 @@
 extern bool SaveStateToModule;
 extern bool SaveRegAllocState;
 
+///==----- Machinery to keep track of where a TraceFunction's code is ------==//
+// This deliberately mimics the code used by ExecutionEngine, in case we ever
+// want to turn the Reoptimizer into an ExecutionEngine.
+
+/// GlobalAddressMap - A mapping between LLVM global values and their
+/// actualized version...
+std::map<const GlobalValue*, uint64_t> GlobalAddressMap;
+
+void addGlobalMapping(const GlobalValue *GV, uint64_t Addr) {
+  uint64_t &CurVal = GlobalAddressMap[GV];
+  assert((CurVal == 0 || Addr == 0) && "GlobalMapping already established!");
+  CurVal = Addr;
+}
+
+/// getPointerToGlobalIfAvailable - This returns the address of the specified
+/// global value if it is available, otherwise it returns null.
+///
+uint64_t getPointerToGlobalIfAvailable(const GlobalValue *GV) {
+  std::map<const GlobalValue*, uint64_t>::iterator I = GlobalAddressMap.find(GV);
+  return I != GlobalAddressMap.end() ? I->second : 0;
+}
+
+///==----------------------------------------------------------------------==///
+
 /// This method is called when we have finally constructed a
 /// trace. The first parameter is the vector of basic blocks that form
 /// the trace; the second parameter is the starting
@@ -59,7 +85,6 @@
   if (!Target) Target = allocateSparcV9TargetMachine (*MP->getModule (), IL);
   const TargetData &TD = Target->getTargetData ();
   if (!MCE) MCE = createTraceOptEmitter (TD);
-  //if (!MCE) MCE = MachineCodeEmitter::createDebugEmitter ();
 
   // Turn the vector of basic blocks into a Trace, and then turn the Trace into
   // a TraceFunction.
@@ -83,17 +108,21 @@
   PM.add (new TargetData (TD));
   PM.add (createVerifierPass ());
   Target->getJITInfo ()->addPassesToJITCompile (PM);
-  DEBUG(PM.add (createMachineFunctionPrinterPass (&std::cerr, "Before unpacking:\n")));
+  DEBUG(PM.add (createMachineFunctionPrinterPass (&std::cerr,
+                                                  "Before unpacking:\n")));
   PM.add (createUnpackTraceFunctionPass (Target, TF));
-  DEBUG(PM.add (createMachineFunctionPrinterPass (&std::cerr, "After unpacking:\n")));
+  DEBUG(PM.add (createMachineFunctionPrinterPass (&std::cerr,
+                                                  "After unpacking:\n")));
   Target->addPassesToEmitMachineCode (PM, *MCE);
   PM.run (*TF->TraceFn);
 
   // Add a branch from address A (the parameter to this method) to the 
   // entry basic block of the unpacked TraceFn. Future executions of the trace
   // will proceed from the optimized version of the code.
-  
-  
+  uint64_t traceStartAddr = getPointerToGlobalIfAvailable (TF->TraceFn);
+  assert (traceStartAddr && "Address of code for TraceFn was NULL after JIT?!");
+  vm->writeBranchInstruction(a, traceStartAddr);
+  doFlush (a, a + 4);
 }
 
 } // end namespace llvm





More information about the llvm-commits mailing list