|
20 | 20 | #include "llvm/ADT/STLExtras.h"
|
21 | 21 | #include "llvm/ADT/SmallString.h"
|
22 | 22 | #include "llvm/ADT/StringExtras.h"
|
| 23 | +#include "llvm/ADT/StringMap.h" |
23 | 24 | #include "llvm/ADT/StringRef.h"
|
24 | 25 | #include "llvm/ADT/StringSwitch.h"
|
25 | 26 | #include "llvm/Support/ErrorHandling.h"
|
@@ -3667,6 +3668,12 @@ static bool GenerateTargetSpecificAttrChecks(const Record *R,
|
3667 | 3668 | static void GenerateHasAttrSpellingStringSwitch(
|
3668 | 3669 | ArrayRef<std::pair<const Record *, FlattenedSpelling>> Attrs,
|
3669 | 3670 | raw_ostream &OS, StringRef Variety, StringRef Scope = "") {
|
| 3671 | + |
| 3672 | + // It turns out that duplicate records for a given spelling. This map combines |
| 3673 | + // matching test strings using '||'. For example, if there are three |
| 3674 | + // conditions A, B, and C, the final result will be: A || B || C. |
| 3675 | + llvm::StringMap<std::string> TestStringMap; |
| 3676 | + |
3670 | 3677 | for (const auto &[Attr, Spelling] : Attrs) {
|
3671 | 3678 | // C++11-style attributes have specific version information associated with
|
3672 | 3679 | // them. If the attribute has no scope, the version information must not
|
@@ -3727,12 +3734,26 @@ static void GenerateHasAttrSpellingStringSwitch(
|
3727 | 3734 | }
|
3728 | 3735 | }
|
3729 | 3736 |
|
3730 |
| - std::string TestStr = !Test.empty() |
3731 |
| - ? Test + " ? " + itostr(Version) + " : 0" |
3732 |
| - : itostr(Version); |
3733 |
| - if (Scope.empty() || Scope == Spelling.nameSpace()) |
3734 |
| - OS << " .Case(\"" << Spelling.name() << "\", " << TestStr << ")\n"; |
| 3737 | + std::string TestStr = |
| 3738 | + !Test.empty() ? '(' + Test + " ? " + itostr(Version) + " : 0" + ')' |
| 3739 | + : '(' + itostr(Version) + ')'; |
| 3740 | + |
| 3741 | + if (Scope.empty() || Scope == Spelling.nameSpace()) { |
| 3742 | + if (TestStringMap.contains(Spelling.name())) { |
| 3743 | + TestStringMap[Spelling.name()] += " || " + TestStr; |
| 3744 | + } else { |
| 3745 | + TestStringMap[Spelling.name()] = TestStr; |
| 3746 | + } |
| 3747 | + } |
| 3748 | + } |
| 3749 | + |
| 3750 | + // Create the actual string switch statement after all the attributes have |
| 3751 | + // been parsed |
| 3752 | + for (auto &entry : TestStringMap) { |
| 3753 | + OS << " .Case(\"" << entry.getKey() << "\", " << entry.getValue() |
| 3754 | + << ")\n"; |
3735 | 3755 | }
|
| 3756 | + |
3736 | 3757 | OS << " .Default(0);\n";
|
3737 | 3758 | }
|
3738 | 3759 |
|
|
0 commit comments