/src/llvm-project/llvm/lib/Analysis/CycleAnalysis.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | //===- CycleAnalysis.cpp - Compute CycleInfo for LLVM IR ------------------===// |
2 | | // |
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 |
6 | | // |
7 | | //===----------------------------------------------------------------------===// |
8 | | |
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" |
13 | | |
14 | | using namespace llvm; |
15 | | |
16 | | namespace llvm { |
17 | | class Module; |
18 | | } |
19 | | |
20 | 0 | CycleInfo CycleAnalysis::run(Function &F, FunctionAnalysisManager &) { |
21 | 0 | CycleInfo CI; |
22 | 0 | CI.compute(F); |
23 | 0 | return CI; |
24 | 0 | } |
25 | | |
26 | | AnalysisKey CycleAnalysis::Key; |
27 | | |
28 | 0 | CycleInfoPrinterPass::CycleInfoPrinterPass(raw_ostream &OS) : OS(OS) {} |
29 | | |
30 | | PreservedAnalyses CycleInfoPrinterPass::run(Function &F, |
31 | 0 | FunctionAnalysisManager &AM) { |
32 | 0 | OS << "CycleInfo for function: " << F.getName() << "\n"; |
33 | 0 | AM.getResult<CycleAnalysis>(F).print(OS); |
34 | |
|
35 | 0 | return PreservedAnalyses::all(); |
36 | 0 | } |
37 | | |
38 | | //===----------------------------------------------------------------------===// |
39 | | // CycleInfoWrapperPass Implementation |
40 | | //===----------------------------------------------------------------------===// |
41 | | // |
42 | | // The implementation details of the wrapper pass that holds a CycleInfo |
43 | | // suitable for use with the legacy pass manager. |
44 | | // |
45 | | //===----------------------------------------------------------------------===// |
46 | | |
47 | | char CycleInfoWrapperPass::ID = 0; |
48 | | |
49 | 0 | CycleInfoWrapperPass::CycleInfoWrapperPass() : FunctionPass(ID) { |
50 | 0 | initializeCycleInfoWrapperPassPass(*PassRegistry::getPassRegistry()); |
51 | 0 | } |
52 | | |
53 | 62 | INITIALIZE_PASS_BEGIN(CycleInfoWrapperPass, "cycles", "Cycle Info Analysis", |
54 | 62 | true, true) |
55 | 62 | INITIALIZE_PASS_END(CycleInfoWrapperPass, "cycles", "Cycle Info Analysis", true, |
56 | | true) |
57 | | |
58 | 0 | void CycleInfoWrapperPass::getAnalysisUsage(AnalysisUsage &AU) const { |
59 | 0 | AU.setPreservesAll(); |
60 | 0 | } |
61 | | |
62 | 0 | bool CycleInfoWrapperPass::runOnFunction(Function &Func) { |
63 | 0 | CI.clear(); |
64 | |
|
65 | 0 | F = &Func; |
66 | 0 | CI.compute(Func); |
67 | 0 | return false; |
68 | 0 | } |
69 | | |
70 | 0 | void CycleInfoWrapperPass::print(raw_ostream &OS, const Module *) const { |
71 | 0 | OS << "CycleInfo for function: " << F->getName() << "\n"; |
72 | 0 | CI.print(OS); |
73 | 0 | } |
74 | | |
75 | 0 | void CycleInfoWrapperPass::releaseMemory() { |
76 | 0 | CI.clear(); |
77 | 0 | F = nullptr; |
78 | 0 | } |