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

Brian Gaeke gaeke at cs.uiuc.edu
Fri Nov 7 16:03:01 PST 2003


Changes in directory reopt/lib/LightWtProfiling:

UnpackTraceFunction.cpp updated: 1.15 -> 1.16

---
Log message:

I finished addGetPointerToStackValInstrs and then realized it may not be needed after all.

insertCopyMachineInstrs is looking better too, now that it doesn't
need addGetPointerToStackValInstrs.  But it does need to know the
type of values.


---
Diffs of the changes:  (+34 -25)

Index: reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp
diff -u reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp:1.15 reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp:1.16
--- reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp:1.15	Thu Nov  6 13:51:06 2003
+++ reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp	Fri Nov  7 16:02:12 2003
@@ -19,27 +19,43 @@
 #include "reopt/MappingInfo.h"
 #include "Support/Debug.h"
 
+#if 0
+/// Append to MVEC the appropriate machine instruction(s) to get a pointer to
+/// the stack-spilled object whose location is described by Source into
+/// register number PointerReg. The frame pointer is in register number
+/// FramePtrReg. Note that the current implementation is SPARC-specific.
+///
 void addGetPointerToStackValInstrs (std::vector<MachineInstr *> &mvec,
-                                    AllocInfo &Source, unsigned SrcReg,
-                                    unsigned FramePtrReg) {
-  // Let OFFSET be the offset of the value from %fp
-  mvec.push_back (BuildMI (V9::ADDi, 3).addReg (FramePtrReg)); // FIXME
-  // construct add     %fp, <OFFSET>, <DESTREG>
+                                    AllocInfo &Source, unsigned PointerReg,
+                                    const unsigned FramePtrReg) {
+  // Only works with objects spilled to the stack.
+  assert (Source.AllocState == AllocInfo::Spilled);
+  // Let Offset be the offset of the value from %fp.
+  int Offset = Source.Placement - 2047;
+  // Construct add %fp, <OFFSET>, <DESTREG>
+  mvec.push_back (BuildMI (V9::ADDi, 3).addReg (FramePtrReg)
+                  .addSImm (Offset).addReg (PointerReg, MOTy::Def));
 }
+#endif
 
-/// Insert (a) machine instruction(s) that copies the value in Source
-/// to the location specified by Target, at the beginning of B. Note
+/// Insert the appropriate machine instruction(s) that copies the value in
+/// Source to the location specified by Target, at the beginning of B. Note
 /// that the current implementation is SPARC-specific.
 ///
-/// FIXME: Not yet finished.
-///
 void insertCopyMachineInstrs (AllocInfo &Source, AllocInfo &Target,
-                              MachineBasicBlock &B) {
+                              MachineBasicBlock &B, const Type *Ty) {
   UltraSparc TM;
   const TargetRegInfo &TRI = TM.getRegInfo ();
   std::vector<MachineInstr *> mvec;
   unsigned SrcReg = 31337, TargReg = 31337;
-  int Offset = -1, RegType = -1; // FIXME: How do we set these correctly?
+  int RegType;
+  // Guess what kind of reg the register was allocated to.
+  if (Ty == Type::FloatTy)
+    RegType = UltraSparcRegInfo::FPSingleRegType;
+  else if (Ty == Type::DoubleTy)
+    RegType = UltraSparcRegInfo::FPDoubleRegType;
+  else
+    RegType = UltraSparcRegInfo::IntRegType;
   if (Source.AllocState == AllocInfo::Allocated)
     SrcReg = Source.Placement;
   if (Target.AllocState == AllocInfo::Allocated)
@@ -48,30 +64,23 @@
   const unsigned StackPtrReg = TRI.getStackPointer ();
   if (Source.AllocState == AllocInfo::Spilled
       && Target.AllocState == AllocInfo::Allocated) {
-    // Emit instructions to construct pointer to Source into SrcReg
-    addGetPointerToStackValInstrs (mvec, Source, SrcReg, FramePtrReg);
     // Emit load instruction from stack loc. Source into register Target
-    TRI.cpMem2RegMI (mvec, SrcReg, Offset, TargReg, RegType);
+    TRI.cpMem2RegMI (mvec, FramePtrReg, Source.Placement, TargReg, RegType);
   } else if (Source.AllocState == AllocInfo::Allocated
              && Target.AllocState == AllocInfo::Allocated) {
     // Emit move instruction from register Source to register Target
     TRI.cpReg2RegMI (mvec, Source.Placement, Target.Placement, RegType);
   } else if (Source.AllocState == AllocInfo::Allocated
              && Target.AllocState == AllocInfo::Spilled) {
-    // Emit instructions to construct pointer to Target into TargReg
-    addGetPointerToStackValInstrs (mvec, Target, TargReg, FramePtrReg);
     // Emit store instruction from register Source to stack loc. Target
-    TRI.cpReg2MemMI (mvec, Source.Placement, TargReg, Offset, RegType);
+    TRI.cpReg2MemMI (mvec, Source.Placement, FramePtrReg, Target.Placement,
+                     RegType);
   } else if (Source.AllocState == AllocInfo::Spilled
              && Target.AllocState == AllocInfo::Spilled) {
-    // Emit instructions to construct pointer to Source into SrcReg
-    addGetPointerToStackValInstrs (mvec, Source, SrcReg, FramePtrReg);
     // Emit load instruction from address in SrcReg into register SrcReg
-    TRI.cpMem2RegMI (mvec, SrcReg, Offset, SrcReg, RegType);
-    // Emit instructions to construct pointer to Target into TargReg
-    addGetPointerToStackValInstrs (mvec, Target, TargReg, FramePtrReg);
+    TRI.cpMem2RegMI (mvec, FramePtrReg, Source.Placement, SrcReg, RegType);
     // Emit store instruction from register SrcReg to stack loc. Target
-    TRI.cpReg2MemMI (mvec, SrcReg, TargReg, Offset, RegType);
+    TRI.cpReg2MemMI (mvec, SrcReg, FramePtrReg, Target.Placement, RegType);
   }
   // Add whatever the TargetRegInfo gave us to the MachineBasicBlock we were
   // provided.
@@ -303,7 +312,7 @@
     AllocInfo Source = getValueAllocStateFromModule (MatrixF, V);
     AllocInfo Target = getValueAllocStateFromGlobal (TraceF, V);
     if (Source != Target)
-      insertCopyMachineInstrs (Source, Target, E);
+      insertCopyMachineInstrs (Source, Target, E, V->getType ());
   }
 
   // Modify EXIT MachineBasicBlocks of MF
@@ -334,7 +343,7 @@
         AllocInfo Source = getValueAllocStateFromGlobal (TraceF, V);
         AllocInfo Target = getValueAllocStateFromModule (MatrixF, V);
         if (Source != Target)
-          insertCopyMachineInstrs (Source, Target, MBB);
+          insertCopyMachineInstrs (Source, Target, MBB, V->getType ());
       }
       // Insert a branch back to the return BasicBlock of the matrix fn.
       insertBranchMachineInstrs (ReturnAddress, MBB);





More information about the llvm-commits mailing list