[llvm-commits] CVS: llvm/lib/Reoptimizer/LightWtProfiling/Trigger/Trace.h

Brian Gaeke gaeke at cs.uiuc.edu
Tue Aug 19 13:20:08 PDT 2003


Changes in directory llvm/lib/Reoptimizer/LightWtProfiling/Trigger:

Trace.h updated: 1.1 -> 1.2

---
Log message:

Many changes suggested by Chris.

Much better head of file comment.
Don't include <iostream>; include <iosfwd> instead. Don't declare
 Module forward.
Don't explicitly record the pointer to the first BasicBlock's parent
 Function (and don't make it an argument to the constructor.)
Make the BasicBlockListType private.
Constify many methods.
Move print() out of line.
Add dump().
Add operator [] and getBlock ().


---
Diffs of the changes:

Index: llvm/lib/Reoptimizer/LightWtProfiling/Trigger/Trace.h
diff -u llvm/lib/Reoptimizer/LightWtProfiling/Trigger/Trace.h:1.1 llvm/lib/Reoptimizer/LightWtProfiling/Trigger/Trace.h:1.2
--- llvm/lib/Reoptimizer/LightWtProfiling/Trigger/Trace.h:1.1	Fri Aug 15 19:14:07 2003
+++ llvm/lib/Reoptimizer/LightWtProfiling/Trigger/Trace.h	Tue Aug 19 13:18:46 2003
@@ -1,76 +1,60 @@
 //===- Trace.h - Wrapper class for traces ------------------------*- C++ -*--=//
 //
-// Encapsulates vectors of BasicBlocks as traces.
+// Represents the sequence of basic blocks (generally associated with some
+// enclosing function) which make up a trace.
 //
 //===----------------------------------------------------------------------===//
 
 #include "llvm/Function.h"
-#include <iostream>
-class Module;
+#include <iosfwd>
 
 #ifndef TRACE_H
 #define TRACE_H
 
 class Trace {
-  /// Function in which this Trace starts.
-  ///
-  Function *F;
-
-public:
   typedef std::vector<BasicBlock *> BasicBlockListType;
   BasicBlockListType BasicBlocks;
 
-  /// getEntryBasicBlock - Return the entry basic block (first block)
-  /// of the trace.
-  ///
-  inline BasicBlock *getEntryBasicBlock () { return BasicBlocks[0]; }
-
+public:
   /// contains - Returns true if this trace contains the given basic
   /// block.
   ///
   inline bool contains (const BasicBlock *X) {
-    return std::find(BasicBlocks.begin(), BasicBlocks.end(), X)
-      != BasicBlocks.end();
+    return std::find (BasicBlocks.begin (), BasicBlocks.end (), X)
+      != BasicBlocks.end ();
   }
 
-  /// Trace ctor - make new Trace from vector of basic blocks, residing
-  /// in given function.
+  /// Trace ctor - Make a new trace from a vector of basic blocks,
+  /// residing in the function which is the parent of the first
+  /// basic block in the vector.
   ///
-  Trace(Function *F_, std::vector<BasicBlock *> vBB) :
-    F(F_), BasicBlocks(vBB) {
+  Trace (const std::vector<BasicBlock *> &vBB) : BasicBlocks (vBB) {
   }
 
-  /// Trace ctor - make new Trace from vector of basic blocks, residing
-  /// in function which is the parent of the first BB in the vector.
+  /// getEntryBasicBlock - Return the entry basic block (first block)
+  /// of the trace.
   ///
-  Trace(std::vector<BasicBlock *> vBB) :
-    F(vBB[0]->getParent ()), BasicBlocks(vBB) {
-  }
+  inline BasicBlock *getEntryBasicBlock () const { return BasicBlocks[0]; }
 
-  /// Return this Trace's parent Function.
+  /// getFunction - Return this trace's parent function.
   ///
-  inline Function *getFunction () { return F; }
+  inline Function *getFunction () const {
+    return getEntryBasicBlock ()->getParent ();
+  }
 
-  /// Return this Module that contains this trace's parent Function.
+  /// getModule - Return this Module that contains this trace's parent
+  /// function.
   ///
-  inline Module *getModule () { return F->getParent(); }
+  inline Module *getModule () const { return getFunction ()->getParent (); }
 
-  inline int getFunctionIndex (BasicBlock *b) { return 0; } // FIXME
+  /// print - Write trace to output stream.
+  ///
+  void print (std::ostream &O) const;
 
-  /// Write trace to file as s-expression
+  /// dump - Debugger convenience method; writes trace to standard error
+  /// output stream.
   ///
-  void print (std::ostream &O) {
-	O << "(trace\n";
-	O << "\t(function-name " << F->getName () << ")\n";
-	O << "\t(function \"" << *F << "\")\n";
-    O << "\t(blocks \n";
-    for (iterator i = begin (), e = end(); i != e; ++i) {
-      unsigned index = getFunctionIndex (*i);
-      O << "\t\t(block " << index << " \"" << (*i)->getName () << "\")\n";
-    }
-    O << "\t)\n";
-    O << ")\n";
-  }
+  void dump () const;
 
   // BasicBlock iterators...
   typedef BasicBlockListType::iterator iterator;
@@ -90,6 +74,9 @@
 
   unsigned                 size() const { return BasicBlocks.size(); }
   bool                    empty() const { return BasicBlocks.empty(); }
+
+  BasicBlock *operator[] (unsigned i) const { return BasicBlocks[i]; }
+  BasicBlock *getBlock (unsigned i)   const { return BasicBlocks[i]; }
 };
 
 #endif // TRACE_H





More information about the llvm-commits mailing list