Teach llvm-bcanalyzer to use one stream's BLOCKINFO to read another stream.

This allows streams that only use BLOCKINFO for debugging purposes to omit
the block entirely. As long as another stream is available with the correct
BLOCKINFO, the first stream can still be analyzed and dumped.

As part of this commit, BitstreamReader gets a move constructor and move
assignment operator, as well as a takeBlockInfo method.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@216826 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Jordan Rose
2014-08-30 17:07:55 +00:00
parent 3af13568fb
commit d421075d0c
7 changed files with 137 additions and 31 deletions

View File

@@ -58,15 +58,27 @@ public:
BitstreamReader() : IgnoreBlockInfoNames(true) {
}
BitstreamReader(const unsigned char *Start, const unsigned char *End) {
IgnoreBlockInfoNames = true;
BitstreamReader(const unsigned char *Start, const unsigned char *End)
: IgnoreBlockInfoNames(true) {
init(Start, End);
}
BitstreamReader(StreamableMemoryObject *bytes) {
BitstreamReader(StreamableMemoryObject *bytes) : IgnoreBlockInfoNames(true) {
BitcodeBytes.reset(bytes);
}
BitstreamReader(BitstreamReader &&Other) {
*this = std::move(Other);
}
BitstreamReader &operator=(BitstreamReader &&Other) {
BitcodeBytes = std::move(Other.BitcodeBytes);
// Explicitly swap block info, so that nothing gets destroyed twice.
std::swap(BlockInfoRecords, Other.BlockInfoRecords);
IgnoreBlockInfoNames = Other.IgnoreBlockInfoNames;
return *this;
}
void init(const unsigned char *Start, const unsigned char *End) {
assert(((End-Start) & 3) == 0 &&"Bitcode stream not a multiple of 4 bytes");
BitcodeBytes.reset(getNonStreamedMemoryObject(Start, End));
@@ -123,6 +135,15 @@ public:
BlockInfoRecords.back().BlockID = BlockID;
return BlockInfoRecords.back();
}
/// Takes block info from the other bitstream reader.
///
/// This is a "take" operation because BlockInfo records are non-trivial, and
/// indeed rather expensive.
void takeBlockInfo(BitstreamReader &&Other) {
assert(!hasBlockInfoRecords());
BlockInfoRecords = std::move(Other.BlockInfoRecords);
}
};