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

Brian Gaeke gaeke at cs.uiuc.edu
Wed Jul 7 14:12:02 PDT 2004


Changes in directory reopt/lib/TraceToFunction:

TraceToFunction.cpp updated: 1.71 -> 1.72

---
Log message:

Replace LiveInToParameterMap with LiveInToArgMap (which maps live-in values
directly to the Argument*s that represent them.)
Make giveNamesToFunctionArgs a member of TraceFunctionBuilder.  Make it
do the job of printing out live-in values and filling in
LiveInToArgMap. (Calling it is now therefore no longer optional.)
Simplify createFunctionArgTypeVector.


---
Diffs of the changes:  (+28 -29)

Index: reopt/lib/TraceToFunction/TraceToFunction.cpp
diff -u reopt/lib/TraceToFunction/TraceToFunction.cpp:1.71 reopt/lib/TraceToFunction/TraceToFunction.cpp:1.72
--- reopt/lib/TraceToFunction/TraceToFunction.cpp:1.71	Wed Jul  7 01:47:15 2004
+++ reopt/lib/TraceToFunction/TraceToFunction.cpp	Wed Jul  7 14:11:25 2004
@@ -24,6 +24,7 @@
 #include "llvm/Transforms/Utils/Cloning.h"
 #include "llvm/Pass.h"
 #include "llvm/Module.h"
+#include "llvm/Argument.h"
 #include "llvm/DerivedTypes.h"
 #include "llvm/iTerminators.h"
 #include "llvm/iPHINode.h"
@@ -69,6 +70,7 @@
 
   TypeVector createFunctionArgTypeVector (PointerType *ST,
                                           const LiveVariableVector &S);
+  void giveNamesToFunctionArgs (LiveVariableVector LVV, Function *F);
   void fillInFunctionBody (Trace &T, Function *F, LiveVariableVector &So);
   int findOffTracePhiSource (const PHINode *newPN);
   void fixupFunctionBodyBB (Trace &T, Function *F, BasicBlock *srcB,
@@ -301,50 +303,47 @@
 /// createFunctionArgTypeVector - Given the live-in vector LVV of a trace,
 /// create a parameter list containing a parameter for each of the
 /// variables in LVV as well as a pointer-to-structure type PST to fill
-/// in which contains the live-outs. As a side effect, fill in the
-/// mapping between live-ins and parameters in
-/// TF->LiveInToParameterMap.
+/// in which contains the live-outs.
 ///
 TypeVector TraceFunctionBuilder::createFunctionArgTypeVector (PointerType *PST,
                                                 const LiveVariableVector &LVV) {
   TypeVector P;
   P.push_back (PST);
-
-  TF->LiveInToParameterMap.clear ();
-  for (LiveVariableVector::const_iterator I = LVV.begin (), E = LVV.end (); I != E;
-       ++I) {
-    Value *V = *I;
-    P.push_back (V->getType ());
-    TF->LiveInToParameterMap[V] = P.size () - 1;
-  }
-  // Print out mapping of instructions producing live-ins to arg numbers.
-  DEBUG(std::cerr << "\nLive-in values:\n";
-        for (ValueToIntMap::iterator I = TF->LiveInToParameterMap.begin (),
-             E = TF->LiveInToParameterMap.end (); I != E; ++I) {
-          WriteAsOperand (std::cerr, I->first, true, true,
-            TF->MatrixFn->getParent ());
-          std::cerr << " is parameter " << I->second << "\n";
-        });
+  for (LiveVariableVector::const_iterator I = LVV.begin (), E = LVV.end ();
+       I != E; ++I)
+    P.push_back ((*I)->getType ());
   return P;
 }
 
 /// giveNamesToFunctionArgs - Name the first argument of F "liveOut",
-/// then name the remaining arguments of F according to LVV.
+/// then name the remaining arguments of F according to LVV. As a
+/// side effect, fills in the mapping between live-ins and arguments in
+/// TF->LiveInToArgMap.
 ///
-static void giveNamesToFunctionArgs (LiveVariableVector LVV, Function *F) {
+void TraceFunctionBuilder::giveNamesToFunctionArgs (LiveVariableVector LVV,
+                                                    Function *F) {
   Function::aiterator argIterator = F->abegin ();
   unsigned argPosition = 0;
 
   argIterator->setName ("liveOut"); // Arg 0 is always the live-out struct.
   ++argPosition;
   ++argIterator;
-  
+
+  // Fill in & print out mapping of instructions producing live-ins to
+  // args, and set arg names.
+  std::cerr << "\nLive-in values:\n";
   for (LiveVariableVector::iterator I = LVV.begin (), E = LVV.end (); I != E;
        ++I) {
-    std::string name ((*I)->getName ());
+    Value *V = *I;
+    WriteAsOperand (std::cerr, *I, true, true, TF->MatrixFn->getParent ());
+    std::cerr << " is argument # " << argPosition << " (%";
+    TF->LiveInToArgMap[V] = &*argIterator;
+
+    std::string name (V->getName ());
     if (name == "")
       name = "arg" + utostr (argPosition);
     argIterator->setName ("liveIn." + name);
+    std::cerr << argIterator->getName () << ")\n";
     ++argPosition;
     ++argIterator;
   }
@@ -382,7 +381,7 @@
         O2CMap[BI] = BI;
     }
   for (LiveVariableVector::iterator I = Si.begin (), E = Si.end (); I != E; ++I)
-    O2CMap[*I] = getFunctionArg (TF->TraceFn, TF->LiveInToParameterMap[*I]);
+    O2CMap[*I] = TF->LiveInToArgMap[*I];
   CloneTraceInto (TF->TraceFn, TF->T, O2CMap, ".ttf");
 }
 
@@ -659,8 +658,6 @@
          PHINode *oldPN = dyn_cast<PHINode> (BI); ++BI) {
       assert (LiveInSet.find (oldPN) != LiveInSet.end ()
               && "Phi nodes in trace entry BB must be live-in");
-      Argument *phiLiveIn = getFunctionArg (F,
-                                            TF->LiveInToParameterMap [oldPN]);
       
       Value *V = O2CMap[oldPN];
       assert (V && isa<PHINode> (V)
@@ -682,8 +679,10 @@
                << "'s off-trace source #" << i << "\n");
         newPN->removeIncomingValue (i);
       }
-      if (foundOffTracePhiSource)
+      if (foundOffTracePhiSource) {
+        Value *phiLiveIn = TF->LiveInToArgMap [oldPN];
         newPN->addIncoming (phiLiveIn, EntryFixup);
+      }
     }
   }
   
@@ -730,7 +729,7 @@
             Index.push_back (Constant::getNullValue (Type::LongTy));  //long 0
             Index.push_back (ConstantUInt::get (Type::UIntTy, Slot));//uint Slot
             GetElementPtrInst *GEP =
-              new GetElementPtrInst (getFunctionArg (F, 0), Index,
+              new GetElementPtrInst (&*F->abegin (), Index,
                                      "liveOutP" + utostr (BranchNumber[BI])
                                      + "_" + utostr (i) + "_" + utostr (Slot));
             FB->getInstList ().push_back (GEP);
@@ -849,7 +848,7 @@
   TF->TraceFn = new Function (FunctionType::get (Type::UIntTy, P, false),
                               GlobalValue::InternalLinkage, name,
                               T.getModule ());
-  DEBUG(giveNamesToFunctionArgs (TF->LiveInVector, TF->TraceFn));
+  giveNamesToFunctionArgs (TF->LiveInVector, TF->TraceFn);
   fillInFunctionBody (T, TF->TraceFn, TF->LiveOutVector);
   return TF;
 }





More information about the llvm-commits mailing list