From 8fe6936e180d12afbbfeb83590baf526395cc272 Mon Sep 17 00:00:00 2001 From: Mehdi Amini Date: Sun, 24 Apr 2016 03:18:11 +0000 Subject: Add a version field in the bitcode for the summary Differential Revision: http://reviews.llvm.org/D19456 From: Mehdi Amini llvm-svn: 267318 --- llvm/lib/Bitcode/Reader/BitcodeReader.cpp | 15 ++++++++++++++- llvm/lib/Bitcode/Writer/BitcodeWriter.cpp | 8 ++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) (limited to 'llvm/lib/Bitcode') diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp index cbacf8127d4..8b583fe4995 100644 --- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp @@ -5995,8 +5995,21 @@ std::error_code ModuleSummaryIndexBitcodeReader::parseModule() { std::error_code ModuleSummaryIndexBitcodeReader::parseEntireSummary() { if (Stream.EnterSubBlock(bitc::GLOBALVAL_SUMMARY_BLOCK_ID)) return error("Invalid record"); - SmallVector Record; + + // Parse version + { + BitstreamEntry Entry = Stream.advanceSkippingSubblocks(); + if (Entry.Kind != BitstreamEntry::Record) + return error("Invalid Summary Block: record for version expected"); + if (Stream.readRecord(Entry.ID, Record) != bitc::FS_VERSION) + return error("Invalid Summary Block: version expected"); + } + const uint64_t Version = Record[0]; + if (Version != 1) + return error("Invalid summary version " + Twine(Version) + ", 1 expected"); + Record.clear(); + // Keep around the last seen summary to be used when we see an optional // "OriginalName" attachement. GlobalValueSummary *LastSeenSummary = nullptr; diff --git a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp index 302629b9176..d0f87e7d9d0 100644 --- a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp +++ b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp @@ -3067,6 +3067,11 @@ void ModuleBitcodeWriter::writeModuleLevelReferences( NameVals.clear(); } +// Current version for the summary. +// This is bumped whenever we introduce changes in the way some record are +// interpreted, like flags for instance. +static const uint64_t INDEX_VERSION = 1; + /// Emit the per-module summary section alongside the rest of /// the module's bitcode. void ModuleBitcodeWriter::writePerModuleGlobalValueSummary() { @@ -3078,6 +3083,8 @@ void ModuleBitcodeWriter::writePerModuleGlobalValueSummary() { Stream.EnterSubblock(bitc::GLOBALVAL_SUMMARY_BLOCK_ID, 3); + Stream.EmitRecord(bitc::FS_VERSION, ArrayRef{INDEX_VERSION}); + // Abbrev for FS_PERMODULE. BitCodeAbbrev *Abbv = new BitCodeAbbrev(); Abbv->Add(BitCodeAbbrevOp(bitc::FS_PERMODULE)); @@ -3162,6 +3169,7 @@ void ModuleBitcodeWriter::writePerModuleGlobalValueSummary() { /// Emit the combined summary section into the combined index file. void IndexBitcodeWriter::writeCombinedGlobalValueSummary() { Stream.EnterSubblock(bitc::GLOBALVAL_SUMMARY_BLOCK_ID, 3); + Stream.EmitRecord(bitc::FS_VERSION, ArrayRef{INDEX_VERSION}); // Abbrev for FS_COMBINED. BitCodeAbbrev *Abbv = new BitCodeAbbrev(); -- cgit v1.2.3