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

Brian Gaeke gaeke at cs.uiuc.edu
Sun May 23 02:47:08 PDT 2004


Changes in directory reopt/lib/LightWtProfiling:

RuntimeOptimizations.cpp updated: 1.37 -> 1.38

---
Log message:

Add another useful command to the gdb command printout in
TraceOptimizerDone(), which makes it easy to print the trace
disassembly.

Make optimizeTrace() keep track of its own initialization, and make
sure that it only runs it once (using the initDone flag). We should
really get around to making this into a class sometime soon.

By the time we get to optimizeTrace(), we have certainly called
initModules(), so just assert that, instead of trying to clean up
if we haven't.

Make the FunctionPassManager and TargetData pointer static.


---
Diffs of the changes:  (+28 -19)

Index: reopt/lib/LightWtProfiling/RuntimeOptimizations.cpp
diff -u reopt/lib/LightWtProfiling/RuntimeOptimizations.cpp:1.37 reopt/lib/LightWtProfiling/RuntimeOptimizations.cpp:1.38
--- reopt/lib/LightWtProfiling/RuntimeOptimizations.cpp:1.37	Thu May 20 13:09:30 2004
+++ reopt/lib/LightWtProfiling/RuntimeOptimizations.cpp	Sun May 23 02:46:23 2004
@@ -37,8 +37,9 @@
 
 namespace llvm {
 
-static TargetMachine *Target = 0;
 static IntrinsicLowering *IL = 0;
+static TargetMachine *Target = 0;
+static const TargetData *TD = 0;
 static MachineCodeEmitter *MCE = 0;
 
 extern bool SaveStateToModule;
@@ -70,10 +71,15 @@
 
 extern void WriteTraceToFile (Trace &T);
 
-extern "C" void TraceOptimizerDone (uint64_t a, uint64_t traceStartAddr) {
+extern "C" void TraceOptimizerDone (uint64_t a, uint64_t traceStartAddr,
+                                    uint64_t traceEndAddr) {
   DEBUG (std::cerr << "\n*** About to return from optimizeTrace(). GDB"
-    << " breakpoints:\n" << std::hex << "display/i $pc\n" << "b *0x" << a
-    << "\n" << "b *0x" << traceStartAddr << std::dec << "\n");
+    << " commands:\n" << std::hex
+    << "display/i $pc\n"
+    << "b *0x" << a << "\n"
+    << "b *0x" << traceStartAddr << "\n"
+    << "disassemble 0x" << traceStartAddr << " 0x" << traceEndAddr << "\n"
+    << std::dec);
 }
 
 /// This method is called when we have finally constructed a
@@ -91,11 +97,20 @@
 
   // Initialization stuff: ensure module has been read in, and allocate a
   // target machine, if there isn't one already.
-  if (!MP) initModules ();
-  if (!IL) IL = new DefaultIntrinsicLowering ();
-  if (!Target) Target = allocateSparcV9TargetMachine (*MP->getModule (), IL);
-  const TargetData &TD = Target->getTargetData ();
-  if (!MCE) MCE = createTraceOptEmitter (TD);
+  static bool initDone = false;
+  if (!initDone) {
+    assert (MP);
+    if (!IL) IL = new DefaultIntrinsicLowering ();
+    if (!Target) Target = allocateSparcV9TargetMachine (*MP->getModule (), IL);
+    if (!TD) TD = &Target->getTargetData ();
+    if (!MCE) MCE = createTraceOptEmitter (*TD);
+    initDone = true;
+
+    // Force the SPARCv9 register allocator to save its state into a global
+    // variable
+    SaveRegAllocState = true;
+    SaveStateToModule = false;
+  }
 
   // Turn the vector of basic blocks into a Trace, and then turn the Trace into
   // a TraceFunction.
@@ -103,21 +118,15 @@
   DEBUG (WriteTraceToFile (T));
   TraceFunction *TF = TraceFunction::get (T);
 
-  // Force the SPARCv9 register allocator to save its state into a global
-  // variable
-  SaveRegAllocState = true;
-  SaveStateToModule = false;
-
   // Verify that the generated function's bytecode is good, then compile it
   // down to machine code. Then, "unpack" it back into its matrix function.
   // FIXME: Register allocation hints also need to be added to the PassManager,
   // so that we do not get clobbered by the overhead of adding copies in
   // UnpackTraceFunction.
-  FunctionPassManager PM (MP);
-  DEBUG(PM.add (new PrintFunctionPass ("Function created from trace for "
-                                 + T.getFunction ()->getName () + ":\n",
+  static FunctionPassManager PM (MP);
+  DEBUG(PM.add (new PrintFunctionPass ("Function created from trace:\n",
                                  &std::cerr)));
-  PM.add (new TargetData (TD));
+  PM.add (new TargetData (*TD));
   PM.add (createVerifierPass ());
   Target->getJITInfo ()->addPassesToJITCompile (PM);
   DEBUG(PM.add (createMachineFunctionPrinterPass (&std::cerr,
@@ -138,7 +147,7 @@
                   << " to point to 0x" << traceStartAddr << std::dec << "\n");
   vm->writeBranchInstruction(a, traceStartAddr);
   doFlush (a, a + 4);
-  TraceOptimizerDone(a, traceStartAddr);
+  TraceOptimizerDone(a, traceStartAddr, MCE->getCurrentPCValue ());
 }
 
 } // end namespace llvm





More information about the llvm-commits mailing list