CycleAnalysis.cpp 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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"
  11. #include "llvm/InitializePasses.h"
  12. using namespace llvm;
  13. template class llvm::GenericCycleInfo<SSAContext>;
  14. template class llvm::GenericCycle<SSAContext>;
  15. CycleInfo CycleAnalysis::run(Function &F, FunctionAnalysisManager &) {
  16. CycleInfo CI;
  17. CI.compute(F);
  18. return CI;
  19. }
  20. AnalysisKey CycleAnalysis::Key;
  21. CycleInfoPrinterPass::CycleInfoPrinterPass(raw_ostream &OS) : OS(OS) {}
  22. PreservedAnalyses CycleInfoPrinterPass::run(Function &F,
  23. FunctionAnalysisManager &AM) {
  24. OS << "CycleInfo for function: " << F.getName() << "\n";
  25. AM.getResult<CycleAnalysis>(F).print(OS);
  26. return PreservedAnalyses::all();
  27. }
  28. //===----------------------------------------------------------------------===//
  29. // CycleInfoWrapperPass Implementation
  30. //===----------------------------------------------------------------------===//
  31. //
  32. // The implementation details of the wrapper pass that holds a CycleInfo
  33. // suitable for use with the legacy pass manager.
  34. //
  35. //===----------------------------------------------------------------------===//
  36. char CycleInfoWrapperPass::ID = 0;
  37. CycleInfoWrapperPass::CycleInfoWrapperPass() : FunctionPass(ID) {
  38. initializeCycleInfoWrapperPassPass(*PassRegistry::getPassRegistry());
  39. }
  40. INITIALIZE_PASS_BEGIN(CycleInfoWrapperPass, "cycles", "Cycle Info Analysis",
  41. true, true)
  42. INITIALIZE_PASS_END(CycleInfoWrapperPass, "cycles", "Cycle Info Analysis", true,
  43. true)
  44. void CycleInfoWrapperPass::getAnalysisUsage(AnalysisUsage &AU) const {
  45. AU.setPreservesAll();
  46. }
  47. bool CycleInfoWrapperPass::runOnFunction(Function &Func) {
  48. CI.clear();
  49. F = &Func;
  50. CI.compute(Func);
  51. return false;
  52. }
  53. void CycleInfoWrapperPass::print(raw_ostream &OS, const Module *) const {
  54. OS << "CycleInfo for function: " << F->getName() << "\n";
  55. CI.print(OS);
  56. }
  57. void CycleInfoWrapperPass::releaseMemory() {
  58. CI.clear();
  59. F = nullptr;
  60. }