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

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


Changes in directory reopt/lib/LightWtProfiling:

RuntimeOptimizations.cpp updated: 1.32 -> 1.33

---
Log message:

Write out traces to files when they are detected, for use with ttftest.


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

Index: reopt/lib/LightWtProfiling/RuntimeOptimizations.cpp
diff -u reopt/lib/LightWtProfiling/RuntimeOptimizations.cpp:1.32 reopt/lib/LightWtProfiling/RuntimeOptimizations.cpp:1.33
--- reopt/lib/LightWtProfiling/RuntimeOptimizations.cpp:1.32	Mon May 17 16:00:19 2004
+++ reopt/lib/LightWtProfiling/RuntimeOptimizations.cpp	Tue May 18 11:51:28 2004
@@ -19,6 +19,7 @@
 #include "reopt/InstrUtils.h"
 #include "Support/Debug.h"
 #include "Support/StringExtras.h"
+#include "Support/FileUtilities.h"
 #include "llvm/Analysis/Verifier.h"
 #include "llvm/Assembly/PrintModulePass.h"
 #include "llvm/CodeGen/MachineFunction.h"
@@ -31,6 +32,7 @@
 #include "llvm/Target/TargetMachine.h"
 #include "llvm/Target/TargetData.h"
 #include "llvm/Target/TargetMachineImpls.h"
+#include <fstream>
 
 namespace llvm {
 
@@ -65,6 +67,35 @@
 
 ///==----------------------------------------------------------------------==///
 
+/// 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 ();
+}   
+
 /// This method is called when we have finally constructed a
 /// trace. The first parameter is the vector of basic blocks that form
 /// the trace; the second parameter is the starting
@@ -89,6 +120,7 @@
   // Turn the vector of basic blocks into a Trace, and then turn the Trace into
   // a TraceFunction.
   Trace T (vBB);
+  WriteTraceToFile (T);
   TraceFunction *TF = TraceFunction::get (T);
 
   // Force the SPARCv9 register allocator to save its state into a global





More information about the llvm-commits mailing list