1 | //===- CycleAnalysis.h - Cycle Info for LLVM IR -----------------*- C++ -*-===// |
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 | /// \file |
9 | /// |
10 | /// This file declares an analysis pass that computes CycleInfo for |
11 | /// LLVM IR, specialized from GenericCycleInfo. |
12 | /// |
13 | //===----------------------------------------------------------------------===// |
14 | |
15 | #ifndef LLVM_ANALYSIS_CYCLEANALYSIS_H |
16 | #define LLVM_ANALYSIS_CYCLEANALYSIS_H |
17 | |
18 | #include "llvm/IR/CycleInfo.h" |
19 | #include "llvm/IR/PassManager.h" |
20 | #include "llvm/IR/SSAContext.h" |
21 | #include "llvm/Pass.h" |
22 | |
23 | namespace llvm { |
24 | |
25 | /// Legacy analysis pass which computes a \ref CycleInfo. |
26 | class CycleInfoWrapperPass : public FunctionPass { |
27 | Function *F = nullptr; |
28 | CycleInfo CI; |
29 | |
30 | public: |
31 | static char ID; |
32 | |
33 | CycleInfoWrapperPass(); |
34 | |
35 | CycleInfo &getResult() { return CI; } |
36 | const CycleInfo &getResult() const { return CI; } |
37 | |
38 | bool runOnFunction(Function &F) override; |
39 | void getAnalysisUsage(AnalysisUsage &AU) const override; |
40 | void releaseMemory() override; |
41 | void print(raw_ostream &OS, const Module *M = nullptr) const override; |
42 | |
43 | // TODO: verify analysis? |
44 | }; |
45 | |
46 | /// Analysis pass which computes a \ref CycleInfo. |
47 | class CycleAnalysis : public AnalysisInfoMixin<CycleAnalysis> { |
48 | friend AnalysisInfoMixin<CycleAnalysis>; |
49 | static AnalysisKey Key; |
50 | |
51 | public: |
52 | /// Provide the result typedef for this analysis pass. |
53 | using Result = CycleInfo; |
54 | |
55 | using LegacyWrapper = CycleInfoWrapperPass; |
56 | |
57 | /// Run the analysis pass over a function and produce a dominator tree. |
58 | CycleInfo run(Function &F, FunctionAnalysisManager &); |
59 | |
60 | // TODO: verify analysis? |
61 | }; |
62 | |
63 | /// Printer pass for the \c DominatorTree. |
64 | class CycleInfoPrinterPass : public PassInfoMixin<CycleInfoPrinterPass> { |
65 | raw_ostream &OS; |
66 | |
67 | public: |
68 | explicit CycleInfoPrinterPass(raw_ostream &OS); |
69 | |
70 | PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM); |
71 | |
72 | static bool isRequired() { return true; } |
73 | }; |
74 | |
75 | } // end namespace llvm |
76 | |
77 | #endif // LLVM_ANALYSIS_CYCLEANALYSIS_H |
78 | |