29void StringTableBuilder::initSize() {
57 : K(K), Alignment(Alignment) {
76 memcpy(Buf +
P.second,
Data.data(),
Data.size());
102 size_t R = Len - Pos;
106 for (
size_t I = 0;
I != R; ++
I)
113static bool tailGreater(
const TailEntry &
A,
const TailEntry &
B,
size_t Pos) {
114 const char *EA =
A.Data +
A.Len, *EB =
B.Data +
B.Len;
115 size_t N = std::min(
A.Len,
B.Len),
I = Pos;
116 for (;
I + 8 <=
N;
I += 8)
117 if (memcmp(EA -
I - 8, EB -
I - 8, 8))
120 unsigned char CA = *(EA -
I - 1), CB = *(EB -
I - 1);
124 return A.Len >
B.Len;
135 for (TailEntry &
E : Vec)
137 if (Vec.
size() > 8) {
138 llvm::sort(Vec, [](
const TailEntry &
A,
const TailEntry &
B) {
139 return A.Key >
B.Key;
145 for (
size_t J = 1; J != Vec.
size(); ++J) {
146 if (Vec[J].
Key != Vec[
I].
Key) {
157 llvm::sort(Vec, [Pos](
const TailEntry &
A,
const TailEntry &
B) {
159 return A.Key >
B.Key;
166 finalizeStringTable(
true);
170 finalizeStringTable(
false);
173void StringTableBuilder::finalizeStringTable(
bool Optimize) {
176 if (
Optimize && StringIndexMap.size()) {
177 std::vector<StringPair *> Strings;
178 Strings.reserve(StringIndexMap.size());
180 Strings.push_back(&
P);
182 if (StringPriorityMap.size()) {
185 return StringPriorityMap.lookup(LHS->first) >
186 StringPriorityMap.lookup(RHS->first);
189 std::vector<TailEntry> Entries(Strings.size());
191 StringRef S =
P->first.val();
193 Entries[
Idx] = {0, S.
data(), uint32_t(S.
size()), uint32_t(Idx)};
196 size_t RangeBegin = 0;
198 if (StringPriorityMap.size()) {
199 uint8_t RangePriority = StringPriorityMap.lookup(Strings[0]->first);
200 for (
size_t I = 1,
E = Strings.size();
I !=
E && RangePriority; ++
I) {
201 uint8_t Priority = StringPriorityMap.lookup(Strings[
I]->first);
202 if (Priority != RangePriority) {
203 multikeySort(EntriesRef.slice(RangeBegin,
I - RangeBegin), 0);
204 RangePriority = Priority;
213 for (
const TailEntry &
E : Entries) {
215 StringRef S =
P->first.val();
217 size_t Pos = Size - S.
size() - (K !=
RAW);
224 Size =
alignTo(Size, Alignment);
243 StringIndexMap[CachedHashStringRef(
" ")] = 0;
250 StringIndexMap[CachedHashStringRef(
"")] = 0;
255 StringIndexMap.clear();
260 auto I = StringIndexMap.find(S);
261 assert(
I != StringIndexMap.end() &&
"String is not in table!");
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
This file defines CachedHashString and CachedHashStringRef.
This file defines the SmallString class.
static bool tailGreater(const TailEntry &A, const TailEntry &B, size_t Pos)
static void multikeySort(MutableArrayRef< TailEntry > Vec, size_t Pos)
static uint64_t tailKey(const char *Data, size_t Len, size_t Pos)
DenseMap< CachedHashStringRef, size_t >::value_type StringPair
size_t size() const
Get the array size.
A container which contains a StringRef plus a precomputed hash.
Represent a mutable reference to an array (0 or more elements consecutively in memory),...
MutableArrayRef< T > slice(size_t N, size_t M) const
Chop off the first N elements of the array, and keep M elements in the array.
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
Represent a constant reference to a string, i.e.
constexpr size_t size() const
Get the string size.
constexpr const char * data() const
Get a pointer to the start of the string (which may not be null terminated).
bool ends_with(StringRef Suffix) const
Check if this string ends with the given Suffix.
LLVM_ABI void finalizeInOrder()
Finalize the string table without reording it.
LLVM_ABI size_t getOffset(CachedHashStringRef S) const
Get the offest of a string in the string table.
LLVM_ABI ~StringTableBuilder()
LLVM_ABI void write(raw_ostream &OS) const
LLVM_ABI void finalize()
Analyze the strings and build the final table.
LLVM_ABI StringTableBuilder(Kind K, Align Alignment=Align(1))
This class implements an extremely fast bulk output stream that can only output to a stream.
uint64_t read64le(const void *P)
void write32le(void *P, uint32_t V)
void write32be(void *P, uint32_t V)
This is an optimization pass for GlobalISel generic memory operations.
auto enumerate(FirstRange &&First, RestRanges &&...Rest)
Given two or more input ranges, returns a new range whose values are tuples (A, B,...
bool isAligned(Align Lhs, uint64_t SizeInBytes)
Checks that SizeInBytes is a multiple of the alignment.
void sort(IteratorTy Start, IteratorTy End)
constexpr uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
LLVM_ATTRIBUTE_VISIBILITY_DEFAULT AnalysisKey InnerAnalysisManagerProxy< AnalysisManagerT, IRUnitT, ExtraArgTs... >::Key
MutableArrayRef(T &OneElt) -> MutableArrayRef< T >
This struct is a compact representation of a valid (non-zero power of two) alignment.