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

Brian Gaeke gaeke at cs.uiuc.edu
Wed Mar 31 10:31:01 PST 2004


Changes in directory reopt/lib/LightWtProfiling:

TraceToFunction.cpp updated: 1.27 -> 1.28

---
Log message:

Use WriteAsOperand in many places to make debug output shorter and faster.
Fix a bug where live-outs would sometimes be stored into the wrong slot (which
might lead to invalid llvm code if the types didn't match).


---
Diffs of the changes:  (+32 -20)

Index: reopt/lib/LightWtProfiling/TraceToFunction.cpp
diff -u reopt/lib/LightWtProfiling/TraceToFunction.cpp:1.27 reopt/lib/LightWtProfiling/TraceToFunction.cpp:1.28
--- reopt/lib/LightWtProfiling/TraceToFunction.cpp:1.27	Thu Mar 11 13:55:15 2004
+++ reopt/lib/LightWtProfiling/TraceToFunction.cpp	Wed Mar 31 10:29:51 2004
@@ -37,6 +37,7 @@
 #include "llvm/iMemory.h"
 #include "llvm/iOther.h"
 #include "llvm/Constants.h"
+#include "llvm/Assembly/Writer.h"
 #include "llvm/Support/CFG.h"      // for succ_iterator, etc.
 #include "Support/StringExtras.h"  // for utostr()
 #define DEBUG_TYPE "tracetofunction"
@@ -219,8 +220,11 @@
   }
   // Print out mapping of instructions to arg numbers.
   DEBUG(for (ValueToIntMap::iterator I = TF->LiveInToParameterMap.begin (),
-	       E = TF->LiveInToParameterMap.end (); I != E; ++I)
-	  std::cerr << I->first << " is parameter " << I->second << "\n");
+	       E = TF->LiveInToParameterMap.end (); I != E; ++I) {
+          WriteAsOperand (std::cerr, I->first, true, true,
+            TF->MatrixFn->getParent ());
+          std::cerr << " is parameter " << I->second << "\n";
+        });
   return P;
 }
 
@@ -463,16 +467,18 @@
 	unsigned Slot = 0;
 	for (LiveVariableSet::iterator SI = So.begin (), SE = So.end ();
 	     SI != SE; ++SI) {
-          if (!T.dominates (cast<Instruction> ((*SI))->getParent (), BI->getParent ())) continue;
-	  std::vector<Value *> Index;
-	  Index.push_back (Constant::getNullValue (Type::LongTy));  //long 0
-	  Index.push_back (ConstantUInt::get (Type::UByteTy, Slot));//ubyte Slot
-	  GetElementPtrInst *GEP =
-	    new GetElementPtrInst (getFunctionArg (F, 0), Index,
-				   "liveOutP" + utostr (BranchNumber[BI])
-				   + "_" + utostr (i) + "_" + utostr (Slot));
-	  FB->getInstList ().push_back (GEP);
-	  FB->getInstList ().push_back (new StoreInst (O2CMap[*SI], GEP));
+      if (T.dominates (cast<Instruction> ((*SI))->getParent (),
+                        BI->getParent ())) {
+	    std::vector<Value *> Index;
+	    Index.push_back (Constant::getNullValue (Type::LongTy));  //long 0
+	    Index.push_back (ConstantUInt::get (Type::UByteTy, Slot));//ubyte Slot
+	    GetElementPtrInst *GEP =
+	      new GetElementPtrInst (getFunctionArg (F, 0), Index,
+				     "liveOutP" + utostr (BranchNumber[BI])
+				     + "_" + utostr (i) + "_" + utostr (Slot));
+	    FB->getInstList ().push_back (GEP);
+	    FB->getInstList ().push_back (new StoreInst (O2CMap[*SI], GEP));
+      }
 	  ++Slot;
 	}
 	// Make FB contain a return instruction that returns the
@@ -511,10 +517,11 @@
       // the corresponding argument of F. We can find out which
       // operands to replace by looking them up in
       // TF->LiveInToParameterMap.
-      if (TF->LiveInToParameterMap.find (V) != TF->LiveInToParameterMap.end ()) {
-	DEBUG(std::cerr << *V << " in instruction " << I
-	      << " is argument " << TF->LiveInToParameterMap[V]
-	      << " in new function\n");
+      if (TF->LiveInToParameterMap.find (V) != TF->LiveInToParameterMap.end ()){
+        DEBUG(WriteAsOperand (std::cerr, V, true, true,
+                              TF->MatrixFn->getParent ());
+              std::cerr << " in instruction:\n " << I << " is argument "
+                        << TF->LiveInToParameterMap[V] << " in new function\n");
 	assert (V->getType () ==
 		getFunctionArg (F, TF->LiveInToParameterMap[V])->getType ()
 		&& "Live-in Value's type doesn't match corresponding arg type");
@@ -551,13 +558,18 @@
 /// Dump out the O2CMap for the given TraceFunction to stderr.
 /// Only called when debugging.
 ///
-static void cloneMapDump (TraceFunction *TF) {
+static void cloneMapDump (TraceFunction *TF, std::ostream &OS) {
+  OS << "\n; TraceToFunction Original-->Clone map follows:\n";
   for (ValueMap::const_iterator i = TF->O2CMap.begin(), e = TF->O2CMap.end();
        i != e; ++i) {
     const std::pair<const Value *, Value *> &elem = *i;
-    std::cerr << "Original value:  " << i->first << "\nmaps to:  "
-              << i->second << "\n";
+    OS << "(original-value \"";
+    WriteAsOperand (OS, i->first, true, true, TF->MatrixFn->getParent ());
+    OS << "\" maps-to \"";
+    WriteAsOperand (OS, i->second, true, true, TF->TraceFn->getParent ());
+    OS << "\")\n";
   }
+  OS << "\n";
 }
 
 TraceFunction *TraceToFunction::traceToFunction (Trace &T) {
@@ -585,7 +597,7 @@
   DEBUG(giveNamesToFunctionArgs (TF->LiveInSet, TF->TraceFn));
   fillInFunctionBody (T, TF->TraceFn, TF->LiveOutSet);
   
-  DEBUG(cloneMapDump(TF));
+  DEBUG(cloneMapDump(TF, std::cerr));
   return TF;
 }
 





More information about the llvm-commits mailing list