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

Brian Gaeke gaeke at cs.uiuc.edu
Tue Jul 6 21:21:18 PDT 2004


Changes in directory reopt/lib/TraceToFunction:

TraceToFunction.cpp updated: 1.68 -> 1.69

---
Log message:

Make LiveIn, LiveOut, and AlternateEntryPoint vectors that exist in
parallel with the sets.  The idea is to gradually reduce dependence on
the sets and use the vectors instead.


---
Diffs of the changes:  (+54 -40)

Index: reopt/lib/TraceToFunction/TraceToFunction.cpp
diff -u reopt/lib/TraceToFunction/TraceToFunction.cpp:1.68 reopt/lib/TraceToFunction/TraceToFunction.cpp:1.69
--- reopt/lib/TraceToFunction/TraceToFunction.cpp:1.68	Wed Jun 23 16:41:34 2004
+++ reopt/lib/TraceToFunction/TraceToFunction.cpp	Tue Jul  6 21:19:51 2004
@@ -52,8 +52,11 @@
   BranchNumberMap BranchNumber;
   TraceFunction *TF;
   std::set<BasicBlock *> AlternateEntryPoints;
-  void getTraceLiveInSet (LiveVariableSet &S, Trace &T);
-  void getTraceLiveOutSet (LiveVariableSet &S, Trace &T);
+  std::vector<BasicBlock *> AlternateEntryPointsV;
+  void getTraceLiveInSet (LiveVariableSet &S, LiveVariableVector &LVV,
+                          Trace &T);
+  void getTraceLiveOutSet (LiveVariableSet &S, LiveVariableVector &LVV,
+                           Trace &T);
 
   FLIMapTy FLIMap;
   BasicBlock *getFLIEdgeSource (BasicBlock *BB) const;
@@ -62,12 +65,12 @@
   void buildFLIMap (Trace &T, FLIMapTy &FLIMap);
 
   TypeVector createFunctionArgTypeVector (PointerType *ST,
-                                          const LiveVariableSet &S);
-  void fillInFunctionBody (Trace &T, Function *F, LiveVariableSet &So);
+                                          const LiveVariableVector &S);
+  void fillInFunctionBody (Trace &T, Function *F, LiveVariableVector &So);
   int findOffTracePhiSource (const PHINode *newPN);
   void fixupFunctionBodyBB (Trace &T, Function *F, BasicBlock *srcB,
                             BasicBlock *dstB, ValueMap &O2CMap,
-                            LiveVariableSet &So);
+                            LiveVariableVector &So);
 
   void cloneMapDump ();
 public:
@@ -170,17 +173,28 @@
   return true;
 }
 
+static void insert (LiveVariableSet &Set, LiveVariableVector &Vector, Value *V){
+  Set.insert (V);
+  if (std::find (Vector.begin (), Vector.end (), V) == Vector.end ())
+    Vector.push_back (V);
+}
+static void insert (std::set<BasicBlock *> &Set, std::vector<BasicBlock *> &Vector, BasicBlock *V){
+  Set.insert (V);
+  if (std::find (Vector.begin (), Vector.end (), V) == Vector.end ())
+    Vector.push_back (V);
+}
+
 /// addTraceLiveInsToSet - helper fn. for getTraceLiveInSet and
 /// getTraceLiveOutSet. Adds the live-ins of T to S, assuming that
 /// the trace starts at StartingFrom and ends at T.end().
-static void addTraceLiveInsToSet (LiveVariableSet &S, Trace &T,
-                                  Trace::iterator StartingFrom) {
+static void addTraceLiveInsToSet (LiveVariableSet &S, LiveVariableVector &LVV,
+                                  Trace &T, Trace::iterator StartingFrom) {
   for (Trace::iterator TI = StartingFrom, TE = T.end (); TI != TE; ++TI)
     for (BasicBlock::iterator Inst = (*TI)->begin (), BE = (*TI)->end ();
          Inst != BE; ++Inst) {
       if (PHINode *PN = dyn_cast<PHINode> (Inst)) {
         if (TI == StartingFrom) {
-          S.insert (Inst); // Add phis from first BB
+          insert(S, LVV, Inst); // Add phis from first BB
         } else {
           // Phi node internal to trace
           DEBUG (std::cerr << "TLV: considering Phi internal to trace: " << Inst->getName () << "\n");
@@ -193,7 +207,7 @@
                     || isa<BasicBlock>(V))) {
                 DEBUG (std::cerr << "TLV: considering Phi source which is on-trace: " << InB->getName () << " with value " << V->getName () << "\n");
                 if (!DefinedInTraceBeforeUse (V, T, StartingFrom, true))
-                  S.insert (V);
+                  insert (S, LVV, V);
               }
             }
           }
@@ -206,7 +220,7 @@
         if (!(isa<Constant> (V) || isa<GlobalValue> (V)
               || isa<BasicBlock>(V)))
           if (!DefinedInTraceBeforeUse (V, T, StartingFrom, true))
-            S.insert (V);
+            insert (S, LVV, V);
       }
     }
 }
@@ -216,8 +230,8 @@
 /// EXCEPT if it's a constant or a global, OR it is defined before being used
 /// in the trace.
 ///
-void TraceFunctionBuilder::getTraceLiveInSet (LiveVariableSet &S, Trace &T) {
-  addTraceLiveInsToSet (S, T, T.begin ());
+void TraceFunctionBuilder::getTraceLiveInSet (LiveVariableSet &S, LiveVariableVector &LVV, Trace &T) {
+  addTraceLiveInsToSet (S, LVV, T, T.begin ());
 }
 
 /// getTraceLiveOutSet - Initializes S with the live-out set of trace T.
@@ -227,7 +241,7 @@
 /// to the NON-traced version of the code caused by early exits that end up
 /// taking back-edge branches.
 ///
-void TraceFunctionBuilder::getTraceLiveOutSet (LiveVariableSet &S, Trace &T) {
+void TraceFunctionBuilder::getTraceLiveOutSet (LiveVariableSet &S, LiveVariableVector &LVV, Trace &T) {
   // Iterate over the instructions in the trace, adding live-out values to S.
   for (Trace::iterator TI = T.begin (), TE = T.end (); TI != TE; ++TI)
     for (BasicBlock::iterator Inst = (*TI)->begin (), BE = (*TI)->end ();
@@ -236,18 +250,18 @@
       if (!(Inst->getType () == Type::VoidTy
             || Inst->getType () == Type::LabelTy))
         if (!DefinedInTraceBeforeUse (Inst, T, T.begin (), false))
-          S.insert (Inst);
+          insert (S, LVV, Inst);
     }
 
   // If there are alternate entry points into the trace, their live-INs are
   // live-OUT from the main trace.
   if (!AlternateEntryPoints.empty ()) {
-    for (std::set<BasicBlock *>::iterator i = AlternateEntryPoints.begin (),
-         e = AlternateEntryPoints.end (); i != e; ++i) {
+    for (std::vector<BasicBlock *>::iterator i = AlternateEntryPointsV.begin (),
+         e = AlternateEntryPointsV.end (); i != e; ++i) {
       // Find the position of the block in the trace.
       Trace::iterator StartingFrom = std::find (T.begin (), T.end (), *i);
       assert (StartingFrom != T.end () && "AlternateEntryPoint not on trace?!");
-      addTraceLiveInsToSet (S, T, StartingFrom);
+      addTraceLiveInsToSet (S, LVV, T, StartingFrom);
     }
   }
 }
@@ -270,13 +284,13 @@
 /// createLiveOutType - Given the live-out set S of a trace, create a
 /// pointer-to-structure type that will encapsulate all the live-outs from S.
 ///
-static PointerType *createLiveOutType (const LiveVariableSet &S) {
+static PointerType *createLiveOutType (const LiveVariableVector &LVV) {
   TypeVector T;
   unsigned Counter = 0;
   // For each variable in S, make a new entry in T having its type.
   DEBUG (std::cerr << "Live-out values:\n");
-  for (LiveVariableSet::const_iterator I = S.begin (), E = S.end (); I != E;
-       ++I) {
+  for (LiveVariableVector::const_iterator I = LVV.begin (), E = LVV.end ();
+       I != E; ++I) {
     DEBUG (WriteAsOperand (std::cerr, *I, true, true,
                            cast<Instruction>(*I)->getParent ()->getParent ()
                              ->getParent ());
@@ -286,20 +300,20 @@
   return PointerType::get (StructType::get (T));
 }
 
-/// createFunctionArgTypeVector - Given the live-in set S of a trace,
+/// createFunctionArgTypeVector - Given the live-in vector LVV of a trace,
 /// create a parameter list containing a parameter for each of the
-/// variables in S as well as a pointer-to-structure type PST to fill
+/// 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.
 ///
 TypeVector TraceFunctionBuilder::createFunctionArgTypeVector (PointerType *PST,
-                                                     const LiveVariableSet &S) {
+                                                const LiveVariableVector &LVV) {
   TypeVector P;
   P.push_back (PST);
 
   TF->LiveInToParameterMap.clear ();
-  for (LiveVariableSet::const_iterator I = S.begin (), E = S.end (); I != E;
+  for (LiveVariableVector::const_iterator I = LVV.begin (), E = LVV.end (); I != E;
        ++I) {
     Value *V = *I;
     P.push_back (V->getType ());
@@ -317,10 +331,9 @@
 }
 
 /// giveNamesToFunctionArgs - Name the first argument of F "liveOut",
-/// then use the ordering imposed by S's iterator to name the
-/// remaining arguments of F.
+/// then name the remaining arguments of F according to LVV.
 ///
-static void giveNamesToFunctionArgs (LiveVariableSet S, Function *F) {
+static void giveNamesToFunctionArgs (LiveVariableVector LVV, Function *F) {
   Function::aiterator argIterator = F->abegin ();
   unsigned argPosition = 0;
 
@@ -328,7 +341,8 @@
   ++argPosition;
   ++argIterator;
   
-  for (LiveVariableSet::iterator I = S.begin (), E = S.end (); I != E; ++I) {
+  for (LiveVariableVector::iterator I = LVV.begin (), E = LVV.end (); I != E;
+       ++I) {
     std::string name ((*I)->getName ());
     if (name == "")
       name = "arg" + utostr (argPosition);
@@ -358,7 +372,7 @@
 ///
 static void cloneTraceBBsIntoFunction (TraceFunction *TF) {
   Function *MF = TF->MatrixFn;
-  LiveVariableSet &Si = TF->LiveInSet;
+  LiveVariableVector &Si = TF->LiveInVector;
   ValueMap &O2CMap = TF->O2CMap;
   for (Function::aiterator AI = MF->abegin (), AE = MF->aend (); AI != AE; ++AI)
     O2CMap[AI] = AI;
@@ -369,7 +383,7 @@
            ++BI)
         O2CMap[BI] = BI;
     }
-  for (LiveVariableSet::iterator I = Si.begin (), E = Si.end (); I != E; ++I)
+  for (LiveVariableVector::iterator I = Si.begin (), E = Si.end (); I != E; ++I)
     O2CMap[*I] = getFunctionArg (TF->TraceFn, TF->LiveInToParameterMap[*I]);
   CloneTraceInto (TF->TraceFn, TF->T, O2CMap, ".ttf");
 }
@@ -461,7 +475,7 @@
 /// argument.
 ///
 void TraceFunctionBuilder::fillInFunctionBody (Trace &T, Function *F,
-                                               LiveVariableSet &So) {
+                                               LiveVariableVector &So) {
   // First copy the basic blocks from the trace.
   cloneTraceBBsIntoFunction (TF);
 
@@ -570,7 +584,7 @@
       if (T.contains (edge.second) && edge.second != T.getEntryBasicBlock ()) {
         DEBUG (std::cerr << "buildFLIMap: " << edge.second->getName()
                << " is a back-edge target that's internal to the trace\n");
-        AlternateEntryPoints.insert (edge.second);
+        insert (AlternateEntryPoints, AlternateEntryPointsV, edge.second);
       }
       // 1. remove the block from the trace if it is in there
       BasicBlock *bb = i;
@@ -623,7 +637,7 @@
                                                 BasicBlock *srcB,
                                                 BasicBlock *dstB,
                                                 ValueMap &O2CMap,
-                                                LiveVariableSet &So) {
+                                                LiveVariableVector &So) {
   assert (T.contains (srcB) && "Source BB is not on the trace");
   assert (dstB->getParent () == F && "Clone is not in the function");
   
@@ -707,7 +721,7 @@
         // Add the getelementptr/store instruction pairs here that
         // correspond to each live-out variable.
         unsigned Slot = 0;
-        for (LiveVariableSet::iterator SI = So.begin (), SE = So.end ();
+        for (LiveVariableVector::iterator SI = So.begin (), SE = So.end ();
              SI != SE; ++SI) {
           if (dominates (T, cast<Instruction> ((*SI))->getParent (),
                          BI->getParent ())) {
@@ -822,11 +836,11 @@
 
   // Get some information about the trace's relationship to its parent
   // function.
-  getTraceLiveInSet (TF->LiveInSet, T);
-  getTraceLiveOutSet (TF->LiveOutSet, T);
+  getTraceLiveInSet (TF->LiveInSet, TF->LiveInVector, T);
+  getTraceLiveOutSet (TF->LiveOutSet, TF->LiveOutVector, T);
   TypeVector P =
-    createFunctionArgTypeVector (createLiveOutType (TF->LiveOutSet),
-                                 TF->LiveInSet);
+    createFunctionArgTypeVector (createLiveOutType (TF->LiveOutVector),
+                                 TF->LiveInVector);
 
   // Make a new internal Function with return type int and parameter
   // list P, in the same Module as the trace's parent function.
@@ -834,8 +848,8 @@
   TF->TraceFn = new Function (FunctionType::get (Type::UIntTy, P, false),
                               GlobalValue::InternalLinkage, name,
                               T.getModule ());
-  DEBUG(giveNamesToFunctionArgs (TF->LiveInSet, TF->TraceFn));
-  fillInFunctionBody (T, TF->TraceFn, TF->LiveOutSet);
+  DEBUG(giveNamesToFunctionArgs (TF->LiveInVector, TF->TraceFn));
+  fillInFunctionBody (T, TF->TraceFn, TF->LiveOutVector);
   return TF;
 }
 





More information about the llvm-commits mailing list