Skip to content

Remove the FunctionEnumeration data structure from CalleeAnalysis #10

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 23, 2015
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