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

Brian Gaeke gaeke at cs.uiuc.edu
Wed Jun 9 15:27:01 PDT 2004


Changes in directory reopt/lib/LightWtProfiling:

UnpackTraceFunction.cpp updated: 1.81 -> 1.82

---
Log message:

Don't clobber matrixFn's frame pointer until the copies are done.
Simplify rewriteProlog's copying code. Make it work for spilled and allocated
values in both matrixFn and traceFn.


---
Diffs of the changes:  (+38 -32)

Index: reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp
diff -u reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp:1.81 reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp:1.82
--- reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp:1.81	Tue Jun  8 13:53:56 2004
+++ reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp	Wed Jun  9 15:26:15 2004
@@ -131,7 +131,6 @@
         std::cerr << " )\n");
 }
 
-
 unsigned UnpackTraceFunction::stackOffsetForReg (const unsigned R) const {
   return 2047 + StaticStackSize + 176 + R * 8;
 }
@@ -181,46 +180,53 @@
       E.push_back (*vi);
   }
 
-  // 3. Caller's stack pointer becomes our frame pointer.
-  E.push_back (BuildMI (V9::ORr, 3).addMReg (g1).addZImm (0)
-    .addMReg (fp, MachineOperand::Def));
-
-  // 4. Insert a copy for each live-in variable to copy it from the stack
-  // to the register that was allocated for it in the TraceFn.
+  // 3. Insert a copy for each live-in variable to copy it from the stack
+  // to the register or stack slot that was allocated for it in the TraceFn.
   LiveVariableSet &Si = TF->LiveInSet;
   for (LiveVariableSet::iterator SI = Si.begin (), SE = Si.end (); SI != SE;
        ++SI) {
     Value *V = *SI;
     std::pair<AllocInfo, AllocInfo> &ai = AllocStates[V];
     AllocInfo &Source = ai.first, &Target = ai.second;
-    if (Source.AllocState == AllocInfo::Allocated
-        && Target.AllocState == AllocInfo::Allocated) {
-      mvec.clear ();
-      assert (TRI.getRegType (Target.Placement)
-              == TRI.getRegType (Source.Placement)
-              && "Live-in value changed reg type?!");
-      unsigned RegType = TRI.getRegType (Target.Placement);
-      TRI.cpMem2RegMI (mvec, sp, stackOffsetForReg (Source.Placement),
-                       Target.Placement, RegType, g2);
-      for (std::vector<MachineInstr *>::iterator vi = mvec.begin (),
-           ve = mvec.end (); vi != ve; ++vi)
-        E.push_back (*vi);
-    } else if (Source.AllocState == AllocInfo::Spilled
-               && Target.AllocState == AllocInfo::Allocated) {
-      mvec.clear ();
-      unsigned RegType = TRI.getRegType (Target.Placement);
-      TRI.cpMem2RegMI (mvec, fp, Source.Placement, Target.Placement, RegType, g2);
-      for (std::vector<MachineInstr *>::iterator vi = mvec.begin (),
-           ve = mvec.end (); vi != ve; ++vi)
-        E.push_back (*vi);
-    } else {
-      std::cerr << "Whoops, can't do live-ins spilled in TraceFn yet\n";
-      abort ();
-    }
+    mvec.clear ();
+    unsigned R;
+    assert ((Target.AllocState == AllocInfo::Allocated
+             || Target.AllocState == AllocInfo::Spilled)
+            && (Source.AllocState == AllocInfo::Allocated
+                || Source.AllocState == AllocInfo::Spilled)
+            && "Can only handle live-in values in registers or stack slots");
+    if (Target.AllocState == AllocInfo::Allocated)
+      R = Target.Placement;
+    else if (Target.AllocState == AllocInfo::Spilled)
+      // We'll save the value first in a register and then on TraceFn's stack
+      R = SparcV9::g3;
+    unsigned RegType = TRI.getRegType (R);
+    if (Source.AllocState == AllocInfo::Allocated)
+      // Copy live-in value from where we saved its reg. on TraceFn's stack
+      TRI.cpMem2RegMI (mvec, sp, stackOffsetForReg (Source.Placement), R,
+                       RegType, g2);
+    else if (Source.AllocState == AllocInfo::Spilled)
+      // Copy live-in value from MatrixFn's stack
+      TRI.cpMem2RegMI (mvec, fp, Source.Placement, R, RegType, g2);
+    if (Target.AllocState == AllocInfo::Spilled)
+      // Finally copy it onto TraceFn's stack
+      TRI.cpReg2MemMI (mvec, R, g1, Target.Placement, RegType, g2);
+    for (std::vector<MachineInstr *>::iterator vi = mvec.begin (),
+         ve = mvec.end (); vi != ve; ++vi)
+      E.push_back (*vi);
   }
+  
+  // 4. Caller's stack pointer becomes our frame pointer.
+  // We do it now because copies (performed above) of live-ins spilled on
+  // MatrixFn's stack need to reference the old frame pointer (fp), and copies
+  // (also performed above) of live-ins spilled on TraceFn's stack need to
+  // reference the new frame pointer (g1).
+  E.push_back (BuildMI (V9::ORr, 3).addMReg (g1).addZImm (0)
+    .addMReg (fp, MachineOperand::Def));
 
   MachineBasicBlock::iterator MBBIt = EntryBB.begin ();
-  for (std::vector<MachineInstr *>::iterator ei = E.begin (), ee = E.end (); ei != ee; ++ei) {
+  for (std::vector<MachineInstr *>::iterator ei = E.begin (), ee = E.end ();
+       ei != ee; ++ei) {
     MBBIt = EntryBB.insert (MBBIt, *ei);
     ++MBBIt;
   }





More information about the llvm-commits mailing list