CycleAnalysis.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. /// Analysis pass which computes a \ref CycleInfo.
  31. class CycleAnalysis : public AnalysisInfoMixin<CycleAnalysis> {
  32. friend AnalysisInfoMixin<CycleAnalysis>;
  33. static AnalysisKey Key;
  34. public:
  35. /// Provide the result typedef for this analysis pass.
  36. using Result = CycleInfo;
  37. /// Run the analysis pass over a function and produce a dominator tree.
  38. CycleInfo run(Function &F, FunctionAnalysisManager &);
  39. // TODO: verify analysis?
  40. };
  41. /// Printer pass for the \c DominatorTree.
  42. class CycleInfoPrinterPass : public PassInfoMixin<CycleInfoPrinterPass> {
  43. raw_ostream &OS;
  44. public:
  45. explicit CycleInfoPrinterPass(raw_ostream &OS);
  46. PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM);
  47. };
  48. /// Legacy analysis pass which computes a \ref CycleInfo.
  49. class CycleInfoWrapperPass : public FunctionPass {
  50. Function *F = nullptr;
  51. CycleInfo CI;
  52. public:
  53. static char ID;
  54. CycleInfoWrapperPass();
  55. CycleInfo &getCycleInfo() { return CI; }
  56. const CycleInfo &getCycleInfo() const { return CI; }
  57. bool runOnFunction(Function &F) override;
  58. void getAnalysisUsage(AnalysisUsage &AU) const override;
  59. void releaseMemory() override;
  60. void print(raw_ostream &OS, const Module *M = nullptr) const override;
  61. // TODO: verify analysis?
  62. };
  63. } // end namespace llvm
  64. #endif // LLVM_ANALYSIS_CYCLEANALYSIS_H
  65. #ifdef __GNUC__
  66. #pragma GCC diagnostic pop
  67. #endif