[llvm] r277534 - Imported statistics types changes
Piotr Padlewski via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 2 15:18:47 PDT 2016
Author: prazek
Date: Tue Aug 2 17:18:47 2016
New Revision: 277534
URL: http://llvm.org/viewvc/llvm-project?rev=277534&view=rev
Log:
Imported statistics types changes
Reviewers: tejohnson, eraman
Subscribers: llvm-commits
Differential Revision: https://reviews.llvm.org/D22980
Modified:
llvm/trunk/include/llvm/Transforms/Utils/ImportedFunctionsInliningStatistics.h
llvm/trunk/lib/Transforms/Utils/ImportedFunctionsInliningStatistics.cpp
Modified: llvm/trunk/include/llvm/Transforms/Utils/ImportedFunctionsInliningStatistics.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Transforms/Utils/ImportedFunctionsInliningStatistics.h?rev=277534&r1=277533&r2=277534&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Transforms/Utils/ImportedFunctionsInliningStatistics.h (original)
+++ llvm/trunk/include/llvm/Transforms/Utils/ImportedFunctionsInliningStatistics.h Tue Aug 2 17:18:47 2016
@@ -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 {
@@ -100,10 +100,10 @@ private:
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();
@@ -114,7 +114,7 @@ private:
/// 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;
Modified: llvm/trunk/lib/Transforms/Utils/ImportedFunctionsInliningStatistics.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/ImportedFunctionsInliningStatistics.cpp?rev=277534&r1=277533&r2=277534&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Utils/ImportedFunctionsInliningStatistics.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/ImportedFunctionsInliningStatistics.cpp Tue Aug 2 17:18:47 2016
@@ -49,9 +49,14 @@ void ImportedFunctionsInliningStatistics
}
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) {
@@ -98,27 +103,27 @@ void ImportedFunctionsInliningStatistics
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 =
@@ -180,22 +185,19 @@ ImportedFunctionsInliningStatistics::Sor
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;
}
More information about the llvm-commits
mailing list