From d78c4db2b4145b4530536df7ae9d180aa99aabe2 Mon Sep 17 00:00:00 2001 From: Nadav Rotem Date: Fri, 20 Nov 2015 22:33:41 -0800 Subject: [PATCH 1/2] [CalleeAnalysis] Remove the enumeration of functions in the module for sorting. Use the function name to sort the calees, not their order in the module. --- lib/SILAnalysis/BasicCalleeAnalysis.cpp | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) diff --git a/lib/SILAnalysis/BasicCalleeAnalysis.cpp b/lib/SILAnalysis/BasicCalleeAnalysis.cpp index 6aa36a30cbc85..86538a8829216 100644 --- a/lib/SILAnalysis/BasicCalleeAnalysis.cpp +++ b/lib/SILAnalysis/BasicCalleeAnalysis.cpp @@ -22,29 +22,14 @@ using namespace swift; void CalleeCache::sortAndUniqueCallees() { - llvm::DenseMap 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. From 693f6af4e8523eab49e4a46713756441141160ca Mon Sep 17 00:00:00 2001 From: Nadav Rotem Date: Fri, 20 Nov 2015 23:35:48 -0800 Subject: [PATCH 2/2] Fix a bug in the lexicographically order of functions in the callee set. This fixes a bug that was introduced in 95b2fa869bf3208c8e52558a008b1c3d02bee706. --- lib/SILAnalysis/BasicCalleeAnalysis.cpp | 3 ++- test/SILAnalysis/function-order.sil | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/SILAnalysis/BasicCalleeAnalysis.cpp b/lib/SILAnalysis/BasicCalleeAnalysis.cpp index 86538a8829216..98f082df2f186 100644 --- a/lib/SILAnalysis/BasicCalleeAnalysis.cpp +++ b/lib/SILAnalysis/BasicCalleeAnalysis.cpp @@ -29,7 +29,8 @@ void CalleeCache::sortAndUniqueCallees() { // Sort by enumeration number so that clients get a stable order. std::sort(Callees.begin(), Callees.end(), [](SILFunction *Left, SILFunction *Right) { - return Left->getName().compare(Right->getName()); + // Check if Right's lexicographical order is greater than Left. + return 1 == Right->getName().compare(Left->getName()); }); // Remove duplicates. diff --git a/test/SILAnalysis/function-order.sil b/test/SILAnalysis/function-order.sil index 0a19e6819e757..340101ee8ff4f 100644 --- a/test/SILAnalysis/function-order.sil +++ b/test/SILAnalysis/function-order.sil @@ -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