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.

111 lines
4.1 KiB

  1. //===- IntervalPartition.h - Interval partition Calculation -----*- 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 file contains the declaration of the IntervalPartition class, which
  11. // calculates and represents the interval partition of a function, or a
  12. // preexisting interval partition.
  13. //
  14. // In this way, the interval partition may be used to reduce a flow graph down
  15. // to its degenerate single node interval partition (unless it is irreducible).
  16. //
  17. // TODO: The IntervalPartition class should take a bool parameter that tells
  18. // whether it should add the "tails" of an interval to an interval itself or if
  19. // they should be represented as distinct intervals.
  20. //
  21. //===----------------------------------------------------------------------===//
  22. #ifndef LLVM_ANALYSIS_INTERVALPARTITION_H
  23. #define LLVM_ANALYSIS_INTERVALPARTITION_H
  24. #include "llvm/Analysis/Interval.h"
  25. #include "llvm/Pass.h"
  26. #include <map>
  27. namespace llvm {
  28. //===----------------------------------------------------------------------===//
  29. //
  30. // IntervalPartition - This class builds and holds an "interval partition" for
  31. // a function. This partition divides the control flow graph into a set of
  32. // maximal intervals, as defined with the properties above. Intuitively, an
  33. // interval is a (possibly nonexistent) loop with a "tail" of non looping
  34. // nodes following it.
  35. //
  36. class IntervalPartition : public FunctionPass {
  37. typedef std::map<BasicBlock*, Interval*> IntervalMapTy;
  38. IntervalMapTy IntervalMap;
  39. typedef std::vector<Interval*> IntervalListTy;
  40. Interval *RootInterval;
  41. std::vector<Interval*> Intervals;
  42. public:
  43. static char ID; // Pass identification, replacement for typeid
  44. IntervalPartition() : FunctionPass(ID), RootInterval(0) {
  45. initializeIntervalPartitionPass(*PassRegistry::getPassRegistry());
  46. }
  47. // run - Calculate the interval partition for this function
  48. virtual bool runOnFunction(Function &F);
  49. // IntervalPartition ctor - Build a reduced interval partition from an
  50. // existing interval graph. This takes an additional boolean parameter to
  51. // distinguish it from a copy constructor. Always pass in false for now.
  52. //
  53. IntervalPartition(IntervalPartition &I, bool);
  54. // print - Show contents in human readable format...
  55. virtual void print(raw_ostream &O, const Module* = 0) const;
  56. // getRootInterval() - Return the root interval that contains the starting
  57. // block of the function.
  58. inline Interval *getRootInterval() { return RootInterval; }
  59. // isDegeneratePartition() - Returns true if the interval partition contains
  60. // a single interval, and thus cannot be simplified anymore.
  61. bool isDegeneratePartition() { return Intervals.size() == 1; }
  62. // TODO: isIrreducible - look for triangle graph.
  63. // getBlockInterval - Return the interval that a basic block exists in.
  64. inline Interval *getBlockInterval(BasicBlock *BB) {
  65. IntervalMapTy::iterator I = IntervalMap.find(BB);
  66. return I != IntervalMap.end() ? I->second : 0;
  67. }
  68. // getAnalysisUsage - Implement the Pass API
  69. virtual void getAnalysisUsage(AnalysisUsage &AU) const {
  70. AU.setPreservesAll();
  71. }
  72. // Interface to Intervals vector...
  73. const std::vector<Interval*> &getIntervals() const { return Intervals; }
  74. // releaseMemory - Reset state back to before function was analyzed
  75. void releaseMemory();
  76. private:
  77. // addIntervalToPartition - Add an interval to the internal list of intervals,
  78. // and then add mappings from all of the basic blocks in the interval to the
  79. // interval itself (in the IntervalMap).
  80. //
  81. void addIntervalToPartition(Interval *I);
  82. // updatePredecessors - Interval generation only sets the successor fields of
  83. // the interval data structures. After interval generation is complete,
  84. // run through all of the intervals and propagate successor info as
  85. // predecessor info.
  86. //
  87. void updatePredecessors(Interval *Int);
  88. };
  89. } // End llvm namespace
  90. #endif