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