[llvm-commits] CVS: reopt/lib/LightWtProfiling/RuntimeOptimizations.cpp
Brian Gaeke
gaeke at cs.uiuc.edu
Sun May 23 05:06:08 PDT 2004
Changes in directory reopt/lib/LightWtProfiling:
RuntimeOptimizations.cpp updated: 1.38 -> 1.39
---
Log message:
Include UnpackTraceFunction.h.
Explicitly save the UnpackTraceFunction object so that we can call
setTraceFunction() on it as necessary.
Move the FunctionPassManager out to global scope.
Move the adding of passes into addPassesToReoptimizeTrace().
In optimizeTrace()'s initialization section, don't check each pointer
individually. Also, set up the FunctionPassManager here and add passes to it.
This means that the only thing we need to do on second and subsequent calls to
optimizeTrace() is set the TraceFunction and run the PassManager.
---
Diffs of the changes: (+36 -23)
Index: reopt/lib/LightWtProfiling/RuntimeOptimizations.cpp
diff -u reopt/lib/LightWtProfiling/RuntimeOptimizations.cpp:1.38 reopt/lib/LightWtProfiling/RuntimeOptimizations.cpp:1.39
--- reopt/lib/LightWtProfiling/RuntimeOptimizations.cpp:1.38 Sun May 23 02:46:23 2004
+++ reopt/lib/LightWtProfiling/RuntimeOptimizations.cpp Sun May 23 05:05:01 2004
@@ -14,6 +14,7 @@
//===----------------------------------------------------------------------===//
#include "ReoptimizerInternal.h"
+#include "reopt/UnpackTraceFunction.h"
#include "reopt/TraceToFunction.h"
#include "reopt/VirtualMem.h"
#include "reopt/InstrUtils.h"
@@ -41,6 +42,8 @@
static TargetMachine *Target = 0;
static const TargetData *TD = 0;
static MachineCodeEmitter *MCE = 0;
+static FunctionPassManager *PM = 0;
+static UnpackTraceFunction *UTF = 0;
extern bool SaveStateToModule;
extern bool SaveRegAllocState;
@@ -82,6 +85,29 @@
<< std::dec);
}
+static void addPassesToReoptimizeTrace (FunctionPassManager &PM,
+ const TargetData *TD,
+ TargetMachine *Target,
+ MachineCodeEmitter *MCE) {
+ // 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.
+ DEBUG(PM.add (new PrintFunctionPass ("Function created from trace:\n",
+ &std::cerr)));
+ PM.add (new TargetData (*TD));
+ DEBUG (PM.add (createVerifierPass ()));
+ Target->getJITInfo ()->addPassesToJITCompile (PM);
+ DEBUG(PM.add (createMachineFunctionPrinterPass (&std::cerr,
+ "Before unpacking:\n")));
+ UTF = new UnpackTraceFunction (Target);
+ PM.add (UTF);
+ DEBUG(PM.add (createMachineFunctionPrinterPass (&std::cerr,
+ "After unpacking:\n")));
+ Target->addPassesToEmitMachineCode (PM, *MCE);
+}
+
/// 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
@@ -100,10 +126,13 @@
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);
+ IL = new DefaultIntrinsicLowering ();
+ Target = allocateSparcV9TargetMachine (*MP->getModule (), IL);
+ TD = &Target->getTargetData ();
+ MCE = createTraceOptEmitter (*TD);
+ // Set up the pass manager and trace function unpacker
+ PM = new FunctionPassManager (MP);
+ addPassesToReoptimizeTrace (*PM, TD, Target, MCE);
initDone = true;
// Force the SPARCv9 register allocator to save its state into a global
@@ -118,31 +147,15 @@
DEBUG (WriteTraceToFile (T));
TraceFunction *TF = TraceFunction::get (T);
- // 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.
- static FunctionPassManager PM (MP);
- DEBUG(PM.add (new PrintFunctionPass ("Function created from trace:\n",
- &std::cerr)));
- PM.add (new TargetData (*TD));
- PM.add (createVerifierPass ());
- Target->getJITInfo ()->addPassesToJITCompile (PM);
- DEBUG(PM.add (createMachineFunctionPrinterPass (&std::cerr,
- "Before unpacking:\n")));
- PM.add (createUnpackTraceFunctionPass (Target, TF));
- DEBUG(PM.add (createMachineFunctionPrinterPass (&std::cerr,
- "After unpacking:\n")));
- Target->addPassesToEmitMachineCode (PM, *MCE);
- PM.run (*TF->TraceFn);
+ // Run optimization passes, then unpack the trace function.
+ UTF->setTraceFunction (TF); // Pass out-of-band information to UTF...
+ 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?!");
-
DEBUG(std::cerr << "Writing branch at 0x" << std::hex << a
<< " to point to 0x" << traceStartAddr << std::dec << "\n");
vm->writeBranchInstruction(a, traceStartAddr);
More information about the llvm-commits
mailing list