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

Brian Gaeke gaeke at cs.uiuc.edu
Thu Oct 30 23:37:00 PST 2003


Changes in directory reopt/lib/LightWtProfiling:

UnpackTraceFunction.cpp updated: 1.6 -> 1.7

---
Log message:

Include reopt/MappingInfo.h.
Copy more decls from TraceToFunction.cpp.
Make insertBranchMachineInstrs take a uint64_t address, because that's what
 the MappingInfo will give us.
Add in type definitions for the types that make up _llvm_regAllocState
Replace getRegisterAllocatedForValue with two methods,
 getValueAllocStateFromModule and getValueAllocStateFromGlobal (also not
 yet implemented, unfortunately.)
Add more comments to insertLiveVariableCopies.
Attempt to use MappingInfo to get the value of ReturnAddress.


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

Index: reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp
diff -u reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp:1.6 reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp:1.7
--- reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp:1.6	Mon Oct 27 13:01:16 2003
+++ reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp	Thu Oct 30 23:36:44 2003
@@ -13,11 +13,14 @@
 #include "llvm/CodeGen/MachineInstr.h"
 #include "llvm/Function.h"
 #include "reopt/ScratchMemory.h"
+#include "reopt/MappingInfo.h"
 #include "Support/Debug.h"
 #include <set>
 
-// FIXME: following decl should be shared with TraceToFunction.cpp in a header
+// FIXME: following decls should be shared with TraceToFunction.cpp in a header
 typedef std::set<Value *> LiveVariableSet;
+typedef std::map<BasicBlock *, BasicBlock *> BasicBlockMap;
+extern BasicBlockMap ReturnBlockForTraceExit;
 
 /// Insert (a) machine instruction(s) for the current architecture, that
 /// copies the value in Source to the location specified by Target, at
@@ -35,8 +38,7 @@
 /// FIXME: refactor this so it shares code with SparcV9CodeEmitter.cpp's
 /// JITResolver::insertJumpAtAddr(), JITResolver::insertFarJumpAtAddr()
 ///
-void insertBranchMachineInstrs (void *TargetPointer, MachineBasicBlock &B) {
-  int64_t Target = (int64_t)(intptr_t)TargetPointer;
+void insertBranchMachineInstrs (uint64_t Target, MachineBasicBlock &B) {
   DEBUG(std::cerr << "Emitting a jump to 0x" << std::hex << Target << "\n");
 
   // FIXME: How do we know where this branch is going to end up in
@@ -92,26 +94,50 @@
   }
 }
 
+extern "C" { 
+  struct OperandAllocStateTuple {
+    unsigned Instruction;
+    unsigned Operand;
+    unsigned AllocState;
+    int Placement;
+  };
+
+  struct FunctionAllocState {
+    unsigned numTuples;
+    struct OperandAllocStateTuple tuples[0];
+  };
+
+  struct ModuleAllocState {
+    unsigned numFunctions;
+    struct FunctionAllocStateTuple *functions[0];
+  };
+
+  /// This global is filled in by PhyRegAlloc's -save-ra-state option:
+  ///
+  extern struct ModuleAllocState _llvm_regAllocState;
+};
+
 /// 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 (0,0,0,0); // placeholder
-#ifdef PSEUDOCODE
-  assert (F has been code-generated);
-  if (F was compiled by llc) {
-    get the saved PhyRegAlloc state for F out of the Module of F;
-  } else {
-    PhyRegAlloc must have put the saved state for F somewhere where we can
-      get at it here;
-  }
-  get the AllocInfo for V from the saved PhyRegAlloc state for F;
-#endif
-  return AI;
+AllocInfo getValueAllocStateFromModule (Function *F, Value *V) {
+
+  // figure out the index I of F in _llvm_regAllocState
+
+  // reconstruct the AllocInfo for V by looking at F's state, which is
+  // in _llvm_regAllocState.functions[I]
+}
+
+/// Get the register number or stack position where V can be found in the
+/// machine code for the function F.
+///
+AllocInfo getValueAllocStateFromGlobal (Function *F, Value *V) {
+  // get the saved PhyRegAlloc state for F out of ExportedFnAllocState
+  // get the AllocInfo for V from the saved PhyRegAlloc state for F
 }
 
 /// Returns a pointer to the return instruction in B, if B contains one,
-/// or null otherwise. FIXME: SPARC target-specific, and not done.
+/// or null otherwise. FIXME: SPARC target-specific.
 ///
 const MachineInstr *containsReturnInstruction (MachineBasicBlock &B) {
   for (MachineBasicBlock::const_reverse_iterator i = B.rbegin (),
@@ -137,38 +163,47 @@
   MachineBasicBlock &E = MF.front (); // E = Entry MBB of MF
   for (LiveVariableSet::iterator SI = Si.begin (), SE = Si.end (); SI != SE;
        ++SI) {
+    // Insert copies from each live-in variable's reg. in the matrix fn.
+    // to its reg. in the trace.
     Value *V = *SI;
-    AllocInfo Source = getRegisterAllocatedForValue (MatrixF, V);
-    AllocInfo Target = getRegisterAllocatedForValue (TraceF, V);
+    AllocInfo Source = getValueAllocStateFromModule (MatrixF, V);
+    AllocInfo Target = getValueAllocStateFromGlobal (TraceF, V);
     if (Source != Target)
       insertCopyMachineInstrs (Source, Target, E);
   }
 
   // Modify EXIT MachineBasicBlocks of MF
   for (MachineFunction::iterator I = MF.begin (), E = MF.end (); I != E; ++I) {
-    MachineBasicBlock &B = *I;
-    if (const MachineInstr *RI = containsReturnInstruction (B)) {
-      void *ReturnAddress; 
-#ifdef PSEUDOCODE
-      Let ReturnAddress be the address in memory of the compiled code
-        for the MachineBasicBlock in MatrixF that RI would have returned to;
-#endif
-      // Erase the contents of B
-      while (!B.empty ()) {
-        MachineBasicBlock::iterator MBBI = B.begin ();
+    MachineBasicBlock &MBB = *I;
+    if (const MachineInstr *RI = containsReturnInstruction (MBB)) {
+      // Let ReturnAddress be the address in memory of the compiled
+      // code for the MachineBasicBlock in MatrixF that RI would have
+      // returned to. Find it by using MappingInfo.
+      BasicBlock *RBB = const_cast<BasicBlock *> (MBB.getBasicBlock ());
+      assert ((ReturnBlockForTraceExit.find (RBB) !=
+               ReturnBlockForTraceExit.end ())
+              && "Can't find matrix fn BB address to return to from trace");
+      uint64_t ReturnAddress = 
+        getBasicBlockInfo(ReturnBlockForTraceExit[RBB]).first;
+      // Erase the contents of MBB.
+      while (!MBB.empty ()) {
+        MachineBasicBlock::iterator MBBI = MBB.begin ();
         MachineInstr *MI = *MBBI;
-        B.erase (MBBI);
+        MBB.erase (MBBI);
         delete MI;
       }
+      // Insert copies from each live-out variable's reg. in the trace
+      // to its reg. in the matrix function.
       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);
+        AllocInfo Source = getValueAllocStateFromGlobal (TraceF, V);
+        AllocInfo Target = getValueAllocStateFromModule (MatrixF, V);
         if (Source != Target)
-          insertCopyMachineInstrs (Source, Target, B);
+          insertCopyMachineInstrs (Source, Target, MBB);
       }
-      insertBranchMachineInstrs (ReturnAddress, B);
+      // Insert a branch back to the return BasicBlock of the matrix fn.
+      insertBranchMachineInstrs (ReturnAddress, MBB);
     }
   }
 }





More information about the llvm-commits mailing list