|
51 | 51 | #include <cassert> |
52 | 52 | #include <iterator> |
53 | 53 | #include <utility> |
| 54 | +#include <cmath> |
54 | 55 |
|
55 | 56 | using namespace llvm; |
56 | 57 |
|
@@ -83,6 +84,9 @@ static cl::opt<unsigned> |
83 | 84 | // Limit on the number of memdep results to process. |
84 | 85 | static const unsigned int NumResultsLimit = 100; |
85 | 86 |
|
| 87 | +// for quickly calculating log |
| 88 | +const float ln2 = 0.69314718f; |
| 89 | + |
86 | 90 | /// This is a helper function that removes Val from 'Inst's set in ReverseMap. |
87 | 91 | /// |
88 | 92 | /// If the set becomes empty, remove Inst's entry. |
@@ -991,33 +995,20 @@ MemDepResult MemoryDependenceResults::getNonLocalInfoForBlock( |
991 | 995 | static void |
992 | 996 | SortNonLocalDepInfoCache(MemoryDependenceResults::NonLocalDepInfo &Cache, |
993 | 997 | unsigned NumSortedEntries) { |
994 | | - switch (Cache.size() - NumSortedEntries) { |
995 | | - case 0: |
996 | | - // done, no new entries. |
997 | | - break; |
998 | | - case 2: { |
999 | | - // Two new entries, insert the last one into place. |
1000 | | - NonLocalDepEntry Val = Cache.back(); |
1001 | | - Cache.pop_back(); |
1002 | | - MemoryDependenceResults::NonLocalDepInfo::iterator Entry = |
1003 | | - std::upper_bound(Cache.begin(), Cache.end() - 1, Val); |
1004 | | - Cache.insert(Entry, Val); |
1005 | | - [[fallthrough]]; |
1006 | | - } |
1007 | | - case 1: |
1008 | | - // One new entry, Just insert the new value at the appropriate position. |
1009 | | - if (Cache.size() != 1) { |
| 998 | + |
| 999 | + auto s = Cache.size() - NumSortedEntries; |
| 1000 | + if (s < log2(Cache.size()) * ln2) { |
| 1001 | + while (s>0) { |
1010 | 1002 | NonLocalDepEntry Val = Cache.back(); |
1011 | 1003 | Cache.pop_back(); |
1012 | 1004 | MemoryDependenceResults::NonLocalDepInfo::iterator Entry = |
1013 | | - llvm::upper_bound(Cache, Val); |
| 1005 | + std::upper_bound(Cache.begin(), Cache.end() - 1, Val); |
1014 | 1006 | Cache.insert(Entry, Val); |
| 1007 | + s--; |
1015 | 1008 | } |
1016 | | - break; |
1017 | | - default: |
1018 | | - // Added many values, do a full scale sort. |
| 1009 | + } |
| 1010 | + else { |
1019 | 1011 | llvm::sort(Cache); |
1020 | | - break; |
1021 | 1012 | } |
1022 | 1013 | } |
1023 | 1014 |
|
|
0 commit comments