1 //===- CodeMetrics.h - Code cost measurements -------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file implements various weight measurements for code, helping
11 // the Inliner and other passes decide whether to duplicate its contents.
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_ANALYSIS_CODEMETRICS_H
16 #define LLVM_ANALYSIS_CODEMETRICS_H
18 #include "llvm/ADT/DenseMap.h"
19 #include "llvm/Support/CallSite.h"
26 class TargetTransformInfo;
29 /// \brief Check whether a call will lower to something small.
31 /// This tests checks whether this callsite will lower to something
32 /// significantly cheaper than a traditional call, often a single
33 /// instruction. Note that if isInstructionFree(CS.getInstruction()) would
34 /// return true, so will this function.
35 bool callIsSmall(ImmutableCallSite CS);
37 /// \brief Utility to calculate the size and a few similar metrics for a set
40 /// \brief True if this function contains a call to setjmp or other functions
41 /// with attribute "returns twice" without having the attribute itself.
42 bool exposesReturnsTwice;
44 /// \brief True if this function calls itself.
47 /// \brief True if this function cannot be duplicated.
49 /// True if this function contains one or more indirect branches, or it contains
50 /// one or more 'noduplicate' instructions.
53 /// \brief True if this function calls alloca (in the C sense).
54 bool usesDynamicAlloca;
56 /// \brief Number of instructions in the analyzed blocks.
59 /// \brief Number of analyzed blocks.
62 /// \brief Keeps track of basic block code size estimates.
63 DenseMap<const BasicBlock *, unsigned> NumBBInsts;
65 /// \brief Keep track of the number of calls to 'big' functions.
68 /// \brief The number of calls to internal functions with a single caller.
70 /// These are likely targets for future inlining, likely exposed by
71 /// interleaved devirtualization.
72 unsigned NumInlineCandidates;
74 /// \brief How many instructions produce vector values.
76 /// The inliner is more aggressive with inlining vector kernels.
77 unsigned NumVectorInsts;
79 /// \brief How many 'ret' instructions the blocks contain.
83 : exposesReturnsTwice(false), isRecursive(false), notDuplicatable(false),
84 usesDynamicAlloca(false), NumInsts(0), NumBlocks(0), NumCalls(0),
85 NumInlineCandidates(0), NumVectorInsts(0), NumRets(0) {}
87 /// \brief Add information about a block to the current state.
88 void analyzeBasicBlock(const BasicBlock *BB, const TargetTransformInfo &TTI);