LLVM 20.0.0git
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"
19
20namespace llvm {
21class AssumptionCache;
22class BasicBlock;
23class Loop;
24class Function;
25template <class T> class SmallPtrSetImpl;
26class TargetTransformInfo;
27class Value;
28
30
31/// Utility to calculate the size and a few similar metrics for a set
32/// of basic blocks.
34 /// True if this function contains a call to setjmp or other functions
35 /// with attribute "returns twice" without having the attribute itself.
36 bool exposesReturnsTwice = false;
37
38 /// True if this function calls itself.
39 bool isRecursive = false;
40
41 /// True if this function cannot be duplicated.
42 ///
43 /// True if this function contains one or more indirect branches, or it contains
44 /// one or more 'noduplicate' instructions.
45 bool notDuplicatable = false;
46
47 /// The kind of convergence specified in this function.
49
50 /// True if this function calls alloca (in the C sense).
51 bool usesDynamicAlloca = false;
52
53 /// Code size cost of the analyzed blocks.
55
56 /// Number of analyzed blocks.
57 unsigned NumBlocks = false;
58
59 /// Keeps track of basic block code size estimates.
61
62 /// Keep track of the number of calls to 'big' functions.
63 unsigned NumCalls = false;
64
65 /// The number of calls to internal functions with a single caller.
66 ///
67 /// These are likely targets for future inlining, likely exposed by
68 /// interleaved devirtualization.
69 unsigned NumInlineCandidates = 0;
70
71 /// How many instructions produce vector values.
72 ///
73 /// The inliner is more aggressive with inlining vector kernels.
74 unsigned NumVectorInsts = 0;
75
76 /// How many 'ret' instructions the blocks contain.
77 unsigned NumRets = 0;
78
79 /// Add information about a block to the current state.
81 const SmallPtrSetImpl<const Value *> &EphValues,
82 bool PrepareForLTO = false, const Loop *L = nullptr);
83
84 /// Collect a loop's ephemeral values (those used only by an assume
85 /// or similar intrinsics in the loop).
86 static void collectEphemeralValues(const Loop *L, AssumptionCache *AC,
88
89 /// Collect a functions's ephemeral values (those used only by an
90 /// assume or similar intrinsics in the function).
91 static void collectEphemeralValues(const Function *L, AssumptionCache *AC,
93};
94
95}
96
97#endif
This file defines the DenseMap class.
This file defines an InstructionCost class that is used when calculating the cost of an instruction,...
A cache of @llvm.assume calls within a function.
LLVM Basic Block Representation.
Definition: BasicBlock.h:61
Represents a single loop in the control flow graph.
Definition: LoopInfo.h:39
A templated base class for SmallPtrSet which provides the typesafe interface that is common across al...
Definition: SmallPtrSet.h:346
This pass provides access to the codegen interfaces that are needed for IR-level transformations.
@ BasicBlock
Various leaf nodes.
Definition: ISDOpcodes.h:71
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
ConvergenceKind
Definition: CodeMetrics.h:29
@ None
Definition: CodeGenData.h:101
Utility to calculate the size and a few similar metrics for a set of basic blocks.
Definition: CodeMetrics.h:33
bool usesDynamicAlloca
True if this function calls alloca (in the C sense).
Definition: CodeMetrics.h:51
unsigned NumBlocks
Number of analyzed blocks.
Definition: CodeMetrics.h:57
ConvergenceKind Convergence
The kind of convergence specified in this function.
Definition: CodeMetrics.h:48
bool notDuplicatable
True if this function cannot be duplicated.
Definition: CodeMetrics.h:45
unsigned NumInlineCandidates
The number of calls to internal functions with a single caller.
Definition: CodeMetrics.h:69
bool isRecursive
True if this function calls itself.
Definition: CodeMetrics.h:39
static void collectEphemeralValues(const Loop *L, AssumptionCache *AC, SmallPtrSetImpl< const Value * > &EphValues)
Collect a loop's ephemeral values (those used only by an assume or similar intrinsics in the loop).
Definition: CodeMetrics.cpp:71
unsigned NumRets
How many 'ret' instructions the blocks contain.
Definition: CodeMetrics.h:77
bool exposesReturnsTwice
True if this function contains a call to setjmp or other functions with attribute "returns twice" wit...
Definition: CodeMetrics.h:36
DenseMap< const BasicBlock *, InstructionCost > NumBBInsts
Keeps track of basic block code size estimates.
Definition: CodeMetrics.h:60
void analyzeBasicBlock(const BasicBlock *BB, const TargetTransformInfo &TTI, const SmallPtrSetImpl< const Value * > &EphValues, bool PrepareForLTO=false, const Loop *L=nullptr)
Add information about a block to the current state.
unsigned NumCalls
Keep track of the number of calls to 'big' functions.
Definition: CodeMetrics.h:63
unsigned NumVectorInsts
How many instructions produce vector values.
Definition: CodeMetrics.h:74
InstructionCost NumInsts
Code size cost of the analyzed blocks.
Definition: CodeMetrics.h:54