Merging r258184:
[oota-llvm.git] / include / llvm / Analysis / Trace.h
index 501a09ecef766411a7ed94c4a17e4fd23a06fdae..bedd654c65217067347526e88a98ef595352f010 100644 (file)
@@ -2,8 +2,8 @@
 //
 //                     The LLVM Compiler Infrastructure
 //
-// This file was developed by the LLVM research group and is distributed under
-// the University of Illinois Open Source License. See LICENSE.TXT for details.
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
 //
 //===----------------------------------------------------------------------===//
 //
 #ifndef LLVM_ANALYSIS_TRACE_H
 #define LLVM_ANALYSIS_TRACE_H
 
-#include <iosfwd>
+#include <cassert>
 #include <vector>
 
-namespace llvm { 
+namespace llvm {
   class BasicBlock;
   class Function;
   class Module;
+  class raw_ostream;
 
 class Trace {
   typedef std::vector<BasicBlock *> BasicBlockListType;
   BasicBlockListType BasicBlocks;
 
 public:
-  /// contains - Returns true if this trace contains the given basic
-  /// block.
-  ///
-  inline bool contains (const BasicBlock *X) {
-    for (unsigned i = 0, e = BasicBlocks.size(); i != e; ++i)
-      if (BasicBlocks[i] == X)
-        return true;
-    return false;
-  }
-
   /// 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 (const std::vector<BasicBlock *> &vBB) : BasicBlocks (vBB) {
-  }
+  Trace(const std::vector<BasicBlock *> &vBB) : BasicBlocks (vBB) {}
 
   /// getEntryBasicBlock - Return the entry basic block (first block)
   /// of the trace.
   ///
   BasicBlock *getEntryBasicBlock () const { return BasicBlocks[0]; }
 
+  /// operator[]/getBlock - Return basic block N in the trace.
+  ///
+  BasicBlock *operator[](unsigned i) const { return BasicBlocks[i]; }
+  BasicBlock *getBlock(unsigned i)   const { return BasicBlocks[i]; }
+
   /// getFunction - Return this trace's parent function.
   ///
   Function *getFunction () const;
@@ -62,14 +57,30 @@ public:
   ///
   Module *getModule () const;
 
-  /// print - Write trace to output stream.
+  /// getBlockIndex - Return the index of the specified basic block in the
+  /// trace, or -1 if it is not in the trace.
+  int getBlockIndex(const BasicBlock *X) const {
+    for (unsigned i = 0, e = BasicBlocks.size(); i != e; ++i)
+      if (BasicBlocks[i] == X)
+        return i;
+    return -1;
+  }
+
+  /// contains - Returns true if this trace contains the given basic
+  /// block.
   ///
-  void print (std::ostream &O) const;
+  bool contains(const BasicBlock *X) const {
+    return getBlockIndex(X) != -1;
+  }
 
-  /// dump - Debugger convenience method; writes trace to standard error
-  /// output stream.
+  /// Returns true if B1 occurs before B2 in the trace, or if it is the same
+  /// block as B2..  Both blocks must be in the trace.
   ///
-  void dump () const;
+  bool dominates(const BasicBlock *B1, const BasicBlock *B2) const {
+    int B1Idx = getBlockIndex(B1), B2Idx = getBlockIndex(B2);
+    assert(B1Idx != -1 && B2Idx != -1 && "Block is not in the trace!");
+    return B1Idx <= B2Idx;
+  }
 
   // BasicBlock iterators...
   typedef BasicBlockListType::iterator iterator;
@@ -90,17 +101,19 @@ public:
   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]; }
+  iterator erase(iterator q)               { return BasicBlocks.erase (q); }
+  iterator erase(iterator q1, iterator q2) { return BasicBlocks.erase (q1, q2); }
+
+  /// print - Write trace to output stream.
+  ///
+  void print(raw_ostream &O) const;
 
-  /// Returns true if B1 and B2 appear on a path from START to an exit
-  /// block => B1 appears before B2. If START is not provided, defaults
-  /// to 0, which means use getEntryBasicBlock().
+  /// dump - Debugger convenience method; writes trace to standard error
+  /// output stream.
   ///
-  bool dominates (const BasicBlock *B1, const BasicBlock *B2,
-                 const BasicBlock *start = 0);
+  void dump() const;
 };
 
 } // end namespace llvm
 
-#endif // TRACE_H
+#endif // LLVM_ANALYSIS_TRACE_H