1 //===- CycleAnalysis.cpp - Compute CycleInfo for LLVM IR ------------------===//
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
7 //===----------------------------------------------------------------------===//
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"
19 CycleInfo
CycleAnalysis::run(Function
&F
, FunctionAnalysisManager
&) {
25 AnalysisKey
CycleAnalysis::Key
;
27 CycleInfoPrinterPass::CycleInfoPrinterPass(raw_ostream
&OS
) : OS(OS
) {}
29 PreservedAnalyses
CycleInfoPrinterPass::run(Function
&F
,
30 FunctionAnalysisManager
&AM
) {
31 OS
<< "CycleInfo for function: " << F
.getName() << "\n";
32 AM
.getResult
<CycleAnalysis
>(F
).print(OS
);
34 return PreservedAnalyses::all();
37 PreservedAnalyses
CycleInfoVerifierPass::run(Function
&F
,
38 FunctionAnalysisManager
&AM
) {
39 CycleInfo
&CI
= AM
.getResult
<CycleAnalysis
>(F
);
41 return PreservedAnalyses::all();
44 //===----------------------------------------------------------------------===//
45 // CycleInfoWrapperPass Implementation
46 //===----------------------------------------------------------------------===//
48 // The implementation details of the wrapper pass that holds a CycleInfo
49 // suitable for use with the legacy pass manager.
51 //===----------------------------------------------------------------------===//
53 char CycleInfoWrapperPass::ID
= 0;
55 CycleInfoWrapperPass::CycleInfoWrapperPass() : FunctionPass(ID
) {
56 initializeCycleInfoWrapperPassPass(*PassRegistry::getPassRegistry());
59 INITIALIZE_PASS_BEGIN(CycleInfoWrapperPass
, "cycles", "Cycle Info Analysis",
61 INITIALIZE_PASS_END(CycleInfoWrapperPass
, "cycles", "Cycle Info Analysis", true,
64 void CycleInfoWrapperPass::getAnalysisUsage(AnalysisUsage
&AU
) const {
68 bool CycleInfoWrapperPass::runOnFunction(Function
&Func
) {
76 void CycleInfoWrapperPass::print(raw_ostream
&OS
, const Module
*) const {
77 OS
<< "CycleInfo for function: " << F
->getName() << "\n";
81 void CycleInfoWrapperPass::releaseMemory() {