LLVM: lib/MC/StringTableBuilder.cpp Source File (original) (raw)

1

2

3

4

5

6

7

8

18#include

19#include

20#include

21#include

22#include

23#include

24

25using namespace llvm;

26

28

29void StringTableBuilder::initSize() {

30

31

32 switch (K) {

35 Size = 0;

36 break;

39 Size = 2;

40 break;

45

46 Size = 1;

47 break;

50

51 Size = 4;

52 break;

53 }

54}

55

57 : K(K), Alignment(Alignment) {

58 initSize();

59}

60

68

69using StringPair = std::pair<CachedHashStringRef, size_t>;

70

73 for (const StringPair &P : StringIndexMap) {

75 if (Data.empty())

76 memcpy(Buf + P.second, Data.data(), Data.size());

77 }

78

79

82 else if (K == XCOFF)

84}

85

86

89 if (Pos >= S.size())

90 return -1;

91 return (unsigned char)S[S.size() - Pos - 1];

92}

93

94

95

97tailcall:

98 if (Vec.size() <= 1)

99 return;

100

101

102

103

105 size_t I = 0;

106 size_t J = Vec.size();

107 for (size_t K = 1; K < J;) {

109 if (C > Pivot)

111 else if (C < Pivot)

113 else

114 K++;

115 }

116

119

120

121

122 if (Pivot != -1) {

123 Vec = Vec.slice(I, J - I);

124 ++Pos;

125 goto tailcall;

126 }

127}

128

131 finalizeStringTable(true);

132}

133

135 finalizeStringTable(false);

136}

137

138void StringTableBuilder::finalizeStringTable(bool Optimize) {

139 Finalized = true;

140

141 if (Optimize && StringIndexMap.size()) {

142 std::vector<StringPair *> Strings;

143 Strings.reserve(StringIndexMap.size());

145 Strings.push_back(&P);

146

147 size_t RangeBegin = 0;

149 if (StringPriorityMap.size()) {

152 return StringPriorityMap.lookup(LHS->first) >

153 StringPriorityMap.lookup(RHS->first);

154 });

155 uint8_t RangePriority = StringPriorityMap.lookup(Strings[0]->first);

156 for (size_t I = 1, E = Strings.size(); I != E && RangePriority; ++I) {

157 uint8_t Priority = StringPriorityMap.lookup(Strings[I]->first);

158 if (Priority != RangePriority) {

159 multikeySort(StringsRef.slice(RangeBegin, I - RangeBegin), 0);

160 RangePriority = Priority;

161 RangeBegin = I;

162 }

163 }

164 }

165 multikeySort(StringsRef.slice(RangeBegin), 0);

166 initSize();

167

168 StringRef Previous;

170 StringRef S = P->first.val();

172 size_t Pos = Size - S.size() - (K != RAW);

174 P->second = Pos;

175 continue;

176 }

177 }

178

179 Size = alignTo(Size, Alignment);

180 P->second = Size;

181

182 Size += S.size();

183 if (K != RAW)

184 ++Size;

185 Previous = S;

186 }

187 }

188

190 Size = alignTo(Size, 4);

192 Size = alignTo(Size, 8);

193

194

195

196

198 StringIndexMap[CachedHashStringRef(" ")] = 0;

199

200

201

202

203

204 if (K == ELF)

205 StringIndexMap[CachedHashStringRef("")] = 0;

206}

207

209 Finalized = false;

210 StringIndexMap.clear();

211}

212

215 auto I = StringIndexMap.find(S);

216 assert(I != StringIndexMap.end() && "String is not in table!");

217 return I->second;

218}

219

223

225 if (Priority)

226 StringPriorityMap[S] = std::max(Priority, StringPriorityMap[S]);

227

228 auto P = StringIndexMap.try_emplace(S);

229 if (P.second) {

230 size_t Start = alignTo(Size, Alignment);

231 P.first->second = Start;

232 Size = Start + S.size() + (K != RAW);

233 }

234 return P.first->second;

235}

assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")

static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")

This file defines CachedHashString and CachedHashStringRef.

This file defines the SmallString class.

static int charTailAt(StringPair *P, size_t Pos)

Definition StringTableBuilder.cpp:87

std::pair< CachedHashStringRef, size_t > StringPair

Definition StringTableBuilder.cpp:69

static void multikeySort(MutableArrayRef< StringPair * > Vec, int Pos)

Definition StringTableBuilder.cpp:96

size_t size() const

size - Get the array size.

A container which contains a StringRef plus a precomputed hash.

MutableArrayRef - Represent a mutable reference to an array (0 or more elements consecutively in memo...

MutableArrayRef< T > slice(size_t N, size_t M) const

slice(n, m) - 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...

StringRef - Represent a constant reference to a string, i.e.

constexpr size_t size() const

size - Get the string size.

bool ends_with(StringRef Suffix) const

Check if this string ends with the given Suffix.

LLVM_ABI void clear()

Definition StringTableBuilder.cpp:208

LLVM_ABI void finalizeInOrder()

Finalize the string table without reording it.

Definition StringTableBuilder.cpp:134

LLVM_ABI size_t getOffset(CachedHashStringRef S) const

Get the offest of a string in the string table.

Definition StringTableBuilder.cpp:213

LLVM_ABI ~StringTableBuilder()

LLVM_ABI size_t add(CachedHashStringRef S, uint8_t Priority=0)

Add a string to the builder.

Definition StringTableBuilder.cpp:220

LLVM_ABI void write(raw_ostream &OS) const

Definition StringTableBuilder.cpp:61

LLVM_ABI void finalize()

Analyze the strings and build the final table.

Definition StringTableBuilder.cpp:129

LLVM_ABI StringTableBuilder(Kind K, Align Alignment=Align(1))

Definition StringTableBuilder.cpp:56

This class implements an extremely fast bulk output stream that can only output to a stream.

@ C

The default llvm calling convention, compatible with C.

void write32le(void *P, uint32_t V)

void write32be(void *P, uint32_t V)

This is an optimization pass for GlobalISel generic memory operations.

bool isAligned(Align Lhs, uint64_t SizeInBytes)

Checks that SizeInBytes is a multiple of the alignment.

void sort(IteratorTy Start, IteratorTy End)

FunctionAddr VTableAddr uintptr_t uintptr_t Data

uint64_t alignTo(uint64_t Size, Align A)

Returns a multiple of A needed to store Size bytes.

void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)

Implement std::swap in terms of BitVector swap.

This struct is a compact representation of a valid (non-zero power of two) alignment.