Path: blob/main/contrib/llvm-project/llvm/lib/Analysis/CycleAnalysis.cpp
35233 views
//===- CycleAnalysis.cpp - Compute CycleInfo for LLVM IR ------------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#include "llvm/Analysis/CycleAnalysis.h"9#include "llvm/ADT/GenericCycleImpl.h"10#include "llvm/IR/CFG.h" // for successors found by ADL in GenericCycleImpl.h11#include "llvm/InitializePasses.h"1213using namespace llvm;1415namespace llvm {16class Module;17} // namespace llvm1819CycleInfo CycleAnalysis::run(Function &F, FunctionAnalysisManager &) {20CycleInfo CI;21CI.compute(F);22return CI;23}2425AnalysisKey CycleAnalysis::Key;2627CycleInfoPrinterPass::CycleInfoPrinterPass(raw_ostream &OS) : OS(OS) {}2829PreservedAnalyses CycleInfoPrinterPass::run(Function &F,30FunctionAnalysisManager &AM) {31OS << "CycleInfo for function: " << F.getName() << "\n";32AM.getResult<CycleAnalysis>(F).print(OS);3334return PreservedAnalyses::all();35}3637//===----------------------------------------------------------------------===//38// CycleInfoWrapperPass Implementation39//===----------------------------------------------------------------------===//40//41// The implementation details of the wrapper pass that holds a CycleInfo42// suitable for use with the legacy pass manager.43//44//===----------------------------------------------------------------------===//4546char CycleInfoWrapperPass::ID = 0;4748CycleInfoWrapperPass::CycleInfoWrapperPass() : FunctionPass(ID) {49initializeCycleInfoWrapperPassPass(*PassRegistry::getPassRegistry());50}5152INITIALIZE_PASS_BEGIN(CycleInfoWrapperPass, "cycles", "Cycle Info Analysis",53true, true)54INITIALIZE_PASS_END(CycleInfoWrapperPass, "cycles", "Cycle Info Analysis", true,55true)5657void CycleInfoWrapperPass::getAnalysisUsage(AnalysisUsage &AU) const {58AU.setPreservesAll();59}6061bool CycleInfoWrapperPass::runOnFunction(Function &Func) {62CI.clear();6364F = &Func;65CI.compute(Func);66return false;67}6869void CycleInfoWrapperPass::print(raw_ostream &OS, const Module *) const {70OS << "CycleInfo for function: " << F->getName() << "\n";71CI.print(OS);72}7374void CycleInfoWrapperPass::releaseMemory() {75CI.clear();76F = nullptr;77}787980