LLVM 18.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
19#include "llvm/IR/InstrTypes.h"
20#include "llvm/IR/PassManager.h"
21
22namespace llvm {
23class DominatorTree;
24class Function;
25class LoopInfo;
26
29 void updateForBB(const BasicBlock &BB, int64_t Direction);
30 void updateAggregateStats(const Function &F, const LoopInfo &LI);
31 void reIncludeBB(const BasicBlock &BB);
32
33public:
36 const LoopInfo &LI);
37
40
41 bool operator==(const FunctionPropertiesInfo &FPI) const {
42 return std::memcmp(this, &FPI, sizeof(FunctionPropertiesInfo)) == 0;
43 }
44
45 bool operator!=(const FunctionPropertiesInfo &FPI) const {
46 return !(*this == FPI);
47 }
48
49 void print(raw_ostream &OS) const;
50
51 /// Number of basic blocks
52 int64_t BasicBlockCount = 0;
53
54 /// Number of blocks reached from a conditional instruction, or that are
55 /// 'cases' of a SwitchInstr.
56 // FIXME: We may want to replace this with a more meaningful metric, like
57 // number of conditionally executed blocks:
58 // 'if (a) s();' would be counted here as 2 blocks, just like
59 // 'if (a) s(); else s2(); s3();' would.
61
62 /// Number of uses of this function, plus 1 if the function is callable
63 /// outside the module.
64 int64_t Uses = 0;
65
66 /// Number of direct calls made from this function to other functions
67 /// defined in this module.
69
70 // Load Instruction Count
71 int64_t LoadInstCount = 0;
72
73 // Store Instruction Count
74 int64_t StoreInstCount = 0;
75
76 // Maximum Loop Depth in the Function
77 int64_t MaxLoopDepth = 0;
78
79 // Number of Top Level Loops in the Function
80 int64_t TopLevelLoopCount = 0;
81
82 // All non-debug instructions
84
85 // Basic blocks grouped by number of successors.
89
90 // Basic blocks grouped by number of predecessors.
94
95 // Basic blocks grouped by size as determined by the number of non-debug
96 // instructions that they contain.
97 int64_t BigBasicBlocks = 0;
98 int64_t MediumBasicBlocks = 0;
99 int64_t SmallBasicBlocks = 0;
100
101 // The number of cast instructions inside the function.
103
104 // The number of floating point instructions inside the function.
106
107 // The number of integer instructions inside the function.
109
110 // Operand type couns
120
121 // Additional CFG Properties
122 int64_t CriticalEdgeCount = 0;
125
126 // Call related instructions
127 int64_t IntrinsicCount = 0;
128 int64_t DirectCallCount = 0;
129 int64_t IndirectCallCount = 0;
138};
139
140// Analysis pass
142 : public AnalysisInfoMixin<FunctionPropertiesAnalysis> {
143
144public:
146
148
150};
151
152/// Printer pass for the FunctionPropertiesAnalysis results.
154 : public PassInfoMixin<FunctionPropertiesPrinterPass> {
155 raw_ostream &OS;
156
157public:
159
161};
162
163/// Correctly update FunctionPropertiesInfo post-inlining. A
164/// FunctionPropertiesUpdater keeps the state necessary for tracking the changes
165/// llvm::InlineFunction makes. The idea is that inlining will at most modify
166/// a few BBs of the Caller (maybe the entry BB and definitely the callsite BB)
167/// and potentially affect exception handling BBs in the case of invoke
168/// inlining.
170public:
172
175 finish(FAM);
176 return isUpdateValid(Caller, FPI, FAM);
177 }
178
179private:
181 BasicBlock &CallSiteBB;
182 Function &Caller;
183
184 static bool isUpdateValid(Function &F, const FunctionPropertiesInfo &FPI,
186
188};
189} // namespace llvm
190#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
This file defines the SmallPtrSet class.
A container for analyses that lazily runs them and caches their results.
Definition: PassManager.h:620
LLVM Basic Block Representation.
Definition: BasicBlock.h:56
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
Definition: InstrTypes.h:1190
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:166
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: PassManager.h:152
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:394
A special type used by analysis passes to provide an address that identifies that particular analysis...
Definition: PassManager.h:69
A CRTP mix-in to automatically provide informational APIs needed for passes.
Definition: PassManager.h:371