Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

119 lines
4.1 KiB

  1. //===- llvm/Analysis/Trace.h - Represent one trace of LLVM code -*- C++ -*-===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is distributed under the University of Illinois Open Source
  6. // License. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. //
  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.
  15. //
  16. //===----------------------------------------------------------------------===//
  17. #ifndef LLVM_ANALYSIS_TRACE_H
  18. #define LLVM_ANALYSIS_TRACE_H
  19. #include <cassert>
  20. #include <vector>
  21. namespace llvm {
  22. class BasicBlock;
  23. class Function;
  24. class Module;
  25. class raw_ostream;
  26. class Trace {
  27. typedef std::vector<BasicBlock *> BasicBlockListType;
  28. BasicBlockListType BasicBlocks;
  29. public:
  30. /// Trace ctor - Make a new trace from a vector of basic blocks,
  31. /// residing in the function which is the parent of the first
  32. /// basic block in the vector.
  33. ///
  34. Trace(const std::vector<BasicBlock *> &vBB) : BasicBlocks (vBB) {}
  35. /// getEntryBasicBlock - Return the entry basic block (first block)
  36. /// of the trace.
  37. ///
  38. BasicBlock *getEntryBasicBlock () const { return BasicBlocks[0]; }
  39. /// operator[]/getBlock - Return basic block N in the trace.
  40. ///
  41. BasicBlock *operator[](unsigned i) const { return BasicBlocks[i]; }
  42. BasicBlock *getBlock(unsigned i) const { return BasicBlocks[i]; }
  43. /// getFunction - Return this trace's parent function.
  44. ///
  45. Function *getFunction () const;
  46. /// getModule - Return this Module that contains this trace's parent
  47. /// function.
  48. ///
  49. Module *getModule () const;
  50. /// getBlockIndex - Return the index of the specified basic block in the
  51. /// trace, or -1 if it is not in the trace.
  52. int getBlockIndex(const BasicBlock *X) const {
  53. for (unsigned i = 0, e = BasicBlocks.size(); i != e; ++i)
  54. if (BasicBlocks[i] == X)
  55. return i;
  56. return -1;
  57. }
  58. /// contains - Returns true if this trace contains the given basic
  59. /// block.
  60. ///
  61. bool contains(const BasicBlock *X) const {
  62. return getBlockIndex(X) != -1;
  63. }
  64. /// Returns true if B1 occurs before B2 in the trace, or if it is the same
  65. /// block as B2.. Both blocks must be in the trace.
  66. ///
  67. bool dominates(const BasicBlock *B1, const BasicBlock *B2) const {
  68. int B1Idx = getBlockIndex(B1), B2Idx = getBlockIndex(B2);
  69. assert(B1Idx != -1 && B2Idx != -1 && "Block is not in the trace!");
  70. return B1Idx <= B2Idx;
  71. }
  72. // BasicBlock iterators...
  73. typedef BasicBlockListType::iterator iterator;
  74. typedef BasicBlockListType::const_iterator const_iterator;
  75. typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
  76. typedef std::reverse_iterator<iterator> reverse_iterator;
  77. iterator begin() { return BasicBlocks.begin(); }
  78. const_iterator begin() const { return BasicBlocks.begin(); }
  79. iterator end () { return BasicBlocks.end(); }
  80. const_iterator end () const { return BasicBlocks.end(); }
  81. reverse_iterator rbegin() { return BasicBlocks.rbegin(); }
  82. const_reverse_iterator rbegin() const { return BasicBlocks.rbegin(); }
  83. reverse_iterator rend () { return BasicBlocks.rend(); }
  84. const_reverse_iterator rend () const { return BasicBlocks.rend(); }
  85. unsigned size() const { return BasicBlocks.size(); }
  86. bool empty() const { return BasicBlocks.empty(); }
  87. iterator erase(iterator q) { return BasicBlocks.erase (q); }
  88. iterator erase(iterator q1, iterator q2) { return BasicBlocks.erase (q1, q2); }
  89. /// print - Write trace to output stream.
  90. ///
  91. void print(raw_ostream &O) const;
  92. /// dump - Debugger convenience method; writes trace to standard error
  93. /// output stream.
  94. ///
  95. void dump() const;
  96. };
  97. } // end namespace llvm
  98. #endif // LLVM_ANALYSIS_TRACE_H