LLVM 20.0.0git
FunctionPropertiesAnalysis.h
Go to the documentation of this file.
1//=- FunctionPropertiesAnalysis.h - Function Properties Analysis --*- 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//
9// This file defines the FunctionPropertiesInfo and FunctionPropertiesAnalysis
10// classes used to extract function properties.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_ANALYSIS_FUNCTIONPROPERTIESANALYSIS_H
15#define LLVM_ANALYSIS_FUNCTIONPROPERTIESANALYSIS_H
16
17#include "llvm/ADT/DenseSet.h"
18#include "llvm/IR/Dominators.h"
19#include "llvm/IR/PassManager.h"
20
21namespace llvm {
22class BasicBlock;
23class CallBase;
24class DominatorTree;
25class Function;
26class LoopInfo;
27
30 void updateForBB(const BasicBlock &BB, int64_t Direction);
31 void updateAggregateStats(const Function &F, const LoopInfo &LI);
32 void reIncludeBB(const BasicBlock &BB);
33
34public:
37 const LoopInfo &LI);
38
41
42 bool operator==(const FunctionPropertiesInfo &FPI) const {
43 return std::memcmp(this, &FPI, sizeof(FunctionPropertiesInfo)) == 0;
44 }
45
46 bool operator!=(const FunctionPropertiesInfo &FPI) const {
47 return !(*this == FPI);
48 }
49
50 void print(raw_ostream &OS) const;
51
52 /// Number of basic blocks
53 int64_t BasicBlockCount = 0;
54
55 /// Number of blocks reached from a conditional instruction, or that are
56 /// 'cases' of a SwitchInstr.
57 // FIXME: We may want to replace this with a more meaningful metric, like
58 // number of conditionally executed blocks:
59 // 'if (a) s();' would be counted here as 2 blocks, just like
60 // 'if (a) s(); else s2(); s3();' would.
62
63 /// Number of uses of this function, plus 1 if the function is callable
64 /// outside the module.
65 int64_t Uses = 0;
66
67 /// Number of direct calls made from this function to other functions
68 /// defined in this module.
70
71 // Load Instruction Count
72 int64_t LoadInstCount = 0;
73
74 // Store Instruction Count
75 int64_t StoreInstCount = 0;
76
77 // Maximum Loop Depth in the Function
78 int64_t MaxLoopDepth = 0;
79
80 // Number of Top Level Loops in the Function
81 int64_t TopLevelLoopCount = 0;
82
83 // All non-debug instructions
85
86 // Basic blocks grouped by number of successors.
90
91 // Basic blocks grouped by number of predecessors.
95
96 // Basic blocks grouped by size as determined by the number of non-debug
97 // instructions that they contain.
98 int64_t BigBasicBlocks = 0;
99 int64_t MediumBasicBlocks = 0;
100 int64_t SmallBasicBlocks = 0;
101
102 // The number of cast instructions inside the function.
104
105 // The number of floating point instructions inside the function.
107
108 // The number of integer instructions inside the function.
110
111 // Operand type couns
121
122 // Additional CFG Properties
123 int64_t CriticalEdgeCount = 0;
126
127 // Call related instructions
128 int64_t IntrinsicCount = 0;
129 int64_t DirectCallCount = 0;
130 int64_t IndirectCallCount = 0;
139};
140
141// Analysis pass
143 : public AnalysisInfoMixin<FunctionPropertiesAnalysis> {
144
145public:
147
149
151};
152
153/// Printer pass for the FunctionPropertiesAnalysis results.
155 : public PassInfoMixin<FunctionPropertiesPrinterPass> {
156 raw_ostream &OS;
157
158public:
160
162
163 static bool isRequired() { return true; }
164};
165
166/// Correctly update FunctionPropertiesInfo post-inlining. A
167/// FunctionPropertiesUpdater keeps the state necessary for tracking the changes
168/// llvm::InlineFunction makes. The idea is that inlining will at most modify
169/// a few BBs of the Caller (maybe the entry BB and definitely the callsite BB)
170/// and potentially affect exception handling BBs in the case of invoke
171/// inlining.
173public:
175
178 finish(FAM);
179 return isUpdateValid(Caller, FPI, FAM);
180 }
181
182private:
184 BasicBlock &CallSiteBB;
185 Function &Caller;
186
187 static bool isUpdateValid(Function &F, const FunctionPropertiesInfo &FPI,
189
190 DominatorTree &getUpdatedDominatorTree(FunctionAnalysisManager &FAM) const;
191
193
194 // Edges we might potentially need to remove from the dominator tree.
196};
197} // namespace llvm
198#endif // LLVM_ANALYSIS_FUNCTIONPROPERTIESANALYSIS_H
This file defines the DenseSet and SmallDenseSet classes.
This header defines various interfaces for pass management in LLVM.
Loop::LoopBounds::Direction Direction
Definition: LoopInfo.cpp:231
#define F(x, y, z)
Definition: MD5.cpp:55
FunctionAnalysisManager FAM
raw_pwrite_stream & OS
A container for analyses that lazily runs them and caches their results.
Definition: PassManager.h:253
LLVM Basic Block Representation.
Definition: BasicBlock.h:61
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
Definition: InstrTypes.h:1120
Implements a dense probed hash-table based set.
Definition: DenseSet.h:278
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.
Definition: Dominators.h:162
FunctionPropertiesInfo run(Function &F, FunctionAnalysisManager &FAM)
bool operator!=(const FunctionPropertiesInfo &FPI) const
int64_t BasicBlockCount
Number of basic blocks.
int64_t Uses
Number of uses of this function, plus 1 if the function is callable outside the module.
bool operator==(const FunctionPropertiesInfo &FPI) const
int64_t BlocksReachedFromConditionalInstruction
Number of blocks reached from a conditional instruction, or that are 'cases' of a SwitchInstr.
static FunctionPropertiesInfo getFunctionPropertiesInfo(const Function &F, const DominatorTree &DT, const LoopInfo &LI)
int64_t DirectCallsToDefinedFunctions
Number of direct calls made from this function to other functions defined in this module.
Printer pass for the FunctionPropertiesAnalysis results.
PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM)
Correctly update FunctionPropertiesInfo post-inlining.
void finish(FunctionAnalysisManager &FAM) const
bool finishAndTest(FunctionAnalysisManager &FAM) const
A set of analyses that are preserved following a run of a transformation pass.
Definition: Analysis.h:111
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1196
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
@ BasicBlock
Various leaf nodes.
Definition: ISDOpcodes.h:71
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
A CRTP mix-in that provides informational APIs needed for analysis passes.
Definition: PassManager.h:92
A special type used by analysis passes to provide an address that identifies that particular analysis...
Definition: Analysis.h:28
A CRTP mix-in to automatically provide informational APIs needed for passes.
Definition: PassManager.h:69