CycleAnalysis.cpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. //===- CycleAnalysis.cpp - Compute CycleInfo for LLVM IR ------------------===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. #include "llvm/Analysis/CycleAnalysis.h"
  9. #include "llvm/ADT/GenericCycleImpl.h"
  10. #include "llvm/IR/CFG.h" // for successors found by ADL in GenericCycleImpl.h
  11. #include "llvm/InitializePasses.h"
  12. using namespace llvm;
  13. namespace llvm {
  14. class Module;
  15. }
  16. template class llvm::GenericCycleInfo<SSAContext>;
  17. template class llvm::GenericCycle<SSAContext>;
  18. CycleInfo CycleAnalysis::run(Function &F, FunctionAnalysisManager &) {
  19. CycleInfo CI;
  20. CI.compute(F);
  21. return CI;
  22. }
  23. AnalysisKey CycleAnalysis::Key;
  24. CycleInfoPrinterPass::CycleInfoPrinterPass(raw_ostream &OS) : OS(OS) {}
  25. PreservedAnalyses CycleInfoPrinterPass::run(Function &F,
  26. FunctionAnalysisManager &AM) {
  27. OS << "CycleInfo for function: " << F.getName() << "\n";
  28. AM.getResult<CycleAnalysis>(F).print(OS);
  29. return PreservedAnalyses::all();
  30. }
  31. //===----------------------------------------------------------------------===//
  32. // CycleInfoWrapperPass Implementation
  33. //===----------------------------------------------------------------------===//
  34. //
  35. // The implementation details of the wrapper pass that holds a CycleInfo
  36. // suitable for use with the legacy pass manager.
  37. //
  38. //===----------------------------------------------------------------------===//
  39. char CycleInfoWrapperPass::ID = 0;
  40. CycleInfoWrapperPass::CycleInfoWrapperPass() : FunctionPass(ID) {
  41. initializeCycleInfoWrapperPassPass(*PassRegistry::getPassRegistry());
  42. }
  43. INITIALIZE_PASS_BEGIN(CycleInfoWrapperPass, "cycles", "Cycle Info Analysis",
  44. true, true)
  45. INITIALIZE_PASS_END(CycleInfoWrapperPass, "cycles", "Cycle Info Analysis", true,
  46. true)
  47. void CycleInfoWrapperPass::getAnalysisUsage(AnalysisUsage &AU) const {
  48. AU.setPreservesAll();
  49. }
  50. bool CycleInfoWrapperPass::runOnFunction(Function &Func) {
  51. CI.clear();
  52. F = &Func;
  53. CI.compute(Func);
  54. return false;
  55. }
  56. void CycleInfoWrapperPass::print(raw_ostream &OS, const Module *) const {
  57. OS << "CycleInfo for function: " << F->getName() << "\n";
  58. CI.print(OS);
  59. }
  60. void CycleInfoWrapperPass::releaseMemory() {
  61. CI.clear();
  62. F = nullptr;
  63. }