LLVM 19.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
18#include "llvm/IR/InstrTypes.h"
19#include "llvm/IR/PassManager.h"
20
21namespace llvm {
22class DominatorTree;
23class Function;
24class LoopInfo;
25
28 void updateForBB(const BasicBlock &BB, int64_t Direction);
29 void updateAggregateStats(const Function &F, const LoopInfo &LI);
30 void reIncludeBB(const BasicBlock &BB);
31
32public:
35 const LoopInfo &LI);
36
39
40 bool operator==(const FunctionPropertiesInfo &FPI) const {
41 return std::memcmp(this, &FPI, sizeof(FunctionPropertiesInfo)) == 0;
42 }
43
44 bool operator!=(const FunctionPropertiesInfo &FPI) const {
45 return !(*this == FPI);
46 }
47
48 void print(raw_ostream &OS) const;
49
50 /// Number of basic blocks
51 int64_t BasicBlockCount = 0;
52
53 /// Number of blocks reached from a conditional instruction, or that are
54 /// 'cases' of a SwitchInstr.
55 // FIXME: We may want to replace this with a more meaningful metric, like
56 // number of conditionally executed blocks:
57 // 'if (a) s();' would be counted here as 2 blocks, just like
58 // 'if (a) s(); else s2(); s3();' would.
60
61 /// Number of uses of this function, plus 1 if the function is callable
62 /// outside the module.
63 int64_t Uses = 0;
64
65 /// Number of direct calls made from this function to other functions
66 /// defined in this module.
68
69 // Load Instruction Count
70 int64_t LoadInstCount = 0;
71
72 // Store Instruction Count
73 int64_t StoreInstCount = 0;
74
75 // Maximum Loop Depth in the Function
76 int64_t MaxLoopDepth = 0;
77
78 // Number of Top Level Loops in the Function
79 int64_t TopLevelLoopCount = 0;
80
81 // All non-debug instructions
83
84 // Basic blocks grouped by number of successors.
88
89 // Basic blocks grouped by number of predecessors.
93
94 // Basic blocks grouped by size as determined by the number of non-debug
95 // instructions that they contain.
96 int64_t BigBasicBlocks = 0;
97 int64_t MediumBasicBlocks = 0;
98 int64_t SmallBasicBlocks = 0;
99
100 // The number of cast instructions inside the function.
102
103 // The number of floating point instructions inside the function.
105
106 // The number of integer instructions inside the function.
108
109 // Operand type couns
119
120 // Additional CFG Properties
121 int64_t CriticalEdgeCount = 0;
124
125 // Call related instructions
126 int64_t IntrinsicCount = 0;
127 int64_t DirectCallCount = 0;
128 int64_t IndirectCallCount = 0;
137};
138
139// Analysis pass
141 : public AnalysisInfoMixin<FunctionPropertiesAnalysis> {
142
143public:
145
147
149};
150
151/// Printer pass for the FunctionPropertiesAnalysis results.
153 : public PassInfoMixin<FunctionPropertiesPrinterPass> {
154 raw_ostream &OS;
155
156public:
158
160
161 static bool isRequired() { return true; }
162};
163
164/// Correctly update FunctionPropertiesInfo post-inlining. A
165/// FunctionPropertiesUpdater keeps the state necessary for tracking the changes
166/// llvm::InlineFunction makes. The idea is that inlining will at most modify
167/// a few BBs of the Caller (maybe the entry BB and definitely the callsite BB)
168/// and potentially affect exception handling BBs in the case of invoke
169/// inlining.
171public:
173
176 finish(FAM);
177 return isUpdateValid(Caller, FPI, FAM);
178 }
179
180private:
182 BasicBlock &CallSiteBB;
183 Function &Caller;
184
185 static bool isUpdateValid(Function &F, const FunctionPropertiesInfo &FPI,
187
189};
190} // namespace llvm
191#endif // LLVM_ANALYSIS_FUNCTIONPROPERTIESANALYSIS_H
Loop::LoopBounds::Direction Direction
Definition: LoopInfo.cpp:230
#define F(x, y, z)
Definition: MD5.cpp:55
FunctionAnalysisManager FAM
This header defines various interfaces for pass management in LLVM.
raw_pwrite_stream & OS
A container for analyses that lazily runs them and caches their results.
Definition: PassManager.h:348
LLVM Basic Block Representation.
Definition: BasicBlock.h:60
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
Definition: InstrTypes.h:1461
Implements a dense probed hash-table based set.
Definition: DenseSet.h:271
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:109
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
This provides a very simple, boring adaptor for a begin and end iterator into a range type.
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:114
A special type used by analysis passes to provide an address that identifies that particular analysis...
Definition: Analysis.h:26
A CRTP mix-in to automatically provide informational APIs needed for passes.
Definition: PassManager.h:91