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

Brian Gaeke gaeke at cs.uiuc.edu
Mon Mar 8 16:50:20 PST 2004


Changes in directory reopt/lib/LightWtProfiling:

UnpackTraceFunction.cpp updated: 1.40 -> 1.41

---
Log message:

Make OperandAllocState's Instruction into an int, so that we can make
 arguments be "Instruction" number -1.
Add new getNumberOfFunctionArg().
Get rid of commented-out code, incl. getSavedStateIndexOfOperandInInstruction().
Teach getValueAllocStateFromModule() and getValueAllocStateFromGlobal
 to get the AllocStates of Arguments.
Add more DEBUG print statements.
Move ReturnBlockForTraceExit inside of TraceFunction.


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

Index: reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp
diff -u reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp:1.40 reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp:1.41
--- reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp:1.40	Mon Mar  1 15:20:02 2004
+++ reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp	Mon Mar  8 16:46:55 2004
@@ -18,6 +18,7 @@
 #include "llvm/CodeGen/MachineInstr.h"
 #include "llvm/IntrinsicLowering.h"
 #include "llvm/Module.h"
+#include "llvm/Argument.h"
 #include "llvm/Support/InstIterator.h"
 #include "Support/Debug.h"
 #include "reopt/MappingInfo.h"
@@ -133,7 +134,7 @@
 
 extern "C" { 
   struct OperandAllocState {
-    unsigned Instruction;
+    int Instruction;
     int Operand;
     unsigned AllocState;
     int Placement;
@@ -180,17 +181,16 @@
   abort ();
 }
 
-#if 0
-static unsigned getSavedStateIndexOfOperandInInstruction (Function *F, Value *V,
-                                                          unsigned VI) {
-  // FIXME; not yet implemented
-  DEBUG(std::cerr << "getSavedStateIndexOfOperandInInstruction(F = "
-        << F->getName() << "(), V = " << *V <<", VI = " << VI << ")\n");
-  std::cerr
-    << "** getSavedStateIndexOfOperandInInstruction() NOT YET IMPLEMENTED **\n";
+static int getNumberOfFunctionArg (const Function *F, const Argument *Arg)
+{
+  int ArgNum = 0;
+  for (Function::const_aiterator i = F->abegin (), e = F->aend (); i != e; ++i){
+    if (Arg == &*i) return ArgNum;
+    ++ArgNum;
+  }
+  std::cerr << "ERROR: getNumberOfFunctionArg couldn't find arg\n";
   abort ();
 }
-#endif
 
 /// 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
@@ -198,22 +198,27 @@
 /// previous invocation of llc.
 ///
 static AllocInfo getValueAllocStateFromModule (Function *F, Value *V) {
-  // 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:
-  Instruction *Instr = cast<Instruction> (V);
   unsigned FI = getLLVMFunctionPositionInfo (F);
-  unsigned VI = getSavedStateIndexOfInstruction (F, Instr);
-  //int VO = getSavedStateIndexOfOperandInInstruction (F, V, VI);
+  FunctionAllocState *FAllocState = _llvm_regAllocState.functions[FI];
+  int InstructionKey = -1, OperandKey = -1;
+  if (Argument *A = dyn_cast<Argument> (V)) {
+    // Find the alloc state of an argument.
+    OperandKey = getNumberOfFunctionArg (F, A);
+  } else {
+    // 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:
+    Instruction *Instr = cast<Instruction> (V);
+    InstructionKey = getSavedStateIndexOfInstruction (F, Instr);
+  }
   // 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];
+  // (InstructionKey, OperandKey, ...):
   for (unsigned i = 0; i < FAllocState->numTuples; ++i) {
-    OperandAllocState &T = FAllocState->tuples[VI];
-    if (T.Instruction == VI && T.Operand == 0)
-      return AllocInfo (T.Instruction, T.Operand,
-                        (AllocInfo::AllocStateTy) T.AllocState,
-                        T.Placement);
+	OperandAllocState &T = FAllocState->tuples[i];
+	if (T.Instruction == InstructionKey && T.Operand == OperandKey)
+	  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.
@@ -228,18 +233,24 @@
 /// variable ExportedFnAllocState exported by PhyRegAlloc.cpp.
 ///
 static AllocInfo getValueAllocStateFromGlobal (Function *F, Value *V) {
-  Instruction *Instr = cast<Instruction> (V);
+  unsigned FI = getLLVMFunctionPositionInfo (F);
   // Get the saved PhyRegAlloc state for F out of ExportedFnAllocState:
   std::vector<AllocInfo> &FState = ExportedFnAllocState[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, Instr);
-  //int VO = getSavedStateIndexOfOperandInInstruction (F, V, VI);
-  // Retrieve the AllocInfo for V by searching FState for a tuple that starts
-  // with (VI, VO, ...):
+  int InstructionKey = -1, OperandKey = -1;
+  if (Argument *A = dyn_cast<Argument> (V)) {
+    // Find the alloc state of an argument.
+    OperandKey = getNumberOfFunctionArg (F, A);
+  } else {
+    // 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:
+    Instruction *Instr = cast<Instruction> (V);
+    InstructionKey = getSavedStateIndexOfInstruction (F, Instr);
+  }
+  // Reconstruct the AllocInfo for V by searching
+  // FState for a tuple that starts with (InstructionKey, OperandKey, ...):
   for (unsigned i = 0, s = FState.size (); i < s; ++i) {
     AllocInfo &T = FState[i];
-    if (T.Instruction == VI && T.Operand == 0)
+    if (T.Instruction == InstructionKey && T.Operand == OperandKey)
       return T;
   }
   // By this time we had better have found it, otherwise we are about to do bad
@@ -250,6 +261,7 @@
   abort ();
 }
 
+
 } // end namespace llvm
 
 ///------------------End SPARC register allocator-specific code -------------///
@@ -310,26 +322,33 @@
   if (MF.getFunction () != TF->TraceFn)
     return false;
 
+  DEBUG(std::cerr << "In UnpackTraceFunction for " << MF.getFunction()->getName() << "()\n");
+
   Function *TraceF = TF->TraceFn, *MatrixF = TF->MatrixFn;
   LiveVariableSet &Si = TF->LiveInSet, &So = TF->LiveOutSet;
 
   // Modify ENTRY MachineBasicBlock of MF
   MachineBasicBlock &E = MF.front (); // E = Entry MBB of MF
   std::vector<CopyInfo> EntryCopies;
+  DEBUG(std::cerr << "UnpackTraceFunction: Modifying entry BB\n");
   for (LiveVariableSet::iterator SI = Si.begin (), SE = Si.end (); SI != SE;
        ++SI) {
     // Insert copies from each live-in variable's reg. in the matrix fn.
     // to its reg. in the trace.
     Value *V = *SI;
+    DEBUG(std::cerr << "UnpackTraceFunction: Looking for alloc state for value: \n" << *V << "\n");
     AllocInfo Source = getValueAllocStateFromModule (MatrixF, V);
+    DEBUG(std::cerr << "UnpackTraceFunction: Source = " << Source << "\n");
     AllocInfo Target = getValueAllocStateFromGlobal (TraceF, V);
+    DEBUG(std::cerr << "UnpackTraceFunction: Target = " << Target << "\n");
     if (Source != Target)
       EntryCopies.push_back (CopyInfo (Source, Target, &E, V->getType ()));
   }
 
+  DEBUG(std::cerr << "UnpackTraceFunction: Inserting copy MachineInstrs:\n");
   for (std::vector<CopyInfo>::iterator i = EntryCopies.begin (),
          e = EntryCopies.end (); i != e; ++i) {
-    DEBUG(std::cerr << *i);
+    DEBUG(std::cerr << "UnpackTraceFunction: " << *i);
     SRI.insertCopyMachineInstrs (i->Src, i->Targ, *i->Blk, i->Ty);
   }
 
@@ -341,11 +360,11 @@
       // code for the MachineBasicBlock in MatrixF that RI would have
       // returned to. Find it by using MappingInfo.
       BasicBlock *RBB = const_cast<BasicBlock *> (MBB.getBasicBlock ());
-      assert ((ReturnBlockForTraceExit.find (RBB) !=
-               ReturnBlockForTraceExit.end ())
+      assert ((TF->ReturnBlockForTraceExit.find (RBB) !=
+               TF->ReturnBlockForTraceExit.end ())
               && "Can't find matrix fn BB address to return to from trace");
       uint64_t ReturnAddress = 
-        getBasicBlockInfo(ReturnBlockForTraceExit[RBB]).first;
+        getBasicBlockInfo(TF->ReturnBlockForTraceExit[RBB]).first;
       // Erase the contents of MBB.
       while (!MBB.empty ()) {
         MachineBasicBlock::iterator MBBI = MBB.begin ();





More information about the llvm-commits mailing list