1//===-- ImportedFunctionsInliningStatistics.h -------------------*- C++ -*-===//
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
7//===----------------------------------------------------------------------===//
8// Generating inliner statistics for imported functions, mostly useful for
10//===----------------------------------------------------------------------===//
12#ifndef LLVM_ANALYSIS_UTILS_IMPORTEDFUNCTIONSINLININGSTATISTICS_H
13#define LLVM_ANALYSIS_UTILS_IMPORTEDFUNCTIONSINLININGSTATISTICS_H
25/// Calculate and dump ThinLTO specific inliner stats.
26/// The main statistics are:
27/// (1) Number of inlined imported functions,
28/// (2) Number of imported functions inlined into importing module (indirect),
29/// (3) Number of non imported functions inlined into importing module
31/// The difference between first and the second is that first stat counts
32/// all performed inlines on imported functions, but the second one only the
33/// functions that have been eventually inlined to a function in the importing
34/// module (by a chain of inlines). Because llvm uses bottom-up inliner, it is
35/// possible to e.g. import function `A`, `B` and then inline `B` to `A`,
36/// and after this `A` might be too big to be inlined into some other function
37/// that calls it. It calculates this statistic by building graph, where
38/// the nodes are functions, and edges are performed inlines and then by marking
39/// the edges starting from not imported function.
41/// If `Verbose` is set to true, then it also dumps statistics
42/// per each inlined function, sorted by the greatest inlines count like
43/// - number of performed inlines
44/// - number of performed inlines to importing module
47 /// InlineGraphNode represents node in graph of inlined functions.
48 struct InlineGraphNode {
49 // Default-constructible and movable.
50 InlineGraphNode() =
default;
51 InlineGraphNode(InlineGraphNode &&) =
default;
52 InlineGraphNode &operator=(InlineGraphNode &&) =
default;
55 /// Incremented every direct inline.
56 int32_t NumberOfInlines = 0;
57 /// Number of inlines into non imported function (possibly indirect via
58 /// intermediate inlines). Computed based on graph search.
59 int32_t NumberOfRealInlines = 0;
60 bool Imported =
false;
69 /// Set information like AllFunctions, ImportedFunctions, ModuleName.
71 /// Record inline of @param Callee to @param Caller for statistis.
73 /// Dump stats computed with InlinerStatistics class.
74 /// If @param Verbose is true then separate statistics for every inlined
75 /// function will be printed.
79 /// Creates new Node in NodeMap and sets attributes, or returns existed one.
80 InlineGraphNode &createInlineGraphNode(
const Function &);
81 void calculateRealInlines();
82 void dfs(InlineGraphNode &GraphNode);
87 std::vector<const NodesMapTy::MapEntryTy*>;
88 /// Returns vector of elements sorted by
89 /// (-NumberOfInlines, -NumberOfRealInlines, FunctionName).
90 SortedNodesTy getSortedNodes();
93 /// This map manage life of all InlineGraphNodes. Unique pointer to
94 /// InlineGraphNode used since the node pointers are also saved in the
95 /// InlinedCallees vector. If it would store InlineGraphNode instead then the
96 /// address of the node would not be invariant.
98 /// Non external functions that have some other function inlined inside.
99 std::vector<StringRef> NonImportedCallers;
100 int AllFunctions = 0;
101 int ImportedFunctions = 0;
113#endif // LLVM_ANALYSIS_UTILS_IMPORTEDFUNCTIONSINLININGSTATISTICS_H
This file defines the StringMap class.
This file defines the SmallVector class.
LLVM_ABI void setModuleInfo(const Module &M)
Set information like AllFunctions, ImportedFunctions, ModuleName.
ImportedFunctionsInliningStatistics()=default
LLVM_ABI void dump(bool Verbose)
Dump stats computed with InlinerStatistics class.
ImportedFunctionsInliningStatistics(const ImportedFunctionsInliningStatistics &)=delete
LLVM_ABI void recordInline(const Function &Caller, const Function &Callee)
Record inline of.
A Module instance is used to store all the information related to an LLVM module.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringMap - This is an unconventional map that is specialized for handling keys that are "strings",...
StringRef - Represent a constant reference to a string, i.e.
This is an optimization pass for GlobalISel generic memory operations.
InlinerFunctionImportStatsOpts