LLVM  15.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/SmallPtrSet.h"
19 #include "llvm/IR/InstrTypes.h"
20 #include "llvm/IR/PassManager.h"
21 
22 namespace llvm {
23 class DominatorTree;
24 class Function;
25 class 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 
33 public:
36 
37  bool operator==(const FunctionPropertiesInfo &FPI) const {
38  return std::memcmp(this, &FPI, sizeof(FunctionPropertiesInfo)) == 0;
39  }
40 
41  bool operator!=(const FunctionPropertiesInfo &FPI) const {
42  return !(*this == FPI);
43  }
44 
45  void print(raw_ostream &OS) const;
46 
47  /// Number of basic blocks
48  int64_t BasicBlockCount = 0;
49 
50  /// Number of blocks reached from a conditional instruction, or that are
51  /// 'cases' of a SwitchInstr.
52  // FIXME: We may want to replace this with a more meaningful metric, like
53  // number of conditionally executed blocks:
54  // 'if (a) s();' would be counted here as 2 blocks, just like
55  // 'if (a) s(); else s2(); s3();' would.
57 
58  /// Number of uses of this function, plus 1 if the function is callable
59  /// outside the module.
60  int64_t Uses = 0;
61 
62  /// Number of direct calls made from this function to other functions
63  /// defined in this module.
65 
66  // Load Instruction Count
67  int64_t LoadInstCount = 0;
68 
69  // Store Instruction Count
70  int64_t StoreInstCount = 0;
71 
72  // Maximum Loop Depth in the Function
73  int64_t MaxLoopDepth = 0;
74 
75  // Number of Top Level Loops in the Function
76  int64_t TopLevelLoopCount = 0;
77 
78  // All non-debug instructions
79  int64_t TotalInstructionCount = 0;
80 };
81 
82 // Analysis pass
84  : public AnalysisInfoMixin<FunctionPropertiesAnalysis> {
85 
86 public:
87  static AnalysisKey Key;
88 
90 
92 };
93 
94 /// Printer pass for the FunctionPropertiesAnalysis results.
96  : public PassInfoMixin<FunctionPropertiesPrinterPass> {
97  raw_ostream &OS;
98 
99 public:
100  explicit FunctionPropertiesPrinterPass(raw_ostream &OS) : OS(OS) {}
101 
103 };
104 
105 /// Correctly update FunctionPropertiesInfo post-inlining. A
106 /// FunctionPropertiesUpdater keeps the state necessary for tracking the changes
107 /// llvm::InlineFunction makes. The idea is that inlining will at most modify
108 /// a few BBs of the Caller (maybe the entry BB and definitely the callsite BB)
109 /// and potentially affect exception handling BBs in the case of invoke
110 /// inlining.
112 public:
114 
115  void finish(FunctionAnalysisManager &FAM) const;
116 
117 private:
119  const BasicBlock &CallSiteBB;
120  const Function &Caller;
121 
122  DenseSet<const BasicBlock *> Successors;
123 };
124 } // namespace llvm
125 #endif // LLVM_ANALYSIS_FUNCTIONPROPERTIESANALYSIS_H
llvm::FunctionPropertiesInfo::getFunctionPropertiesInfo
static FunctionPropertiesInfo getFunctionPropertiesInfo(const Function &F, FunctionAnalysisManager &FAM)
Definition: FunctionPropertiesAnalysis.cpp:84
llvm::PreservedAnalyses
A set of analyses that are preserved following a run of a transformation pass.
Definition: PassManager.h:152
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:17
llvm::FunctionPropertiesInfo::operator==
bool operator==(const FunctionPropertiesInfo &FPI) const
Definition: FunctionPropertiesAnalysis.h:37
llvm::PassInfoMixin
A CRTP mix-in to automatically provide informational APIs needed for passes.
Definition: PassManager.h:371
llvm::Function
Definition: Function.h:60
llvm::FunctionPropertiesPrinterPass::run
PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM)
Definition: FunctionPropertiesAnalysis.cpp:121
llvm::FunctionPropertiesInfo::TopLevelLoopCount
int64_t TopLevelLoopCount
Definition: FunctionPropertiesAnalysis.h:76
memcmp
Merge contiguous icmps into a memcmp
Definition: MergeICmps.cpp:899
FAM
FunctionAnalysisManager FAM
Definition: PassBuilderBindings.cpp:59
llvm::FunctionPropertiesPrinterPass
Printer pass for the FunctionPropertiesAnalysis results.
Definition: FunctionPropertiesAnalysis.h:95
llvm::FunctionPropertiesAnalysis::run
FunctionPropertiesInfo run(Function &F, FunctionAnalysisManager &FAM)
Definition: FunctionPropertiesAnalysis.cpp:116
llvm::FunctionPropertiesInfo::LoadInstCount
int64_t LoadInstCount
Definition: FunctionPropertiesAnalysis.h:67
F
#define F(x, y, z)
Definition: MD5.cpp:55
llvm::BasicBlock
LLVM Basic Block Representation.
Definition: BasicBlock.h:55
llvm::FunctionPropertiesAnalysis::Key
static AnalysisKey Key
Definition: FunctionPropertiesAnalysis.h:87
InstrTypes.h
llvm::FunctionPropertiesUpdater::finish
void finish(FunctionAnalysisManager &FAM) const
Definition: FunctionPropertiesAnalysis.cpp:179
llvm::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:54
SmallPtrSet.h
llvm::FunctionPropertiesPrinterPass::FunctionPropertiesPrinterPass
FunctionPropertiesPrinterPass(raw_ostream &OS)
Definition: FunctionPropertiesAnalysis.h:100
llvm::DenseSet
Implements a dense probed hash-table based set.
Definition: DenseSet.h:268
llvm::AnalysisKey
A special type used by analysis passes to provide an address that identifies that particular analysis...
Definition: PassManager.h:69
llvm::FunctionPropertiesUpdater
Correctly update FunctionPropertiesInfo post-inlining.
Definition: FunctionPropertiesAnalysis.h:111
iterator_range.h
llvm::AnalysisInfoMixin
A CRTP mix-in that provides informational APIs needed for analysis passes.
Definition: PassManager.h:394
llvm::FunctionPropertiesInfo::print
void print(raw_ostream &OS) const
Definition: FunctionPropertiesAnalysis.cpp:99
llvm::FunctionPropertiesInfo::Uses
int64_t Uses
Number of uses of this function, plus 1 if the function is callable outside the module.
Definition: FunctionPropertiesAnalysis.h:60
llvm::FunctionPropertiesAnalysis
Definition: FunctionPropertiesAnalysis.h:83
llvm::LoopInfo
Definition: LoopInfo.h:1102
llvm::FunctionPropertiesInfo::MaxLoopDepth
int64_t MaxLoopDepth
Definition: FunctionPropertiesAnalysis.h:73
Direction
Loop::LoopBounds::Direction Direction
Definition: LoopInfo.cpp:226
PassManager.h
llvm::FunctionPropertiesInfo::BlocksReachedFromConditionalInstruction
int64_t BlocksReachedFromConditionalInstruction
Number of blocks reached from a conditional instruction, or that are 'cases' of a SwitchInstr.
Definition: FunctionPropertiesAnalysis.h:56
llvm::FunctionPropertiesInfo::operator!=
bool operator!=(const FunctionPropertiesInfo &FPI) const
Definition: FunctionPropertiesAnalysis.h:41
llvm::FunctionPropertiesInfo::TotalInstructionCount
int64_t TotalInstructionCount
Definition: FunctionPropertiesAnalysis.h:79
llvm::FunctionPropertiesInfo::BasicBlockCount
int64_t BasicBlockCount
Number of basic blocks.
Definition: FunctionPropertiesAnalysis.h:48
llvm::CallBase
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
Definition: InstrTypes.h:1174
llvm::AnalysisManager
A container for analyses that lazily runs them and caches their results.
Definition: InstructionSimplify.h:42
llvm::FunctionPropertiesUpdater::FunctionPropertiesUpdater
FunctionPropertiesUpdater(FunctionPropertiesInfo &FPI, const CallBase &CB)
Definition: FunctionPropertiesAnalysis.cpp:129
BB
Common register allocation spilling lr str ldr sxth r3 ldr mla r4 can lr mov lr str ldr sxth r3 mla r4 and then merge mul and lr str ldr sxth r3 mla r4 It also increase the likelihood the store may become dead bb27 Successors according to LLVM BB
Definition: README.txt:39
llvm::FunctionPropertiesInfo
Definition: FunctionPropertiesAnalysis.h:27
llvm::FunctionPropertiesInfo::StoreInstCount
int64_t StoreInstCount
Definition: FunctionPropertiesAnalysis.h:70
llvm::codeview::PublicSymFlags::Function
@ Function
llvm::FunctionPropertiesInfo::DirectCallsToDefinedFunctions
int64_t DirectCallsToDefinedFunctions
Number of direct calls made from this function to other functions defined in this module.
Definition: FunctionPropertiesAnalysis.h:64