LLVM API Documentation

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CodeMetrics.h
Go to the documentation of this file.
1 //===- CodeMetrics.h - Code cost measurements -------------------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file implements various weight measurements for code, helping
11 // the Inliner and other passes decide whether to duplicate its contents.
12 //
13 //===----------------------------------------------------------------------===//
14 
15 #ifndef LLVM_ANALYSIS_CODEMETRICS_H
16 #define LLVM_ANALYSIS_CODEMETRICS_H
17 
18 #include "llvm/ADT/DenseMap.h"
19 #include "llvm/Support/CallSite.h"
20 
21 namespace llvm {
22 class BasicBlock;
23 class Function;
24 class Instruction;
25 class DataLayout;
26 class TargetTransformInfo;
27 class Value;
28 
29 /// \brief Check whether a call will lower to something small.
30 ///
31 /// This tests checks whether this callsite will lower to something
32 /// significantly cheaper than a traditional call, often a single
33 /// instruction. Note that if isInstructionFree(CS.getInstruction()) would
34 /// return true, so will this function.
35 bool callIsSmall(ImmutableCallSite CS);
36 
37 /// \brief Utility to calculate the size and a few similar metrics for a set
38 /// of basic blocks.
39 struct CodeMetrics {
40  /// \brief True if this function contains a call to setjmp or other functions
41  /// with attribute "returns twice" without having the attribute itself.
43 
44  /// \brief True if this function calls itself.
46 
47  /// \brief True if this function cannot be duplicated.
48  ///
49  /// True if this function contains one or more indirect branches, or it contains
50  /// one or more 'noduplicate' instructions.
52 
53  /// \brief True if this function calls alloca (in the C sense).
55 
56  /// \brief Number of instructions in the analyzed blocks.
57  unsigned NumInsts;
58 
59  /// \brief Number of analyzed blocks.
60  unsigned NumBlocks;
61 
62  /// \brief Keeps track of basic block code size estimates.
64 
65  /// \brief Keep track of the number of calls to 'big' functions.
66  unsigned NumCalls;
67 
68  /// \brief The number of calls to internal functions with a single caller.
69  ///
70  /// These are likely targets for future inlining, likely exposed by
71  /// interleaved devirtualization.
73 
74  /// \brief How many instructions produce vector values.
75  ///
76  /// The inliner is more aggressive with inlining vector kernels.
77  unsigned NumVectorInsts;
78 
79  /// \brief How many 'ret' instructions the blocks contain.
80  unsigned NumRets;
81 
86 
87  /// \brief Add information about a block to the current state.
88  void analyzeBasicBlock(const BasicBlock *BB, const TargetTransformInfo &TTI);
89 };
90 
91 }
92 
93 #endif
Various leaf nodes.
Definition: ISDOpcodes.h:60
bool isRecursive
True if this function calls itself.
Definition: CodeMetrics.h:45
unsigned NumVectorInsts
How many instructions produce vector values.
Definition: CodeMetrics.h:77
unsigned NumCalls
Keep track of the number of calls to 'big' functions.
Definition: CodeMetrics.h:66
unsigned NumInlineCandidates
The number of calls to internal functions with a single caller.
Definition: CodeMetrics.h:72
bool notDuplicatable
True if this function cannot be duplicated.
Definition: CodeMetrics.h:51
unsigned NumBlocks
Number of analyzed blocks.
Definition: CodeMetrics.h:60
void analyzeBasicBlock(const BasicBlock *BB, const TargetTransformInfo &TTI)
Add information about a block to the current state.
Definition: CodeMetrics.cpp:25
#define false
Definition: ConvertUTF.c:64
bool usesDynamicAlloca
True if this function calls alloca (in the C sense).
Definition: CodeMetrics.h:54
LLVM Basic Block Representation.
Definition: BasicBlock.h:72
DenseMap< const BasicBlock *, unsigned > NumBBInsts
Keeps track of basic block code size estimates.
Definition: CodeMetrics.h:63
bool exposesReturnsTwice
True if this function contains a call to setjmp or other functions with attribute "returns twice" wit...
Definition: CodeMetrics.h:42
Utility to calculate the size and a few similar metrics for a set of basic blocks.
Definition: CodeMetrics.h:39
unsigned NumRets
How many 'ret' instructions the blocks contain.
Definition: CodeMetrics.h:80
bool callIsSmall(ImmutableCallSite CS)
Check whether a call will lower to something small.
unsigned NumInsts
Number of instructions in the analyzed blocks.
Definition: CodeMetrics.h:57