10eae32dcSDimitry Andric //===- CycleAnalysis.cpp - Compute CycleInfo for LLVM IR ------------------===// 20eae32dcSDimitry Andric // 30eae32dcSDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 40eae32dcSDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 50eae32dcSDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 60eae32dcSDimitry Andric // 70eae32dcSDimitry Andric //===----------------------------------------------------------------------===// 80eae32dcSDimitry Andric 90eae32dcSDimitry Andric #include "llvm/Analysis/CycleAnalysis.h" 100eae32dcSDimitry Andric #include "llvm/ADT/GenericCycleImpl.h" 1181ad6265SDimitry Andric #include "llvm/IR/CFG.h" // for successors found by ADL in GenericCycleImpl.h 120eae32dcSDimitry Andric #include "llvm/InitializePasses.h" 130eae32dcSDimitry Andric 140eae32dcSDimitry Andric using namespace llvm; 150eae32dcSDimitry Andric 1681ad6265SDimitry Andric namespace llvm { 1781ad6265SDimitry Andric class Module; 18*0fca6ea1SDimitry Andric } // namespace llvm 1981ad6265SDimitry Andric 200eae32dcSDimitry Andric CycleInfo CycleAnalysis::run(Function &F, FunctionAnalysisManager &) { 210eae32dcSDimitry Andric CycleInfo CI; 220eae32dcSDimitry Andric CI.compute(F); 230eae32dcSDimitry Andric return CI; 240eae32dcSDimitry Andric } 250eae32dcSDimitry Andric 260eae32dcSDimitry Andric AnalysisKey CycleAnalysis::Key; 270eae32dcSDimitry Andric 280eae32dcSDimitry Andric CycleInfoPrinterPass::CycleInfoPrinterPass(raw_ostream &OS) : OS(OS) {} 290eae32dcSDimitry Andric 300eae32dcSDimitry Andric PreservedAnalyses CycleInfoPrinterPass::run(Function &F, 310eae32dcSDimitry Andric FunctionAnalysisManager &AM) { 320eae32dcSDimitry Andric OS << "CycleInfo for function: " << F.getName() << "\n"; 330eae32dcSDimitry Andric AM.getResult<CycleAnalysis>(F).print(OS); 340eae32dcSDimitry Andric 350eae32dcSDimitry Andric return PreservedAnalyses::all(); 360eae32dcSDimitry Andric } 370eae32dcSDimitry Andric 380eae32dcSDimitry Andric //===----------------------------------------------------------------------===// 390eae32dcSDimitry Andric // CycleInfoWrapperPass Implementation 400eae32dcSDimitry Andric //===----------------------------------------------------------------------===// 410eae32dcSDimitry Andric // 420eae32dcSDimitry Andric // The implementation details of the wrapper pass that holds a CycleInfo 430eae32dcSDimitry Andric // suitable for use with the legacy pass manager. 440eae32dcSDimitry Andric // 450eae32dcSDimitry Andric //===----------------------------------------------------------------------===// 460eae32dcSDimitry Andric 470eae32dcSDimitry Andric char CycleInfoWrapperPass::ID = 0; 480eae32dcSDimitry Andric 490eae32dcSDimitry Andric CycleInfoWrapperPass::CycleInfoWrapperPass() : FunctionPass(ID) { 500eae32dcSDimitry Andric initializeCycleInfoWrapperPassPass(*PassRegistry::getPassRegistry()); 510eae32dcSDimitry Andric } 520eae32dcSDimitry Andric 530eae32dcSDimitry Andric INITIALIZE_PASS_BEGIN(CycleInfoWrapperPass, "cycles", "Cycle Info Analysis", 540eae32dcSDimitry Andric true, true) 550eae32dcSDimitry Andric INITIALIZE_PASS_END(CycleInfoWrapperPass, "cycles", "Cycle Info Analysis", true, 560eae32dcSDimitry Andric true) 570eae32dcSDimitry Andric 580eae32dcSDimitry Andric void CycleInfoWrapperPass::getAnalysisUsage(AnalysisUsage &AU) const { 590eae32dcSDimitry Andric AU.setPreservesAll(); 600eae32dcSDimitry Andric } 610eae32dcSDimitry Andric 620eae32dcSDimitry Andric bool CycleInfoWrapperPass::runOnFunction(Function &Func) { 630eae32dcSDimitry Andric CI.clear(); 640eae32dcSDimitry Andric 650eae32dcSDimitry Andric F = &Func; 660eae32dcSDimitry Andric CI.compute(Func); 670eae32dcSDimitry Andric return false; 680eae32dcSDimitry Andric } 690eae32dcSDimitry Andric 700eae32dcSDimitry Andric void CycleInfoWrapperPass::print(raw_ostream &OS, const Module *) const { 710eae32dcSDimitry Andric OS << "CycleInfo for function: " << F->getName() << "\n"; 720eae32dcSDimitry Andric CI.print(OS); 730eae32dcSDimitry Andric } 740eae32dcSDimitry Andric 750eae32dcSDimitry Andric void CycleInfoWrapperPass::releaseMemory() { 760eae32dcSDimitry Andric CI.clear(); 770eae32dcSDimitry Andric F = nullptr; 780eae32dcSDimitry Andric } 79