[llvm-commits] CVS: reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp
Brian Gaeke
gaeke at cs.uiuc.edu
Tue Oct 14 16:27:02 PDT 2003
Changes in directory reopt/lib/LightWtProfiling:
UnpackTraceFunction.cpp added (r1.1)
---
Log message:
Work in progress: unpack trace-to-function functions back into gooey
lumps of code. Maybe you could say it defunctifies functions. Or something.
---
Diffs of the changes: (+98 -0)
Index: reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp
diff -c /dev/null reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp:1.1
*** /dev/null Tue Oct 14 16:26:09 2003
--- reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp Tue Oct 14 16:25:58 2003
***************
*** 0 ****
--- 1,98 ----
+ //===- UnpackTraceFunction.cpp - Convert functions back to traces -*- C++ -*--=//
+ //
+ // WARNING, WARNING, WARNING; THIS IS HALF-UNIMPLEMENTED WORK IN PROGRESS!
+ // Methods to convert functions, which had previously been converted from
+ // traces into functions, back into traces.
+ //
+ //===-----------------------------------------------------------------------===//
+
+ #include "llvm/CodeGen/MachineBasicBlock.h"
+ #include "llvm/CodeGen/MachineFunction.h"
+ #include "llvm/Function.h"
+ #include <set>
+
+ // FIXME: following decl should be shared with TraceToFunction.cpp in a header
+ typedef std::set<Value *> LiveVariableSet;
+
+ struct AllocInfo {
+ // FIXME: this should be the same as what you see in PhyRegAlloc.cpp
+ // but with equality/inequality operators
+ bool operator== (const AllocInfo &X) const { return false; /* FIXME */ }
+ bool operator!= (const AllocInfo &X) const { return !(*this == X); }
+ };
+
+ /// Insert a machine instruction for the current architecture, that
+ /// copies the value in Source to the location specified by Target, at
+ /// the beginning of B.
+ ///
+ void insertCopy (AllocInfo &Source, AllocInfo &Target, MachineBasicBlock &B) {
+ // FIXME: not yet implemented
+ }
+
+ /// Get the register number or stack position where V can be found in the
+ /// machine code for the function F.
+ ///
+ AllocInfo getRegisterAllocatedForValue (Function *F, Value *V) {
+ AllocInfo AI;
+ // FIXME: not yet implemented
+ return AI;
+ }
+
+ /// Returns a pointer to the return instruction in B, if B contains one,
+ /// or null otherwise.
+ ///
+ MachineInstr *containsReturnInstruction (MachineBasicBlock &B) {
+ // FIXME: not yet implemented
+ return 0;
+ }
+
+ /// Insert copies in two places in the machine code for TraceF:
+ /// first, at the entry basic block to copy the values in Si from
+ /// MatrixF's registers to TraceF's registers, and second,
+ /// at each exit basic block to copy the values in So from TraceF's
+ /// registers to MatrixF's registers.
+ ///
+ void insertLiveVariableCopies(Function *MatrixF, Function *TraceF,
+ LiveVariableSet &Si, LiveVariableSet &So) {
+ MachineFunction &MF = MachineFunction::get (TraceF);
+
+ // Modify ENTRY MachineBasicBlock of MF
+ MachineBasicBlock &E = MF.front (); // E = Entry MBB of MF
+ for (LiveVariableSet::iterator SI = Si.begin (), SE = Si.end (); SI != SE;
+ ++SI) {
+ Value *V = *SI;
+ AllocInfo Source = getRegisterAllocatedForValue (MatrixF, V);
+ AllocInfo Target = getRegisterAllocatedForValue (TraceF, V);
+ if (Source != Target)
+ insertCopy (Source, Target, E);
+ }
+
+ // Modify EXIT MachineBasicBlocks of MF
+ for (MachineFunction::iterator I = MF.begin (), E = MF.end (); I != E; ++I) {
+ MachineBasicBlock &B = *I;
+ if (MachineInstr *RI = containsReturnInstruction (B)) {
+ #ifdef PSEUDOCODE
+ Erase the contents of B;
+ #endif
+ for (LiveVariableSet::iterator SI = So.begin (), SE = So.end ();
+ SI != SE; ++SI) {
+ Value *V = *SI;
+ AllocInfo Source = getRegisterAllocatedForValue (TraceF, V);
+ AllocInfo Target = getRegisterAllocatedForValue (MatrixF, V);
+ if (Source != Target)
+ insertCopy (Source, Target, B);
+ }
+ #ifdef PSEUDOCODE
+ Let RBB be the address in memory of the MachineBasicBlock in MatrixF
+ that RI would have returned to;
+ if (RBB is within the range of a Branch Always) {
+ Create a new "Branch Always" MachineInstr MI, which branches to RBB;
+ Insert MI at the end of the MachineBasicBlock B;
+ } else {
+ Use nifty "insert far call" code in SparcV9CodeEmitter;
+ }
+ #endif
+ }
+ }
+ }
+
More information about the llvm-commits
mailing list