53 std::reverse_copy(
N->Name.begin(),
N->Name.end(), std::back_inserter(S));
56 std::reverse(S.begin(), S.end());
80 bool LongName = NameInfo & 0x40;
82 std::size_t
Size = NameInfo & ~0xC0;
94 N.Value = ((
H << 16) | (M << 8) | L) >> 3;
96 bool HasChildren = L & 0x02;
97 N.HasSibling = L & 0x01;
106 N.HasSibling =
H & 0x80;
107 bool HasChildren =
H & 0x40;
110 N.ChildrenOffset = (
H << 16);
121 std::size_t &Consummed,
char &PreviousCharInName,
122 char &PreviousCharInNeedle,
bool IsPrefix =
false) {
126 if (!
Name.startswith(Needle))
128 Consummed = Needle.
size();
134 auto NamePos =
Name.begin();
135 auto NeedlePos = Needle.
begin();
137 char PreviousCharInNameOrigin = PreviousCharInName;
138 char PreviousCharInNeedleOrigin = PreviousCharInNeedle;
140 auto IgnoreSpaces = [](
auto It,
auto End,
char &PreviousChar,
141 bool IgnoreEnd =
false) {
143 const auto Next = std::next(It);
147 *It ==
' ' || *It ==
'_' ||
148 (*It ==
'-' && isAlnum(PreviousChar) &&
149 ((Next !=
End && isAlnum(*Next)) || (Next ==
End && IgnoreEnd)));
159 NamePos = IgnoreSpaces(NamePos,
Name.end(), PreviousCharInName);
161 IgnoreSpaces(NeedlePos, Needle.
end(), PreviousCharInNeedle, IsPrefix);
162 if (NeedlePos == Needle.
end())
164 if (NamePos ==
Name.end())
166 if (toUpper(*NeedlePos) != toUpper(*NamePos))
171 Consummed = std::distance(
Name.begin(), NamePos);
172 if (NeedlePos != Needle.
end()) {
173 PreviousCharInName = PreviousCharInNameOrigin;
174 PreviousCharInNeedle = PreviousCharInNeedleOrigin;
176 return NeedlePos == Needle.
end();
179static std::tuple<Node, bool, uint32_t>
181 char PreviousCharInName,
char PreviousCharInNeedle,
184 std::size_t Consummed = 0;
187 PreviousCharInName, PreviousCharInNeedle);
189 return std::make_tuple(
N,
false, 0);
191 if (
Name.size() - Consummed == 0 &&
N.Value != 0xFFFFFFFF)
192 return std::make_tuple(
N,
true,
N.Value);
194 if (
N.hasChildren()) {
200 std::tie(
C, Matches,
Value) =
202 PreviousCharInName, PreviousCharInNeedle, Buffer, &
N);
204 std::reverse_copy(
C.Name.begin(),
C.Name.end(),
205 std::back_inserter(Buffer));
206 return std::make_tuple(
N,
true,
Value);
208 ChildOffset +=
C.Size;
213 return std::make_tuple(
N,
false, 0);
216static std::tuple<Node, bool, uint32_t>
226 {
"D",
"YAE",
"GS" },
227 {
"DD",
"EO",
"N", },
229 {
"M",
"YEO",
"NH" },
233 {
"SS",
"WAE",
"LM" },
237 {
"C",
"WEO",
"LP" },
256constexpr const char32_t SBase = 0xAC00;
262 char &PreviousInName,
int &Pos,
int Column) {
263 assert(Column == 0 || Column == 1 || Column == 2);
265 char NeedleStart = 0;
267 int Prev = PreviousInName;
268 for (std::size_t
I = 0;
I < CountPerColumn[Column];
I++) {
270 if (
int(Syllable.
size()) <= Len)
272 std::size_t Consummed = 0;
273 char PreviousInNameCopy = PreviousInName;
274 bool DoesStartWith =
startsWith(
Name, Syllable, Strict, Consummed,
275 PreviousInNameCopy, NeedleStart);
280 Prev = PreviousInNameCopy;
284 PreviousInName = Prev;
288static std::optional<char32_t>
292 std::size_t Consummed = 0;
293 char NameStart = 0, NeedleStart = 0;
294 bool DoesStartWith =
startsWith(
Name,
"HANGUL SYLLABLE ", Strict, Consummed,
295 NameStart, NeedleStart);
299 int L = -1, V = -1,
T = -1;
303 if (L != -1 && V != -1 &&
T != -1 &&
Name.empty()) {
305 Buffer.
append(
"HANGUL SYLLABLE ");
328 {
"CJK UNIFIED IDEOGRAPH-", 0x3400, 0x4DBF},
329 {
"CJK UNIFIED IDEOGRAPH-", 0x4E00, 0x9FFF},
330 {
"CJK UNIFIED IDEOGRAPH-", 0x20000, 0x2A6DF},
331 {
"CJK UNIFIED IDEOGRAPH-", 0x2A700, 0x2B739},
332 {
"CJK UNIFIED IDEOGRAPH-", 0x2B740, 0x2B81D},
333 {
"CJK UNIFIED IDEOGRAPH-", 0x2B820, 0x2CEA1},
334 {
"CJK UNIFIED IDEOGRAPH-", 0x2CEB0, 0x2EBE0},
335 {
"CJK UNIFIED IDEOGRAPH-", 0x30000, 0x3134A},
336 {
"CJK UNIFIED IDEOGRAPH-", 0x31350, 0x323AF},
337 {
"TANGUT IDEOGRAPH-", 0x17000, 0x187F7},
338 {
"TANGUT IDEOGRAPH-", 0x18D00, 0x18D08},
339 {
"KHITAN SMALL SCRIPT CHARACTER-", 0x18B00, 0x18CD5},
340 {
"NUSHU CHARACTER-", 0x1B170, 0x1B2FB},
341 {
"CJK COMPATIBILITY IDEOGRAPH-", 0xF900, 0xFA6D},
342 {
"CJK COMPATIBILITY IDEOGRAPH-", 0xFA70, 0xFAD9},
343 {
"CJK COMPATIBILITY IDEOGRAPH-", 0x2F800, 0x2FA1D},
346static std::optional<char32_t>
350 std::size_t Consummed = 0;
351 char NameStart = 0, NeedleStart = 0;
352 bool DoesStartWith =
startsWith(
Name, Item.Prefix, Strict, Consummed,
353 NameStart, NeedleStart,
true);
357 unsigned long long V = 0;
365 Buffer.
append(Item.Prefix);
366 Buffer.
append(utohexstr(V,
true));
390 std::reverse(Buffer.
begin(), Buffer.
end());
393 if (!Strict &&
Value == 0x116c &&
395 Buffer =
"HANGUL JUNGSEONG O-E";
410std::optional<LooseMatchingResult>
427 std::size_t LargestEditDistance = 0;
429 Matches.
reserve(MaxMatchesCount + 1);
432 char32_t Value) ->
bool {
433 if (Distance > LargestEditDistance) {
434 if (Matches.
size() == MaxMatchesCount)
436 LargestEditDistance = Distance;
451 return a.
Name < GetName();
454 if (It == Matches.
end() && Matches.
size() == MaxMatchesCount)
458 Matches.
insert(It, std::move(M));
459 if (Matches.
size() > MaxMatchesCount)
468 Out.reserve(
Name.size());
469 for (
char C :
Name) {
471 Out.push_back(toUpper(
C));
478 const std::size_t Columns =
485 std::vector<char> Distances(
488 auto Get = [&Distances, Columns](
size_t Column, std::size_t Row) ->
char & {
491 return Distances[Row * Columns + Column];
494 for (std::size_t
I = 0;
I < Columns;
I++)
501 auto VisitNode = [&](
const Node &
N, std::size_t Row,
502 auto &VisitNode) ->
void {
504 for (; J <
N.Name.size(); J++) {
505 if (!isAlnum(
N.Name[J]))
510 for (std::size_t
I = 1;
I < Columns;
I++) {
511 const int Delete = Get(
I - 1, Row) + 1;
512 const int Insert = Get(
I, Row - 1) + 1;
515 Get(
I - 1, Row - 1) + (NormalizedName[
I - 1] !=
N.Name[J] ? 1 : 0);
517 Get(
I, Row) = std::min(Insert, std::min(Delete, Replace));
523 unsigned Cost = Get(Columns - 1, Row - 1);
524 if (
N.Value != 0xFFFFFFFF) {
528 if (
N.hasChildren()) {
529 auto ChildOffset =
N.ChildrenOffset;
532 ChildOffset +=
C.Size;
535 VisitNode(
C, Row, VisitNode);
543 VisitNode(Root, 1, VisitNode);
ReachingDefAnalysis InstSet InstSet & Ignore
#define LLVM_ATTRIBUTE_UNUSED
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
@ Normalize
Normalize - Normalize according to the given loops.
void append(StringRef RHS)
Append from a StringRef.
void reserve(size_type N)
iterator insert(iterator I, T &&Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringRef - Represent a constant reference to a string, i.e.
constexpr bool empty() const
empty - Check if the string is empty.
constexpr size_t size() const
size - Get the string size.
static constexpr size_t npos
LLVM Value Representation.
@ C
The default llvm calling convention, compatible with C.
static std::tuple< Node, bool, uint32_t > compareNode(uint32_t Offset, StringRef Name, bool Strict, char PreviousCharInName, char PreviousCharInNeedle, BufferType &Buffer, const Node *Parent=nullptr)
static Node readNode(uint32_t Offset, const Node *Parent=nullptr)
constexpr const uint32_t TCount
const std::size_t UnicodeNameToCodepointLargestNameSize
std::optional< char32_t > nameToCodepointStrict(StringRef Name)
Maps the name or the alias of a Unicode character to its associated codepoints.
SmallVector< MatchForCodepointName > nearestMatchesForCodepointName(StringRef Pattern, std::size_t MaxMatchesCount)
const std::size_t UnicodeNameToCodepointIndexSize
constexpr const char *const HangulSyllables[][3]
std::optional< LooseMatchingResult > nameToCodepointLooseMatching(StringRef Name)
constexpr const uint32_t LCount
static std::optional< char32_t > nameToHangulCodePoint(StringRef Name, bool Strict, BufferType &Buffer)
constexpr const uint32_t VCount
const uint8_t * UnicodeNameToCodepointIndex
static const GeneratedNamesData GeneratedNamesDataTable[]
static std::size_t findSyllable(StringRef Name, bool Strict, char &PreviousInName, int &Pos, int Column)
static std::optional< char32_t > nameToCodepoint(StringRef Name, bool Strict, BufferType &Buffer)
static std::optional< char32_t > nameToGeneratedCodePoint(StringRef Name, bool Strict, BufferType &Buffer)
constexpr const char32_t SBase
const char * UnicodeNameToCodepointDict
static bool startsWith(StringRef Name, StringRef Needle, bool Strict, std::size_t &Consummed, char &PreviousCharInName, char &PreviousCharInNeedle, bool IsPrefix=false)
This is an optimization pass for GlobalISel generic memory operations.
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
detail::ValueMatchesPoly< M > HasValue(M Matcher)
auto lower_bound(R &&Range, T &&Value)
Provide wrappers to std::lower_bound which take ranges instead of having to pass begin/end explicitly...
bool getAsUnsignedInteger(StringRef Str, unsigned Radix, unsigned long long &Result)
Helper functions for StringRef::getAsInteger.
constexpr bool isValid() const
std::string fullName() const
constexpr bool hasChildren() const