Operand numbers are now ints. Save the register allocation of the value
authorBrian Gaeke <gaeke@uiuc.edu>
Mon, 10 Nov 2003 00:05:26 +0000 (00:05 +0000)
committerBrian Gaeke <gaeke@uiuc.edu>
Mon, 10 Nov 2003 00:05:26 +0000 (00:05 +0000)
each instruction produces as "operand" -1, and the other operands as 0
.. n, as before. PhyRegAlloc::saveState() is refactored into
PhyRegAlloc::saveStateForValue().

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@9842 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/RegAlloc/AllocInfo.h
lib/CodeGen/RegAlloc/PhyRegAlloc.cpp
lib/CodeGen/RegAlloc/PhyRegAlloc.h
lib/Target/SparcV9/RegAlloc/AllocInfo.h
lib/Target/SparcV9/RegAlloc/PhyRegAlloc.cpp
lib/Target/SparcV9/RegAlloc/PhyRegAlloc.h

index 1f5357ab79a19cede38a5f7849d776881aec6796..f83f2103be7fbd43a5997c0d1da87f52364e3322 100644 (file)
@@ -25,7 +25,7 @@
 ///
 struct AllocInfo {
   unsigned Instruction;
-  unsigned Operand;
+  int Operand; // (-1 if Instruction, or 0...n-1 for an operand.)
   enum AllocStateTy { NotAllocated = 0, Allocated, Spilled };
   AllocStateTy AllocState;
   int Placement;
@@ -40,7 +40,7 @@ struct AllocInfo {
   static StructType *getConstantType () {
     std::vector<const Type *> TV;
     TV.push_back (Type::UIntTy);
-    TV.push_back (Type::UIntTy);
+    TV.push_back (Type::IntTy);
     TV.push_back (Type::UIntTy);
     TV.push_back (Type::IntTy);
     return StructType::get (TV);
@@ -53,7 +53,7 @@ struct AllocInfo {
     StructType *ST = getConstantType ();
     std::vector<Constant *> CV;
     CV.push_back (ConstantUInt::get (Type::UIntTy, Instruction));
-    CV.push_back (ConstantUInt::get (Type::UIntTy, Operand));
+    CV.push_back (ConstantSInt::get (Type::IntTy, Operand));
     CV.push_back (ConstantUInt::get (Type::UIntTy, AllocState));
     CV.push_back (ConstantSInt::get (Type::IntTy, Placement));
     return ConstantStruct::get (ST, CV);
index 42150232d2211503a578b2447b09665d9776f070..fd615545f234d4db45fc7adc980d73e5aa233bc7 100644 (file)
@@ -1137,6 +1137,31 @@ void PhyRegAlloc::allocateStackSpace4SpilledLRs() {
 }
 
 
+void PhyRegAlloc::saveStateForValue (std::vector<AllocInfo> &state,
+                                     const Value *V, unsigned Insn, int Opnd) {
+  LiveRangeMapType::const_iterator HMI = LRI->getLiveRangeMap ()->find (V); 
+  LiveRangeMapType::const_iterator HMIEnd = LRI->getLiveRangeMap ()->end ();   
+  AllocInfo::AllocStateTy AllocState = AllocInfo::NotAllocated; 
+  int Placement = -1; 
+  if ((HMI != HMIEnd) && HMI->second) { 
+    LiveRange *L = HMI->second; 
+    assert ((L->hasColor () || L->isMarkedForSpill ()) 
+            && "Live range exists but not colored or spilled"); 
+    if (L->hasColor ()) { 
+      AllocState = AllocInfo::Allocated; 
+      Placement = MRI.getUnifiedRegNum (L->getRegClassID (), 
+                                        L->getColor ()); 
+    } else if (L->isMarkedForSpill ()) { 
+      AllocState = AllocInfo::Spilled; 
+      assert (L->hasSpillOffset () 
+              && "Live range marked for spill but has no spill offset"); 
+      Placement = L->getSpillOffFromFP (); 
+    } 
+  } 
+  state.push_back (AllocInfo (Insn, Opnd, AllocState, Placement)); 
+}
+
+
 /// Save the global register allocation decisions made by the register
 /// allocator so that they can be accessed later (sort of like "poor man's
 /// debug info").
@@ -1144,32 +1169,14 @@ void PhyRegAlloc::allocateStackSpace4SpilledLRs() {
 void PhyRegAlloc::saveState () {
   std::vector<AllocInfo> &state = FnAllocState[Fn];
   unsigned Insn = 0;
-  LiveRangeMapType::const_iterator HMIEnd = LRI->getLiveRangeMap ()->end ();   
   for (const_inst_iterator II=inst_begin (Fn), IE=inst_end (Fn); II!=IE; ++II){
+    saveStateForValue (state, (*II), Insn, -1);
     for (unsigned i = 0; i < (*II)->getNumOperands (); ++i) {
       const Value *V = (*II)->getOperand (i);
-      // Don't worry about it unless it's something whose reg. we'll need.
-      if (!isa<Argument> (V) && !isa<Instruction> (V))
-        continue;
-      LiveRangeMapType::const_iterator HMI = LRI->getLiveRangeMap ()->find (V);
-      AllocInfo::AllocStateTy AllocState = AllocInfo::NotAllocated;
-      int Placement = -1;
-      if ((HMI != HMIEnd) && HMI->second) {
-        LiveRange *L = HMI->second;
-        assert ((L->hasColor () || L->isMarkedForSpill ())
-                && "Live range exists but not colored or spilled");
-        if (L->hasColor()) {
-          AllocState = AllocInfo::Allocated;
-          Placement = MRI.getUnifiedRegNum (L->getRegClassID (),
-                                            L->getColor ());
-        } else if (L->isMarkedForSpill ()) {
-          AllocState = AllocInfo::Spilled;
-          assert (L->hasSpillOffset ()
-                  && "Live range marked for spill but has no spill offset");
-          Placement = L->getSpillOffFromFP ();
-        }
-      }
-      state.push_back (AllocInfo (Insn, i, AllocState, Placement));
+      // Don't worry about it unless it's something whose reg. we'll need. 
+      if (!isa<Argument> (V) && !isa<Instruction> (V)) 
+        continue; 
+      saveStateForValue (state, V, Insn, i);
     }
     ++Insn;
   }
@@ -1209,7 +1216,7 @@ void PhyRegAlloc::verifySavedState () {
 /// Finish the job of saveState(), by collapsing FnAllocState into an LLVM
 /// Constant and stuffing it inside the Module. (NOTE: Soon, there will be
 /// other, better ways of storing the saved state; this one is cumbersome and
-/// will never work with the JIT.)
+/// does not work well with the JIT.)
 ///
 bool PhyRegAlloc::doFinalization (Module &M) { 
   if (!SaveRegAllocState)
@@ -1261,8 +1268,8 @@ bool PhyRegAlloc::doFinalization (Module &M) {
                             GlobalValue::InternalLinkage, S,
                             F->getName () + ".regAllocState", &M);
 
-      // Have: { uint, [Size x { uint, uint, uint, int }] } *
-      // Cast it to: { uint, [0 x { uint, uint, uint, int }] } *
+      // Have: { uint, [Size x { uint, int, uint, int }] } *
+      // Cast it to: { uint, [0 x { uint, int, uint, int }] } *
       Constant *CE = ConstantExpr::getCast (ConstantPointerRef::get (GV), PT);
       allstate.push_back (CE);
     }
@@ -1270,7 +1277,7 @@ bool PhyRegAlloc::doFinalization (Module &M) {
 
   unsigned Size = allstate.size ();
   // Final structure type is:
-  // { uint, [Size x { uint, [0 x { uint, uint, uint, int }] } *] }
+  // { uint, [Size x { uint, [0 x { uint, int, uint, int }] } *] }
   std::vector<const Type *> TV2;
   TV2.push_back (Type::UIntTy);
   ArrayType *AT2 = ArrayType::get (PT, Size);
index 5fdd60f7ee0d888554f5912f5770add899a4c2fa..c524f9f56cbe569b15c303c6885fb01a452f6287 100644 (file)
@@ -122,6 +122,9 @@ private:
   void addInterferencesForArgs();
   void createIGNodeListsAndIGs();
   void buildInterferenceGraphs();
+
+  void saveStateForValue (std::vector<AllocInfo> &state,
+                          const Value *V, unsigned Insn, int Opnd);
   void saveState();
   void verifySavedState();
 
index 1f5357ab79a19cede38a5f7849d776881aec6796..f83f2103be7fbd43a5997c0d1da87f52364e3322 100644 (file)
@@ -25,7 +25,7 @@
 ///
 struct AllocInfo {
   unsigned Instruction;
-  unsigned Operand;
+  int Operand; // (-1 if Instruction, or 0...n-1 for an operand.)
   enum AllocStateTy { NotAllocated = 0, Allocated, Spilled };
   AllocStateTy AllocState;
   int Placement;
@@ -40,7 +40,7 @@ struct AllocInfo {
   static StructType *getConstantType () {
     std::vector<const Type *> TV;
     TV.push_back (Type::UIntTy);
-    TV.push_back (Type::UIntTy);
+    TV.push_back (Type::IntTy);
     TV.push_back (Type::UIntTy);
     TV.push_back (Type::IntTy);
     return StructType::get (TV);
@@ -53,7 +53,7 @@ struct AllocInfo {
     StructType *ST = getConstantType ();
     std::vector<Constant *> CV;
     CV.push_back (ConstantUInt::get (Type::UIntTy, Instruction));
-    CV.push_back (ConstantUInt::get (Type::UIntTy, Operand));
+    CV.push_back (ConstantSInt::get (Type::IntTy, Operand));
     CV.push_back (ConstantUInt::get (Type::UIntTy, AllocState));
     CV.push_back (ConstantSInt::get (Type::IntTy, Placement));
     return ConstantStruct::get (ST, CV);
index 42150232d2211503a578b2447b09665d9776f070..fd615545f234d4db45fc7adc980d73e5aa233bc7 100644 (file)
@@ -1137,6 +1137,31 @@ void PhyRegAlloc::allocateStackSpace4SpilledLRs() {
 }
 
 
+void PhyRegAlloc::saveStateForValue (std::vector<AllocInfo> &state,
+                                     const Value *V, unsigned Insn, int Opnd) {
+  LiveRangeMapType::const_iterator HMI = LRI->getLiveRangeMap ()->find (V); 
+  LiveRangeMapType::const_iterator HMIEnd = LRI->getLiveRangeMap ()->end ();   
+  AllocInfo::AllocStateTy AllocState = AllocInfo::NotAllocated; 
+  int Placement = -1; 
+  if ((HMI != HMIEnd) && HMI->second) { 
+    LiveRange *L = HMI->second; 
+    assert ((L->hasColor () || L->isMarkedForSpill ()) 
+            && "Live range exists but not colored or spilled"); 
+    if (L->hasColor ()) { 
+      AllocState = AllocInfo::Allocated; 
+      Placement = MRI.getUnifiedRegNum (L->getRegClassID (), 
+                                        L->getColor ()); 
+    } else if (L->isMarkedForSpill ()) { 
+      AllocState = AllocInfo::Spilled; 
+      assert (L->hasSpillOffset () 
+              && "Live range marked for spill but has no spill offset"); 
+      Placement = L->getSpillOffFromFP (); 
+    } 
+  } 
+  state.push_back (AllocInfo (Insn, Opnd, AllocState, Placement)); 
+}
+
+
 /// Save the global register allocation decisions made by the register
 /// allocator so that they can be accessed later (sort of like "poor man's
 /// debug info").
@@ -1144,32 +1169,14 @@ void PhyRegAlloc::allocateStackSpace4SpilledLRs() {
 void PhyRegAlloc::saveState () {
   std::vector<AllocInfo> &state = FnAllocState[Fn];
   unsigned Insn = 0;
-  LiveRangeMapType::const_iterator HMIEnd = LRI->getLiveRangeMap ()->end ();   
   for (const_inst_iterator II=inst_begin (Fn), IE=inst_end (Fn); II!=IE; ++II){
+    saveStateForValue (state, (*II), Insn, -1);
     for (unsigned i = 0; i < (*II)->getNumOperands (); ++i) {
       const Value *V = (*II)->getOperand (i);
-      // Don't worry about it unless it's something whose reg. we'll need.
-      if (!isa<Argument> (V) && !isa<Instruction> (V))
-        continue;
-      LiveRangeMapType::const_iterator HMI = LRI->getLiveRangeMap ()->find (V);
-      AllocInfo::AllocStateTy AllocState = AllocInfo::NotAllocated;
-      int Placement = -1;
-      if ((HMI != HMIEnd) && HMI->second) {
-        LiveRange *L = HMI->second;
-        assert ((L->hasColor () || L->isMarkedForSpill ())
-                && "Live range exists but not colored or spilled");
-        if (L->hasColor()) {
-          AllocState = AllocInfo::Allocated;
-          Placement = MRI.getUnifiedRegNum (L->getRegClassID (),
-                                            L->getColor ());
-        } else if (L->isMarkedForSpill ()) {
-          AllocState = AllocInfo::Spilled;
-          assert (L->hasSpillOffset ()
-                  && "Live range marked for spill but has no spill offset");
-          Placement = L->getSpillOffFromFP ();
-        }
-      }
-      state.push_back (AllocInfo (Insn, i, AllocState, Placement));
+      // Don't worry about it unless it's something whose reg. we'll need. 
+      if (!isa<Argument> (V) && !isa<Instruction> (V)) 
+        continue; 
+      saveStateForValue (state, V, Insn, i);
     }
     ++Insn;
   }
@@ -1209,7 +1216,7 @@ void PhyRegAlloc::verifySavedState () {
 /// Finish the job of saveState(), by collapsing FnAllocState into an LLVM
 /// Constant and stuffing it inside the Module. (NOTE: Soon, there will be
 /// other, better ways of storing the saved state; this one is cumbersome and
-/// will never work with the JIT.)
+/// does not work well with the JIT.)
 ///
 bool PhyRegAlloc::doFinalization (Module &M) { 
   if (!SaveRegAllocState)
@@ -1261,8 +1268,8 @@ bool PhyRegAlloc::doFinalization (Module &M) {
                             GlobalValue::InternalLinkage, S,
                             F->getName () + ".regAllocState", &M);
 
-      // Have: { uint, [Size x { uint, uint, uint, int }] } *
-      // Cast it to: { uint, [0 x { uint, uint, uint, int }] } *
+      // Have: { uint, [Size x { uint, int, uint, int }] } *
+      // Cast it to: { uint, [0 x { uint, int, uint, int }] } *
       Constant *CE = ConstantExpr::getCast (ConstantPointerRef::get (GV), PT);
       allstate.push_back (CE);
     }
@@ -1270,7 +1277,7 @@ bool PhyRegAlloc::doFinalization (Module &M) {
 
   unsigned Size = allstate.size ();
   // Final structure type is:
-  // { uint, [Size x { uint, [0 x { uint, uint, uint, int }] } *] }
+  // { uint, [Size x { uint, [0 x { uint, int, uint, int }] } *] }
   std::vector<const Type *> TV2;
   TV2.push_back (Type::UIntTy);
   ArrayType *AT2 = ArrayType::get (PT, Size);
index 5fdd60f7ee0d888554f5912f5770add899a4c2fa..c524f9f56cbe569b15c303c6885fb01a452f6287 100644 (file)
@@ -122,6 +122,9 @@ private:
   void addInterferencesForArgs();
   void createIGNodeListsAndIGs();
   void buildInterferenceGraphs();
+
+  void saveStateForValue (std::vector<AllocInfo> &state,
+                          const Value *V, unsigned Insn, int Opnd);
   void saveState();
   void verifySavedState();