32 for (
unsigned i = 0, e = Matches[0]->first.size(); i != e; ++i) {
34 char Letter = Matches[0]->first[i];
37 if (
Match->first[i] != Letter)
41 return Matches[0]->first.size();
49bool StringMatcher::EmitStringMatcherForChar(
50 const std::vector<const StringPair *> &Matches,
unsigned CharNo,
51 unsigned IndentCount,
bool IgnoreDuplicates)
const {
52 assert(!Matches.empty() &&
"Must have at least one string to match!");
53 std::string Indent(IndentCount * 2 + 4,
' ');
57 if (CharNo == Matches[0]->first.size()) {
58 if (Matches.size() > 1 && !IgnoreDuplicates)
64 std::pair<StringRef, StringRef>
Split =
Code.split(
'\n');
65 OS << Indent <<
Split.first <<
"\t // \"" << Matches[0]->first <<
"\"\n";
68 while (!
Code.empty()) {
70 OS << Indent <<
Split.first <<
"\n";
77 std::map<char, std::vector<const StringPair*>> MatchesByLetter;
80 MatchesByLetter[
Match->first[CharNo]].push_back(
Match);
84 if (MatchesByLetter.size() == 1) {
86 unsigned NumChars = FirstNonCommonLetter-CharNo;
92 OS << Indent <<
"if (" << StrVariableName <<
"[" << CharNo <<
"] != '"
93 << Matches[0]->first[CharNo] <<
"')\n";
94 OS << Indent <<
" break;\n";
98 OS << Indent <<
"if (memcmp(" << StrVariableName <<
".data()+" << CharNo
99 <<
", \"" << Matches[0]->first.
substr(CharNo, NumChars) <<
"\", "
100 << NumChars <<
") != 0)\n";
101 OS << Indent <<
" break;\n";
104 return EmitStringMatcherForChar(Matches, FirstNonCommonLetter, IndentCount,
110 OS << Indent <<
"switch (" << StrVariableName <<
"[" << CharNo <<
"]) {\n";
111 OS << Indent <<
"default: break;\n";
113 for (
const auto &LI : MatchesByLetter) {
115 OS << Indent <<
"case '" << LI.first <<
"':\t // " << LI.second.size()
117 if (LI.second.size() != 1)
119 OS <<
" to match.\n";
120 if (EmitStringMatcherForChar(LI.second, CharNo + 1, IndentCount + 1,
122 OS << Indent <<
" break;\n";
125 OS << Indent <<
"}\n";
133 if (Matches.empty())
return;
136 std::map<unsigned, std::vector<const StringPair*>> MatchesByLength;
139 MatchesByLength[
Match.first.size()].push_back(&
Match);
143 OS.
indent(Indent*2+2) <<
"switch (" << StrVariableName <<
".size()) {\n";
144 OS.
indent(Indent*2+2) <<
"default: break;\n";
146 for (
const auto &LI : MatchesByLength) {
148 <<
"case " << LI.first <<
":\t // " << LI.second.size() <<
" string"
149 << (LI.second.size() == 1 ?
"" :
"s") <<
" to match.\n";
150 if (EmitStringMatcherForChar(LI.second, 0, Indent, IgnoreDuplicates))
151 OS.
indent(Indent*2+4) <<
"break;\n";
154 OS.
indent(Indent*2+2) <<
"}\n";
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static unsigned FindFirstNonCommonLetter(const std::vector< const StringMatcher::StringPair * > &Matches)
FindFirstNonCommonLetter - Find the first character in the keys of the string pairs that is not share...
std::pair< CachedHashStringRef, size_t > StringPair
void Emit(unsigned Indent=0, bool IgnoreDuplicates=false) const
Emit - Top level entry point.
std::pair< std::string, std::string > StringPair
StringRef - Represent a constant reference to a string, i.e.
constexpr StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
raw_ostream & indent(unsigned NumSpaces)
indent - Insert 'NumSpaces' spaces.
NodeAddr< CodeNode * > Code
This is an optimization pass for GlobalISel generic memory operations.
void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.