LLVM  16.0.0git
HashTable.cpp
Go to the documentation of this file.
1 //===- HashTable.cpp - PDB Hash Table -------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
13 #include "llvm/Support/Error.h"
15 #include <cstdint>
16 #include <utility>
17 
18 using namespace llvm;
19 using namespace llvm::pdb;
20 
22  SparseBitVector<> &V) {
23  uint32_t NumWords;
24  if (auto EC = Stream.readInteger(NumWords))
25  return joinErrors(
26  std::move(EC),
27  make_error<RawError>(raw_error_code::corrupt_file,
28  "Expected hash table number of words"));
29 
30  for (uint32_t I = 0; I != NumWords; ++I) {
31  uint32_t Word;
32  if (auto EC = Stream.readInteger(Word))
33  return joinErrors(std::move(EC),
34  make_error<RawError>(raw_error_code::corrupt_file,
35  "Expected hash table word"));
36  for (unsigned Idx = 0; Idx < 32; ++Idx)
37  if (Word & (1U << Idx))
38  V.set((I * 32) + Idx);
39  }
40  return Error::success();
41 }
42 
44  SparseBitVector<> &Vec) {
45  constexpr int BitsPerWord = 8 * sizeof(uint32_t);
46 
47  int ReqBits = Vec.find_last() + 1;
48  uint32_t ReqWords = alignTo(ReqBits, BitsPerWord) / BitsPerWord;
49  if (auto EC = Writer.writeInteger(ReqWords))
50  return joinErrors(
51  std::move(EC),
52  make_error<RawError>(raw_error_code::corrupt_file,
53  "Could not write linear map number of words"));
54 
55  uint32_t Idx = 0;
56  for (uint32_t I = 0; I != ReqWords; ++I) {
57  uint32_t Word = 0;
58  for (uint32_t WordIdx = 0; WordIdx < 32; ++WordIdx, ++Idx) {
59  if (Vec.test(Idx))
60  Word |= (1 << WordIdx);
61  }
62  if (auto EC = Writer.writeInteger(Word))
63  return joinErrors(std::move(EC), make_error<RawError>(
65  "Could not write linear map word"));
66  }
67  return Error::success();
68 }
llvm::alignTo
uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
Definition: Alignment.h:156
BinaryStreamReader.h
llvm::pdb::readSparseBitVector
Error readSparseBitVector(BinaryStreamReader &Stream, SparseBitVector<> &V)
Definition: HashTable.cpp:21
MathExtras.h
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
llvm::BinaryStreamWriter::writeInteger
Error writeInteger(T Value)
Write the integer Value to the underlying stream in the specified endianness.
Definition: BinaryStreamWriter.h:58
llvm::pdb::writeSparseBitVector
Error writeSparseBitVector(BinaryStreamWriter &Writer, SparseBitVector<> &Vec)
Definition: HashTable.cpp:43
llvm::BinaryStreamWriter
Provides write only access to a subclass of WritableBinaryStream.
Definition: BinaryStreamWriter.h:30
llvm::Error::success
static ErrorSuccess success()
Create a success value.
Definition: Error.h:329
Error.h
HashTable.h
RawError.h
llvm::SparseBitVector
Definition: SparseBitVector.h:256
llvm::pdb::raw_error_code::corrupt_file
@ corrupt_file
llvm::BinaryStreamReader::readInteger
Error readInteger(T &Dest)
Read an integer of the specified endianness into Dest and update the stream's offset.
Definition: BinaryStreamReader.h:68
llvm::pdb
Definition: ConcreteSymbolEnumerator.h:20
llvm::BinaryStreamReader
Provides read only access to a subclass of BinaryStream.
Definition: BinaryStreamReader.h:29
llvm::SparseBitVector::set
void set(unsigned Idx)
Definition: SparseBitVector.h:508
move
compiles ldr LCPI1_0 ldr ldr mov lsr tst moveq r1 ldr LCPI1_1 and r0 bx lr It would be better to do something like to fold the shift into the conditional move
Definition: README.txt:546
llvm::SparseBitVector::test
bool test(unsigned Idx) const
Definition: SparseBitVector.h:472
I
#define I(x, y, z)
Definition: MD5.cpp:58
llvm::joinErrors
Error joinErrors(Error E1, Error E2)
Concatenate errors.
Definition: Error.h:426
llvm::irsymtab::storage::Word
support::ulittle32_t Word
Definition: IRSymtab.h:52
uint32_t
llvm::Error
Lightweight error class with error context and mandatory checking.
Definition: Error.h:155
BinaryStreamWriter.h
llvm::SparseBitVector::find_last
int find_last() const
Definition: SparseBitVector.h:788