Start removing the use of an ad-hoc 'never inline' set and instead
[oota-llvm.git] / include / llvm / Analysis / CodeMetrics.h
1 //===- CodeMetrics.h - Code cost measurements -------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file implements various weight measurements for code, helping
11 // the Inliner and other passes decide whether to duplicate its contents.
12 //
13 //===----------------------------------------------------------------------===//
14
15 #ifndef LLVM_ANALYSIS_CODEMETRICS_H
16 #define LLVM_ANALYSIS_CODEMETRICS_H
17
18 #include "llvm/ADT/DenseMap.h"
19
20 namespace llvm {
21   class BasicBlock;
22   class Function;
23   class TargetData;
24   class Value;
25
26   /// \brief Check whether a call will lower to something small.
27   ///
28   /// This tests checks whether calls to this function will lower to something
29   /// significantly cheaper than a traditional call, often a single
30   /// instruction.
31   bool callIsSmall(const Function *F);
32
33   /// \brief Utility to calculate the size and a few similar metrics for a set
34   /// of basic blocks.
35   struct CodeMetrics {
36     /// \brief True if this function contains a call to setjmp or other functions
37     /// with attribute "returns twice" without having the attribute itself.
38     bool exposesReturnsTwice;
39
40     /// \brief True if this function calls itself.
41     bool isRecursive;
42
43     /// \brief True if this function contains one or more indirect branches.
44     bool containsIndirectBr;
45
46     /// \brief True if this function calls alloca (in the C sense).
47     bool usesDynamicAlloca;
48
49     /// \brief Number of instructions in the analyzed blocks.
50     unsigned NumInsts;
51
52     /// \brief Number of analyzed blocks.
53     unsigned NumBlocks;
54
55     /// \brief Keeps track of basic block code size estimates.
56     DenseMap<const BasicBlock *, unsigned> NumBBInsts;
57
58     /// \brief Keep track of the number of calls to 'big' functions.
59     unsigned NumCalls;
60
61     /// \brief The number of calls to internal functions with a single caller.
62     ///
63     /// These are likely targets for future inlining, likely exposed by
64     /// interleaved devirtualization.
65     unsigned NumInlineCandidates;
66
67     /// \brief How many instructions produce vector values.
68     ///
69     /// The inliner is more aggressive with inlining vector kernels.
70     unsigned NumVectorInsts;
71
72     /// \brief How many 'ret' instructions the blocks contain.
73     unsigned NumRets;
74
75     CodeMetrics() : exposesReturnsTwice(false), isRecursive(false),
76                     containsIndirectBr(false), usesDynamicAlloca(false),
77                     NumInsts(0), NumBlocks(0), NumCalls(0),
78                     NumInlineCandidates(0), NumVectorInsts(0),
79                     NumRets(0) {}
80
81     /// \brief Add information about a block to the current state.
82     void analyzeBasicBlock(const BasicBlock *BB, const TargetData *TD = 0);
83
84     /// \brief Add information about a function to the current state.
85     void analyzeFunction(Function *F, const TargetData *TD = 0);
86   };
87 }
88
89 #endif