|
23 | 23 | #include "swift/SILOptimizer/Utils/SILOptFunctionBuilder.h"
|
24 | 24 | #include "swift/SILOptimizer/Utils/GenericCloner.h"
|
25 | 25 | #include "swift/SILOptimizer/Utils/SpecializationMangler.h"
|
| 26 | +#include "swift/Demangling/ManglingMacros.h" |
26 | 27 | #include "swift/Strings.h"
|
27 | 28 |
|
28 | 29 | using namespace swift;
|
@@ -2499,91 +2500,24 @@ static bool linkSpecialization(SILModule &M, SILFunction *F) {
|
2499 | 2500 | return false;
|
2500 | 2501 | }
|
2501 | 2502 |
|
2502 |
| -bool swift::isKnownPrespecialization(StringRef SpecName) { |
2503 |
| - // Completely disable for now. |
2504 |
| -#if false |
2505 |
| - |
2506 |
| - /// The list of classes and functions from the stdlib |
2507 |
| - /// whose specializations we want to preserve. |
2508 |
| - static const char *const KnownPrespecializations[] = { |
2509 |
| - "Array", |
2510 |
| - "_ArrayBuffer", |
2511 |
| - "_ContiguousArrayBuffer", |
2512 |
| - "Range", |
2513 |
| - "RangeIterator", |
2514 |
| - "CountableRange", |
2515 |
| - "CountableRangeIterator", |
2516 |
| - "ClosedRange", |
2517 |
| - "ClosedRangeIterator", |
2518 |
| - "CountableClosedRange", |
2519 |
| - "CountableClosedRangeIterator", |
2520 |
| - "IndexingIterator", |
2521 |
| - "Collection", |
2522 |
| - "ReversedCollection", |
2523 |
| - "MutableCollection", |
2524 |
| - "BidirectionalCollection", |
2525 |
| - "RandomAccessCollection", |
2526 |
| - "ReversedRandomAccessCollection", |
2527 |
| - "RangeReplaceableCollection", |
2528 |
| - "_allocateUninitializedArray", |
2529 |
| - "UTF8", |
2530 |
| - "UTF16", |
2531 |
| - "String", |
2532 |
| - "_StringBuffer", |
2533 |
| - }; |
2534 |
| - |
2535 |
| - // TODO: Once there is an efficient API to check if |
2536 |
| - // a given symbol is a specialization of a specific type, |
2537 |
| - // use it instead. Doing demangling just for this check |
2538 |
| - // is just wasteful. |
2539 |
| - auto DemangledNameString = |
2540 |
| - swift::Demangle::demangleSymbolAsString(SpecName); |
2541 |
| - |
2542 |
| - StringRef DemangledName = DemangledNameString; |
2543 |
| - |
2544 |
| - LLVM_DEBUG(llvm::dbgs() << "Check if known: " << DemangledName << "\n"); |
2545 |
| - |
2546 |
| - auto pos = DemangledName.find("generic ", 0); |
2547 |
| - auto oldpos = pos; |
2548 |
| - if (pos == StringRef::npos) |
2549 |
| - return false; |
2550 |
| - |
2551 |
| - // Create "of Swift" |
2552 |
| - llvm::SmallString<64> OfString; |
2553 |
| - llvm::raw_svector_ostream buffer(OfString); |
2554 |
| - buffer << "of "; |
2555 |
| - buffer << STDLIB_NAME <<'.'; |
2556 |
| - |
2557 |
| - StringRef OfStr = buffer.str(); |
2558 |
| - LLVM_DEBUG(llvm::dbgs() << "Check substring: " << OfStr << "\n"); |
2559 |
| - |
2560 |
| - pos = DemangledName.find(OfStr, oldpos); |
2561 |
| - |
2562 |
| - if (pos == StringRef::npos) { |
2563 |
| - // Create "of (extension in Swift).Swift" |
2564 |
| - llvm::SmallString<64> OfString; |
2565 |
| - llvm::raw_svector_ostream buffer(OfString); |
2566 |
| - buffer << "of (extension in " << STDLIB_NAME << "):"; |
2567 |
| - buffer << STDLIB_NAME << '.'; |
2568 |
| - OfStr = buffer.str(); |
2569 |
| - pos = DemangledName.find(OfStr, oldpos); |
2570 |
| - LLVM_DEBUG(llvm::dbgs() << "Check substring: " << OfStr << "\n"); |
2571 |
| - if (pos == StringRef::npos) |
2572 |
| - return false; |
2573 |
| - } |
| 2503 | +#define PRESPEC_SYMBOL(s) MANGLE_AS_STRING(s), |
| 2504 | +static const char *PrespecSymbols[] = { |
| 2505 | +#include "OnonePrespecializations.def" |
| 2506 | + nullptr |
| 2507 | +}; |
| 2508 | +#undef PRESPEC_SYMBOL |
2574 | 2509 |
|
2575 |
| - pos += OfStr.size(); |
| 2510 | +llvm::DenseSet<StringRef> PrespecSet; |
2576 | 2511 |
|
2577 |
| - for (auto NameStr : KnownPrespecializations) { |
2578 |
| - StringRef Name = NameStr; |
2579 |
| - auto pos1 = DemangledName.find(Name, pos); |
2580 |
| - if (pos1 == pos && !isalpha(DemangledName[pos1+Name.size()])) { |
2581 |
| - return true; |
| 2512 | +bool swift::isKnownPrespecialization(StringRef SpecName) { |
| 2513 | + if (PrespecSet.empty()) { |
| 2514 | + const char **Pos = &PrespecSymbols[0]; |
| 2515 | + while (const char *Sym = *Pos++) { |
| 2516 | + PrespecSet.insert(Sym); |
2582 | 2517 | }
|
| 2518 | + assert(!PrespecSet.empty()); |
2583 | 2519 | }
|
2584 |
| - |
2585 |
| -#endif |
2586 |
| - return false; |
| 2520 | + return PrespecSet.count(SpecName) != 0; |
2587 | 2521 | }
|
2588 | 2522 |
|
2589 | 2523 | /// Try to look up an existing specialization in the specialization cache.
|
|
0 commit comments