LLVM  10.0.0svn
CodeMetrics.h
Go to the documentation of this file.
1 //===- CodeMetrics.h - Code cost measurements -------------------*- 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 implements various weight measurements for code, helping
10 // the Inliner and other passes decide whether to duplicate its contents.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_ANALYSIS_CODEMETRICS_H
15 #define LLVM_ANALYSIS_CODEMETRICS_H
16 
17 #include "llvm/ADT/DenseMap.h"
18 #include "llvm/ADT/SmallPtrSet.h"
19 
20 namespace llvm {
21 class AssumptionCache;
22 class BasicBlock;
23 class Loop;
24 class Function;
25 class Instruction;
26 class DataLayout;
27 class TargetTransformInfo;
28 class Value;
29 
30 /// Utility to calculate the size and a few similar metrics for a set
31 /// of basic blocks.
32 struct CodeMetrics {
33  /// True if this function contains a call to setjmp or other functions
34  /// with attribute "returns twice" without having the attribute itself.
35  bool exposesReturnsTwice = false;
36 
37  /// True if this function calls itself.
38  bool isRecursive = false;
39 
40  /// True if this function cannot be duplicated.
41  ///
42  /// True if this function contains one or more indirect branches, or it contains
43  /// one or more 'noduplicate' instructions.
44  bool notDuplicatable = false;
45 
46  /// True if this function contains a call to a convergent function.
47  bool convergent = false;
48 
49  /// True if this function calls alloca (in the C sense).
50  bool usesDynamicAlloca = false;
51 
52  /// Number of instructions in the analyzed blocks.
53  unsigned NumInsts = false;
54 
55  /// Number of analyzed blocks.
56  unsigned NumBlocks = false;
57 
58  /// Keeps track of basic block code size estimates.
60 
61  /// Keep track of the number of calls to 'big' functions.
62  unsigned NumCalls = false;
63 
64  /// The number of calls to internal functions with a single caller.
65  ///
66  /// These are likely targets for future inlining, likely exposed by
67  /// interleaved devirtualization.
68  unsigned NumInlineCandidates = 0;
69 
70  /// How many instructions produce vector values.
71  ///
72  /// The inliner is more aggressive with inlining vector kernels.
73  unsigned NumVectorInsts = 0;
74 
75  /// How many 'ret' instructions the blocks contain.
76  unsigned NumRets = 0;
77 
78  /// Add information about a block to the current state.
79  void analyzeBasicBlock(const BasicBlock *BB, const TargetTransformInfo &TTI,
80  const SmallPtrSetImpl<const Value*> &EphValues);
81 
82  /// Collect a loop's ephemeral values (those used only by an assume
83  /// or similar intrinsics in the loop).
84  static void collectEphemeralValues(const Loop *L, AssumptionCache *AC,
86 
87  /// Collect a functions's ephemeral values (those used only by an
88  /// assume or similar intrinsics in the function).
89  static void collectEphemeralValues(const Function *L, AssumptionCache *AC,
91 };
92 
93 }
94 
95 #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:70
This class represents lattice values for constants.
Definition: AllocatorList.h:23
Various leaf nodes.
Definition: ISDOpcodes.h:59
bool convergent
True if this function contains a call to a convergent function.
Definition: CodeMetrics.h:47
bool isRecursive
True if this function calls itself.
Definition: CodeMetrics.h:38
unsigned NumVectorInsts
How many instructions produce vector values.
Definition: CodeMetrics.h:73
unsigned NumCalls
Keep track of the number of calls to &#39;big&#39; functions.
Definition: CodeMetrics.h:62
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:68
bool notDuplicatable
True if this function cannot be duplicated.
Definition: CodeMetrics.h:44
unsigned NumBlocks
Number of analyzed blocks.
Definition: CodeMetrics.h:56
bool usesDynamicAlloca
True if this function calls alloca (in the C sense).
Definition: CodeMetrics.h:50
LLVM Basic Block Representation.
Definition: BasicBlock.h:57
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:59
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:35
Utility to calculate the size and a few similar metrics for a set of basic blocks.
Definition: CodeMetrics.h:32
Represents a single loop in the control flow graph.
Definition: LoopInfo.h:509
unsigned NumRets
How many &#39;ret&#39; instructions the blocks contain.
Definition: CodeMetrics.h:76
unsigned NumInsts
Number of instructions in the analyzed blocks.
Definition: CodeMetrics.h:53