LLVM 24.0.0git
CycleAnalysis.cpp
Go to the documentation of this file.
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
10#include "llvm/IR/CFG.h" // for successors found by ADL in GenericCycleImpl.h
13
14using namespace llvm;
15
16// Always verify cycle info if expensive checking is enabled.
17#ifdef EXPENSIVE_CHECKS
18bool llvm::VerifyCycleInfo = true;
19#else
21#endif
25 cl::desc("Verify cycle info (time consuming)"));
26
27namespace llvm {
28class Module;
29} // namespace llvm
30
36
38 FunctionAnalysisManager::Invalidator &) {
39 // Check whether the analysis, all analyses on functions, or the function's
40 // CFG have been preserved.
41 auto PAC = PA.getChecker<CycleAnalysis>();
42 return !(PAC.preserved() || PAC.preservedSet<AllAnalysesOn<Function>>() ||
43 PAC.preservedSet<CFGAnalyses>());
44}
45
46AnalysisKey CycleAnalysis::Key;
47
49
52 OS << "CycleInfo for function: " << F.getName() << "\n";
54
56}
57
64
65//===----------------------------------------------------------------------===//
66// CycleInfoWrapperPass Implementation
67//===----------------------------------------------------------------------===//
68//
69// The implementation details of the wrapper pass that holds a CycleInfo
70// suitable for use with the legacy pass manager.
71//
72//===----------------------------------------------------------------------===//
73
75
77
78INITIALIZE_PASS_BEGIN(CycleInfoWrapperPass, "cycles", "Cycle Info Analysis",
79 true, true)
80INITIALIZE_PASS_END(CycleInfoWrapperPass, "cycles", "Cycle Info Analysis", true,
81 true)
82
84 AU.setPreservesAll();
85}
86
88 CI.clear();
89
90 F = &Func;
91 CI.compute(Func);
92 return false;
93}
94
96 OS << "CycleInfo for function: " << F->getName() << "\n";
97 CI.print(OS);
98}
99
101 if (VerifyCycleInfo)
102 CI.verify();
103}
104
106 CI.clear();
107 F = nullptr;
108}
static cl::opt< bool, true > VerifyCycleInfoX("verify-cycle-info", cl::location(VerifyCycleInfo), cl::Hidden, cl::desc("Verify cycle info (time consuming)"))
This file declares an analysis pass that computes CycleInfo for LLVM IR, specialized from GenericCycl...
This file provides various utilities for inspecting and working with the control flow graph in LLVM I...
#define F(x, y, z)
Definition MD5.cpp:54
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
Definition PassSupport.h:44
#define INITIALIZE_PASS_BEGIN(passName, arg, name, cfg, analysis)
Definition PassSupport.h:39
This templated class represents "all analyses that operate over <aparticular IR unit>" (e....
Definition Analysis.h:50
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
Represent the analysis usage information of a pass.
Represents analyses that only rely on functions' control flow.
Definition Analysis.h:73
Analysis pass which computes a CycleInfo.
LLVM_ABI CycleInfo run(Function &F, FunctionAnalysisManager &)
Run the analysis pass over a function and produce a dominator tree.
LLVM_ABI CycleInfoPrinterPass(raw_ostream &OS)
LLVM_ABI PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM)
Legacy analysis pass which computes a CycleInfo.
void verifyAnalysis() const override
verifyAnalysis() - This member can be implemented by a analysis pass to check state of analysis infor...
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
void print(raw_ostream &OS, const Module *M=nullptr) const override
print - Print out the internal state of the pass.
bool runOnFunction(Function &F) override
runOnFunction - Virtual method overriden by subclasses to do the per-function processing of the pass.
void releaseMemory() override
releaseMemory() - This member can be implemented by a pass if it wants to be able to release its memo...
LLVM_ABI bool invalidate(Function &F, const PreservedAnalyses &PA, FunctionAnalysisManager::Invalidator &)
Handle invalidation explicitly. Defined in CycleAnalysis.cpp.
FunctionPass(char &pid)
Definition Pass.h:314
void verify() const
Verify that the entire cycle tree well-formed.
void compute(FunctionT &F)
Compute the cycle info for a function.
A Module instance is used to store all the information related to an LLVM module.
Definition Module.h:68
A set of analyses that are preserved following a run of a transformation pass.
Definition Analysis.h:112
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Definition Analysis.h:118
PreservedAnalysisChecker getChecker() const
Build a checker for this PreservedAnalyses and the specified analysis type.
Definition Analysis.h:275
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition raw_ostream.h:53
LocationClass< Ty > location(Ty &L)
This is an optimization pass for GlobalISel generic memory operations.
Printable print(const GCNRegPressure &RP, const GCNSubtarget *ST=nullptr, unsigned DynamicVGPRBlockSize=0)
LLVM_ABI bool VerifyCycleInfo
Enable verification of cycle info.
AnalysisManager< Function > FunctionAnalysisManager
Convenience typedef for the Function analysis manager.
A special type used by analysis passes to provide an address that identifies that particular analysis...
Definition Analysis.h:29
LLVM_ABI PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM)