summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--llvm/include/llvm/Transforms/Utils/ImportedFunctionsInliningStatistics.h10
-rw-r--r--llvm/lib/Transforms/Utils/ImportedFunctionsInliningStatistics.cpp48
2 files changed, 30 insertions, 28 deletions
diff --git a/llvm/include/llvm/Transforms/Utils/ImportedFunctionsInliningStatistics.h b/llvm/include/llvm/Transforms/Utils/ImportedFunctionsInliningStatistics.h
index f239e03f1b4..1c488ae7f6f 100644
--- a/llvm/include/llvm/Transforms/Utils/ImportedFunctionsInliningStatistics.h
+++ b/llvm/include/llvm/Transforms/Utils/ImportedFunctionsInliningStatistics.h
@@ -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;
diff --git a/llvm/lib/Transforms/Utils/ImportedFunctionsInliningStatistics.cpp b/llvm/lib/Transforms/Utils/ImportedFunctionsInliningStatistics.cpp
index 7f27e96602c..ed018bb7310 100644
--- a/llvm/lib/Transforms/Utils/ImportedFunctionsInliningStatistics.cpp
+++ b/llvm/lib/Transforms/Utils/ImportedFunctionsInliningStatistics.cpp
@@ -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) {
@@ -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 =
@@ -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;
}
OpenPOWER on IntegriCloud