Skip to content

Commit

Permalink
Imported statistics types changes
Browse files Browse the repository at this point in the history
Reviewers: tejohnson, eraman

Subscribers: llvm-commits

Differential Revision: https://reviews.llvm.org/D22980

llvm-svn: 277534
  • Loading branch information
prazek committed Aug 2, 2016
1 parent 777efb1 commit 47509f6
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 28 deletions.
Expand Up @@ -15,8 +15,8 @@

#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/StringMap.h"
#include <string>
#include <unordered_map>
#include <vector>

namespace llvm {
Expand Down Expand Up @@ -100,10 +100,10 @@ class ImportedFunctionsInliningStatistics {
void dfs(InlineGraphNode &GraphNode);

using NodesMapTy =
std::unordered_map<std::string, std::unique_ptr<InlineGraphNode>>;
llvm::StringMap<std::unique_ptr<InlineGraphNode>>;
using SortedNodesTy =
std::vector<std::pair<std::string, std::unique_ptr<InlineGraphNode>>>;
/// Clears NodesMap and returns vector of elements sorted by
std::vector<const NodesMapTy::MapEntryTy*>;
/// Returns vector of elements sorted by
/// (-NumberOfInlines, -NumberOfRealInlines, FunctionName).
SortedNodesTy getSortedNodes();

Expand All @@ -114,7 +114,7 @@ class ImportedFunctionsInliningStatistics {
/// address of the node would not be invariant.
NodesMapTy NodesMap;
/// Non external functions that have some other function inlined inside.
std::vector<std::string> NonImportedCallers;
std::vector<StringRef> NonImportedCallers;
int AllFunctions = 0;
int ImportedFunctions = 0;
StringRef ModuleName;
Expand Down
48 changes: 25 additions & 23 deletions llvm/lib/Transforms/Utils/ImportedFunctionsInliningStatistics.cpp
Expand Up @@ -49,9 +49,14 @@ void ImportedFunctionsInliningStatistics::recordInline(const Function &Caller,
}

CallerNode.InlinedCallees.push_back(&CalleeNode);
if (!CallerNode.Imported)
// Save Caller as a starting node for traversal.
NonImportedCallers.push_back(Caller.getName());
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());
}
}

void ImportedFunctionsInliningStatistics::setModuleInfo(const Module &M) {
Expand Down Expand Up @@ -98,27 +103,27 @@ void ImportedFunctionsInliningStatistics::dump(const bool Verbose) {
Ostream << "-- List of inlined functions:\n";

for (const auto &Node : SortedNodes) {
assert(Node.second->NumberOfInlines >= Node.second->NumberOfRealInlines);
if (Node.second->NumberOfInlines == 0)
assert(Node->second->NumberOfInlines >= Node->second->NumberOfRealInlines);
if (Node->second->NumberOfInlines == 0)
continue;

if (Node.second->Imported) {
if (Node->second->Imported) {
InlinedImportedFunctionsCount++;
InlinedImportedFunctionsToImportingModuleCount +=
int(Node.second->NumberOfRealInlines > 0);
int(Node->second->NumberOfRealInlines > 0);
} else {
InlinedNotImportedFunctionsCount++;
InlinedNotImportedFunctionsToImportingModuleCount +=
int(Node.second->NumberOfRealInlines > 0);
int(Node->second->NumberOfRealInlines > 0);
}

if (Verbose)
Ostream << "Inlined "
<< (Node.second->Imported ? "imported " : "not imported ")
<< "function [" << Node.first << "]"
<< ": #inlines = " << Node.second->NumberOfInlines
<< (Node->second->Imported ? "imported " : "not imported ")
<< "function [" << Node->first() << "]"
<< ": #inlines = " << Node->second->NumberOfInlines
<< ", #inlines_to_importing_module = "
<< Node.second->NumberOfRealInlines << "\n";
<< Node->second->NumberOfRealInlines << "\n";
}

auto InlinedFunctionsCount =
Expand Down Expand Up @@ -180,22 +185,19 @@ ImportedFunctionsInliningStatistics::SortedNodesTy
ImportedFunctionsInliningStatistics::getSortedNodes() {
SortedNodesTy SortedNodes;
SortedNodes.reserve(NodesMap.size());

for (auto &&Node : NodesMap)
SortedNodes.emplace_back(Node.first, std::move(Node.second));

NodesMap.clear(); // We don't want to leave nullptrs.
for (const NodesMapTy::value_type& Node : NodesMap)
SortedNodes.push_back(&Node);

std::sort(
SortedNodes.begin(), SortedNodes.end(),
[&](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;
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();
});
return SortedNodes;
}

0 comments on commit 47509f6

Please sign in to comment.