1 //===- llvm/Analysis/Trace.h - Represent one trace of LLVM code -*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file was developed by the LLVM research group and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This class represents a single trace of LLVM basic blocks. A trace is a
11 // single entry, multiple exit, region of code that is often hot. Trace-based
12 // optimizations treat traces almost like they are a large, strange, basic
13 // block: because the trace path is assumed to be hot, optimizations for the
14 // fall-through path are made at the expense of the non-fall-through paths.
16 //===----------------------------------------------------------------------===//
18 #ifndef LLVM_ANALYSIS_TRACE_H
19 #define LLVM_ANALYSIS_TRACE_H
30 typedef std::vector<BasicBlock *> BasicBlockListType;
31 BasicBlockListType BasicBlocks;
34 /// contains - Returns true if this trace contains the given basic
37 inline bool contains (const BasicBlock *X) {
38 for (unsigned i = 0, e = BasicBlocks.size(); i != e; ++i)
39 if (BasicBlocks[i] == X)
44 /// Trace ctor - Make a new trace from a vector of basic blocks,
45 /// residing in the function which is the parent of the first
46 /// basic block in the vector.
48 Trace (const std::vector<BasicBlock *> &vBB) : BasicBlocks (vBB) {
51 /// getEntryBasicBlock - Return the entry basic block (first block)
54 BasicBlock *getEntryBasicBlock () const { return BasicBlocks[0]; }
56 /// getFunction - Return this trace's parent function.
58 Function *getFunction () const;
60 /// getModule - Return this Module that contains this trace's parent
63 Module *getModule () const;
65 /// print - Write trace to output stream.
67 void print (std::ostream &O) const;
69 /// dump - Debugger convenience method; writes trace to standard error
74 // BasicBlock iterators...
75 typedef BasicBlockListType::iterator iterator;
76 typedef BasicBlockListType::const_iterator const_iterator;
77 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
78 typedef std::reverse_iterator<iterator> reverse_iterator;
80 iterator begin() { return BasicBlocks.begin(); }
81 const_iterator begin() const { return BasicBlocks.begin(); }
82 iterator end () { return BasicBlocks.end(); }
83 const_iterator end () const { return BasicBlocks.end(); }
85 reverse_iterator rbegin() { return BasicBlocks.rbegin(); }
86 const_reverse_iterator rbegin() const { return BasicBlocks.rbegin(); }
87 reverse_iterator rend () { return BasicBlocks.rend(); }
88 const_reverse_iterator rend () const { return BasicBlocks.rend(); }
90 unsigned size() const { return BasicBlocks.size(); }
91 bool empty() const { return BasicBlocks.empty(); }
93 BasicBlock *operator[] (unsigned i) const { return BasicBlocks[i]; }
94 BasicBlock *getBlock (unsigned i) const { return BasicBlocks[i]; }
96 /// Returns true if B1 and B2 appear on a path from START to an exit
97 /// block => B1 appears before B2. If START is not provided, defaults
98 /// to 0, which means use getEntryBasicBlock().
100 bool dominates (const BasicBlock *B1, const BasicBlock *B2,
101 const BasicBlock *start = 0);
104 } // end namespace llvm