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 bool IsPrefix =
false) {
126 if (!
Name.starts_with(Needle))
128 Consummed = Needle.
size();
134 auto NamePos =
Name.begin();
135 auto NeedlePos = Needle.
begin();
137 char PreviousCharInNameOrigin = PreviousCharInName;
138 char PreviousCharInNeedle = *Needle.
begin();
139 auto IgnoreSpaces = [](
auto It,
auto End,
char &PreviousChar,
140 bool IsPrefix =
false) {
142 const auto Next = std::next(It);
147 *It ==
' ' || *It ==
'_' ||
148 (*It ==
'-' && isAlnum(PreviousChar) &&
149 ((Next !=
End && isAlnum(*Next)) || (Next ==
End && IsPrefix)));
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;
175 return NeedlePos == Needle.
end();
178static std::tuple<Node, bool, uint32_t>
181 const Node *Parent =
nullptr) {
183 std::size_t Consummed = 0;
184 bool DoesStartWith =
N.IsRoot ||
startsWith(
Name,
N.Name, Strict, Consummed,
187 return std::make_tuple(
N,
false, 0);
189 if (
Name.size() - Consummed == 0 &&
N.Value != 0xFFFFFFFF)
190 return std::make_tuple(
N,
true,
N.Value);
192 if (
N.hasChildren()) {
198 std::tie(
C, Matches,
Value) =
200 PreviousCharInName, Buffer, &
N);
202 std::reverse_copy(
C.Name.begin(),
C.Name.end(),
203 std::back_inserter(Buffer));
204 return std::make_tuple(
N,
true,
Value);
206 ChildOffset +=
C.Size;
211 return std::make_tuple(
N,
false, 0);
214static std::tuple<Node, bool, uint32_t>
224 {
"D",
"YAE",
"GS" },
225 {
"DD",
"EO",
"N", },
227 {
"M",
"YEO",
"NH" },
231 {
"SS",
"WAE",
"LM" },
235 {
"C",
"WEO",
"LP" },
254constexpr const char32_t SBase = 0xAC00;
260 char &PreviousInName,
int &Pos,
int Column) {
261 assert(Column == 0 || Column == 1 || Column == 2);
264 int Prev = PreviousInName;
265 for (std::size_t
I = 0;
I < CountPerColumn[Column];
I++) {
267 if (
int(Syllable.
size()) <= Len)
269 std::size_t Consummed = 0;
270 char PreviousInNameCopy = PreviousInName;
272 startsWith(
Name, Syllable, Strict, Consummed, PreviousInNameCopy);
277 Prev = PreviousInNameCopy;
281 PreviousInName = Prev;
285static std::optional<char32_t>
289 std::size_t Consummed = 0;
292 startsWith(
Name,
"HANGUL SYLLABLE ", Strict, Consummed, NameStart);
296 int L = -1, V = -1,
T = -1;
300 if (L != -1 && V != -1 &&
T != -1 &&
Name.empty()) {
302 Buffer.
append(
"HANGUL SYLLABLE ");
325 {
"CJK UNIFIED IDEOGRAPH-", 0x3400, 0x4DBF},
326 {
"CJK UNIFIED IDEOGRAPH-", 0x4E00, 0x9FFF},
327 {
"CJK UNIFIED IDEOGRAPH-", 0x20000, 0x2A6DF},
328 {
"CJK UNIFIED IDEOGRAPH-", 0x2A700, 0x2B739},
329 {
"CJK UNIFIED IDEOGRAPH-", 0x2B740, 0x2B81D},
330 {
"CJK UNIFIED IDEOGRAPH-", 0x2B820, 0x2CEA1},
331 {
"CJK UNIFIED IDEOGRAPH-", 0x2CEB0, 0x2EBE0},
332 {
"CJK UNIFIED IDEOGRAPH-", 0x2EBF0, 0x2EE5D},
333 {
"CJK UNIFIED IDEOGRAPH-", 0x30000, 0x3134A},
334 {
"CJK UNIFIED IDEOGRAPH-", 0x31350, 0x323AF},
335 {
"TANGUT IDEOGRAPH-", 0x17000, 0x187F7},
336 {
"TANGUT IDEOGRAPH-", 0x18D00, 0x18D08},
337 {
"KHITAN SMALL SCRIPT CHARACTER-", 0x18B00, 0x18CD5},
338 {
"NUSHU CHARACTER-", 0x1B170, 0x1B2FB},
339 {
"CJK COMPATIBILITY IDEOGRAPH-", 0xF900, 0xFA6D},
340 {
"CJK COMPATIBILITY IDEOGRAPH-", 0xFA70, 0xFAD9},
341 {
"CJK COMPATIBILITY IDEOGRAPH-", 0x2F800, 0x2FA1D},
344static std::optional<char32_t>
348 std::size_t Consummed = 0;
350 bool DoesStartWith =
startsWith(
Name, Item.Prefix, Strict, Consummed,
355 unsigned long long V = 0;
363 Buffer.
append(Item.Prefix);
364 Buffer.
append(utohexstr(V,
true));
388 std::reverse(Buffer.
begin(), Buffer.
end());
391 if (!Strict &&
Value == 0x116c &&
Name.contains_insensitive(
"O-E")) {
392 Buffer =
"HANGUL JUNGSEONG O-E";
407std::optional<LooseMatchingResult>
424 std::size_t LargestEditDistance = 0;
426 Matches.
reserve(MaxMatchesCount + 1);
429 char32_t Value) ->
bool {
430 if (Distance > LargestEditDistance) {
431 if (Matches.
size() == MaxMatchesCount)
433 LargestEditDistance = Distance;
448 return a.
Name < GetName();
451 if (It == Matches.
end() && Matches.
size() == MaxMatchesCount)
455 Matches.
insert(It, std::move(M));
456 if (Matches.
size() > MaxMatchesCount)
465 Out.reserve(
Name.size());
466 for (
char C :
Name) {
468 Out.push_back(toUpper(
C));
475 const std::size_t Columns =
482 std::vector<char> Distances(
485 auto Get = [&Distances, Columns](
size_t Column, std::size_t Row) ->
char & {
488 return Distances[Row * Columns + Column];
491 for (std::size_t
I = 0;
I < Columns;
I++)
498 auto VisitNode = [&](
const Node &
N, std::size_t Row,
499 auto &VisitNode) ->
void {
501 for (; J <
N.Name.size(); J++) {
502 if (!isAlnum(
N.Name[J]))
507 for (std::size_t
I = 1;
I < Columns;
I++) {
508 const int Delete = Get(
I - 1, Row) + 1;
509 const int Insert = Get(
I, Row - 1) + 1;
512 Get(
I - 1, Row - 1) + (NormalizedName[
I - 1] !=
N.Name[J] ? 1 : 0);
514 Get(
I, Row) = std::min(Insert, std::min(Delete, Replace));
520 unsigned Cost = Get(Columns - 1, Row - 1);
521 if (
N.Value != 0xFFFFFFFF) {
525 if (
N.hasChildren()) {
526 auto ChildOffset =
N.ChildrenOffset;
529 ChildOffset +=
C.Size;
532 VisitNode(
C, Row, VisitNode);
540 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.
LLVM Value Representation.
@ C
The default llvm calling convention, compatible with C.
static Node readNode(uint32_t Offset, const Node *Parent=nullptr)
constexpr const uint32_t TCount
const std::size_t UnicodeNameToCodepointLargestNameSize
static bool startsWith(StringRef Name, StringRef Needle, bool Strict, std::size_t &Consummed, char &PreviousCharInName, bool IsPrefix=false)
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::tuple< Node, bool, uint32_t > compareNode(uint32_t Offset, StringRef Name, bool Strict, char PreviousCharInName, BufferType &Buffer, const Node *Parent=nullptr)
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
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