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.

124 lines
4.2 KiB

  1. //===- llvm/Analysis/LoopDependenceAnalysis.h --------------- -*- 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. // LoopDependenceAnalysis is an LLVM pass that analyses dependences in memory
  11. // accesses in loops.
  12. //
  13. // Please note that this is work in progress and the interface is subject to
  14. // change.
  15. //
  16. // TODO: adapt as interface progresses
  17. //
  18. //===----------------------------------------------------------------------===//
  19. #ifndef LLVM_ANALYSIS_LOOP_DEPENDENCE_ANALYSIS_H
  20. #define LLVM_ANALYSIS_LOOP_DEPENDENCE_ANALYSIS_H
  21. #include "llvm/ADT/DenseSet.h"
  22. #include "llvm/ADT/FoldingSet.h"
  23. #include "llvm/ADT/SmallVector.h"
  24. #include "llvm/Analysis/LoopPass.h"
  25. #include "llvm/Support/Allocator.h"
  26. namespace llvm {
  27. class AliasAnalysis;
  28. class AnalysisUsage;
  29. class ScalarEvolution;
  30. class SCEV;
  31. class Value;
  32. class raw_ostream;
  33. class LoopDependenceAnalysis : public LoopPass {
  34. AliasAnalysis *AA;
  35. ScalarEvolution *SE;
  36. /// L - The loop we are currently analysing.
  37. Loop *L;
  38. /// TODO: doc
  39. enum DependenceResult { Independent = 0, Dependent = 1, Unknown = 2 };
  40. /// TODO: doc
  41. struct Subscript {
  42. /// TODO: Add distance, direction, breaking conditions, ...
  43. };
  44. /// DependencePair - Represents a data dependence relation between to memory
  45. /// reference instructions.
  46. struct DependencePair : public FastFoldingSetNode {
  47. Value *A;
  48. Value *B;
  49. DependenceResult Result;
  50. SmallVector<Subscript, 4> Subscripts;
  51. DependencePair(const FoldingSetNodeID &ID, Value *a, Value *b) :
  52. FastFoldingSetNode(ID), A(a), B(b), Result(Unknown), Subscripts() {}
  53. };
  54. /// findOrInsertDependencePair - Return true if a DependencePair for the
  55. /// given Values already exists, false if a new DependencePair had to be
  56. /// created. The third argument is set to the pair found or created.
  57. bool findOrInsertDependencePair(Value*, Value*, DependencePair*&);
  58. /// getLoops - Collect all loops of the loop nest L in which
  59. /// a given SCEV is variant.
  60. void getLoops(const SCEV*, DenseSet<const Loop*>*) const;
  61. /// isLoopInvariant - True if a given SCEV is invariant in all loops of the
  62. /// loop nest starting at the innermost loop L.
  63. bool isLoopInvariant(const SCEV*) const;
  64. /// isAffine - An SCEV is affine with respect to the loop nest starting at
  65. /// the innermost loop L if it is of the form A+B*X where A, B are invariant
  66. /// in the loop nest and X is a induction variable in the loop nest.
  67. bool isAffine(const SCEV*) const;
  68. /// TODO: doc
  69. bool isZIVPair(const SCEV*, const SCEV*) const;
  70. bool isSIVPair(const SCEV*, const SCEV*) const;
  71. DependenceResult analyseZIV(const SCEV*, const SCEV*, Subscript*) const;
  72. DependenceResult analyseSIV(const SCEV*, const SCEV*, Subscript*) const;
  73. DependenceResult analyseMIV(const SCEV*, const SCEV*, Subscript*) const;
  74. DependenceResult analyseSubscript(const SCEV*, const SCEV*, Subscript*) const;
  75. DependenceResult analysePair(DependencePair*) const;
  76. public:
  77. static char ID; // Class identification, replacement for typeinfo
  78. LoopDependenceAnalysis() : LoopPass(ID) {
  79. initializeLoopDependenceAnalysisPass(*PassRegistry::getPassRegistry());
  80. }
  81. /// isDependencePair - Check whether two values can possibly give rise to
  82. /// a data dependence: that is the case if both are instructions accessing
  83. /// memory and at least one of those accesses is a write.
  84. bool isDependencePair(const Value*, const Value*) const;
  85. /// depends - Return a boolean indicating if there is a data dependence
  86. /// between two instructions.
  87. bool depends(Value*, Value*);
  88. bool runOnLoop(Loop*, LPPassManager&);
  89. virtual void releaseMemory();
  90. virtual void getAnalysisUsage(AnalysisUsage&) const;
  91. void print(raw_ostream&, const Module* = 0) const;
  92. private:
  93. FoldingSet<DependencePair> Pairs;
  94. BumpPtrAllocator PairAllocator;
  95. }; // class LoopDependenceAnalysis
  96. // createLoopDependenceAnalysisPass - This creates an instance of the
  97. // LoopDependenceAnalysis pass.
  98. //
  99. LoopPass *createLoopDependenceAnalysisPass();
  100. } // namespace llvm
  101. #endif /* LLVM_ANALYSIS_LOOP_DEPENDENCE_ANALYSIS_H */