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

Brian Gaeke gaeke at niobe.cs.uiuc.edu
Fri Aug 15 19:15:00 PDT 2003


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

Trace.h added (r1.1)

---
Log message:

Data structure to contain traces. This is very much a work in progress,
so constructive criticisms are welcome...


---
Diffs of the changes:

Index: llvm/lib/Reoptimizer/LightWtProfiling/Trigger/Trace.h
diff -c /dev/null llvm/lib/Reoptimizer/LightWtProfiling/Trigger/Trace.h:1.1
*** /dev/null	Fri Aug 15 19:14:17 2003
--- llvm/lib/Reoptimizer/LightWtProfiling/Trigger/Trace.h	Fri Aug 15 19:14:07 2003
***************
*** 0 ****
--- 1,95 ----
+ //===- Trace.h - Wrapper class for traces ------------------------*- C++ -*--=//
+ //
+ // Encapsulates vectors of BasicBlocks as traces.
+ //
+ //===----------------------------------------------------------------------===//
+ 
+ #include "llvm/Function.h"
+ #include <iostream>
+ class Module;
+ 
+ #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]; }
+ 
+   /// 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();
+   }
+ 
+   /// Trace ctor - make new Trace from vector of basic blocks, residing
+   /// in given function.
+   ///
+   Trace(Function *F_, std::vector<BasicBlock *> vBB) :
+     F(F_), 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.
+   ///
+   Trace(std::vector<BasicBlock *> vBB) :
+     F(vBB[0]->getParent ()), BasicBlocks(vBB) {
+   }
+ 
+   /// Return this Trace's parent Function.
+   ///
+   inline Function *getFunction () { return F; }
+ 
+   /// Return this Module that contains this trace's parent Function.
+   ///
+   inline Module *getModule () { return F->getParent(); }
+ 
+   inline int getFunctionIndex (BasicBlock *b) { return 0; } // FIXME
+ 
+   /// Write trace to file as s-expression
+   ///
+   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";
+   }
+ 
+   // BasicBlock iterators...
+   typedef BasicBlockListType::iterator iterator;
+   typedef BasicBlockListType::const_iterator const_iterator;
+   typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
+   typedef std::reverse_iterator<iterator> reverse_iterator;
+ 
+   iterator                begin()       { return BasicBlocks.begin(); }
+   const_iterator          begin() const { return BasicBlocks.begin(); }
+   iterator                end  ()       { return BasicBlocks.end();   }
+   const_iterator          end  () const { return BasicBlocks.end();   }
+ 
+   reverse_iterator       rbegin()       { return BasicBlocks.rbegin(); }
+   const_reverse_iterator rbegin() const { return BasicBlocks.rbegin(); }
+   reverse_iterator       rend  ()       { return BasicBlocks.rend();   }
+   const_reverse_iterator rend  () const { return BasicBlocks.rend();   }
+ 
+   unsigned                 size() const { return BasicBlocks.size(); }
+   bool                    empty() const { return BasicBlocks.empty(); }
+ };
+ 
+ #endif // TRACE_H





More information about the llvm-commits mailing list