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

Brian Gaeke gaeke at cs.uiuc.edu
Sun May 30 14:37:03 PDT 2004


Changes in directory reopt/lib/LightWtProfiling:

UnpackTraceFunction.cpp updated: 1.76 -> 1.77

---
Log message:

Merge RegsToRestore into RegsToSave; rename findRegsToRestore to findRegsToSave.
Hack AllocStates into a data member of the UnpackTraceFunction pass.
Clear out both RegsToSave and AllocStates before filling them.
Get rid of CopyInfo, which is now unused.


---
Diffs of the changes:  (+40 -63)

Index: reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp
diff -u reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp:1.76 reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp:1.77
--- reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp:1.76	Sun May 30 04:01:27 2004
+++ reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp	Sun May 30 14:36:14 2004
@@ -29,26 +29,6 @@
 
 namespace llvm {
 
-/// Structure describing a single live variable copy.
-///
-struct CopyInfo {
-  AllocInfo Src;
-  AllocInfo Targ;
-  MachineBasicBlock *Blk;
-  const Type *Ty;
-  CopyInfo (AllocInfo &_Src, AllocInfo &_Targ, MachineBasicBlock *_Blk,
-			const Type *_Ty) : Src (_Src), Targ (_Targ), Blk (_Blk),
-							   Ty (_Ty) {}
-};
-
-/// Print method for CopyInfo objects.
-///
-std::ostream &operator<< (std::ostream &OS, CopyInfo &CI) {
-  OS << "(Src " << CI.Src << " Targ " << CI.Targ << " Blk " << CI.Blk
-	 << " Ty " << *CI.Ty << ")";
-  return OS;
-}
-
 // Ripped off from SparcV9PrologEpilogInserter
 unsigned UnpackTraceFunction::getStaticStackSize (MachineFunction &MF) {
   const TargetFrameInfo& frameInfo = MF.getTarget().getFrameInfo();
@@ -78,16 +58,20 @@
   return 0;
 }
 
+// defined in ValueAllocState.cpp:
+extern std::pair<AllocInfo, AllocInfo>
+GetValueAllocState (TraceFunction *TF, Value *V, bool preferLiveIn = true);
+
 /// Fill in the set of registers used in this function, which is kept in
-/// 'RegsToRestore' in the UnpackTraceFunction Pass object, and is used by
+/// 'RegsToSave' in the UnpackTraceFunction Pass object, and is used by
 /// rewriteProlog() and rewriteEpilog(). Registers are
 /// represented by their 'unified register numbers' as used in the SPARCv9
 /// back-end.
 ///
-void
-UnpackTraceFunction::findRegsToRestore (MachineFunction &MF) {
+void UnpackTraceFunction::findRegsToSave (MachineFunction &MF) {
   const TargetRegInfo &TRI = TM->getRegInfo ();
   bool intCCRegSeen = false, floatCCRegSeen = false;
+  RegsToSave.clear ();
   for (MachineFunction::iterator fi = MF.begin (), fe = MF.end ();
     fi != fe; ++fi)
     for (MachineBasicBlock::iterator bi = fi->begin (), be = fi->end ();
@@ -103,7 +87,7 @@
             floatCCRegSeen = true;
           } else if (regNo != SparcV9::g0 && regNo != SparcV9::o6 /* sp */) {
             // Defs of certain registers are ignored
-            RegsToRestore.insert (regNo);
+            RegsToSave.insert (regNo);
           }
         }
       }
@@ -113,18 +97,37 @@
   // If the intcc regs are used, then we only put %ccr in the
   // set, not the individual intcc regs.
   if (floatCCRegSeen)
-    RegsToRestore.insert (SparcV9::fsr);
+    RegsToSave.insert (SparcV9::fsr);
   if (intCCRegSeen)
-    RegsToRestore.insert (SparcV9::ccr);
+    RegsToSave.insert (SparcV9::ccr);
 
   // Always put fp in the set because it is restored unconditionally.
   static const unsigned fp = SparcV9::i6;
-  RegsToRestore.insert (fp);
+  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.
+  LiveVariableSet &Si = TF->LiveInSet;
+  AllocStates.clear ();
+  for (LiveVariableSet::iterator SI = Si.begin (), SE = Si.end (); SI != SE;
+       ++SI) {
+    Value *V = *SI;
+    std::pair<Value *, std::pair<AllocInfo, AllocInfo> > as =
+      std::make_pair (V, GetValueAllocState (TF, V));
+    AllocStates.insert (as);
+    AllocInfo &Source = as.second.first, &Target = as.second.second;
+    assert (Source.AllocState == AllocInfo::Allocated &&
+            Target.AllocState == AllocInfo::Allocated && 
+            "Only handle live-in values in registers for now!");
+    RegsToSave.insert (Source.Placement);
+    RegsToSave.insert (Target.Placement);
+  }
 
-  DEBUG(std::cerr << "findRegsToRestore: RegsToRestore (size " 
-        << RegsToRestore.size () << ") contains: (";
-        for (std::set<unsigned>::iterator i = RegsToRestore.begin (),
-             e = RegsToRestore.end (); i != e; ++i) { std::cerr << *i << " "; }
+  DEBUG(std::cerr << "findRegsToSave: RegsToSave (size " 
+        << RegsToSave.size () << ") contains: (";
+        for (std::set<unsigned>::iterator i = RegsToSave.begin (),
+             e = RegsToSave.end (); i != e; ++i) { std::cerr << *i << " "; }
         std::cerr << " )\n");
 }
 
@@ -133,10 +136,6 @@
   return 2047 + StaticStackSize + 176 + R * 8;
 }
 
-// defined in ValueAllocState.cpp:
-extern std::pair<AllocInfo, AllocInfo>
-GetValueAllocState (TraceFunction *TF, Value *V, bool preferLiveIn = true);
-
 void UnpackTraceFunction::rewriteProlog (MachineFunction &MF,
                                          MachineBasicBlock &E) {
   const TargetRegInfo &TRI = TM->getRegInfo ();
@@ -156,29 +155,7 @@
   BuildMI (&E, V9::ADDi, 3).addMReg (sp).addSImm (-TotalStackSize)
     .addMReg (sp, MachineOperand::Def);
 
-  // 2. 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.
-  RegsToSave = RegsToRestore;
-  LiveVariableSet &Si = TF->LiveInSet;
-  std::map<Value *, std::pair<AllocInfo, AllocInfo> > AllocStates;
-  for (LiveVariableSet::iterator SI = Si.begin (), SE = Si.end (); SI != SE;
-       ++SI) {
-    Value *V = *SI;
-    std::pair<Value *, std::pair<AllocInfo, AllocInfo> > as =
-      std::make_pair (V, GetValueAllocState (TF, V));
-    AllocStates.insert (as);
-    AllocInfo &Source = as.second.first, &Target = as.second.second;
-    assert (Source.AllocState == AllocInfo::Allocated &&
-            Target.AllocState == AllocInfo::Allocated && 
-            "Only handle live-in values in registers for now!");
-    DEBUG (std::cerr << "rewriteProlog: Need to save incoming live value "
-           << "in reg " << Source.Placement << " onto the stack\n");
-    RegsToSave.insert (Source.Placement);
-    RegsToSave.insert (Target.Placement);
-  }
-
-  // 3. Save used registers onto the stack.
+  // 2. Save used registers onto the stack.
   std::vector<MachineInstr *> mvec;
   int RegType;
   for (std::set<unsigned>::iterator i = RegsToSave.begin (),
@@ -202,12 +179,13 @@
       E.push_back (*vi);
   }
 
-  // Caller's stack pointer becomes our frame pointer.
+  // 3. Caller's stack pointer becomes our frame pointer.
   BuildMI (&E, 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.
+  LiveVariableSet &Si = TF->LiveInSet;
   for (LiveVariableSet::iterator SI = Si.begin (), SE = Si.end (); SI != SE;
        ++SI) {
     Value *V = *SI;
@@ -332,10 +310,9 @@
   DEBUG(std::cerr << "UnpackTraceFunction: unpacking "
           << MF.getFunction()->getName() << "()\n");
 
-  // Initialize RegsToRestore with the set of registers we'll need to restore
-  // in the epilog. This is a subset of the registers we'll need to save on the
-  // stack in the prolog!
-  findRegsToRestore (MF);
+  // Initialize RegsToSave with the set of registers we'll need to save in the
+  // prolog and restore in the epilog.
+  findRegsToSave (MF);
 
   // Calculate the stack size.
   // The actual amount we will allocate is (Static Stack Frame Size + Slop +





More information about the llvm-commits mailing list