Skip to content

Commit

Permalink
[CalleeAnalysis] Remove the enumeration of functions in the module fo…
Browse files Browse the repository at this point in the history
…r sorting.

Use the function name to sort the calees, not their order in the module.
  • Loading branch information
nadavrot committed Nov 23, 2015
1 parent 293d08e commit d78c4db
Showing 1 changed file with 2 additions and 17 deletions.
19 changes: 2 additions & 17 deletions lib/SILAnalysis/BasicCalleeAnalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,29 +22,14 @@
using namespace swift;

void CalleeCache::sortAndUniqueCallees() {
llvm::DenseMap<SILFunction *, unsigned int> FunctionEnumeration;

// Enumerate the functions in the module to use as keys in sorting.
unsigned int count = 0;
for (auto &F : M)
FunctionEnumeration[&F] = count++;

auto Lookup = [&FunctionEnumeration](SILFunction *F) -> unsigned int {
auto It = FunctionEnumeration.find(F);
assert(It != FunctionEnumeration.end() &&
"Function unexpectedly not found in enumeration!");

return It->second;
};

// Sort the callees for each decl and remove duplicates.
for (auto &Pair : TheCache) {
auto &Callees = *Pair.second.getPointer();

// Sort by enumeration number so that clients get a stable order.
std::sort(Callees.begin(), Callees.end(),
[&Lookup](SILFunction *Left, SILFunction *Right) {
return Lookup(Left) < Lookup(Right);
[](SILFunction *Left, SILFunction *Right) {
return Left->getName().compare(Right->getName());
});

// Remove duplicates.
Expand Down

0 comments on commit d78c4db

Please sign in to comment.