9#ifndef LLVM_SUPPORT_BINARYITEMSTREAM_H
10#define LLVM_SUPPORT_BINARYITEMSTREAM_H
22 static size_t length(
const T &Item) =
delete;
33template <
typename T,
typename Traits = BinaryItemTraits<T>>
42 auto ExpectedIndex = translateOffsetIndex(
Offset);
44 return ExpectedIndex.takeError();
45 const auto &Item = Items[*ExpectedIndex];
48 if (
Size > Traits::length(Item))
56 auto ExpectedIndex = translateOffsetIndex(
Offset);
58 return ExpectedIndex.takeError();
59 Buffer = Traits::bytes(Items[*ExpectedIndex]);
69 return ItemEndOffsets.empty() ? 0 : ItemEndOffsets.back();
73 void computeItemOffsets() {
74 ItemEndOffsets.clear();
75 ItemEndOffsets.reserve(Items.size());
77 for (
const auto &Item : Items) {
79 assert(Len > 0 &&
"no empty items");
81 ItemEndOffsets.push_back(CurrentOffset);
91 size_t Idx = std::distance(ItemEndOffsets.begin(), Iter);
92 assert(
Idx < Items.size() &&
"binary search for offset failed");
100 std::vector<uint64_t> ItemEndOffsets;
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
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
ArrayRef< T > take_front(size_t N=1) const
Return a copy of *this with only the first N elements.
BinaryItemStream represents a sequence of objects stored in some kind of external container but for w...
llvm::endianness getEndian() const override
Error readLongestContiguousChunk(uint64_t Offset, ArrayRef< uint8_t > &Buffer) override
Given an offset into the stream, read as much as possible without copying any data.
Error readBytes(uint64_t Offset, uint64_t Size, ArrayRef< uint8_t > &Buffer) override
Given an offset into the stream and a number of bytes, attempt to read the bytes and set the output A...
BinaryItemStream(llvm::endianness Endian)
uint64_t getLength() override
Return the number of bytes of data in this stream.
void setItems(ArrayRef< T > ItemArray)
An interface for accessing data in a stream-like format, but which discourages copying.
Error checkOffsetForRead(uint64_t Offset, uint64_t DataSize)
Lightweight error class with error context and mandatory checking.
static ErrorSuccess success()
Create a success value.
This is an optimization pass for GlobalISel generic memory operations.
auto lower_bound(R &&Range, T &&Value)
Provide wrappers to std::lower_bound which take ranges instead of having to pass begin/end explicitly...
static ArrayRef< uint8_t > bytes(const T &Item)=delete
static size_t length(const T &Item)=delete