diff options
Diffstat (limited to 'llvm/lib/DebugInfo/MSF/MappedBlockStream.cpp')
| -rw-r--r-- | llvm/lib/DebugInfo/MSF/MappedBlockStream.cpp | 90 |
1 files changed, 45 insertions, 45 deletions
diff --git a/llvm/lib/DebugInfo/MSF/MappedBlockStream.cpp b/llvm/lib/DebugInfo/MSF/MappedBlockStream.cpp index 5dc9c86b34fd..00fc70ca5a54 100644 --- a/llvm/lib/DebugInfo/MSF/MappedBlockStream.cpp +++ b/llvm/lib/DebugInfo/MSF/MappedBlockStream.cpp @@ -35,7 +35,7 @@ public: } // end anonymous namespace -using Interval = std::pair<uint32_t, uint32_t>; +using Interval = std::pair<uint64_t, uint64_t>; static Interval intersect(const Interval &I1, const Interval &I2) { return std::make_pair(std::max(I1.first, I2.first), @@ -85,7 +85,7 @@ MappedBlockStream::createFpmStream(const MSFLayout &Layout, return createStream(Layout.SB->BlockSize, SL, MsfData, Allocator); } -Error MappedBlockStream::readBytes(uint32_t Offset, uint32_t Size, +Error MappedBlockStream::readBytes(uint64_t Offset, uint64_t Size, ArrayRef<uint8_t> &Buffer) { // Make sure we aren't trying to read beyond the end of the stream. if (auto EC = checkOffsetForRead(Offset, Size)) @@ -138,7 +138,7 @@ Error MappedBlockStream::readBytes(uint32_t Offset, uint32_t Size, if (Intersection != RequestExtent) continue; - uint32_t CacheRangeOffset = + uint64_t CacheRangeOffset = AbsoluteDifference(CachedExtent.first, Intersection.first); Buffer = CachedAlloc.slice(CacheRangeOffset, Size); return Error::success(); @@ -163,14 +163,14 @@ Error MappedBlockStream::readBytes(uint32_t Offset, uint32_t Size, return Error::success(); } -Error MappedBlockStream::readLongestContiguousChunk(uint32_t Offset, +Error MappedBlockStream::readLongestContiguousChunk(uint64_t Offset, ArrayRef<uint8_t> &Buffer) { // Make sure we aren't trying to read beyond the end of the stream. if (auto EC = checkOffsetForRead(Offset, 1)) return EC; - uint32_t First = Offset / BlockSize; - uint32_t Last = First; + uint64_t First = Offset / BlockSize; + uint64_t Last = First; while (Last < getNumBlocks() - 1) { if (StreamLayout.Blocks[Last] != StreamLayout.Blocks[Last + 1] - 1) @@ -178,13 +178,13 @@ Error MappedBlockStream::readLongestContiguousChunk(uint32_t Offset, ++Last; } - uint32_t OffsetInFirstBlock = Offset % BlockSize; - uint32_t BytesFromFirstBlock = BlockSize - OffsetInFirstBlock; - uint32_t BlockSpan = Last - First + 1; - uint32_t ByteSpan = BytesFromFirstBlock + (BlockSpan - 1) * BlockSize; + uint64_t OffsetInFirstBlock = Offset % BlockSize; + uint64_t BytesFromFirstBlock = BlockSize - OffsetInFirstBlock; + uint64_t BlockSpan = Last - First + 1; + uint64_t ByteSpan = BytesFromFirstBlock + (BlockSpan - 1) * BlockSize; ArrayRef<uint8_t> BlockData; - uint32_t MsfOffset = blockToOffset(StreamLayout.Blocks[First], BlockSize); + uint64_t MsfOffset = blockToOffset(StreamLayout.Blocks[First], BlockSize); if (auto EC = MsfData.readBytes(MsfOffset, BlockSize, BlockData)) return EC; @@ -193,9 +193,9 @@ Error MappedBlockStream::readLongestContiguousChunk(uint32_t Offset, return Error::success(); } -uint32_t MappedBlockStream::getLength() { return StreamLayout.Length; } +uint64_t MappedBlockStream::getLength() { return StreamLayout.Length; } -bool MappedBlockStream::tryReadContiguously(uint32_t Offset, uint32_t Size, +bool MappedBlockStream::tryReadContiguously(uint64_t Offset, uint64_t Size, ArrayRef<uint8_t> &Buffer) { if (Size == 0) { Buffer = ArrayRef<uint8_t>(); @@ -206,15 +206,15 @@ bool MappedBlockStream::tryReadContiguously(uint32_t Offset, uint32_t Size, // all subsequent blocks are contiguous. For example, a 10k read with a 4k // block size can be filled with a reference if, from the starting offset, // 3 blocks in a row are contiguous. - uint32_t BlockNum = Offset / BlockSize; - uint32_t OffsetInBlock = Offset % BlockSize; - uint32_t BytesFromFirstBlock = std::min(Size, BlockSize - OffsetInBlock); - uint32_t NumAdditionalBlocks = + uint64_t BlockNum = Offset / BlockSize; + uint64_t OffsetInBlock = Offset % BlockSize; + uint64_t BytesFromFirstBlock = std::min(Size, BlockSize - OffsetInBlock); + uint64_t NumAdditionalBlocks = alignTo(Size - BytesFromFirstBlock, BlockSize) / BlockSize; - uint32_t RequiredContiguousBlocks = NumAdditionalBlocks + 1; - uint32_t E = StreamLayout.Blocks[BlockNum]; - for (uint32_t I = 0; I < RequiredContiguousBlocks; ++I, ++E) { + uint64_t RequiredContiguousBlocks = NumAdditionalBlocks + 1; + uint64_t E = StreamLayout.Blocks[BlockNum]; + for (uint64_t I = 0; I < RequiredContiguousBlocks; ++I, ++E) { if (StreamLayout.Blocks[I + BlockNum] != E) return false; } @@ -225,8 +225,8 @@ bool MappedBlockStream::tryReadContiguously(uint32_t Offset, uint32_t Size, // cross-block span, explicitly resize the ArrayRef to cover the entire // request length. ArrayRef<uint8_t> BlockData; - uint32_t FirstBlockAddr = StreamLayout.Blocks[BlockNum]; - uint32_t MsfOffset = blockToOffset(FirstBlockAddr, BlockSize); + uint64_t FirstBlockAddr = StreamLayout.Blocks[BlockNum]; + uint64_t MsfOffset = blockToOffset(FirstBlockAddr, BlockSize); if (auto EC = MsfData.readBytes(MsfOffset, BlockSize, BlockData)) { consumeError(std::move(EC)); return false; @@ -236,28 +236,28 @@ bool MappedBlockStream::tryReadContiguously(uint32_t Offset, uint32_t Size, return true; } -Error MappedBlockStream::readBytes(uint32_t Offset, +Error MappedBlockStream::readBytes(uint64_t Offset, MutableArrayRef<uint8_t> Buffer) { - uint32_t BlockNum = Offset / BlockSize; - uint32_t OffsetInBlock = Offset % BlockSize; + uint64_t BlockNum = Offset / BlockSize; + uint64_t OffsetInBlock = Offset % BlockSize; // Make sure we aren't trying to read beyond the end of the stream. if (auto EC = checkOffsetForRead(Offset, Buffer.size())) return EC; - uint32_t BytesLeft = Buffer.size(); - uint32_t BytesWritten = 0; + uint64_t BytesLeft = Buffer.size(); + uint64_t BytesWritten = 0; uint8_t *WriteBuffer = Buffer.data(); while (BytesLeft > 0) { - uint32_t StreamBlockAddr = StreamLayout.Blocks[BlockNum]; + uint64_t StreamBlockAddr = StreamLayout.Blocks[BlockNum]; ArrayRef<uint8_t> BlockData; - uint32_t Offset = blockToOffset(StreamBlockAddr, BlockSize); + uint64_t Offset = blockToOffset(StreamBlockAddr, BlockSize); if (auto EC = MsfData.readBytes(Offset, BlockSize, BlockData)) return EC; const uint8_t *ChunkStart = BlockData.data() + OffsetInBlock; - uint32_t BytesInChunk = std::min(BytesLeft, BlockSize - OffsetInBlock); + uint64_t BytesInChunk = std::min(BytesLeft, BlockSize - OffsetInBlock); ::memcpy(WriteBuffer + BytesWritten, ChunkStart, BytesInChunk); BytesWritten += BytesInChunk; @@ -271,7 +271,7 @@ Error MappedBlockStream::readBytes(uint32_t Offset, void MappedBlockStream::invalidateCache() { CacheMap.shrink_and_clear(); } -void MappedBlockStream::fixCacheAfterWrite(uint32_t Offset, +void MappedBlockStream::fixCacheAfterWrite(uint64_t Offset, ArrayRef<uint8_t> Data) const { // If this write overlapped a read which previously came from the pool, // someone may still be holding a pointer to that alloc which is now invalid. @@ -297,10 +297,10 @@ void MappedBlockStream::fixCacheAfterWrite(uint32_t Offset, auto Intersection = intersect(WriteInterval, CachedInterval); assert(Intersection.first <= Intersection.second); - uint32_t Length = Intersection.second - Intersection.first; - uint32_t SrcOffset = + uint64_t Length = Intersection.second - Intersection.first; + uint64_t SrcOffset = AbsoluteDifference(WriteInterval.first, Intersection.first); - uint32_t DestOffset = + uint64_t DestOffset = AbsoluteDifference(CachedInterval.first, Intersection.first); ::memcpy(Alloc.data() + DestOffset, Data.data() + SrcOffset, Length); } @@ -370,39 +370,39 @@ WritableMappedBlockStream::createFpmStream(const MSFLayout &Layout, return createStream(Layout.SB->BlockSize, MinLayout, MsfData, Allocator); } -Error WritableMappedBlockStream::readBytes(uint32_t Offset, uint32_t Size, +Error WritableMappedBlockStream::readBytes(uint64_t Offset, uint64_t Size, ArrayRef<uint8_t> &Buffer) { return ReadInterface.readBytes(Offset, Size, Buffer); } Error WritableMappedBlockStream::readLongestContiguousChunk( - uint32_t Offset, ArrayRef<uint8_t> &Buffer) { + uint64_t Offset, ArrayRef<uint8_t> &Buffer) { return ReadInterface.readLongestContiguousChunk(Offset, Buffer); } -uint32_t WritableMappedBlockStream::getLength() { +uint64_t WritableMappedBlockStream::getLength() { return ReadInterface.getLength(); } -Error WritableMappedBlockStream::writeBytes(uint32_t Offset, +Error WritableMappedBlockStream::writeBytes(uint64_t Offset, ArrayRef<uint8_t> Buffer) { // Make sure we aren't trying to write beyond the end of the stream. if (auto EC = checkOffsetForWrite(Offset, Buffer.size())) return EC; - uint32_t BlockNum = Offset / getBlockSize(); - uint32_t OffsetInBlock = Offset % getBlockSize(); + uint64_t BlockNum = Offset / getBlockSize(); + uint64_t OffsetInBlock = Offset % getBlockSize(); - uint32_t BytesLeft = Buffer.size(); - uint32_t BytesWritten = 0; + uint64_t BytesLeft = Buffer.size(); + uint64_t BytesWritten = 0; while (BytesLeft > 0) { - uint32_t StreamBlockAddr = getStreamLayout().Blocks[BlockNum]; - uint32_t BytesToWriteInChunk = + uint64_t StreamBlockAddr = getStreamLayout().Blocks[BlockNum]; + uint64_t BytesToWriteInChunk = std::min(BytesLeft, getBlockSize() - OffsetInBlock); const uint8_t *Chunk = Buffer.data() + BytesWritten; ArrayRef<uint8_t> ChunkData(Chunk, BytesToWriteInChunk); - uint32_t MsfOffset = blockToOffset(StreamBlockAddr, getBlockSize()); + uint64_t MsfOffset = blockToOffset(StreamBlockAddr, getBlockSize()); MsfOffset += OffsetInBlock; if (auto EC = WriteInterface.writeBytes(MsfOffset, ChunkData)) return EC; |
