| 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 | |
| 9 | #include "llvm/Analysis/CycleAnalysis.h" |
| 10 | #include "llvm/IR/CFG.h" // for successors found by ADL in GenericCycleImpl.h |
| 11 | #include "llvm/InitializePasses.h" |
| 12 | |
| 13 | using namespace llvm; |
| 14 | |
| 15 | namespace llvm { |
| 16 | class Module; |
| 17 | } // namespace llvm |
| 18 | |
| 19 | CycleInfo CycleAnalysis::run(Function &F, FunctionAnalysisManager &) { |
| 20 | CycleInfo CI; |
| 21 | CI.compute(F); |
| 22 | return CI; |
| 23 | } |
| 24 | |
| 25 | AnalysisKey CycleAnalysis::Key; |
| 26 | |
| 27 | CycleInfoPrinterPass::CycleInfoPrinterPass(raw_ostream &OS) : OS(OS) {} |
| 28 | |
| 29 | PreservedAnalyses CycleInfoPrinterPass::run(Function &F, |
| 30 | FunctionAnalysisManager &AM) { |
| 31 | OS << "CycleInfo for function: " << F.getName() << "\n" ; |
| 32 | AM.getResult<CycleAnalysis>(IR&: F).print(Out&: OS); |
| 33 | |
| 34 | return PreservedAnalyses::all(); |
| 35 | } |
| 36 | |
| 37 | PreservedAnalyses CycleInfoVerifierPass::run(Function &F, |
| 38 | FunctionAnalysisManager &AM) { |
| 39 | CycleInfo &CI = AM.getResult<CycleAnalysis>(IR&: F); |
| 40 | CI.verify(); |
| 41 | return PreservedAnalyses::all(); |
| 42 | } |
| 43 | |
| 44 | //===----------------------------------------------------------------------===// |
| 45 | // CycleInfoWrapperPass Implementation |
| 46 | //===----------------------------------------------------------------------===// |
| 47 | // |
| 48 | // The implementation details of the wrapper pass that holds a CycleInfo |
| 49 | // suitable for use with the legacy pass manager. |
| 50 | // |
| 51 | //===----------------------------------------------------------------------===// |
| 52 | |
| 53 | char CycleInfoWrapperPass::ID = 0; |
| 54 | |
| 55 | CycleInfoWrapperPass::CycleInfoWrapperPass() : FunctionPass(ID) {} |
| 56 | |
| 57 | INITIALIZE_PASS_BEGIN(CycleInfoWrapperPass, "cycles" , "Cycle Info Analysis" , |
| 58 | true, true) |
| 59 | INITIALIZE_PASS_END(CycleInfoWrapperPass, "cycles" , "Cycle Info Analysis" , true, |
| 60 | true) |
| 61 | |
| 62 | void CycleInfoWrapperPass::getAnalysisUsage(AnalysisUsage &AU) const { |
| 63 | AU.setPreservesAll(); |
| 64 | } |
| 65 | |
| 66 | bool CycleInfoWrapperPass::runOnFunction(Function &Func) { |
| 67 | CI.clear(); |
| 68 | |
| 69 | F = &Func; |
| 70 | CI.compute(F&: Func); |
| 71 | return false; |
| 72 | } |
| 73 | |
| 74 | void CycleInfoWrapperPass::print(raw_ostream &OS, const Module *) const { |
| 75 | OS << "CycleInfo for function: " << F->getName() << "\n" ; |
| 76 | CI.print(Out&: OS); |
| 77 | } |
| 78 | |
| 79 | void CycleInfoWrapperPass::releaseMemory() { |
| 80 | CI.clear(); |
| 81 | F = nullptr; |
| 82 | } |
| 83 | |