LLVM  14.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/Analysis/LoopInfo.h"
18 #include "llvm/IR/PassManager.h"
19 
20 namespace llvm {
21 class Function;
22 
24 public:
26  const LoopInfo &LI);
27 
28  void print(raw_ostream &OS) const;
29 
30  /// Number of basic blocks
31  int64_t BasicBlockCount = 0;
32 
33  /// Number of blocks reached from a conditional instruction, or that are
34  /// 'cases' of a SwitchInstr.
35  // FIXME: We may want to replace this with a more meaningful metric, like
36  // number of conditionally executed blocks:
37  // 'if (a) s();' would be counted here as 2 blocks, just like
38  // 'if (a) s(); else s2(); s3();' would.
40 
41  /// Number of uses of this function, plus 1 if the function is callable
42  /// outside the module.
43  int64_t Uses = 0;
44 
45  /// Number of direct calls made from this function to other functions
46  /// defined in this module.
48 
49  // Load Instruction Count
50  int64_t LoadInstCount = 0;
51 
52  // Store Instruction Count
53  int64_t StoreInstCount = 0;
54 
55  // Maximum Loop Depth in the Function
56  int64_t MaxLoopDepth = 0;
57 
58  // Number of Top Level Loops in the Function
59  int64_t TopLevelLoopCount = 0;
60 };
61 
62 // Analysis pass
64  : public AnalysisInfoMixin<FunctionPropertiesAnalysis> {
65 
66 public:
67  static AnalysisKey Key;
68 
70 
72 };
73 
74 /// Printer pass for the FunctionPropertiesAnalysis results.
76  : public PassInfoMixin<FunctionPropertiesPrinterPass> {
77  raw_ostream &OS;
78 
79 public:
80  explicit FunctionPropertiesPrinterPass(raw_ostream &OS) : OS(OS) {}
81 
83 };
84 
85 } // namespace llvm
86 #endif // LLVM_ANALYSIS_FUNCTIONPROPERTIESANALYSIS_H
llvm::PreservedAnalyses
A set of analyses that are preserved following a run of a transformation pass.
Definition: PassManager.h:155
llvm
This file implements support for optimizing divisions by a constant.
Definition: AllocatorList.h:23
llvm::PassInfoMixin
A CRTP mix-in to automatically provide informational APIs needed for passes.
Definition: PassManager.h:374
llvm::Function
Definition: Function.h:62
llvm::FunctionPropertiesPrinterPass::run
PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM)
Definition: FunctionPropertiesAnalysis.cpp:82
llvm::FunctionPropertiesInfo::TopLevelLoopCount
int64_t TopLevelLoopCount
Definition: FunctionPropertiesAnalysis.h:59
FAM
FunctionAnalysisManager FAM
Definition: PassBuilderBindings.cpp:59
llvm::FunctionPropertiesPrinterPass
Printer pass for the FunctionPropertiesAnalysis results.
Definition: FunctionPropertiesAnalysis.h:75
llvm::FunctionPropertiesAnalysis::run
Result run(Function &F, FunctionAnalysisManager &FAM)
Definition: FunctionPropertiesAnalysis.cpp:76
llvm::FunctionPropertiesInfo::LoadInstCount
int64_t LoadInstCount
Definition: FunctionPropertiesAnalysis.h:50
F
#define F(x, y, z)
Definition: MD5.cpp:56
llvm::FunctionPropertiesInfo::getFunctionPropertiesInfo
static FunctionPropertiesInfo getFunctionPropertiesInfo(const Function &F, const LoopInfo &LI)
Definition: FunctionPropertiesAnalysis.cpp:20
llvm::FunctionPropertiesAnalysis::Key
static AnalysisKey Key
Definition: FunctionPropertiesAnalysis.h:67
llvm::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:53
LoopInfo.h
llvm::FunctionPropertiesPrinterPass::FunctionPropertiesPrinterPass
FunctionPropertiesPrinterPass(raw_ostream &OS)
Definition: FunctionPropertiesAnalysis.h:80
llvm::AnalysisKey
A special type used by analysis passes to provide an address that identifies that particular analysis...
Definition: PassManager.h:72
llvm::AnalysisInfoMixin
A CRTP mix-in that provides informational APIs needed for analysis passes.
Definition: PassManager.h:397
llvm::FunctionPropertiesInfo::print
void print(raw_ostream &OS) const
Definition: FunctionPropertiesAnalysis.cpp:60
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:43
llvm::FunctionPropertiesAnalysis
Definition: FunctionPropertiesAnalysis.h:63
llvm::LoopInfo
Definition: LoopInfo.h:1083
llvm::FunctionPropertiesInfo::MaxLoopDepth
int64_t MaxLoopDepth
Definition: FunctionPropertiesAnalysis.h:56
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:39
llvm::FunctionPropertiesInfo::BasicBlockCount
int64_t BasicBlockCount
Number of basic blocks.
Definition: FunctionPropertiesAnalysis.h:31
llvm::AnalysisManager
A container for analyses that lazily runs them and caches their results.
Definition: InstructionSimplify.h:44
llvm::FunctionPropertiesInfo
Definition: FunctionPropertiesAnalysis.h:23
llvm::FunctionPropertiesInfo::StoreInstCount
int64_t StoreInstCount
Definition: FunctionPropertiesAnalysis.h:53
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:47