23 ImportedFunctionsInliningStatistics::InlineGraphNode &
24 ImportedFunctionsInliningStatistics::createInlineGraphNode(
const Function &
F) {
26 auto &ValueLookup = NodesMap[F.
getName()];
28 ValueLookup = std::make_unique<InlineGraphNode>();
29 ValueLookup->Imported = F.
hasMetadata(
"thinlto_src_module");
37 InlineGraphNode &CallerNode = createInlineGraphNode(Caller);
38 InlineGraphNode &CalleeNode = createInlineGraphNode(Callee);
39 CalleeNode.NumberOfInlines++;
41 if (!CallerNode.Imported && !CalleeNode.Imported) {
46 CalleeNode.NumberOfRealInlines++;
50 CallerNode.InlinedCallees.push_back(&CalleeNode);
51 if (!CallerNode.Imported) {
54 assert(It != NodesMap.
end() &&
"The node should be already there.");
57 NonImportedCallers.push_back(It->first());
67 ImportedFunctions += int(F.
hasMetadata(
"thinlto_src_module"));
70 static std::string
getStatString(
const char *Msg, int32_t Fraction, int32_t All,
71 const char *PercentageOfMsg,
72 bool LineEnd =
true) {
75 Result = 100 *
static_cast<double>(Fraction) / All;
77 std::stringstream Str;
78 Str << std::setprecision(4) << Msg <<
": " << Fraction <<
" [" << Result
79 <<
"% of " << PercentageOfMsg <<
"]";
86 calculateRealInlines();
87 NonImportedCallers.clear();
89 int32_t InlinedImportedFunctionsCount = 0;
90 int32_t InlinedNotImportedFunctionsCount = 0;
92 int32_t InlinedImportedFunctionsToImportingModuleCount = 0;
93 int32_t InlinedNotImportedFunctionsToImportingModuleCount = 0;
95 const auto SortedNodes = getSortedNodes();
100 Ostream <<
"------- Dumping inliner stats for [" << ModuleName
104 Ostream <<
"-- List of inlined functions:\n";
106 for (
const auto &Node : SortedNodes) {
107 assert(Node->second->NumberOfInlines >= Node->second->NumberOfRealInlines);
108 if (Node->second->NumberOfInlines == 0)
111 if (Node->second->Imported) {
112 InlinedImportedFunctionsCount++;
113 InlinedImportedFunctionsToImportingModuleCount +=
114 int(Node->second->NumberOfRealInlines > 0);
116 InlinedNotImportedFunctionsCount++;
117 InlinedNotImportedFunctionsToImportingModuleCount +=
118 int(Node->second->NumberOfRealInlines > 0);
122 Ostream <<
"Inlined " 123 << (Node->second->Imported ?
"imported " :
"not imported ")
124 <<
"function [" << Node->first() <<
"]" 125 <<
": #inlines = " << Node->second->NumberOfInlines
126 <<
", #inlines_to_importing_module = " 127 << Node->second->NumberOfRealInlines <<
"\n";
130 auto InlinedFunctionsCount =
131 InlinedImportedFunctionsCount + InlinedNotImportedFunctionsCount;
132 auto NotImportedFuncCount = AllFunctions - ImportedFunctions;
133 auto ImportedNotInlinedIntoModule =
134 ImportedFunctions - InlinedImportedFunctionsToImportingModuleCount;
136 Ostream <<
"-- Summary:\n" 137 <<
"All functions: " << AllFunctions
138 <<
", imported functions: " << ImportedFunctions <<
"\n" 140 AllFunctions,
"all functions")
142 InlinedImportedFunctionsCount, ImportedFunctions,
143 "imported functions")
144 <<
getStatString(
"imported functions inlined into importing module",
145 InlinedImportedFunctionsToImportingModuleCount,
146 ImportedFunctions,
"imported functions",
148 <<
getStatString(
", remaining", ImportedNotInlinedIntoModule,
149 ImportedFunctions,
"imported functions")
151 InlinedNotImportedFunctionsCount,
152 NotImportedFuncCount,
"non-imported functions")
154 "non-imported functions inlined into importing module",
155 InlinedNotImportedFunctionsToImportingModuleCount,
156 NotImportedFuncCount,
"non-imported functions");
161 void ImportedFunctionsInliningStatistics::calculateRealInlines() {
164 NonImportedCallers.erase(
165 std::unique(NonImportedCallers.begin(), NonImportedCallers.end()),
166 NonImportedCallers.end());
168 for (
const auto &
Name : NonImportedCallers) {
169 auto &Node = *NodesMap[
Name];
175 void ImportedFunctionsInliningStatistics::dfs(InlineGraphNode &GraphNode) {
176 assert(!GraphNode.Visited);
177 GraphNode.Visited =
true;
178 for (
auto *
const InlinedFunctionNode : GraphNode.InlinedCallees) {
179 InlinedFunctionNode->NumberOfRealInlines++;
180 if (!InlinedFunctionNode->Visited)
181 dfs(*InlinedFunctionNode);
185 ImportedFunctionsInliningStatistics::SortedNodesTy
186 ImportedFunctionsInliningStatistics::getSortedNodes() {
187 SortedNodesTy SortedNodes;
188 SortedNodes.reserve(NodesMap.
size());
190 SortedNodes.push_back(&Node);
192 llvm::sort(SortedNodes, [&](
const SortedNodesTy::value_type &Lhs,
193 const SortedNodesTy::value_type &Rhs) {
194 if (Lhs->second->NumberOfInlines != Rhs->second->NumberOfInlines)
195 return Lhs->second->NumberOfInlines > Rhs->second->NumberOfInlines;
196 if (Lhs->second->NumberOfRealInlines != Rhs->second->NumberOfRealInlines)
197 return Lhs->second->NumberOfRealInlines >
198 Rhs->second->NumberOfRealInlines;
199 return Lhs->first() < Rhs->first();
void setModuleInfo(const Module &M)
Set information like AllFunctions, ImportedFunctions, ModuleName.
This class represents lattice values for constants.
StringMapEntry - This is used to represent one value that is inserted into a StringMap.
A Module instance is used to store all the information related to an LLVM module. ...
void recordInline(const Function &Caller, const Function &Callee)
Record inline of.
amdgpu Simplify well known AMD library false FunctionCallee Value const Twine & Name
iterator find(StringRef Key)
StringRef getName() const
Get a short "name" for the module.
* if(!EatIfPresent(lltok::kw_thread_local)) return false
ParseOptionalThreadLocal := /*empty.
iterator_range< iterator > functions()
void sort(IteratorTy Start, IteratorTy End)
Module.h This file contains the declarations for the Module class.
static std::string getStatString(const char *Msg, int32_t Fraction, int32_t All, const char *PercentageOfMsg, bool LineEnd=true)
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
void dump(bool Verbose)
Dump stats computed with InlinerStatistics class.
StringRef getName() const
Return a constant reference to the value's name.
bool isDeclaration() const
Return true if the primary definition of this global value is outside of the current translation unit...
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
A raw_ostream that writes to an std::string.
bool hasMetadata() const
Check if this has any metadata.