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

Brian Gaeke gaeke at cs.uiuc.edu
Tue Jul 20 19:52:00 PDT 2004



Changes in directory reopt/lib/LightWtProfiling:

UnpackTraceFunction.cpp updated: 1.100 -> 1.101

---
Log message:

Don't touch the MatrixFn's %fp - apparently, this is some kind of ABI
violation. Instead, we'll use %g1 as our TraceFn %fp.


---
Diffs of the changes:  (+33 -71)

Index: reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp
diff -u reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp:1.100 reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp:1.101
--- reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp:1.100	Tue Jul 20 18:07:55 2004
+++ reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp	Tue Jul 20 21:51:50 2004
@@ -108,10 +108,6 @@
   if (intCCRegSeen)
     RegsToSave.insert (SparcV9::ccr);
 
-  // Always put fp in the set because it is restored unconditionally.
-  static const unsigned fp = SparcV9::i6;
-  RegsToSave.insert (fp);
-
   // Get the saved register allocator state for all live-in variables.
   // We are going to need to save live-in values which reside in registers
   // on the stack, so we need to dig their register numbers out now.
@@ -179,8 +175,8 @@
 void UnpackTraceFunction::rewriteProlog (MachineFunction &MF,
                                          MachineBasicBlock &EntryBB) {
   const SparcV9RegInfo &TRI = *TM->getRegInfo ();
-  static const unsigned sp = SparcV9::o6, fp = SparcV9::i6, g1 = SparcV9::g1,
-    g2 = SparcV9::g2;
+  static const unsigned sp = SparcV9::o6, MatrixFP = SparcV9::i6,
+    TraceFP = SparcV9::g1, g2 = SparcV9::g2;
 
   // UTF prolog: start out by clearing SAVE and stack-load instructions out
   // of the entry BB.
@@ -190,9 +186,10 @@
 
   std::vector<MachineInstr *> E;
 
-  // 0. Save caller's stack pointer in %g1.
+  // 0. Save caller's stack pointer in TraceFP (%g1); it will be used
+  // as TraceFn's frame pointer.
   E.push_back (BuildMI (V9::ORr, 3).addMReg (sp).addZImm (0)
-    .addMReg (g1, MachineOperand::Def));
+    .addMReg (TraceFP, MachineOperand::Def));
 
   // 1. Emit ADD instruction to allocate the right amount of stack space.
   E.push_back (BuildMI (V9::ADDi, 3).addMReg (sp).addSImm (-TotalStackSize)
@@ -242,24 +239,15 @@
                        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);
+      TRI.cpMem2RegMI (mvec, MatrixFP, 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);
+      TRI.cpReg2MemMI (mvec, R, TraceFP, 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));
-  fpIsTraceFP = true;
-
   MachineBasicBlock::iterator MBBIt = EntryBB.begin ();
   for (std::vector<MachineInstr *>::iterator ei = E.begin (), ee = E.end ();
        ei != ee; ++ei) {
@@ -353,11 +341,9 @@
        const AllocInfo &Target, Value *liveOutValue, Value *liveOutTraceValue) {
   const SparcV9RegInfo &TRI = *TM->getRegInfo ();
   std::vector<MachineInstr *> mvec;
-  static const unsigned sp = SparcV9::o6, fp = SparcV9::i6, g1 = SparcV9::g1,
-    g2 = SparcV9::g2, g3 = SparcV9::g3;
+  static const unsigned sp = SparcV9::o6, TraceFP = SparcV9::g1,
+    g2 = SparcV9::g2, g3 = SparcV9::g3, MatrixFP = SparcV9::i6;
 
-  assert (fpIsTraceFP
-          && "Can't call addLiveOutCopy without TraceFn stack frame pointer");
   assert ((Target.AllocState == AllocInfo::Allocated
           || Target.AllocState == AllocInfo::Spilled)
           && "Live-out values must be in regs or spilled in the matrixFn");
@@ -369,7 +355,7 @@
            << RegStr (Target.Placement) << " to RegsToSave set\n");
     RegsToSave.insert (Target.Placement);
   }
-  unsigned R = g1, RegType;
+  unsigned R = SparcV9::g4, RegType;
   // We don't need to use a temp reg. if the live-out value is already
   // in a register in the TraceFn.
   if (Source.AllocState == AllocInfo::Allocated)
@@ -385,7 +371,7 @@
                             g2, mvec);
   } else if (Source.AllocState == AllocInfo::Spilled) {
     // Copy live-out value from TraceFn's stack to the register.
-    TRI.cpMem2RegMI (mvec, fp, Source.Placement, R, RegType, g2);
+    TRI.cpMem2RegMI (mvec, TraceFP, Source.Placement, R, RegType, g2);
   }
 
   // Most live-outs are in registers in MatrixFn. They get saved on TraceFn's
@@ -399,12 +385,7 @@
     // MatrixFn's stack, so MatrixFn's frame pointer will be the base
     // register. But first we need to load it from the stack (FIXME: we
     // should only do this once!)
-    static const unsigned matrixFP = SparcV9::g3;
-    TRI.cpMem2RegMI (mvec, sp, stackOffsetForReg (fp), matrixFP,
-                     TRI.getRegType(matrixFP), g2);
-    DEBUG (std::cerr << "addLiveOutCopy: loading matrixFn's frame pointer; "
-           << "value is spilled at offset = " << Target.Placement << "\n");
-    BaseReg = matrixFP;
+    BaseReg = MatrixFP;
     Offset = Target.Placement;
   }
   TRI.cpReg2MemMI (mvec, R, BaseReg, Offset, RegType, g2);
@@ -465,8 +446,8 @@
 
 bool UnpackTraceFunction::rewriteEpilogInstr (MachineBasicBlock &MBB,
                                               MachineBasicBlock::iterator iter){
-  static const unsigned sp = SparcV9::o6, fp = SparcV9::i6, g1 = SparcV9::g1,
-    g2 = SparcV9::g2, g3 = SparcV9::g3, matrixFP = SparcV9::g3;
+  static const unsigned sp = SparcV9::o6, g1 = SparcV9::g1,
+    g2 = SparcV9::g2, g3 = SparcV9::g3;
   const TargetInstrInfo &TII = *TM->getInstrInfo ();
   const SparcV9RegInfo &TRI = *TM->getRegInfo ();
   MachineInstr &inst = *iter;
@@ -501,8 +482,6 @@
         std::pair<AllocInfo, AllocInfo> ai = GetValueAllocState (TF, V, false);
         AllocInfo &MatrixAI = ai.first;
         if (MatrixAI.AllocState == AllocInfo::Allocated) {
-          assert (fpIsTraceFP
-                  && "Need TraceFn frame pointer to store live-out registers");
           // MatrixAI.Placement is the register allocated to V in MatrixFn.
           unsigned MatrixReg = MatrixAI.Placement;
           // Store V onto TraceFn's stack, from which it will be reloaded into a
@@ -514,22 +493,10 @@
             RegsToSave.insert (MatrixReg);
         } else if (MatrixAI.AllocState == AllocInfo::Spilled) {
           // MatrixAI.Placement is the stack slot allocated to V in MatrixFn.
-          // Make sure we have MatrixFn's frame pointer in a register:
-          if (!g3IsMatrixFP) {
-            // Insert a load instruction before this one to load matrixFP off
-            // the TraceFn stack.
-            std::vector<MachineInstr *> mvec;
-            TRI.cpMem2RegMI (mvec, sp, stackOffsetForReg (fp), matrixFP,
-                             TRI.getRegType(matrixFP), g2);
-            for (std::vector<MachineInstr *>::iterator i = mvec.begin (),
-                 e = mvec.end (); i != e; ++i) {
-              DEBUG (std::cerr << "rewriteEpilogInstr: inserting " << *i << "\n");
-              MBB.insert (iter, *i);
-            }
-            g3IsMatrixFP = true;
-          }
+          static const unsigned MatrixFP = SparcV9::i6;
           // Store it into its stack slot on MatrixFn's stack.
-          newBaseReg = matrixFP;
+          // using MatrixFn's frame pointer as the base register.
+          newBaseReg = MatrixFP;
           newImmedOffset = MatrixAI.Placement;
         } else {
           assert (0 && "Live-outs must be allocated or spilled in MatrixFn");
@@ -563,10 +530,6 @@
 
 void UnpackTraceFunction::rewriteEpilog (MachineFunction &MF,
                                          MachineBasicBlock &MBB) {
-  // We start out each trace-exit MBB with %fp holding the TraceFn frame
-  // pointer.
-  fpIsTraceFP = true;
-
   // Rewrite any stores into live-out pseudo-arguments to store into stack
   // slots instead. Delete old epilog leftovers in the process.
   for (MachineBasicBlock::iterator i = MBB.begin (), e = MBB.end (); i != e; ) {
@@ -596,19 +559,9 @@
        const PHINode *PN = dyn_cast<PHINode> (Inst); ++Inst)
     eliminatePhiAtTraceExit (MF, MBB, PN);
 
-  // Restore MatrixFn's FP. Warning! After this point, addLiveOutCopy won't work
-  // anymore, because it depends on being able to access TraceFn's frame
-  // pointer in %fp.
-  const SparcV9RegInfo &TRI = *TM->getRegInfo ();
-  static const unsigned fp = SparcV9::i6, sp = SparcV9::o6, g2 = SparcV9::g2;
+  static const unsigned sp = SparcV9::o6, g2 = SparcV9::g2;
   std::vector<MachineInstr *> mvec;
-  TRI.cpMem2RegMI (mvec, sp, stackOffsetForReg (fp), fp, TRI.getRegType(fp),
-                   g2);
-  for (std::vector<MachineInstr *>::iterator vi = mvec.begin (),
-       ve = mvec.end (); vi != ve; ++vi)
-    MBB.push_back (*vi);
-  fpIsTraceFP = false;
-  RegsToSave.erase (fp);
+  const SparcV9RegInfo &TRI = *TM->getRegInfo ();
 
   // Get the set of registers used in this function which we saved in
   // findRegsToSave, earlier, and restore all used registers from stack
@@ -660,7 +613,6 @@
 
   DEBUG(std::cerr << "UnpackTraceFunction: unpacking "
           << MF.getFunction()->getName() << "()\n");
-  fpIsTraceFP = false;
 
   // Initialize RegsToSave with the set of registers we'll need to save in the
   // prolog and restore in the epilog.
@@ -676,12 +628,22 @@
   DEBUG(std::cerr << "UnpackTraceFunction: Stack sizes: static = "
         << StaticStackSize << ", total = " << TotalStackSize << "\n");
 
-  // Rewrite function prolog, found in the entry MachineBasicBlock of MF
-  rewriteProlog (MF, MF.front ());
-
-  // Rewrite function epilogs, found in every exit MachineBasicBlock of MF
   for (MachineFunction::iterator I = MF.begin (), E = MF.end (); I != E; ++I) {
     MachineBasicBlock &MBB = *I;
+    static const unsigned fp = SparcV9::i6, TraceFP = SparcV9::g1;
+    if (I == MF.begin()) {
+      // Rewrite function prolog, found in the entry MachineBasicBlock of MF.
+      rewriteProlog (MF, MBB);
+      continue;
+    }
+    // Rewrite references to %fp to use TraceFP (%g1) instead.
+    for (MachineBasicBlock::iterator BI = MBB.begin (), BE = MBB.end ();
+         BI != BE; ++BI)
+      for (unsigned i = 0; i < BI->getNumOperands(); ++i)
+        if (BI->getOperand (i).hasAllocatedReg ()
+            && BI->getOperand (i).getReg () == fp)
+          BI->SetMachineOperandReg (i, TraceFP);
+    // Rewrite function epilogs, found in every exit MachineBasicBlock of MF.
     if (containsReturnInstr (MBB))
       rewriteEpilog (MF, MBB);
   }





More information about the llvm-commits mailing list