llvm.org GIT mirror llvm / 509156a
Read 64 bits at a time in the bitcode reader. The reading of 64 bit values could still be optimized, but at least this cuts down on the number of virtual calls to fetch more data. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@221865 91177308-0d34-0410-b5e6-96231b3b80d8 Rafael Espindola 5 years ago
3 changed file(s) with 17 addition(s) and 20 deletion(s). Raw diff Collapse all Expand all
176176 /// follow the word size of the host machine for efficiency. We use word_t in
177177 /// places that are aware of this to make it perfectly explicit what is going
178178 /// on.
179 typedef uint32_t word_t;
179 typedef size_t word_t;
180180 word_t CurWord;
181181
182182 /// This is the number of bits in CurWord that are valid. This is always from
183 /// [0...31/63] inclusive (depending on word size).
183 /// [0...bits_of(size_t)-1] inclusive.
184184 unsigned BitsInCurWord;
185185
186186 // This is the declared size of code values used for the current block, in
332332 Size = NextChar;
333333 return;
334334 }
335 assert(BytesRead == sizeof(Array));
336335
337336 // Handle big-endian byte-swapping if necessary.
338337 support::detail::packed_endian_specific_integral<
340339 memcpy(&EndianValue, Array, sizeof(Array));
341340
342341 CurWord = EndianValue;
343 NextChar += sizeof(word_t);
344 BitsInCurWord = sizeof(word_t) * 8;
342 NextChar += BytesRead;
343 BitsInCurWord = BytesRead * 8;
345344 }
346345
347346 uint32_t Read(unsigned NumBits) {
348347 assert(NumBits && NumBits <= 32 &&
349348 "Cannot return zero or more than 32 bits!");
350349
350 static const unsigned Mask = sizeof(word_t) > 4 ? 0x3f : 0x1f;
351
351352 // If the field is fully contained by CurWord, return it quickly.
352353 if (BitsInCurWord >= NumBits) {
353354 uint32_t R = uint32_t(CurWord) & (~0U >> (32-NumBits));
354355
355356 // Use a mask to avoid undefined behavior.
356 CurWord >>= (NumBits & 0x1f);
357 CurWord >>= (NumBits & Mask);
357358
358359 BitsInCurWord -= NumBits;
359360 return R;
368369 if (BitsLeft > BitsInCurWord)
369370 return 0;
370371
371 uint32_t R2 = uint32_t(CurWord) & (~0U >> (sizeof(word_t) * 8 - BitsLeft));
372 uint32_t R2 =
373 uint32_t(CurWord) & (~word_t(0) >> (sizeof(word_t) * 8 - BitsLeft));
372374
373375 // Use a mask to avoid undefined behavior.
374 CurWord >>= (BitsLeft & 0x1f);
376 CurWord >>= (BitsLeft & Mask);
375377
376378 BitsInCurWord -= BitsLeft;
377379
7070 size_t bytes = Streamer->GetBytes(&Bytes[BytesRead + BytesSkipped],
7171 kChunkSize);
7272 BytesRead += bytes;
73 if (bytes < kChunkSize) {
74 assert((!ObjectSize || BytesRead >= Pos) &&
75 "Unexpected short read fetching bitcode");
76 if (BytesRead <= Pos) { // reached EOF/ran out of bytes
77 ObjectSize = BytesRead;
78 EOFReached = true;
79 return false;
80 }
73 if (BytesRead <= Pos) { // reached EOF/ran out of bytes
74 ObjectSize = BytesRead;
75 EOFReached = true;
76 return false;
8177 }
8278 }
8379 return true;
8989 uint64_t StreamingMemoryObject::readBytes(uint8_t *Buf, uint64_t Size,
9090 uint64_t Address) const {
9191 fetchToPos(Address + Size - 1);
92 uint64_t BufferSize = Bytes.size() - BytesSkipped;
93 if (Address >= BufferSize)
92 if (Address >= BytesRead)
9493 return 0;
9594
9695 uint64_t End = Address + Size;
97 if (End > BufferSize)
98 End = BufferSize;
96 if (End > BytesRead)
97 End = BytesRead;
9998 Size = End - Address;
10099 assert(Size >= 0);
101100 memcpy(Buf, &Bytes[Address + BytesSkipped], Size);