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

Brian Gaeke gaeke at cs.uiuc.edu
Sun Aug 22 20:10:41 PDT 2004



Changes in directory reopt/lib/LightWtProfiling:

UnpackTraceFunction.cpp updated: 1.107 -> 1.108
---
Log message:

getStaticStackSize has been made a static nonmember function.
rewriteProlog now returns the place where it stopped modifying the BB.
Refactor the code that runOnMachineBasicBlock uses to modify each basic block
in the trace into a new member function, postprocessMachineInstrsForTrace().


---
Diffs of the changes:  (+36 -30)

Index: reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp
diff -u reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp:1.107 reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp:1.108
--- reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp:1.107	Thu Aug  5 01:11:11 2004
+++ reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp	Sun Aug 22 22:10:31 2004
@@ -33,17 +33,14 @@
 namespace llvm {
 
 // Ripped off from SparcV9PrologEpilogInserter
-unsigned UnpackTraceFunction::getStaticStackSize (MachineFunction &MF) {
+static unsigned getStaticStackSize (MachineFunction &MF) {
   const TargetFrameInfo& frameInfo = *MF.getTarget().getFrameInfo();
-
   unsigned staticStackSize = MF.getInfo()->getStaticStackSize();
-
-  if (staticStackSize < (unsigned) frameInfo.getMinStackFrameSize())
-    staticStackSize = (unsigned) frameInfo.getMinStackFrameSize();
-  if (unsigned padsz = (staticStackSize %
-                        (unsigned) frameInfo.getStackFrameSizeAlignment()))
-    staticStackSize += frameInfo.getStackFrameSizeAlignment() - padsz;
-
+  if (staticStackSize < (unsigned)SparcV9FrameInfo::MinStackFrameSize)
+    staticStackSize = SparcV9FrameInfo::MinStackFrameSize;
+  if (unsigned padsz = staticStackSize % 
+                       SparcV9FrameInfo::StackFrameSizeAlignment)
+    staticStackSize += SparcV9FrameInfo::StackFrameSizeAlignment - padsz;
   return staticStackSize;
 }
 
@@ -195,7 +192,8 @@
   std::cerr << " in TraceFn\n";
 }
 
-void UnpackTraceFunction::rewriteProlog (MachineBasicBlock &EntryBB) {
+MachineBasicBlock::iterator
+UnpackTraceFunction::rewriteProlog (MachineBasicBlock &EntryBB) {
   // UTF prolog: start out by clearing SAVE and stack-load instructions out
   // of the entry BB.
   while (EntryBB.front().getOpcode() == V9::SAVEi
@@ -268,12 +266,14 @@
       E.push_back (*vi);
   }
   
+  // Insert the generated code. Return an iterator pointing to where we left off.
   MachineBasicBlock::iterator MBBIt = EntryBB.begin ();
   for (std::vector<MachineInstr *>::iterator ei = E.begin (), ee = E.end ();
        ei != ee; ++ei) {
     MBBIt = EntryBB.insert (MBBIt, *ei);
     ++MBBIt;
   }
+  return MBBIt;
 }
 
 static void regAllocConstORi (std::vector<MachineInstr *> &mvec,
@@ -611,28 +611,24 @@
   BuildMI (&MBB, V9::NOP, 0);
 }
 
-bool UnpackTraceFunction::runOnMachineBasicBlock (MachineBasicBlock &MBB) {
+void UnpackTraceFunction::postprocessMachineInstrsForTrace (MachineBasicBlock &MBB,
+                                                            MachineBasicBlock::iterator Start) {
   const SparcV9RegInfo &TRI = *TM->getRegInfo ();
-  if (&MBB == &MBB.getParent()->front()) {
-	// Rewrite function prolog, found in the entry MachineBasicBlock.
-	rewriteProlog (MBB);
-	return true;
-  }
-  for (MachineBasicBlock::iterator BI = MBB.begin (); BI != MBB.end (); ++BI) {
-	// Rewrite references to %fp to use TraceFP (%g1) instead.
-	for (unsigned i = 0; i < BI->getNumOperands(); ++i)
-	  if (BI->getOperand (i).hasAllocatedReg ()
-		  && BI->getOperand (i).getReg () == MatrixFP)
-		BI->SetMachineOperandReg (i, TraceFP);
-	// If this is a CALL, add compensation code around it.
-	if (BI->getOpcode() == V9::CALL || BI->getOpcode() == V9::JMPLCALLi) {
+  for (MachineBasicBlock::iterator BI = Start; BI != MBB.end (); ++BI) {
+    // Rewrite references to %fp to use TraceFP (%g1) instead.
+    for (unsigned i = 0; i < BI->getNumOperands(); ++i)
+      if (BI->getOperand (i).hasAllocatedReg ()
+          && BI->getOperand (i).getReg () == MatrixFP)
+        BI->SetMachineOperandReg (i, TraceFP);
+    // If this is a CALL, add compensation code around it.
+    if (BI->getOpcode() == V9::CALL || BI->getOpcode() == V9::JMPLCALLi) {
       std::vector<MachineInstr *> mvec;
-	  // Save TraceFP on the stack.
+      // Save TraceFP on the stack.
       TRI.cpReg2MemMI (mvec, TraceFP, sp, stackOffsetForReg (TraceFP), 
                        TRI.getRegType (TraceFP), g2);
-	  // Let fp = g1.
+      // Let fp = g1.
       mvec.push_back (BuildMI (V9::ORr, 3).addMReg (TraceFP).addZImm (0)
-        .addMReg (MatrixFP, MachineOperand::Def));
+                      .addMReg (MatrixFP, MachineOperand::Def));
       unsigned R;
       // Insert all the instrs into the MBB after the call instruction.
       for (std::vector<MachineInstr *>::iterator ei = mvec.begin (),
@@ -642,7 +638,7 @@
       }
       ++BI; // Skip over the call instruction.
       ++BI; // Skip over the delay slot.
-	  // Load saved TraceFP and MatrixFP off the TraceFn stack.
+            // Load saved TraceFP and MatrixFP off the TraceFn stack.
       mvec.clear();
       TRI.cpMem2RegMI (mvec, sp, stackOffsetForReg (MatrixFP), MatrixFP,
                        TRI.getRegType (MatrixFP), g2);
@@ -655,11 +651,21 @@
         ++BI;
       }
       --BI;
-	}
+    }
   }
+}
+
+bool UnpackTraceFunction::runOnMachineBasicBlock (MachineBasicBlock &MBB) {
+  MachineBasicBlock::iterator Start = MBB.begin ();
+  if (&MBB == &MBB.getParent()->front())
+	  // Rewrite function prolog, found in the entry MachineBasicBlock.
+	  Start = rewriteProlog (MBB);
+  
+  postprocessMachineInstrsForTrace (MBB, Start);
+  
   // Rewrite function epilogs, found in every exit MachineBasicBlock of MF.
   if (containsReturnInstr (MBB))
-	rewriteEpilog (MBB);
+    rewriteEpilog (MBB);
   return true; // MachineBasicBlock was modified
 }
 






More information about the llvm-commits mailing list