CycleAnalysis.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===- CycleAnalysis.h - Cycle Info for LLVM IR -----------------*- C++ -*-===//
  7. //
  8. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  9. // See https://llvm.org/LICENSE.txt for license information.
  10. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  11. //
  12. //===----------------------------------------------------------------------===//
  13. /// \file
  14. ///
  15. /// This file declares an analysis pass that computes CycleInfo for
  16. /// LLVM IR, specialized from GenericCycleInfo.
  17. ///
  18. //===----------------------------------------------------------------------===//
  19. #ifndef LLVM_ANALYSIS_CYCLEANALYSIS_H
  20. #define LLVM_ANALYSIS_CYCLEANALYSIS_H
  21. #include "llvm/ADT/GenericCycleInfo.h"
  22. #include "llvm/IR/PassManager.h"
  23. #include "llvm/IR/SSAContext.h"
  24. #include "llvm/Pass.h"
  25. namespace llvm {
  26. extern template class GenericCycleInfo<SSAContext>;
  27. extern template class GenericCycle<SSAContext>;
  28. using CycleInfo = GenericCycleInfo<SSAContext>;
  29. using Cycle = CycleInfo::CycleT;
  30. /// Legacy analysis pass which computes a \ref CycleInfo.
  31. class CycleInfoWrapperPass : public FunctionPass {
  32. Function *F = nullptr;
  33. CycleInfo CI;
  34. public:
  35. static char ID;
  36. CycleInfoWrapperPass();
  37. CycleInfo &getResult() { return CI; }
  38. const CycleInfo &getResult() const { return CI; }
  39. bool runOnFunction(Function &F) override;
  40. void getAnalysisUsage(AnalysisUsage &AU) const override;
  41. void releaseMemory() override;
  42. void print(raw_ostream &OS, const Module *M = nullptr) const override;
  43. // TODO: verify analysis?
  44. };
  45. /// Analysis pass which computes a \ref CycleInfo.
  46. class CycleAnalysis : public AnalysisInfoMixin<CycleAnalysis> {
  47. friend AnalysisInfoMixin<CycleAnalysis>;
  48. static AnalysisKey Key;
  49. public:
  50. /// Provide the result typedef for this analysis pass.
  51. using Result = CycleInfo;
  52. using LegacyWrapper = CycleInfoWrapperPass;
  53. /// Run the analysis pass over a function and produce a dominator tree.
  54. CycleInfo run(Function &F, FunctionAnalysisManager &);
  55. // TODO: verify analysis?
  56. };
  57. /// Printer pass for the \c DominatorTree.
  58. class CycleInfoPrinterPass : public PassInfoMixin<CycleInfoPrinterPass> {
  59. raw_ostream &OS;
  60. public:
  61. explicit CycleInfoPrinterPass(raw_ostream &OS);
  62. PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM);
  63. };
  64. } // end namespace llvm
  65. #endif // LLVM_ANALYSIS_CYCLEANALYSIS_H
  66. #ifdef __GNUC__
  67. #pragma GCC diagnostic pop
  68. #endif