LLVM  14.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"
18 
19 namespace llvm {
20 class AssumptionCache;
21 class BasicBlock;
22 class Loop;
23 class Function;
24 template <class T> class SmallPtrSetImpl;
25 class TargetTransformInfo;
26 class Value;
27 
28 /// Utility to calculate the size and a few similar metrics for a set
29 /// of basic blocks.
30 struct CodeMetrics {
31  /// True if this function contains a call to setjmp or other functions
32  /// with attribute "returns twice" without having the attribute itself.
33  bool exposesReturnsTwice = false;
34 
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 contains a call to a convergent function.
45  bool convergent = false;
46 
47  /// True if this function calls alloca (in the C sense).
48  bool usesDynamicAlloca = false;
49 
50  /// Number of instructions in the analyzed blocks.
51  unsigned NumInsts = false;
52 
53  /// Number of analyzed blocks.
54  unsigned NumBlocks = false;
55 
56  /// Keeps track of basic block code size estimates.
58 
59  /// Keep track of the number of calls to 'big' functions.
60  unsigned NumCalls = false;
61 
62  /// The number of calls to internal functions with a single caller.
63  ///
64  /// These are likely targets for future inlining, likely exposed by
65  /// interleaved devirtualization.
66  unsigned NumInlineCandidates = 0;
67 
68  /// How many instructions produce vector values.
69  ///
70  /// The inliner is more aggressive with inlining vector kernels.
71  unsigned NumVectorInsts = 0;
72 
73  /// How many 'ret' instructions the blocks contain.
74  unsigned NumRets = 0;
75 
76  /// Add information about a block to the current state.
78  const SmallPtrSetImpl<const Value *> &EphValues,
79  bool PrepareForLTO = false);
80 
81  /// Collect a loop's ephemeral values (those used only by an assume
82  /// or similar intrinsics in the loop).
83  static void collectEphemeralValues(const Loop *L, AssumptionCache *AC,
85 
86  /// Collect a functions's ephemeral values (those used only by an
87  /// assume or similar intrinsics in the function).
88  static void collectEphemeralValues(const Function *L, AssumptionCache *AC,
90 };
91 
92 }
93 
94 #endif
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AllocatorList.h:23
llvm::Function
Definition: Function.h:62
llvm::Loop
Represents a single loop in the control flow graph.
Definition: LoopInfo.h:530
llvm::CodeMetrics
Utility to calculate the size and a few similar metrics for a set of basic blocks.
Definition: CodeMetrics.h:30
llvm::TargetTransformInfo
This pass provides access to the codegen interfaces that are needed for IR-level transformations.
Definition: TargetTransformInfo.h:169
llvm::CodeMetrics::NumInsts
unsigned NumInsts
Number of instructions in the analyzed blocks.
Definition: CodeMetrics.h:51
DenseMap.h
llvm::BasicBlock
LLVM Basic Block Representation.
Definition: BasicBlock.h:58
llvm::CodeMetrics::convergent
bool convergent
True if this function contains a call to a convergent function.
Definition: CodeMetrics.h:45
llvm::CodeMetrics::usesDynamicAlloca
bool usesDynamicAlloca
True if this function calls alloca (in the C sense).
Definition: CodeMetrics.h:48
llvm::CodeMetrics::collectEphemeralValues
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
llvm::CodeMetrics::NumBlocks
unsigned NumBlocks
Number of analyzed blocks.
Definition: CodeMetrics.h:54
llvm::DenseMap
Definition: DenseMap.h:714
llvm::CodeMetrics::notDuplicatable
bool notDuplicatable
True if this function cannot be duplicated.
Definition: CodeMetrics.h:42
llvm::CodeMetrics::NumBBInsts
DenseMap< const BasicBlock *, unsigned > NumBBInsts
Keeps track of basic block code size estimates.
Definition: CodeMetrics.h:57
llvm::ISD::BasicBlock
@ BasicBlock
Various leaf nodes.
Definition: ISDOpcodes.h:71
llvm::CodeMetrics::analyzeBasicBlock
void analyzeBasicBlock(const BasicBlock *BB, const TargetTransformInfo &TTI, const SmallPtrSetImpl< const Value * > &EphValues, bool PrepareForLTO=false)
Add information about a block to the current state.
Definition: CodeMetrics.cpp:117
llvm::CodeMetrics::isRecursive
bool isRecursive
True if this function calls itself.
Definition: CodeMetrics.h:36
llvm::AssumptionCache
A cache of @llvm.assume calls within a function.
Definition: AssumptionCache.h:42
llvm::CodeMetrics::NumCalls
unsigned NumCalls
Keep track of the number of calls to 'big' functions.
Definition: CodeMetrics.h:60
llvm::TargetStackID::Value
Value
Definition: TargetFrameLowering.h:27
llvm::CodeMetrics::NumRets
unsigned NumRets
How many 'ret' instructions the blocks contain.
Definition: CodeMetrics.h:74
llvm::CodeMetrics::exposesReturnsTwice
bool exposesReturnsTwice
True if this function contains a call to setjmp or other functions with attribute "returns twice" wit...
Definition: CodeMetrics.h:33
llvm::SmallPtrSetImpl< const Value * >
llvm::CodeMetrics::NumVectorInsts
unsigned NumVectorInsts
How many instructions produce vector values.
Definition: CodeMetrics.h:71
BB
Common register allocation spilling lr str ldr sxth r3 ldr mla r4 can lr mov lr str ldr sxth r3 mla r4 and then merge mul and lr str ldr sxth r3 mla r4 It also increase the likelihood the store may become dead bb27 Successors according to LLVM BB
Definition: README.txt:39
llvm::codeview::PublicSymFlags::Function
@ Function
llvm::CodeMetrics::NumInlineCandidates
unsigned NumInlineCandidates
The number of calls to internal functions with a single caller.
Definition: CodeMetrics.h:66