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