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

Brian Gaeke gaeke at cs.uiuc.edu
Tue Nov 4 16:12:02 PST 2003


Changes in directory reopt/lib/LightWtProfiling:

UnpackTraceFunction.cpp updated: 1.10 -> 1.11

---
Log message:

Fix some compilation errors in the stubby insertCopyMachineInstrs().

Fill in the rest of getValueAllocStateFromModule() and
getValueAllocStateFromGlobal(), and update their comments.


---
Diffs of the changes:  (+46 -18)

Index: reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp
diff -u reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp:1.10 reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp:1.11
--- reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp:1.10	Tue Nov  4 12:26:06 2003
+++ reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp	Tue Nov  4 16:11:41 2003
@@ -25,13 +25,13 @@
 ///
 void insertCopyMachineInstrs (AllocInfo &Source, AllocInfo &Target,
                               MachineBasicBlock &B) {
-  if (Source.AllocState == Spilled && Target.AllocState == Allocated) {
+  if (Source.AllocState == AllocInfo::Spilled && Target.AllocState == AllocInfo::Allocated) {
     //Insert load instruction from stack loc. Source into register Target
-  } else if (Source.AllocState == Allocated && Target.AllocState == Allocated) {
+  } else if (Source.AllocState == AllocInfo::Allocated && Target.AllocState == AllocInfo::Allocated) {
     //Insert move instruction from register Source to register Target
-  } else if (Source.AllocState == Allocated && Target.AllocState == Spilled) {
+  } else if (Source.AllocState == AllocInfo::Allocated && Target.AllocState == AllocInfo::Spilled) {
     //Insert store instruction from register Source to stack loc. Target
-  } else if (Source.AllocState == Spilled && Target.AllocState == Spilled) {
+  } else if (Source.AllocState == AllocInfo::Spilled && Target.AllocState == AllocInfo::Spilled) {
     //Get a temporary register Temp somehow
     //Insert load instruction from stack loc. Source into register Temp
     //Insert store instruction from register Temp to stack loc. Target
@@ -136,32 +136,60 @@
                                                    unsigned VI) {
 }
 
-/// Get the register number or stack position where V can be found in the
-/// machine code for the function F.
+/// Returns the register number or stack position where V can be found in the
+/// machine code for the function F, which it finds by searching the global
+/// variable _llvm_regAllocState written out by PhyRegAlloc.cpp during a
+/// previous invocation of llc.
 ///
 AllocInfo getValueAllocStateFromModule (Function *F, Value *V) {
-  // Figure out the indices of the in _llvm_regAllocState
+  // Figure out the indices (FI, VI, VO) that can be used to look up V, which
+  // is an operand of some instruction in F, in _llvm_regAllocState:
   unsigned FI = getSavedStateIndexOfFunction (F);
   unsigned VI = getSavedStateIndexOfInstruction (F, V);
   unsigned VO = getSavedStateIndexOfOperandInInstruction (F, V, VI);
-  // Reconstruct the AllocInfo for V by looking at F's state, which is
-  // in _llvm_regAllocState.functions[I]
-  FunctionAllocState &FAllocState = _llvm_regAllocState.functions[FI];
-  for (unsigned i = 0; i < FAllocState.numTuples; ++i) {
-    OperandAllocState &T = FAllocState.tuples[VI];
+  // Reconstruct the AllocInfo for V by searching
+  // _llvm_regAllocState.functions[FI] for a tuple that starts with
+  // (VI, VO, ...):
+  FunctionAllocState *FAllocState = _llvm_regAllocState.functions[FI];
+  for (unsigned i = 0; i < FAllocState->numTuples; ++i) {
+    OperandAllocState &T = FAllocState->tuples[VI];
     if (T.Instruction == VI && T.Operand == VO)
-      return AllocInfo (T.Instruction, T.Operand, T.AllocState, T.Placement);
+      return AllocInfo (T.Instruction, T.Operand,
+                        (AllocInfo::AllocStateTy) T.AllocState,
+                        T.Placement);
   }
+  // By this time we had better have found it, otherwise we are about to do bad
+  // things.
+  std::cerr << "ERROR: UnpackTraceFunction: No saved AllocInfo found for "
+            << F->getName () << "()'s value " << *V
+            << " in getValueAllocStateFromModule()\n";
+  abort ();
 }
 
-/// Get the register number or stack position where V can be found in the
-/// machine code for the function F.
+/// Returns the register number or stack position where V can be found in the
+/// machine code for the function F, which it finds by searching the global
+/// variable ExportedFnAllocState exported by PhyRegAlloc.cpp.
 ///
 AllocInfo getValueAllocStateFromGlobal (Function *F, Value *V) {
-  // get the saved PhyRegAlloc state for F out of ExportedFnAllocState
+  // Get the saved PhyRegAlloc state for F out of ExportedFnAllocState:
   std::vector<AllocInfo> &FState = ExportedFnAllocState[F];
-
-  // get the AllocInfo for V from the saved PhyRegAlloc state for F
+  // Figure out the indices (VI, VO) that can be used to look up V, which is an
+  // operand of some instruction in F, in FState:
+  unsigned VI = getSavedStateIndexOfInstruction (F, V);
+  unsigned VO = getSavedStateIndexOfOperandInInstruction (F, V, VI);
+  // Retrieve the AllocInfo for V by searching FState for a tuple that starts
+  // with (VI, VO, ...):
+  for (unsigned i = 0, s = FState.size (); i < s; ++i) {
+    AllocInfo &T = FState[i];
+    if (T.Instruction == VI && T.Operand == VO)
+      return T;
+  }
+  // By this time we had better have found it, otherwise we are about to do bad
+  // things.
+  std::cerr << "ERROR: UnpackTraceFunction: No saved AllocInfo found for "
+            << F->getName () << "()'s value " << *V
+            << " in getValueAllocStateFromGlobal()\n";
+  abort ();
 }
 
 /// Returns a pointer to the return instruction in B, if B contains one,





More information about the llvm-commits mailing list