[llvm-commits] CVS: reopt/tools/ttftest/ttftest.cpp

Brian Gaeke gaeke at cs.uiuc.edu
Tue May 18 11:52:01 PDT 2004


Changes in directory reopt/tools/ttftest:

ttftest.cpp updated: 1.1 -> 1.2

---
Log message:

Write out traces to files when they are loaded, for testing purposes.


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

Index: reopt/tools/ttftest/ttftest.cpp
diff -u reopt/tools/ttftest/ttftest.cpp:1.1 reopt/tools/ttftest/ttftest.cpp:1.2
--- reopt/tools/ttftest/ttftest.cpp:1.1	Mon May 17 16:25:25 2004
+++ reopt/tools/ttftest/ttftest.cpp	Tue May 18 11:51:30 2004
@@ -19,6 +19,8 @@
 #include "llvm/Bytecode/Reader.h"
 #include "reopt/TraceToFunction.h"
 #include "llvm/Module.h"
+#include "Support/FileUtilities.h"
+#include "Support/StringExtras.h"
 #include <iostream>
 #include <iterator>
 #include <fstream>
@@ -34,6 +36,7 @@
   return block;
 }
 
+
 /// ReadTraceFromFile - Given a module, read a trace for some function
 /// in that module from the named file. Returns the Trace object, or a null
 /// pointer (and sets ErrorStr) if there was an error.
@@ -70,6 +73,36 @@
   return new Trace (vBB);
 }
 
+
+/// getBasicBlockIndex - Returns the index of BB in its parent function.
+///
+int getBasicBlockIndex (BasicBlock *BB) {
+  int bbNum = 0;
+  Function *F = BB->getParent ();
+  Function::iterator block = F->begin();
+  while (&*block != BB) {
+    ++block;
+    ++bbNum;
+  }
+  return bbNum;
+}
+
+void WriteTraceToFile (Trace &T) {
+  std::string filename; 
+  unsigned count = 0;
+  do {
+    ++count;
+    filename = T.getFunction ()->getName () + ".trace" + utostr (count)
+             + ".txt";
+  } while (FileOpenable(filename));
+  std::ofstream out (filename.c_str ());
+  out << T.getFunction ()->getName () << "\n";
+  for (Trace::iterator i = T.begin (), e = T.end (); i != e; ++i) 
+    out << getBasicBlockIndex (*i) << " ";
+  out << "\n";
+  out.close ();
+}
+
 int main (int argc, char **argv) {
   const char *bytecodeFileName = argv[1];
   const char *traceFileName = argv[2];
@@ -89,6 +122,7 @@
     std::cerr << "Error reading trace: " << err << "\n";
     exit (1);
   }
+  WriteTraceToFile (*T);
 
   // Run TraceToFunction on the Trace
   TraceFunction *TF = TraceFunction::get (*T);





More information about the llvm-commits mailing list