[llvm-commits] CVS: reopt/lib/LightWtProfiling/RuntimeOptimizations.cpp
Brian Gaeke
gaeke at cs.uiuc.edu
Wed May 26 16:28:01 PDT 2004
Changes in directory reopt/lib/LightWtProfiling:
RuntimeOptimizations.cpp updated: 1.40 -> 1.41
---
Log message:
Use the new TraceJIT subclass of ExecutionEngine to optimize traces.
---
Diffs of the changes: (+9 -74)
Index: reopt/lib/LightWtProfiling/RuntimeOptimizations.cpp
diff -u reopt/lib/LightWtProfiling/RuntimeOptimizations.cpp:1.40 reopt/lib/LightWtProfiling/RuntimeOptimizations.cpp:1.41
--- reopt/lib/LightWtProfiling/RuntimeOptimizations.cpp:1.40 Wed May 26 05:05:29 2004
+++ reopt/lib/LightWtProfiling/RuntimeOptimizations.cpp Wed May 26 16:23:37 2004
@@ -14,6 +14,7 @@
//===----------------------------------------------------------------------===//
#include "ReoptimizerInternal.h"
+#include "../TraceJIT/TraceJIT.h"
#include "reopt/UnpackTraceFunction.h"
#include "reopt/TraceToFunction.h"
#include "reopt/VirtualMem.h"
@@ -34,42 +35,9 @@
namespace llvm {
-static IntrinsicLowering *IL = 0;
-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;
-///==----- 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;
-}
-
-///==----------------------------------------------------------------------==///
-
-extern void WriteTraceToFile (Trace &T);
-
extern "C" void TraceOptimizerDone (uint64_t a, uint64_t traceStartAddr,
uint64_t traceEndAddr) {
DEBUG (std::cerr << "\n*** About to return from optimizeTrace(). GDB"
@@ -81,29 +49,6 @@
<< 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
@@ -119,18 +64,10 @@
// Initialization stuff: ensure module has been read in, and allocate a
// target machine, if there isn't one already.
- static bool initDone = false;
- if (!initDone) {
+ static TraceJIT *TJIT = 0;
+ if (!TJIT) {
assert (MP);
- 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;
-
+ TJIT = TraceJIT::create (MP);
// Force the SPARCv9 register allocator to save its state into a global
// variable
SaveRegAllocState = true;
@@ -140,23 +77,21 @@
// Turn the vector of basic blocks into a Trace, and then turn the Trace into
// a TraceFunction.
Trace T (vBB);
- DEBUG (WriteTraceToFile (T));
+ DEBUG (WriteTraceToFile (&T));
TraceFunction *TF = TraceFunction::get (T);
- // Run optimization passes, then unpack the trace function.
- UTF->setTraceFunction (TF); // Pass out-of-band information to UTF...
- PM->run (*TF->TraceFn);
+ // Compile the TraceFunction to machine code using the optimizing trace JIT compiler, and
+ // unpack the resulting optimized trace back into its matrix function.
+ uint64_t traceStartAddr = TJIT->compileTraceFunction (TF);
// 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);
doFlush (a, a + 4);
- TraceOptimizerDone(a, traceStartAddr, MCE->getCurrentPCValue ());
+ TraceOptimizerDone(a, traceStartAddr, TJIT->getEmitter ()->getCurrentPCValue ());
}
} // end namespace llvm
More information about the llvm-commits
mailing list