Skip to content

Commit

Permalink
Merge pull request #10 from nadavrot/calee_analysis_branch
Browse files Browse the repository at this point in the history
Remove the FunctionEnumeration data structure from CalleeAnalysis
  • Loading branch information
nadavrot committed Nov 23, 2015
2 parents 293d08e + 693f6af commit 5ed14f1
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 18 deletions.
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

0 comments on commit 5ed14f1

Please sign in to comment.