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/ADT/GenericCycleImpl.h" 11 #include "llvm/IR/CFG.h" 12 #include "llvm/InitializePasses.h" 13 14 using namespace llvm; 15 16 template class llvm::GenericCycleInfo<SSAContext>; 17 template class llvm::GenericCycle<SSAContext>; 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>(F).print(OS); 33 34 return PreservedAnalyses::all(); 35 } 36 37 //===----------------------------------------------------------------------===// 38 // CycleInfoWrapperPass Implementation 39 //===----------------------------------------------------------------------===// 40 // 41 // The implementation details of the wrapper pass that holds a CycleInfo 42 // suitable for use with the legacy pass manager. 43 // 44 //===----------------------------------------------------------------------===// 45 46 char CycleInfoWrapperPass::ID = 0; 47 48 CycleInfoWrapperPass::CycleInfoWrapperPass() : FunctionPass(ID) { 49 initializeCycleInfoWrapperPassPass(*PassRegistry::getPassRegistry()); 50 } 51 52 INITIALIZE_PASS_BEGIN(CycleInfoWrapperPass, "cycles", "Cycle Info Analysis", 53 true, true) 54 INITIALIZE_PASS_END(CycleInfoWrapperPass, "cycles", "Cycle Info Analysis", true, 55 true) 56 57 void CycleInfoWrapperPass::getAnalysisUsage(AnalysisUsage &AU) const { 58 AU.setPreservesAll(); 59 } 60 61 bool CycleInfoWrapperPass::runOnFunction(Function &Func) { 62 CI.clear(); 63 64 F = &Func; 65 CI.compute(Func); 66 return false; 67 } 68 69 void CycleInfoWrapperPass::print(raw_ostream &OS, const Module *) const { 70 OS << "CycleInfo for function: " << F->getName() << "\n"; 71 CI.print(OS); 72 } 73 74 void CycleInfoWrapperPass::releaseMemory() { 75 CI.clear(); 76 F = nullptr; 77 } 78