LLVM 17.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
18using namespace llvm;
19using namespace llvm::pdb;
20
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>(
64 raw_error_code::corrupt_file,
65 "Could not write linear map word"));
66 }
67 return Error::success();
68}
Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx
#define I(x, y, z)
Definition: MD5.cpp:58
Provides read only access to a subclass of BinaryStream.
Error readInteger(T &Dest)
Read an integer of the specified endianness into Dest and update the stream's offset.
Provides write only access to a subclass of WritableBinaryStream.
Error writeInteger(T Value)
Write the integer Value to the underlying stream in the specified endianness.
Lightweight error class with error context and mandatory checking.
Definition: Error.h:156
static ErrorSuccess success()
Create a success value.
Definition: Error.h:330
void set(unsigned Idx)
bool test(unsigned Idx) const
Error readSparseBitVector(BinaryStreamReader &Stream, SparseBitVector<> &V)
Definition: HashTable.cpp:21
Error writeSparseBitVector(BinaryStreamWriter &Writer, SparseBitVector<> &Vec)
Definition: HashTable.cpp:43
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
Error joinErrors(Error E1, Error E2)
Concatenate errors.
Definition: Error.h:427
uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
Definition: Alignment.h:155