[clang][bytecode][NFC] Only get expr when checking for UB (#125397)
[llvm-project.git] / llvm / lib / Analysis / CycleAnalysis.cpp
blobbdba3ab2acfc971c6da9b1f42c5d1f82e3e56d2a
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 //===----------------------------------------------------------------------===//
9 #include "llvm/Analysis/CycleAnalysis.h"
10 #include "llvm/IR/CFG.h" // for successors found by ADL in GenericCycleImpl.h
11 #include "llvm/InitializePasses.h"
13 using namespace llvm;
15 namespace llvm {
16 class Module;
17 } // namespace llvm
19 CycleInfo CycleAnalysis::run(Function &F, FunctionAnalysisManager &) {
20 CycleInfo CI;
21 CI.compute(F);
22 return CI;
25 AnalysisKey CycleAnalysis::Key;
27 CycleInfoPrinterPass::CycleInfoPrinterPass(raw_ostream &OS) : OS(OS) {}
29 PreservedAnalyses CycleInfoPrinterPass::run(Function &F,
30 FunctionAnalysisManager &AM) {
31 OS << "CycleInfo for function: " << F.getName() << "\n";
32 AM.getResult<CycleAnalysis>(F).print(OS);
34 return PreservedAnalyses::all();
37 PreservedAnalyses CycleInfoVerifierPass::run(Function &F,
38 FunctionAnalysisManager &AM) {
39 CycleInfo &CI = AM.getResult<CycleAnalysis>(F);
40 CI.verify();
41 return PreservedAnalyses::all();
44 //===----------------------------------------------------------------------===//
45 // CycleInfoWrapperPass Implementation
46 //===----------------------------------------------------------------------===//
48 // The implementation details of the wrapper pass that holds a CycleInfo
49 // suitable for use with the legacy pass manager.
51 //===----------------------------------------------------------------------===//
53 char CycleInfoWrapperPass::ID = 0;
55 CycleInfoWrapperPass::CycleInfoWrapperPass() : FunctionPass(ID) {
56 initializeCycleInfoWrapperPassPass(*PassRegistry::getPassRegistry());
59 INITIALIZE_PASS_BEGIN(CycleInfoWrapperPass, "cycles", "Cycle Info Analysis",
60 true, true)
61 INITIALIZE_PASS_END(CycleInfoWrapperPass, "cycles", "Cycle Info Analysis", true,
62 true)
64 void CycleInfoWrapperPass::getAnalysisUsage(AnalysisUsage &AU) const {
65 AU.setPreservesAll();
68 bool CycleInfoWrapperPass::runOnFunction(Function &Func) {
69 CI.clear();
71 F = &Func;
72 CI.compute(Func);
73 return false;
76 void CycleInfoWrapperPass::print(raw_ostream &OS, const Module *) const {
77 OS << "CycleInfo for function: " << F->getName() << "\n";
78 CI.print(OS);
81 void CycleInfoWrapperPass::releaseMemory() {
82 CI.clear();
83 F = nullptr;