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