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/ADT/GenericCycleImpl.h"
11 #include "llvm/IR/CFG.h" // for successors found by ADL in GenericCycleImpl.h
12 #include "llvm/InitializePasses.h"
20 CycleInfo
CycleAnalysis::run(Function
&F
, FunctionAnalysisManager
&) {
26 AnalysisKey
CycleAnalysis::Key
;
28 CycleInfoPrinterPass::CycleInfoPrinterPass(raw_ostream
&OS
) : OS(OS
) {}
30 PreservedAnalyses
CycleInfoPrinterPass::run(Function
&F
,
31 FunctionAnalysisManager
&AM
) {
32 OS
<< "CycleInfo for function: " << F
.getName() << "\n";
33 AM
.getResult
<CycleAnalysis
>(F
).print(OS
);
35 return PreservedAnalyses::all();
38 //===----------------------------------------------------------------------===//
39 // CycleInfoWrapperPass Implementation
40 //===----------------------------------------------------------------------===//
42 // The implementation details of the wrapper pass that holds a CycleInfo
43 // suitable for use with the legacy pass manager.
45 //===----------------------------------------------------------------------===//
47 char CycleInfoWrapperPass::ID
= 0;
49 CycleInfoWrapperPass::CycleInfoWrapperPass() : FunctionPass(ID
) {
50 initializeCycleInfoWrapperPassPass(*PassRegistry::getPassRegistry());
53 INITIALIZE_PASS_BEGIN(CycleInfoWrapperPass
, "cycles", "Cycle Info Analysis",
55 INITIALIZE_PASS_END(CycleInfoWrapperPass
, "cycles", "Cycle Info Analysis", true,
58 void CycleInfoWrapperPass::getAnalysisUsage(AnalysisUsage
&AU
) const {
62 bool CycleInfoWrapperPass::runOnFunction(Function
&Func
) {
70 void CycleInfoWrapperPass::print(raw_ostream
&OS
, const Module
*) const {
71 OS
<< "CycleInfo for function: " << F
->getName() << "\n";
75 void CycleInfoWrapperPass::releaseMemory() {