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

Brian Gaeke gaeke at cs.uiuc.edu
Fri Jul 9 15:57:00 PDT 2004


Changes in directory reopt/lib/LightWtProfiling:

UnpackTraceFunction.cpp updated: 1.93 -> 1.94

---
Log message:

Add comment for addLiveOutCopy, along with when it is appropriate to call it.
Refactor trace exit phi elimination code into new eliminatePhiAtTraceExit
method.
Wrap some long lines.  Other minor comment edits.


---
Diffs of the changes:  (+68 -43)

Index: reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp
diff -u reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp:1.93 reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp:1.94
--- reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp:1.93	Fri Jul  9 14:41:27 2004
+++ reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp	Fri Jul  9 15:55:35 2004
@@ -334,6 +334,10 @@
          std::cerr << "copyConstantToRegister Output: " << **i << "\n");
 }
 
+/// addLiveOutCopy - Add a copy of the Value which is liveOutValue in the
+/// MatrixFn and liveOutTraceValue in the TraceFn, from Source to Target,
+/// at the end of MF's basic block MBB.
+///
 void UnpackTraceFunction::addLiveOutCopy (MachineFunction &MF,
        MachineBasicBlock &MBB, const AllocInfo &Source,
        const AllocInfo &Target, Value *liveOutValue, Value *liveOutTraceValue) {
@@ -396,6 +400,53 @@
     MBB.push_back (*vi);
 }
 
+/// eliminatePhiAtTraceExit - Perform Phi elimination along trace exit edges.
+///
+void UnpackTraceFunction::eliminatePhiAtTraceExit (MachineFunction &MF,
+                                                   MachineBasicBlock &MBB,
+                                                   const PHINode *PN) {
+  for (unsigned i = 0, e = PN->getNumIncomingValues (); i != e; ++i) {
+    // If PN has a source S from the source of the trace exit (MBB's
+    // predecessor), then we have to copy S's incoming value into its PhiCp
+    // register.
+    const BasicBlock *Src = PN->getIncomingBlock (i);
+    if (TF->T.contains (Src)) {
+      BasicBlock *SrcTTF = cast<BasicBlock> (TF->getCorrespondingValue (Src));
+      DEBUG (std::cerr << "rewriteEpilog: considering Phi node "
+             << PN->getName ()
+             << ", found on-trace source #" << i << " (" << Src->getName ()
+             << ", corresponding to " << SrcTTF->getName () << " on trace)\n"
+             << *PN << "\n"); 
+      const BasicBlock *TraceExitingBB = *pred_begin(MBB.getBasicBlock ());
+      DEBUG (std::cerr << "rewriteEpilog: trace exiting BB for this block is "
+             << TraceExitingBB->getName () << "\n");
+      if (TraceExitingBB == SrcTTF) {
+        Value *V = PN->getIncomingValue (i);
+        DEBUG (std::cerr << "rewriteEpilog: found match: trace exiting BB is "
+               << "phi source; phi's incoming value from " << Src->getName () 
+               << " is " << V->getName () << "\n");
+        std::pair<AllocInfo, AllocInfo> outgoingValueAI =
+          GetValueAllocState (TF, V, false);
+        std::pair<AllocInfo, AllocInfo> phiCpAI = // we want the PhiCp node
+          GetValueAllocState (TF, const_cast<PHINode *> (PN), true);
+        DEBUG (std::cerr << "rewriteEpilog: Outgoing value is in ";
+               PrintAI (outgoingValueAI.second);
+               std::cerr << " in TraceFn, and " << PN->getName()
+                         << "'s PhiCp node is in ";
+               PrintAI (phiCpAI.first);
+               std::cerr << " in MatrixFn\n");
+        
+        AllocInfo &Target = phiCpAI.first, &Source = outgoingValueAI.second;
+        DEBUG (std::cerr << "rewriteEpilog: copying live-out phi value: ";
+               PrintValueAIs(V->getName(), Target, Source));
+        addLiveOutCopy (MF, MBB, Source, Target, V,
+                        TF->getCorrespondingValue (V, false));
+      }
+    }
+    DEBUG (std::cerr << "\n");
+  }
+}
+
 void UnpackTraceFunction::rewriteEpilog (MachineFunction &MF,
                                          MachineBasicBlock &MBB) {
   const SparcV9RegInfo &TRI = *TM->getRegInfo ();
@@ -417,45 +468,13 @@
   DEBUG (std::cerr << "rewriteEpilog: Return block for trace exit path is:\n"
          << *RBB << "\n");
   
-  // Perform Phi elimination along trace exit edges.
+  // If there are Phi nodes in the target of the trace-exiting branch, we must
+  // eliminate them by inserting copies now.
   for (BasicBlock::const_iterator Inst = RBB->begin ();
        const PHINode *PN = dyn_cast<PHINode> (Inst); ++Inst)
-    for (unsigned i = 0, e = PN->getNumIncomingValues (); i != e; ++i) {
-      // If PN has a source S from the source of the trace exit (MBB's predecessor),
-      // then we have to copy S's incoming value into its PhiCp register.
-      const BasicBlock *Src = PN->getIncomingBlock (i);
-      if (TF->T.contains (Src)) {
-        BasicBlock *SrcTTF = cast<BasicBlock> (TF->getCorrespondingValue (Src));
-        DEBUG (std::cerr << "rewriteEpilog: considering Phi node " << PN->getName ()
-               << ", found on-trace source #" << i << " (" << Src->getName ()
-               << ", corresponding to " << SrcTTF->getName () << " on trace)\n"
-               << *PN << "\n"); 
-        const BasicBlock *TraceExitingBB = *pred_begin(MBB.getBasicBlock ());
-        DEBUG (std::cerr << "rewriteEpilog: trace exiting BB for this block is "
-               << TraceExitingBB->getName () << "\n");
-        if (TraceExitingBB == SrcTTF) {
-          Value *V = PN->getIncomingValue (i);
-          DEBUG (std::cerr << "rewriteEpilog: found match: trace exiting BB is "
-                 << "phi source; phi's incoming value from " << Src->getName () 
-                 << " is " << V->getName () << "\n");
-          std::pair<AllocInfo, AllocInfo> outgoingValueAI = GetValueAllocState (TF, V, false);
-          std::pair<AllocInfo, AllocInfo> phiCpAI =
-            GetValueAllocState (TF, const_cast<PHINode *> (PN), true); // we want the PhiCp node
-          DEBUG (std::cerr << "rewriteEpilog: Outgoing value is in ";
-                 PrintAI (outgoingValueAI.second);
-                 std::cerr << " in TraceFn, and " << PN->getName() << "'s PhiCp node is in ";
-                 PrintAI (phiCpAI.first);
-                 std::cerr << " in MatrixFn\n");
-          
-          AllocInfo &Target = phiCpAI.first, &Source = outgoingValueAI.second;
-          DEBUG (std::cerr << "rewriteEpilog: copying live-out phi value: ";
-                 PrintValueAIs(V->getName(), Target, Source));
-          addLiveOutCopy (MF, MBB, Source, Target, V, TF->getCorrespondingValue (V, false));
-        }
-      }
-      DEBUG (std::cerr << "\n");
-    }
-      
+    eliminatePhiAtTraceExit (MF, MBB, PN);
+//===----------------------------------------------------------------------===//
+
   // Insert stores from each live-out variable's reg. in the trace
   // to its stack slot in the trace function, from which it will be
   // reloaded below into a register. 
@@ -469,10 +488,13 @@
     AllocInfo &Target = ai.first, &Source = ai.second;
     DEBUG (std::cerr << "rewriteEpilog: copying live-out value: ";
            PrintValueAIs(V->getName(), Target, Source));
-    addLiveOutCopy (MF, MBB, Source, Target, V, TF->getCorrespondingValue (V, false));
+    addLiveOutCopy (MF, MBB, Source, Target, V,
+                    TF->getCorrespondingValue (V, false));
   }
 
-  // Restore old FP.
+  // Restore old FP. Warning! After this point, addLiveOutCopy won't work
+  // anymore, because it depends on being able to access TraceFn's frame
+  // pointer in %fp.
   mvec.clear ();
   TRI.cpMem2RegMI (mvec, sp, stackOffsetForReg (fp), fp, TRI.getRegType(fp),
                    g2);
@@ -482,14 +504,15 @@
   RegsToSave.erase (fp);
 
   // Get the set of registers used in this function which we saved in
-  // rewriteProlog, earlier, and restore all used registers from stack
+  // findRegsToSave, earlier, and restore all used registers from stack
   // except SP.
   for (std::set<unsigned>::iterator i = RegsToSave.begin (),
          e = RegsToSave.end (); i != e; ++i) {
     mvec.clear ();
     unsigned R = *i;
     DEBUG (std::cerr << "rewriteEpilog: Reloading " << RegStr (R) << "\n");
-    TRI.cpMem2RegMI (mvec, sp, stackOffsetForReg (R), R, TRI.getRegType (R), g2);
+    TRI.cpMem2RegMI (mvec, sp, stackOffsetForReg (R), R, TRI.getRegType (R),
+                     g2);
     for (std::vector<MachineInstr *>::iterator vi = mvec.begin (),
            ve = mvec.end (); vi != ve; ++vi)
       MBB.push_back (*vi);
@@ -500,8 +523,10 @@
     .addMReg (sp, MachineOperand::Def);
   
   // Let ReturnAddress be the address in memory of the compiled
-  // code for RBB. We find this by consulting our mapping information.
-  std::pair<uint64_t, uint64_t> BlockAddrs = getBasicBlockInfo(const_cast<BasicBlock *> (RBB));
+  // code for RBB. We find this by consulting the mapping information
+  // generated by llc.
+  std::pair<uint64_t, uint64_t> BlockAddrs =
+    getBasicBlockInfo(const_cast<BasicBlock *> (RBB));
   uint64_t ReturnAddress = BlockAddrs.first;
   DEBUG(std::cerr
         << "rewriteEpilog: Mapping info says addresses are: return address ="





More information about the llvm-commits mailing list