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

Brian Gaeke gaeke at cs.uiuc.edu
Fri Apr 9 12:08:02 PDT 2004


Changes in directory reopt/lib/LightWtProfiling:

UnpackTraceFunction.cpp updated: 1.51 -> 1.52

---
Log message:

Don't include llvm/IntrinsicLowering.h.
Collapse together some of the various false separations I've made in the
code, including SparcV9ReoptInfo <--> UnpackTraceFunction.... let's face
it, this pass is fundamentally SparcV9-specific.
Add more comments, including doxygen comments.
Wrap long lines.


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

Index: reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp
diff -u reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp:1.51 reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp:1.52
--- reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp:1.51	Thu Apr  8 15:28:07 2004
+++ reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp	Fri Apr  9 12:06:51 2004
@@ -17,16 +17,12 @@
 #include "llvm/CodeGen/MachineFunctionPass.h"
 #include "llvm/CodeGen/MachineFunctionInfo.h"
 #include "llvm/CodeGen/MachineInstr.h"
-#include "llvm/IntrinsicLowering.h"
 #include "llvm/Module.h"
 #include "llvm/Argument.h"
 #include "llvm/Assembly/Writer.h"
 #include "llvm/Support/InstIterator.h"
 #include "Support/Debug.h"
 #include "reopt/MappingInfo.h"
-
-///---------------------- SPARC backend-specific code -----------------------///
-
 #include "../../../../lib/Target/SparcV9/RegAlloc/AllocInfo.h"
 #include "../../../../lib/Target/SparcV9/RegAlloc/PhyRegAlloc.h"
 #include "../../../../lib/Target/SparcV9/SparcV9RegInfo.h"
@@ -34,20 +30,52 @@
 
 namespace llvm {
 
-class SparcV9ReoptInfo {
+/// This pass inserts copies in two places in the machine
+/// code for TF->TraceFn: first, at the entry basic block to copy the values in
+/// TF->LiveInSet from TF->MatrixFn's registers to TF->TraceFn's registers, and
+/// second, at each exit basic block to copy the values in TF->LiveOutSet from
+/// TF->TraceFn's registers to TF->MatrixFn's registers.
+///
+class UnpackTraceFunction : public MachineFunctionPass {
   TargetMachine *TM;
-public:
-  SparcV9ReoptInfo (TargetMachine *_TM) : TM (_TM) {}
+  TraceFunction *TF;
+
   unsigned getStaticStackSize (MachineFunction &MF);
   void insertCopyMachineInstrs (AllocInfo &Source, AllocInfo &Target,
                                 MachineBasicBlock &B, const Type *Ty);
   void insertBranchMachineInstrs (uint64_t Target, MachineBasicBlock &B);
   const MachineInstr *containsReturnInstr (MachineBasicBlock &B);
   void rewriteProlog (MachineFunction &MF, MachineBasicBlock &E);
+public:
+  UnpackTraceFunction (TargetMachine *_TM, TraceFunction *_TF) :
+    TM (_TM), TF (_TF) { }
+  const char *getPassName () const { return "Unpack trace function"; }
+  virtual bool runOnMachineFunction (MachineFunction &MF);
 };
 
+/// 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) {}
+};
+
+/// Create a new UnpackTraceFunction pass that will unpack a given
+/// TraceFunction, for which machine code has been generated, into
+/// its matrix function.
+///
+FunctionPass *createUnpackTraceFunctionPass (TargetMachine *TM,
+                                             TraceFunction *TF) {
+  return new UnpackTraceFunction (TM, TF);
+}
+
 // Ripped off from SparcV9PrologEpilogInserter
-unsigned SparcV9ReoptInfo::getStaticStackSize (MachineFunction &MF) {
+unsigned UnpackTraceFunction::getStaticStackSize (MachineFunction &MF) {
   const TargetFrameInfo& frameInfo = MF.getTarget().getFrameInfo();
 
   unsigned staticStackSize = MF.getInfo()->getStaticStackSize();
@@ -64,10 +92,10 @@
 /// Insert the appropriate machine instruction(s) that copies the value in
 /// Source to the location specified by Target, at the beginning of B.
 ///
-void SparcV9ReoptInfo::insertCopyMachineInstrs (AllocInfo &Source,
-                                                AllocInfo &Target,
-                                                MachineBasicBlock &B,
-                                                const Type *Ty) {
+void UnpackTraceFunction::insertCopyMachineInstrs (AllocInfo &Source,
+                                                   AllocInfo &Target,
+                                                   MachineBasicBlock &B,
+                                                   const Type *Ty) {
   const TargetRegInfo &TRI = TM->getRegInfo ();
   std::vector<MachineInstr *> mvec;
   int RegType;
@@ -113,8 +141,8 @@
 
 /// Append to B a branch from the end of B to TargetAddr.
 ///
-void SparcV9ReoptInfo::insertBranchMachineInstrs (uint64_t Target,
-                                                  MachineBasicBlock &B) {
+void UnpackTraceFunction::insertBranchMachineInstrs (uint64_t Target,
+                                                     MachineBasicBlock &B) {
   // If the target is close enough to fit into the 19-bit disp of a "ba"
   // instruction, then we really DO get a "ba" instruction.  We get the backend
   // to calculate the PC-relative address from the absolute address upon
@@ -134,7 +162,7 @@
 /// one, or null otherwise.
 ///
 const MachineInstr *
-SparcV9ReoptInfo::containsReturnInstr (MachineBasicBlock &B) {
+UnpackTraceFunction::containsReturnInstr (MachineBasicBlock &B) {
   for (MachineBasicBlock::const_reverse_iterator i = B.rbegin (),
          e = B.rend (); i != e; ++i) {
     const MachineInstr &MI = *i;
@@ -144,8 +172,8 @@
   return 0;
 }
 
-void SparcV9ReoptInfo::rewriteProlog (MachineFunction &MF,
-                                      MachineBasicBlock &E) {
+void UnpackTraceFunction::rewriteProlog (MachineFunction &MF,
+                                         MachineBasicBlock &E) {
   const TargetRegInfo &TRI = TM->getRegInfo ();
   static const unsigned 
     fp = SparcV9IntRegClass::i6,
@@ -208,19 +236,11 @@
            ve = mvec.end (); vi != ve; ++vi)
       E.push_back (*vi);
   }
-
-  // 
-  
 }
 
-} // end namespace llvm
-
-///---------------------- End SPARC backend-specific code -------------------///
-
-///---------------------- SPARC register allocator-specific code ------------///
-
-namespace llvm {
-
+/// Data structures describing the register allocator state
+/// that gets saved by -save-ra-state.
+///
 extern "C" { 
   struct OperandAllocState {
     int Instruction;
@@ -228,17 +248,14 @@
     unsigned AllocState;
     int Placement;
   };
-
   struct FunctionAllocState {
     unsigned numTuples;
-    struct OperandAllocState tuples[0];
+    struct OperandAllocState tuples[0]; // variable length
   };
-
   struct ModuleAllocState {
     unsigned numFunctions;
-    struct FunctionAllocState *functions[0];
+    struct FunctionAllocState *functions[0]; // variable length
   };
-
   /// This global is filled in by PhyRegAlloc's -save-ra-state option
   /// in LLC output:
   ///
@@ -250,6 +267,8 @@
 ///
 extern PhyRegAlloc::SavedStateMapTy ExportedFnAllocState;
 
+/// Returns the index of the given Instruction in the given Function.
+///
 static unsigned getSavedStateIndexOfInstruction (const Function *F,
                                                  const Instruction *I) {
   unsigned Key = 0;
@@ -270,6 +289,9 @@
   abort ();
 }
 
+/// Returns the index of the given Argument in the given Function's
+/// argument list.
+///
 static int getNumberOfFunctionArg (const Function *F, const Argument *Arg)
 {
   int ArgNum = 0;
@@ -333,7 +355,9 @@
     OperandKey = getNumberOfFunctionArg (F, A);
   } else {
     if (! isa<Instruction> (V)) {
-      std::cerr << "ERROR: Don't know how to look up alloc state for this Value:\n\t" << *V << "\n";
+      std::cerr
+        << "ERROR: Don't know how to look up alloc state for this Value:\n\t"
+        << *V << "\n";
       abort ();
     }
     // Figure out the indices (VI, VO) that can be used to look up V,
@@ -361,51 +385,15 @@
   abort ();
 }
 
-
-} // end namespace llvm
-
-///------------------End SPARC register allocator-specific code -------------///
-
-namespace llvm {
-
-/// UnpackTraceFunction - This pass inserts copies in two places in the machine
-/// code for TF->TraceFn: first, at the entry basic block to copy the values in
-/// TF->LiveInSet from TF->MatrixFn's registers to TF->TraceFn's registers, and
-/// second, at each exit basic block to copy the values in TF->LiveOutSet from
-/// TF->TraceFn's registers to TF->MatrixFn's registers.
+/// Print method for CopyInfo objects.
 ///
-class UnpackTraceFunction : public MachineFunctionPass {
-  TargetMachine *TM;
-  TraceFunction *TF;
-  SparcV9ReoptInfo SRI;
-public:
-  UnpackTraceFunction (TargetMachine *_TM, TraceFunction *_TF) :
-    TM (_TM), TF (_TF), SRI (_TM) { }
-  const char *getPassName () const { return "Unpack trace function"; }
-  virtual bool runOnMachineFunction (MachineFunction &MF);
-};
-
-FunctionPass *createUnpackTraceFunctionPass (TargetMachine *TM,
-                                             TraceFunction *TF) {
-  return new UnpackTraceFunction (TM, TF);
-}
-
-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) {}
-};
-
-std::ostream &operator << (std::ostream &OS, CopyInfo &CI) {
-  OS << "(Src " << CI.Src << " Targ " << CI.Targ << " Blk " << CI.Blk << " Ty "
-     << *CI.Ty << ")";
+std::ostream &operator<< (std::ostream &OS, CopyInfo &CI) {
+  OS << "(Src " << CI.Src << " Targ " << CI.Targ << " Blk " << CI.Blk
+	 << " Ty " << *CI.Ty << ")";
   return OS;
 }
 
-/// runOnMachineFunction - This method is provided with MF, which is the
+/// This method is provided with MF, which is the
 /// machine code for TF->TraceFn.  We modify it (according to the description
 /// of the pass, above) using the information provided along with TF when this
 /// Pass object was created.
@@ -433,7 +421,7 @@
   std::vector<CopyInfo> EntryCopies;
   DEBUG(std::cerr << "UnpackTraceFunction: Modifying entry BB\n");
 
-  SRI.rewriteProlog (MF, E);
+  rewriteProlog (MF, E);
 
   for (LiveVariableSet::iterator SI = Si.begin (), SE = Si.end (); SI != SE;
        ++SI) {
@@ -457,14 +445,14 @@
   for (std::vector<CopyInfo>::iterator i = EntryCopies.begin (),
          e = EntryCopies.end (); i != e; ++i) {
     DEBUG(std::cerr << "UnpackTraceFunction: " << *i << "\n");
-    SRI.insertCopyMachineInstrs (i->Src, i->Targ, *i->Blk, i->Ty);
+    insertCopyMachineInstrs (i->Src, i->Targ, *i->Blk, i->Ty);
   }
   DEBUG(std::cerr << "-------------\n\n");
 
   // Modify EXIT MachineBasicBlocks of MF
   for (MachineFunction::iterator I = MF.begin (), E = MF.end (); I != E; ++I) {
     MachineBasicBlock &MBB = *I;
-    if (const MachineInstr *RI = SRI.containsReturnInstr (MBB)) {
+    if (const MachineInstr *RI = containsReturnInstr (MBB)) {
       // Let ReturnAddress be the address in memory of the compiled
       // code for the MachineBasicBlock in MatrixF that RI would have
       // returned to. Find it by using MappingInfo.
@@ -484,10 +472,10 @@
           getValueAllocStateFromGlobal (TraceF, TF->getCorrespondingValue (V));
         AllocInfo Target = getValueAllocStateFromModule (MatrixF, V);
         if (Source != Target)
-          SRI.insertCopyMachineInstrs (Source, Target, MBB, V->getType ());
+          insertCopyMachineInstrs (Source, Target, MBB, V->getType ());
       }
       // Insert a branch back to the return BasicBlock of the matrix fn.
-      SRI.insertBranchMachineInstrs (ReturnAddress, MBB);
+      insertBranchMachineInstrs (ReturnAddress, MBB);
     }
   }
 





More information about the llvm-commits mailing list