Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 3 additions & 17 deletions lib/SILAnalysis/BasicCalleeAnalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,29 +22,15 @@
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) {
// Check if Right's lexicographical order is greater than Left.
return 1 == Right->getName().compare(Left->getName());
});

// Remove duplicates.
Expand Down
2 changes: 1 addition & 1 deletion test/SILAnalysis/function-order.sil
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import Builtin
// CHECK-NEXT: public_bottom
// CHECK-NEXT: public_middle
// CHECK-NEXT: public_top
// CHECK-NEXT: private_derived_foo
// CHECK-NEXT: private_base_foo
// CHECK-NEXT: private_derived_foo
// CHECK-NEXT: call_private
// CHECK-NEXT: internal_base_foo
// CHECK-NEXT: internal_derived_foo
Expand Down