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