mirror of
https://github.com/RPCSX/llvm.git
synced 2026-01-31 01:05:23 +01:00
PDBs can be extremely large. We're already mapping the entire PDB into the process's address space, but to make matters worse the blocks of the PDB are not arranged contiguously. So, when we have something like an array or a string embedded into the stream, we have to make a copy. Since it's convenient to use traditional data structures to iterate and manipulate these records, we need the memory to be contiguous. As a result of this, we were using roughly twice as much memory as the file size of the PDB, because every stream was copied out and re-stitched together contiguously. This patch addresses this by improving the MappedBlockStream to allocate from a BumpPtrAllocator only when a read requires a discontiguous read. Furthermore, it introduces some data structures backed by a stream which can iterate over both fixed and variable length records of a PDB. Since everything is backed by a stream and not a buffer, we can read almost everything from the PDB with zero copies. Differential Revision: http://reviews.llvm.org/D20654 Reviewed By: ruiu git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@270951 91177308-0d34-0410-b5e6-96231b3b80d8
82 lines
2.3 KiB
C++
82 lines
2.3 KiB
C++
//===- StreamRef.h - A copyable reference to a stream -----------*- C++ -*-===//
|
|
//
|
|
// The LLVM Compiler Infrastructure
|
|
//
|
|
// This file is distributed under the University of Illinois Open Source
|
|
// License. See LICENSE.TXT for details.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#ifndef LLVM_DEBUGINFO_CODEVIEW_STREAMREF_H
|
|
#define LLVM_DEBUGINFO_CODEVIEW_STREAMREF_H
|
|
|
|
#include "llvm/DebugInfo/CodeView/StreamInterface.h"
|
|
|
|
namespace llvm {
|
|
namespace codeview {
|
|
|
|
class StreamRef : public StreamInterface {
|
|
public:
|
|
StreamRef() : Stream(nullptr), ViewOffset(0), Length(0) {}
|
|
StreamRef(const StreamInterface &Stream)
|
|
: Stream(&Stream), ViewOffset(0), Length(Stream.getLength()) {}
|
|
StreamRef(const StreamInterface &Stream, uint32_t Offset, uint32_t Length)
|
|
: Stream(&Stream), ViewOffset(Offset), Length(Length) {}
|
|
StreamRef(const StreamRef &Other)
|
|
: Stream(Other.Stream), ViewOffset(Other.ViewOffset),
|
|
Length(Other.Length) {}
|
|
|
|
Error readBytes(uint32_t Offset,
|
|
MutableArrayRef<uint8_t> Buffer) const override {
|
|
return Stream->readBytes(ViewOffset + Offset, Buffer);
|
|
}
|
|
|
|
Error readBytes(uint32_t Offset, uint32_t Size,
|
|
ArrayRef<uint8_t> &Buffer) const override {
|
|
return Stream->readBytes(ViewOffset + Offset, Size, Buffer);
|
|
}
|
|
|
|
uint32_t getLength() const override { return Length; }
|
|
StreamRef drop_front(uint32_t N) const {
|
|
if (!Stream)
|
|
return StreamRef();
|
|
|
|
N = std::min(N, Length);
|
|
return StreamRef(*Stream, ViewOffset + N, Length - N);
|
|
}
|
|
|
|
StreamRef keep_front(uint32_t N) const {
|
|
if (!Stream)
|
|
return StreamRef();
|
|
N = std::min(N, Length);
|
|
return StreamRef(*Stream, ViewOffset, N);
|
|
}
|
|
|
|
bool operator==(const StreamRef &Other) const {
|
|
if (Stream != Other.Stream)
|
|
return false;
|
|
if (ViewOffset != Other.ViewOffset)
|
|
return false;
|
|
if (Length != Other.Length)
|
|
return false;
|
|
return true;
|
|
}
|
|
|
|
bool operator!=(const StreamRef &Other) const { return !(*this == Other); }
|
|
|
|
StreamRef &operator=(const StreamRef &Other) {
|
|
Stream = Other.Stream;
|
|
ViewOffset = Other.ViewOffset;
|
|
Length = Other.Length;
|
|
return *this;
|
|
}
|
|
|
|
private:
|
|
const StreamInterface *Stream;
|
|
uint32_t ViewOffset;
|
|
uint32_t Length;
|
|
};
|
|
}
|
|
}
|
|
|
|
#endif // LLVM_DEBUGINFO_CODEVIEW_STREAMREF_H
|