Added ThinLTO inlining statistics
Summary:
copypasta doc of ImportedFunctionsInliningStatistics class
\brief Calculate and dump ThinLTO specific inliner stats.
The main statistics are:
(1) Number of inlined imported functions,
(2) Number of imported functions inlined into importing module (indirect),
(3) Number of non imported functions inlined into importing module
(indirect).
The difference between first and the second is that first stat counts
all performed inlines on imported functions, but the second one only the
functions that have been eventually inlined to a function in the importing
module (by a chain of inlines). Because llvm uses bottom-up inliner, it is
possible to e.g. import function `A`, `B` and then inline `B` to `A`,
and after this `A` might be too big to be inlined into some other function
that calls it. It calculates this statistic by building graph, where
the nodes are functions, and edges are performed inlines and then by marking
the edges starting from not imported function.
If `Verbose` is set to true, then it also dumps statistics
per each inlined function, sorted by the greatest inlines count like
- number of performed inlines
- number of performed inlines to importing module
Reviewers: eraman, tejohnson, mehdi_amini
Subscribers: mehdi_amini, llvm-commits
Differential Revision: https://reviews.llvm.org/D22491
llvm-svn: 277089
2016-07-29 08:27:16 +08:00
|
|
|
//===-- ImportedFunctionsInliningStats.cpp ----------------------*- C++ -*-===//
|
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
Added ThinLTO inlining statistics
Summary:
copypasta doc of ImportedFunctionsInliningStatistics class
\brief Calculate and dump ThinLTO specific inliner stats.
The main statistics are:
(1) Number of inlined imported functions,
(2) Number of imported functions inlined into importing module (indirect),
(3) Number of non imported functions inlined into importing module
(indirect).
The difference between first and the second is that first stat counts
all performed inlines on imported functions, but the second one only the
functions that have been eventually inlined to a function in the importing
module (by a chain of inlines). Because llvm uses bottom-up inliner, it is
possible to e.g. import function `A`, `B` and then inline `B` to `A`,
and after this `A` might be too big to be inlined into some other function
that calls it. It calculates this statistic by building graph, where
the nodes are functions, and edges are performed inlines and then by marking
the edges starting from not imported function.
If `Verbose` is set to true, then it also dumps statistics
per each inlined function, sorted by the greatest inlines count like
- number of performed inlines
- number of performed inlines to importing module
Reviewers: eraman, tejohnson, mehdi_amini
Subscribers: mehdi_amini, llvm-commits
Differential Revision: https://reviews.llvm.org/D22491
llvm-svn: 277089
2016-07-29 08:27:16 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Generating inliner statistics for imported functions, mostly useful for
|
|
|
|
// ThinLTO.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2021-01-21 04:39:55 +08:00
|
|
|
#include "llvm/Analysis/Utils/ImportedFunctionsInliningStatistics.h"
|
Added ThinLTO inlining statistics
Summary:
copypasta doc of ImportedFunctionsInliningStatistics class
\brief Calculate and dump ThinLTO specific inliner stats.
The main statistics are:
(1) Number of inlined imported functions,
(2) Number of imported functions inlined into importing module (indirect),
(3) Number of non imported functions inlined into importing module
(indirect).
The difference between first and the second is that first stat counts
all performed inlines on imported functions, but the second one only the
functions that have been eventually inlined to a function in the importing
module (by a chain of inlines). Because llvm uses bottom-up inliner, it is
possible to e.g. import function `A`, `B` and then inline `B` to `A`,
and after this `A` might be too big to be inlined into some other function
that calls it. It calculates this statistic by building graph, where
the nodes are functions, and edges are performed inlines and then by marking
the edges starting from not imported function.
If `Verbose` is set to true, then it also dumps statistics
per each inlined function, sorted by the greatest inlines count like
- number of performed inlines
- number of performed inlines to importing module
Reviewers: eraman, tejohnson, mehdi_amini
Subscribers: mehdi_amini, llvm-commits
Differential Revision: https://reviews.llvm.org/D22491
llvm-svn: 277089
2016-07-29 08:27:16 +08:00
|
|
|
#include "llvm/ADT/STLExtras.h"
|
|
|
|
#include "llvm/IR/Function.h"
|
|
|
|
#include "llvm/IR/Module.h"
|
2021-01-21 03:25:43 +08:00
|
|
|
#include "llvm/Support/CommandLine.h"
|
Added ThinLTO inlining statistics
Summary:
copypasta doc of ImportedFunctionsInliningStatistics class
\brief Calculate and dump ThinLTO specific inliner stats.
The main statistics are:
(1) Number of inlined imported functions,
(2) Number of imported functions inlined into importing module (indirect),
(3) Number of non imported functions inlined into importing module
(indirect).
The difference between first and the second is that first stat counts
all performed inlines on imported functions, but the second one only the
functions that have been eventually inlined to a function in the importing
module (by a chain of inlines). Because llvm uses bottom-up inliner, it is
possible to e.g. import function `A`, `B` and then inline `B` to `A`,
and after this `A` might be too big to be inlined into some other function
that calls it. It calculates this statistic by building graph, where
the nodes are functions, and edges are performed inlines and then by marking
the edges starting from not imported function.
If `Verbose` is set to true, then it also dumps statistics
per each inlined function, sorted by the greatest inlines count like
- number of performed inlines
- number of performed inlines to importing module
Reviewers: eraman, tejohnson, mehdi_amini
Subscribers: mehdi_amini, llvm-commits
Differential Revision: https://reviews.llvm.org/D22491
llvm-svn: 277089
2016-07-29 08:27:16 +08:00
|
|
|
#include "llvm/Support/Debug.h"
|
|
|
|
#include "llvm/Support/raw_ostream.h"
|
|
|
|
#include <algorithm>
|
|
|
|
#include <iomanip>
|
|
|
|
#include <sstream>
|
2021-04-19 21:51:57 +08:00
|
|
|
#include <string>
|
|
|
|
|
Added ThinLTO inlining statistics
Summary:
copypasta doc of ImportedFunctionsInliningStatistics class
\brief Calculate and dump ThinLTO specific inliner stats.
The main statistics are:
(1) Number of inlined imported functions,
(2) Number of imported functions inlined into importing module (indirect),
(3) Number of non imported functions inlined into importing module
(indirect).
The difference between first and the second is that first stat counts
all performed inlines on imported functions, but the second one only the
functions that have been eventually inlined to a function in the importing
module (by a chain of inlines). Because llvm uses bottom-up inliner, it is
possible to e.g. import function `A`, `B` and then inline `B` to `A`,
and after this `A` might be too big to be inlined into some other function
that calls it. It calculates this statistic by building graph, where
the nodes are functions, and edges are performed inlines and then by marking
the edges starting from not imported function.
If `Verbose` is set to true, then it also dumps statistics
per each inlined function, sorted by the greatest inlines count like
- number of performed inlines
- number of performed inlines to importing module
Reviewers: eraman, tejohnson, mehdi_amini
Subscribers: mehdi_amini, llvm-commits
Differential Revision: https://reviews.llvm.org/D22491
llvm-svn: 277089
2016-07-29 08:27:16 +08:00
|
|
|
using namespace llvm;
|
|
|
|
|
2021-01-21 03:25:43 +08:00
|
|
|
cl::opt<InlinerFunctionImportStatsOpts> InlinerFunctionImportStats(
|
|
|
|
"inliner-function-import-stats",
|
|
|
|
cl::init(InlinerFunctionImportStatsOpts::No),
|
|
|
|
cl::values(clEnumValN(InlinerFunctionImportStatsOpts::Basic, "basic",
|
|
|
|
"basic statistics"),
|
|
|
|
clEnumValN(InlinerFunctionImportStatsOpts::Verbose, "verbose",
|
|
|
|
"printing of statistics for each inlined function")),
|
|
|
|
cl::Hidden, cl::desc("Enable inliner stats for imported functions"));
|
|
|
|
|
Added ThinLTO inlining statistics
Summary:
copypasta doc of ImportedFunctionsInliningStatistics class
\brief Calculate and dump ThinLTO specific inliner stats.
The main statistics are:
(1) Number of inlined imported functions,
(2) Number of imported functions inlined into importing module (indirect),
(3) Number of non imported functions inlined into importing module
(indirect).
The difference between first and the second is that first stat counts
all performed inlines on imported functions, but the second one only the
functions that have been eventually inlined to a function in the importing
module (by a chain of inlines). Because llvm uses bottom-up inliner, it is
possible to e.g. import function `A`, `B` and then inline `B` to `A`,
and after this `A` might be too big to be inlined into some other function
that calls it. It calculates this statistic by building graph, where
the nodes are functions, and edges are performed inlines and then by marking
the edges starting from not imported function.
If `Verbose` is set to true, then it also dumps statistics
per each inlined function, sorted by the greatest inlines count like
- number of performed inlines
- number of performed inlines to importing module
Reviewers: eraman, tejohnson, mehdi_amini
Subscribers: mehdi_amini, llvm-commits
Differential Revision: https://reviews.llvm.org/D22491
llvm-svn: 277089
2016-07-29 08:27:16 +08:00
|
|
|
ImportedFunctionsInliningStatistics::InlineGraphNode &
|
|
|
|
ImportedFunctionsInliningStatistics::createInlineGraphNode(const Function &F) {
|
|
|
|
|
|
|
|
auto &ValueLookup = NodesMap[F.getName()];
|
|
|
|
if (!ValueLookup) {
|
2019-08-15 23:54:37 +08:00
|
|
|
ValueLookup = std::make_unique<InlineGraphNode>();
|
2019-09-05 01:28:48 +08:00
|
|
|
ValueLookup->Imported = F.hasMetadata("thinlto_src_module");
|
Added ThinLTO inlining statistics
Summary:
copypasta doc of ImportedFunctionsInliningStatistics class
\brief Calculate and dump ThinLTO specific inliner stats.
The main statistics are:
(1) Number of inlined imported functions,
(2) Number of imported functions inlined into importing module (indirect),
(3) Number of non imported functions inlined into importing module
(indirect).
The difference between first and the second is that first stat counts
all performed inlines on imported functions, but the second one only the
functions that have been eventually inlined to a function in the importing
module (by a chain of inlines). Because llvm uses bottom-up inliner, it is
possible to e.g. import function `A`, `B` and then inline `B` to `A`,
and after this `A` might be too big to be inlined into some other function
that calls it. It calculates this statistic by building graph, where
the nodes are functions, and edges are performed inlines and then by marking
the edges starting from not imported function.
If `Verbose` is set to true, then it also dumps statistics
per each inlined function, sorted by the greatest inlines count like
- number of performed inlines
- number of performed inlines to importing module
Reviewers: eraman, tejohnson, mehdi_amini
Subscribers: mehdi_amini, llvm-commits
Differential Revision: https://reviews.llvm.org/D22491
llvm-svn: 277089
2016-07-29 08:27:16 +08:00
|
|
|
}
|
|
|
|
return *ValueLookup;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ImportedFunctionsInliningStatistics::recordInline(const Function &Caller,
|
|
|
|
const Function &Callee) {
|
|
|
|
|
|
|
|
InlineGraphNode &CallerNode = createInlineGraphNode(Caller);
|
|
|
|
InlineGraphNode &CalleeNode = createInlineGraphNode(Callee);
|
|
|
|
CalleeNode.NumberOfInlines++;
|
|
|
|
|
|
|
|
if (!CallerNode.Imported && !CalleeNode.Imported) {
|
|
|
|
// Direct inline from not imported callee to not imported caller, so we
|
|
|
|
// don't have to add this to graph. It might be very helpful if you wanna
|
|
|
|
// get the inliner statistics in compile step where there are no imported
|
|
|
|
// functions. In this case the graph would be empty.
|
|
|
|
CalleeNode.NumberOfRealInlines++;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
CallerNode.InlinedCallees.push_back(&CalleeNode);
|
2016-08-03 06:18:47 +08:00
|
|
|
if (!CallerNode.Imported) {
|
|
|
|
// We could avoid second lookup, but it would make the code ultra ugly.
|
|
|
|
auto It = NodesMap.find(Caller.getName());
|
|
|
|
assert(It != NodesMap.end() && "The node should be already there.");
|
|
|
|
// Save Caller as a starting node for traversal. The string has to be one
|
|
|
|
// from map because Caller can disappear (and function name with it).
|
|
|
|
NonImportedCallers.push_back(It->first());
|
|
|
|
}
|
Added ThinLTO inlining statistics
Summary:
copypasta doc of ImportedFunctionsInliningStatistics class
\brief Calculate and dump ThinLTO specific inliner stats.
The main statistics are:
(1) Number of inlined imported functions,
(2) Number of imported functions inlined into importing module (indirect),
(3) Number of non imported functions inlined into importing module
(indirect).
The difference between first and the second is that first stat counts
all performed inlines on imported functions, but the second one only the
functions that have been eventually inlined to a function in the importing
module (by a chain of inlines). Because llvm uses bottom-up inliner, it is
possible to e.g. import function `A`, `B` and then inline `B` to `A`,
and after this `A` might be too big to be inlined into some other function
that calls it. It calculates this statistic by building graph, where
the nodes are functions, and edges are performed inlines and then by marking
the edges starting from not imported function.
If `Verbose` is set to true, then it also dumps statistics
per each inlined function, sorted by the greatest inlines count like
- number of performed inlines
- number of performed inlines to importing module
Reviewers: eraman, tejohnson, mehdi_amini
Subscribers: mehdi_amini, llvm-commits
Differential Revision: https://reviews.llvm.org/D22491
llvm-svn: 277089
2016-07-29 08:27:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void ImportedFunctionsInliningStatistics::setModuleInfo(const Module &M) {
|
|
|
|
ModuleName = M.getName();
|
|
|
|
for (const auto &F : M.functions()) {
|
2017-03-25 01:59:06 +08:00
|
|
|
if (F.isDeclaration())
|
|
|
|
continue;
|
Added ThinLTO inlining statistics
Summary:
copypasta doc of ImportedFunctionsInliningStatistics class
\brief Calculate and dump ThinLTO specific inliner stats.
The main statistics are:
(1) Number of inlined imported functions,
(2) Number of imported functions inlined into importing module (indirect),
(3) Number of non imported functions inlined into importing module
(indirect).
The difference between first and the second is that first stat counts
all performed inlines on imported functions, but the second one only the
functions that have been eventually inlined to a function in the importing
module (by a chain of inlines). Because llvm uses bottom-up inliner, it is
possible to e.g. import function `A`, `B` and then inline `B` to `A`,
and after this `A` might be too big to be inlined into some other function
that calls it. It calculates this statistic by building graph, where
the nodes are functions, and edges are performed inlines and then by marking
the edges starting from not imported function.
If `Verbose` is set to true, then it also dumps statistics
per each inlined function, sorted by the greatest inlines count like
- number of performed inlines
- number of performed inlines to importing module
Reviewers: eraman, tejohnson, mehdi_amini
Subscribers: mehdi_amini, llvm-commits
Differential Revision: https://reviews.llvm.org/D22491
llvm-svn: 277089
2016-07-29 08:27:16 +08:00
|
|
|
AllFunctions++;
|
2019-09-05 01:28:48 +08:00
|
|
|
ImportedFunctions += int(F.hasMetadata("thinlto_src_module"));
|
Added ThinLTO inlining statistics
Summary:
copypasta doc of ImportedFunctionsInliningStatistics class
\brief Calculate and dump ThinLTO specific inliner stats.
The main statistics are:
(1) Number of inlined imported functions,
(2) Number of imported functions inlined into importing module (indirect),
(3) Number of non imported functions inlined into importing module
(indirect).
The difference between first and the second is that first stat counts
all performed inlines on imported functions, but the second one only the
functions that have been eventually inlined to a function in the importing
module (by a chain of inlines). Because llvm uses bottom-up inliner, it is
possible to e.g. import function `A`, `B` and then inline `B` to `A`,
and after this `A` might be too big to be inlined into some other function
that calls it. It calculates this statistic by building graph, where
the nodes are functions, and edges are performed inlines and then by marking
the edges starting from not imported function.
If `Verbose` is set to true, then it also dumps statistics
per each inlined function, sorted by the greatest inlines count like
- number of performed inlines
- number of performed inlines to importing module
Reviewers: eraman, tejohnson, mehdi_amini
Subscribers: mehdi_amini, llvm-commits
Differential Revision: https://reviews.llvm.org/D22491
llvm-svn: 277089
2016-07-29 08:27:16 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
static std::string getStatString(const char *Msg, int32_t Fraction, int32_t All,
|
|
|
|
const char *PercentageOfMsg,
|
|
|
|
bool LineEnd = true) {
|
|
|
|
double Result = 0;
|
|
|
|
if (All != 0)
|
|
|
|
Result = 100 * static_cast<double>(Fraction) / All;
|
|
|
|
|
|
|
|
std::stringstream Str;
|
|
|
|
Str << std::setprecision(4) << Msg << ": " << Fraction << " [" << Result
|
|
|
|
<< "% of " << PercentageOfMsg << "]";
|
|
|
|
if (LineEnd)
|
|
|
|
Str << "\n";
|
|
|
|
return Str.str();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ImportedFunctionsInliningStatistics::dump(const bool Verbose) {
|
|
|
|
calculateRealInlines();
|
|
|
|
NonImportedCallers.clear();
|
|
|
|
|
|
|
|
int32_t InlinedImportedFunctionsCount = 0;
|
|
|
|
int32_t InlinedNotImportedFunctionsCount = 0;
|
|
|
|
|
|
|
|
int32_t InlinedImportedFunctionsToImportingModuleCount = 0;
|
|
|
|
int32_t InlinedNotImportedFunctionsToImportingModuleCount = 0;
|
|
|
|
|
|
|
|
const auto SortedNodes = getSortedNodes();
|
|
|
|
std::string Out;
|
|
|
|
Out.reserve(5000);
|
|
|
|
raw_string_ostream Ostream(Out);
|
|
|
|
|
|
|
|
Ostream << "------- Dumping inliner stats for [" << ModuleName
|
|
|
|
<< "] -------\n";
|
|
|
|
|
|
|
|
if (Verbose)
|
|
|
|
Ostream << "-- List of inlined functions:\n";
|
|
|
|
|
|
|
|
for (const auto &Node : SortedNodes) {
|
2016-08-03 06:18:47 +08:00
|
|
|
assert(Node->second->NumberOfInlines >= Node->second->NumberOfRealInlines);
|
|
|
|
if (Node->second->NumberOfInlines == 0)
|
Added ThinLTO inlining statistics
Summary:
copypasta doc of ImportedFunctionsInliningStatistics class
\brief Calculate and dump ThinLTO specific inliner stats.
The main statistics are:
(1) Number of inlined imported functions,
(2) Number of imported functions inlined into importing module (indirect),
(3) Number of non imported functions inlined into importing module
(indirect).
The difference between first and the second is that first stat counts
all performed inlines on imported functions, but the second one only the
functions that have been eventually inlined to a function in the importing
module (by a chain of inlines). Because llvm uses bottom-up inliner, it is
possible to e.g. import function `A`, `B` and then inline `B` to `A`,
and after this `A` might be too big to be inlined into some other function
that calls it. It calculates this statistic by building graph, where
the nodes are functions, and edges are performed inlines and then by marking
the edges starting from not imported function.
If `Verbose` is set to true, then it also dumps statistics
per each inlined function, sorted by the greatest inlines count like
- number of performed inlines
- number of performed inlines to importing module
Reviewers: eraman, tejohnson, mehdi_amini
Subscribers: mehdi_amini, llvm-commits
Differential Revision: https://reviews.llvm.org/D22491
llvm-svn: 277089
2016-07-29 08:27:16 +08:00
|
|
|
continue;
|
|
|
|
|
2016-08-03 06:18:47 +08:00
|
|
|
if (Node->second->Imported) {
|
Added ThinLTO inlining statistics
Summary:
copypasta doc of ImportedFunctionsInliningStatistics class
\brief Calculate and dump ThinLTO specific inliner stats.
The main statistics are:
(1) Number of inlined imported functions,
(2) Number of imported functions inlined into importing module (indirect),
(3) Number of non imported functions inlined into importing module
(indirect).
The difference between first and the second is that first stat counts
all performed inlines on imported functions, but the second one only the
functions that have been eventually inlined to a function in the importing
module (by a chain of inlines). Because llvm uses bottom-up inliner, it is
possible to e.g. import function `A`, `B` and then inline `B` to `A`,
and after this `A` might be too big to be inlined into some other function
that calls it. It calculates this statistic by building graph, where
the nodes are functions, and edges are performed inlines and then by marking
the edges starting from not imported function.
If `Verbose` is set to true, then it also dumps statistics
per each inlined function, sorted by the greatest inlines count like
- number of performed inlines
- number of performed inlines to importing module
Reviewers: eraman, tejohnson, mehdi_amini
Subscribers: mehdi_amini, llvm-commits
Differential Revision: https://reviews.llvm.org/D22491
llvm-svn: 277089
2016-07-29 08:27:16 +08:00
|
|
|
InlinedImportedFunctionsCount++;
|
|
|
|
InlinedImportedFunctionsToImportingModuleCount +=
|
2016-08-03 06:18:47 +08:00
|
|
|
int(Node->second->NumberOfRealInlines > 0);
|
Added ThinLTO inlining statistics
Summary:
copypasta doc of ImportedFunctionsInliningStatistics class
\brief Calculate and dump ThinLTO specific inliner stats.
The main statistics are:
(1) Number of inlined imported functions,
(2) Number of imported functions inlined into importing module (indirect),
(3) Number of non imported functions inlined into importing module
(indirect).
The difference between first and the second is that first stat counts
all performed inlines on imported functions, but the second one only the
functions that have been eventually inlined to a function in the importing
module (by a chain of inlines). Because llvm uses bottom-up inliner, it is
possible to e.g. import function `A`, `B` and then inline `B` to `A`,
and after this `A` might be too big to be inlined into some other function
that calls it. It calculates this statistic by building graph, where
the nodes are functions, and edges are performed inlines and then by marking
the edges starting from not imported function.
If `Verbose` is set to true, then it also dumps statistics
per each inlined function, sorted by the greatest inlines count like
- number of performed inlines
- number of performed inlines to importing module
Reviewers: eraman, tejohnson, mehdi_amini
Subscribers: mehdi_amini, llvm-commits
Differential Revision: https://reviews.llvm.org/D22491
llvm-svn: 277089
2016-07-29 08:27:16 +08:00
|
|
|
} else {
|
|
|
|
InlinedNotImportedFunctionsCount++;
|
|
|
|
InlinedNotImportedFunctionsToImportingModuleCount +=
|
2016-08-03 06:18:47 +08:00
|
|
|
int(Node->second->NumberOfRealInlines > 0);
|
Added ThinLTO inlining statistics
Summary:
copypasta doc of ImportedFunctionsInliningStatistics class
\brief Calculate and dump ThinLTO specific inliner stats.
The main statistics are:
(1) Number of inlined imported functions,
(2) Number of imported functions inlined into importing module (indirect),
(3) Number of non imported functions inlined into importing module
(indirect).
The difference between first and the second is that first stat counts
all performed inlines on imported functions, but the second one only the
functions that have been eventually inlined to a function in the importing
module (by a chain of inlines). Because llvm uses bottom-up inliner, it is
possible to e.g. import function `A`, `B` and then inline `B` to `A`,
and after this `A` might be too big to be inlined into some other function
that calls it. It calculates this statistic by building graph, where
the nodes are functions, and edges are performed inlines and then by marking
the edges starting from not imported function.
If `Verbose` is set to true, then it also dumps statistics
per each inlined function, sorted by the greatest inlines count like
- number of performed inlines
- number of performed inlines to importing module
Reviewers: eraman, tejohnson, mehdi_amini
Subscribers: mehdi_amini, llvm-commits
Differential Revision: https://reviews.llvm.org/D22491
llvm-svn: 277089
2016-07-29 08:27:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (Verbose)
|
|
|
|
Ostream << "Inlined "
|
2016-08-03 06:18:47 +08:00
|
|
|
<< (Node->second->Imported ? "imported " : "not imported ")
|
|
|
|
<< "function [" << Node->first() << "]"
|
|
|
|
<< ": #inlines = " << Node->second->NumberOfInlines
|
Added ThinLTO inlining statistics
Summary:
copypasta doc of ImportedFunctionsInliningStatistics class
\brief Calculate and dump ThinLTO specific inliner stats.
The main statistics are:
(1) Number of inlined imported functions,
(2) Number of imported functions inlined into importing module (indirect),
(3) Number of non imported functions inlined into importing module
(indirect).
The difference between first and the second is that first stat counts
all performed inlines on imported functions, but the second one only the
functions that have been eventually inlined to a function in the importing
module (by a chain of inlines). Because llvm uses bottom-up inliner, it is
possible to e.g. import function `A`, `B` and then inline `B` to `A`,
and after this `A` might be too big to be inlined into some other function
that calls it. It calculates this statistic by building graph, where
the nodes are functions, and edges are performed inlines and then by marking
the edges starting from not imported function.
If `Verbose` is set to true, then it also dumps statistics
per each inlined function, sorted by the greatest inlines count like
- number of performed inlines
- number of performed inlines to importing module
Reviewers: eraman, tejohnson, mehdi_amini
Subscribers: mehdi_amini, llvm-commits
Differential Revision: https://reviews.llvm.org/D22491
llvm-svn: 277089
2016-07-29 08:27:16 +08:00
|
|
|
<< ", #inlines_to_importing_module = "
|
2016-08-03 06:18:47 +08:00
|
|
|
<< Node->second->NumberOfRealInlines << "\n";
|
Added ThinLTO inlining statistics
Summary:
copypasta doc of ImportedFunctionsInliningStatistics class
\brief Calculate and dump ThinLTO specific inliner stats.
The main statistics are:
(1) Number of inlined imported functions,
(2) Number of imported functions inlined into importing module (indirect),
(3) Number of non imported functions inlined into importing module
(indirect).
The difference between first and the second is that first stat counts
all performed inlines on imported functions, but the second one only the
functions that have been eventually inlined to a function in the importing
module (by a chain of inlines). Because llvm uses bottom-up inliner, it is
possible to e.g. import function `A`, `B` and then inline `B` to `A`,
and after this `A` might be too big to be inlined into some other function
that calls it. It calculates this statistic by building graph, where
the nodes are functions, and edges are performed inlines and then by marking
the edges starting from not imported function.
If `Verbose` is set to true, then it also dumps statistics
per each inlined function, sorted by the greatest inlines count like
- number of performed inlines
- number of performed inlines to importing module
Reviewers: eraman, tejohnson, mehdi_amini
Subscribers: mehdi_amini, llvm-commits
Differential Revision: https://reviews.llvm.org/D22491
llvm-svn: 277089
2016-07-29 08:27:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
auto InlinedFunctionsCount =
|
|
|
|
InlinedImportedFunctionsCount + InlinedNotImportedFunctionsCount;
|
|
|
|
auto NotImportedFuncCount = AllFunctions - ImportedFunctions;
|
|
|
|
auto ImportedNotInlinedIntoModule =
|
|
|
|
ImportedFunctions - InlinedImportedFunctionsToImportingModuleCount;
|
|
|
|
|
|
|
|
Ostream << "-- Summary:\n"
|
|
|
|
<< "All functions: " << AllFunctions
|
|
|
|
<< ", imported functions: " << ImportedFunctions << "\n"
|
|
|
|
<< getStatString("inlined functions", InlinedFunctionsCount,
|
|
|
|
AllFunctions, "all functions")
|
|
|
|
<< getStatString("imported functions inlined anywhere",
|
|
|
|
InlinedImportedFunctionsCount, ImportedFunctions,
|
|
|
|
"imported functions")
|
|
|
|
<< getStatString("imported functions inlined into importing module",
|
|
|
|
InlinedImportedFunctionsToImportingModuleCount,
|
|
|
|
ImportedFunctions, "imported functions",
|
|
|
|
/*LineEnd=*/false)
|
|
|
|
<< getStatString(", remaining", ImportedNotInlinedIntoModule,
|
|
|
|
ImportedFunctions, "imported functions")
|
|
|
|
<< getStatString("non-imported functions inlined anywhere",
|
|
|
|
InlinedNotImportedFunctionsCount,
|
|
|
|
NotImportedFuncCount, "non-imported functions")
|
|
|
|
<< getStatString(
|
|
|
|
"non-imported functions inlined into importing module",
|
|
|
|
InlinedNotImportedFunctionsToImportingModuleCount,
|
|
|
|
NotImportedFuncCount, "non-imported functions");
|
|
|
|
Ostream.flush();
|
|
|
|
dbgs() << Out;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ImportedFunctionsInliningStatistics::calculateRealInlines() {
|
|
|
|
// Removing duplicated Callers.
|
llvm::sort(C.begin(), C.end(), ...) -> llvm::sort(C, ...)
Summary: The convenience wrapper in STLExtras is available since rL342102.
Reviewers: dblaikie, javed.absar, JDevlieghere, andreadb
Subscribers: MatzeB, sanjoy, arsenm, dschuff, mehdi_amini, sdardis, nemanjai, jvesely, nhaehnle, sbc100, jgravelle-google, eraman, aheejin, kbarton, JDevlieghere, javed.absar, gbedwell, jrtc27, mgrang, atanasyan, steven_wu, george.burgess.iv, dexonsmith, kristina, jsji, llvm-commits
Differential Revision: https://reviews.llvm.org/D52573
llvm-svn: 343163
2018-09-27 10:13:45 +08:00
|
|
|
llvm::sort(NonImportedCallers);
|
Added ThinLTO inlining statistics
Summary:
copypasta doc of ImportedFunctionsInliningStatistics class
\brief Calculate and dump ThinLTO specific inliner stats.
The main statistics are:
(1) Number of inlined imported functions,
(2) Number of imported functions inlined into importing module (indirect),
(3) Number of non imported functions inlined into importing module
(indirect).
The difference between first and the second is that first stat counts
all performed inlines on imported functions, but the second one only the
functions that have been eventually inlined to a function in the importing
module (by a chain of inlines). Because llvm uses bottom-up inliner, it is
possible to e.g. import function `A`, `B` and then inline `B` to `A`,
and after this `A` might be too big to be inlined into some other function
that calls it. It calculates this statistic by building graph, where
the nodes are functions, and edges are performed inlines and then by marking
the edges starting from not imported function.
If `Verbose` is set to true, then it also dumps statistics
per each inlined function, sorted by the greatest inlines count like
- number of performed inlines
- number of performed inlines to importing module
Reviewers: eraman, tejohnson, mehdi_amini
Subscribers: mehdi_amini, llvm-commits
Differential Revision: https://reviews.llvm.org/D22491
llvm-svn: 277089
2016-07-29 08:27:16 +08:00
|
|
|
NonImportedCallers.erase(
|
|
|
|
std::unique(NonImportedCallers.begin(), NonImportedCallers.end()),
|
|
|
|
NonImportedCallers.end());
|
|
|
|
|
|
|
|
for (const auto &Name : NonImportedCallers) {
|
|
|
|
auto &Node = *NodesMap[Name];
|
|
|
|
if (!Node.Visited)
|
|
|
|
dfs(Node);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ImportedFunctionsInliningStatistics::dfs(InlineGraphNode &GraphNode) {
|
|
|
|
assert(!GraphNode.Visited);
|
|
|
|
GraphNode.Visited = true;
|
|
|
|
for (auto *const InlinedFunctionNode : GraphNode.InlinedCallees) {
|
|
|
|
InlinedFunctionNode->NumberOfRealInlines++;
|
|
|
|
if (!InlinedFunctionNode->Visited)
|
|
|
|
dfs(*InlinedFunctionNode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ImportedFunctionsInliningStatistics::SortedNodesTy
|
|
|
|
ImportedFunctionsInliningStatistics::getSortedNodes() {
|
|
|
|
SortedNodesTy SortedNodes;
|
|
|
|
SortedNodes.reserve(NodesMap.size());
|
2021-01-21 04:39:55 +08:00
|
|
|
for (const NodesMapTy::value_type &Node : NodesMap)
|
2016-08-03 06:18:47 +08:00
|
|
|
SortedNodes.push_back(&Node);
|
Added ThinLTO inlining statistics
Summary:
copypasta doc of ImportedFunctionsInliningStatistics class
\brief Calculate and dump ThinLTO specific inliner stats.
The main statistics are:
(1) Number of inlined imported functions,
(2) Number of imported functions inlined into importing module (indirect),
(3) Number of non imported functions inlined into importing module
(indirect).
The difference between first and the second is that first stat counts
all performed inlines on imported functions, but the second one only the
functions that have been eventually inlined to a function in the importing
module (by a chain of inlines). Because llvm uses bottom-up inliner, it is
possible to e.g. import function `A`, `B` and then inline `B` to `A`,
and after this `A` might be too big to be inlined into some other function
that calls it. It calculates this statistic by building graph, where
the nodes are functions, and edges are performed inlines and then by marking
the edges starting from not imported function.
If `Verbose` is set to true, then it also dumps statistics
per each inlined function, sorted by the greatest inlines count like
- number of performed inlines
- number of performed inlines to importing module
Reviewers: eraman, tejohnson, mehdi_amini
Subscribers: mehdi_amini, llvm-commits
Differential Revision: https://reviews.llvm.org/D22491
llvm-svn: 277089
2016-07-29 08:27:16 +08:00
|
|
|
|
2018-10-01 06:31:29 +08:00
|
|
|
llvm::sort(SortedNodes, [&](const SortedNodesTy::value_type &Lhs,
|
|
|
|
const SortedNodesTy::value_type &Rhs) {
|
|
|
|
if (Lhs->second->NumberOfInlines != Rhs->second->NumberOfInlines)
|
|
|
|
return Lhs->second->NumberOfInlines > Rhs->second->NumberOfInlines;
|
|
|
|
if (Lhs->second->NumberOfRealInlines != Rhs->second->NumberOfRealInlines)
|
|
|
|
return Lhs->second->NumberOfRealInlines >
|
|
|
|
Rhs->second->NumberOfRealInlines;
|
|
|
|
return Lhs->first() < Rhs->first();
|
|
|
|
});
|
Added ThinLTO inlining statistics
Summary:
copypasta doc of ImportedFunctionsInliningStatistics class
\brief Calculate and dump ThinLTO specific inliner stats.
The main statistics are:
(1) Number of inlined imported functions,
(2) Number of imported functions inlined into importing module (indirect),
(3) Number of non imported functions inlined into importing module
(indirect).
The difference between first and the second is that first stat counts
all performed inlines on imported functions, but the second one only the
functions that have been eventually inlined to a function in the importing
module (by a chain of inlines). Because llvm uses bottom-up inliner, it is
possible to e.g. import function `A`, `B` and then inline `B` to `A`,
and after this `A` might be too big to be inlined into some other function
that calls it. It calculates this statistic by building graph, where
the nodes are functions, and edges are performed inlines and then by marking
the edges starting from not imported function.
If `Verbose` is set to true, then it also dumps statistics
per each inlined function, sorted by the greatest inlines count like
- number of performed inlines
- number of performed inlines to importing module
Reviewers: eraman, tejohnson, mehdi_amini
Subscribers: mehdi_amini, llvm-commits
Differential Revision: https://reviews.llvm.org/D22491
llvm-svn: 277089
2016-07-29 08:27:16 +08:00
|
|
|
return SortedNodes;
|
|
|
|
}
|