LLVM  8.0.1
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/ADT/SmallPtrSet.h"
20 #include "llvm/IR/CallSite.h"
21 
22 namespace llvm {
23 class AssumptionCache;
24 class BasicBlock;
25 class Loop;
26 class Function;
27 class Instruction;
28 class DataLayout;
29 class TargetTransformInfo;
30 class Value;
31 
32 /// Check whether a call will lower to something small.
33 ///
34 /// This tests checks whether this callsite will lower to something
35 /// significantly cheaper than a traditional call, often a single
36 /// instruction. Note that if isInstructionFree(CS.getInstruction()) would
37 /// return true, so will this function.
38 bool callIsSmall(ImmutableCallSite CS);
39 
40 /// Utility to calculate the size and a few similar metrics for a set
41 /// of basic blocks.
42 struct CodeMetrics {
43  /// True if this function contains a call to setjmp or other functions
44  /// with attribute "returns twice" without having the attribute itself.
45  bool exposesReturnsTwice = false;
46 
47  /// True if this function calls itself.
48  bool isRecursive = false;
49 
50  /// True if this function cannot be duplicated.
51  ///
52  /// True if this function contains one or more indirect branches, or it contains
53  /// one or more 'noduplicate' instructions.
54  bool notDuplicatable = false;
55 
56  /// True if this function contains a call to a convergent function.
57  bool convergent = false;
58 
59  /// True if this function calls alloca (in the C sense).
60  bool usesDynamicAlloca = false;
61 
62  /// Number of instructions in the analyzed blocks.
63  unsigned NumInsts = false;
64 
65  /// Number of analyzed blocks.
66  unsigned NumBlocks = false;
67 
68  /// Keeps track of basic block code size estimates.
70 
71  /// Keep track of the number of calls to 'big' functions.
72  unsigned NumCalls = false;
73 
74  /// The number of calls to internal functions with a single caller.
75  ///
76  /// These are likely targets for future inlining, likely exposed by
77  /// interleaved devirtualization.
78  unsigned NumInlineCandidates = 0;
79 
80  /// How many instructions produce vector values.
81  ///
82  /// The inliner is more aggressive with inlining vector kernels.
83  unsigned NumVectorInsts = 0;
84 
85  /// How many 'ret' instructions the blocks contain.
86  unsigned NumRets = 0;
87 
88  /// Add information about a block to the current state.
89  void analyzeBasicBlock(const BasicBlock *BB, const TargetTransformInfo &TTI,
90  const SmallPtrSetImpl<const Value*> &EphValues);
91 
92  /// Collect a loop's ephemeral values (those used only by an assume
93  /// or similar intrinsics in the loop).
94  static void collectEphemeralValues(const Loop *L, AssumptionCache *AC,
96 
97  /// Collect a functions's ephemeral values (those used only by an
98  /// assume or similar intrinsics in the function).
99  static void collectEphemeralValues(const Function *L, AssumptionCache *AC,
100  SmallPtrSetImpl<const Value *> &EphValues);
101 };
102 
103 }
104 
105 #endif
static void collectEphemeralValues(const Loop *L, AssumptionCache *AC, SmallPtrSetImpl< const Value *> &EphValues)
Collect a loop&#39;s ephemeral values (those used only by an assume or similar intrinsics in the loop)...
Definition: CodeMetrics.cpp:72
This class represents lattice values for constants.
Definition: AllocatorList.h:24
Various leaf nodes.
Definition: ISDOpcodes.h:60
bool convergent
True if this function contains a call to a convergent function.
Definition: CodeMetrics.h:57
bool isRecursive
True if this function calls itself.
Definition: CodeMetrics.h:48
unsigned NumVectorInsts
How many instructions produce vector values.
Definition: CodeMetrics.h:83
unsigned NumCalls
Keep track of the number of calls to &#39;big&#39; functions.
Definition: CodeMetrics.h:72
A cache of @llvm.assume calls within a function.
unsigned NumInlineCandidates
The number of calls to internal functions with a single caller.
Definition: CodeMetrics.h:78
bool notDuplicatable
True if this function cannot be duplicated.
Definition: CodeMetrics.h:54
unsigned NumBlocks
Number of analyzed blocks.
Definition: CodeMetrics.h:66
bool usesDynamicAlloca
True if this function calls alloca (in the C sense).
Definition: CodeMetrics.h:60
LLVM Basic Block Representation.
Definition: BasicBlock.h:58
void analyzeBasicBlock(const BasicBlock *BB, const TargetTransformInfo &TTI, const SmallPtrSetImpl< const Value *> &EphValues)
Add information about a block to the current state.
DenseMap< const BasicBlock *, unsigned > NumBBInsts
Keeps track of basic block code size estimates.
Definition: CodeMetrics.h:69
This pass provides access to the codegen interfaces that are needed for IR-level transformations.
bool exposesReturnsTwice
True if this function contains a call to setjmp or other functions with attribute "returns twice" wit...
Definition: CodeMetrics.h:45
Utility to calculate the size and a few similar metrics for a set of basic blocks.
Definition: CodeMetrics.h:42
Represents a single loop in the control flow graph.
Definition: LoopInfo.h:465
unsigned NumRets
How many &#39;ret&#39; instructions the blocks contain.
Definition: CodeMetrics.h:86
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:63