[llvm] r267318 - Add a version field in the bitcode for the summary

Mehdi Amini via llvm-commits llvm-commits at lists.llvm.org
Sat Apr 23 20:18:11 PDT 2016


Author: mehdi_amini
Date: Sat Apr 23 22:18:11 2016
New Revision: 267318

URL: http://llvm.org/viewvc/llvm-project?rev=267318&view=rev
Log:
Add a version field in the bitcode for the summary

Differential Revision: http://reviews.llvm.org/D19456

From: Mehdi Amini <mehdi.amini at apple.com>

Added:
    llvm/trunk/test/Bitcode/summary_version.ll
Modified:
    llvm/trunk/include/llvm/Bitcode/LLVMBitCodes.h
    llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp
    llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp
    llvm/trunk/test/Bitcode/thinlto-alias.ll
    llvm/trunk/test/Bitcode/thinlto-function-summary-callgraph-pgo.ll
    llvm/trunk/test/Bitcode/thinlto-function-summary-callgraph.ll
    llvm/trunk/test/Bitcode/thinlto-function-summary-originalnames.ll
    llvm/trunk/test/Bitcode/thinlto-function-summary.ll
    llvm/trunk/test/tools/llvm-lto/thinlto.ll
    llvm/trunk/tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp

Modified: llvm/trunk/include/llvm/Bitcode/LLVMBitCodes.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Bitcode/LLVMBitCodes.h?rev=267318&r1=267317&r2=267318&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Bitcode/LLVMBitCodes.h (original)
+++ llvm/trunk/include/llvm/Bitcode/LLVMBitCodes.h Sat Apr 23 22:18:11 2016
@@ -219,6 +219,8 @@ enum GlobalValueSummarySymtabCodes {
   FS_COMBINED_ALIAS = 8,
   // COMBINED_ORIGINAL_NAME: [original_name_hash]
   FS_COMBINED_ORIGINAL_NAME = 9,
+  // VERSION of the summary, bumped when adding flags for instance.
+  FS_VERSION = 10,
 };
 
 enum MetadataCodes {

Modified: llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp?rev=267318&r1=267317&r2=267318&view=diff
==============================================================================
--- llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp (original)
+++ llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp Sat Apr 23 22:18:11 2016
@@ -5995,8 +5995,21 @@ std::error_code ModuleSummaryIndexBitcod
 std::error_code ModuleSummaryIndexBitcodeReader::parseEntireSummary() {
   if (Stream.EnterSubBlock(bitc::GLOBALVAL_SUMMARY_BLOCK_ID))
     return error("Invalid record");
-
   SmallVector<uint64_t, 64> 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;

Modified: llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp?rev=267318&r1=267317&r2=267318&view=diff
==============================================================================
--- llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp (original)
+++ llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp Sat Apr 23 22:18:11 2016
@@ -3067,6 +3067,11 @@ void ModuleBitcodeWriter::writeModuleLev
   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::writePerModule
 
   Stream.EnterSubblock(bitc::GLOBALVAL_SUMMARY_BLOCK_ID, 3);
 
+  Stream.EmitRecord(bitc::FS_VERSION, ArrayRef<uint64_t>{INDEX_VERSION});
+
   // Abbrev for FS_PERMODULE.
   BitCodeAbbrev *Abbv = new BitCodeAbbrev();
   Abbv->Add(BitCodeAbbrevOp(bitc::FS_PERMODULE));
@@ -3162,6 +3169,7 @@ void ModuleBitcodeWriter::writePerModule
 /// 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<uint64_t>{INDEX_VERSION});
 
   // Abbrev for FS_COMBINED.
   BitCodeAbbrev *Abbv = new BitCodeAbbrev();

Added: llvm/trunk/test/Bitcode/summary_version.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Bitcode/summary_version.ll?rev=267318&view=auto
==============================================================================
--- llvm/trunk/test/Bitcode/summary_version.ll (added)
+++ llvm/trunk/test/Bitcode/summary_version.ll Sat Apr 23 22:18:11 2016
@@ -0,0 +1,12 @@
+; Check summary versioning
+; RUN: opt  -module-summary  %s -o - | llvm-bcanalyzer -dump | FileCheck %s
+
+; CHECK: <GLOBALVAL_SUMMARY_BLOCK
+; CHECK: <VERSION op0=1/>
+
+
+
+; Need a function for the summary to be populated.
+define void @foo() {
+    ret void
+}

Modified: llvm/trunk/test/Bitcode/thinlto-alias.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Bitcode/thinlto-alias.ll?rev=267318&r1=267317&r2=267318&view=diff
==============================================================================
--- llvm/trunk/test/Bitcode/thinlto-alias.ll (original)
+++ llvm/trunk/test/Bitcode/thinlto-alias.ll Sat Apr 23 22:18:11 2016
@@ -6,6 +6,7 @@
 ; RUN: llvm-bcanalyzer -dump %t3.thinlto.bc | FileCheck %s --check-prefix=COMBINED
 
 ; CHECK:       <GLOBALVAL_SUMMARY_BLOCK
+; CHECK-NEXT:    <VERSION
 ; See if the call to func is registered, using the expected callsite count
 ; and value id matching the subsequent value symbol table.
 ; CHECK-NEXT:    <PERMODULE {{.*}} op4=[[FUNCID:[0-9]+]] op5=1/>
@@ -17,6 +18,7 @@
 ; CHECK-NEXT:  </VALUE_SYMTAB>
 
 ; COMBINED:       <GLOBALVAL_SUMMARY_BLOCK
+; COMBINED-NEXT:    <VERSION
 ; See if the call to analias is registered, using the expected callsite count
 ; and value id matching the subsequent value symbol table.
 ; COMBINED-NEXT:    <COMBINED {{.*}} op4=[[ALIASID:[0-9]+]] op5=1/>

Modified: llvm/trunk/test/Bitcode/thinlto-function-summary-callgraph-pgo.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Bitcode/thinlto-function-summary-callgraph-pgo.ll?rev=267318&r1=267317&r2=267318&view=diff
==============================================================================
--- llvm/trunk/test/Bitcode/thinlto-function-summary-callgraph-pgo.ll (original)
+++ llvm/trunk/test/Bitcode/thinlto-function-summary-callgraph-pgo.ll Sat Apr 23 22:18:11 2016
@@ -6,6 +6,7 @@
 ; RUN: llvm-bcanalyzer -dump %t3.thinlto.bc | FileCheck %s --check-prefix=COMBINED
 
 ; CHECK:       <GLOBALVAL_SUMMARY_BLOCK
+; CHECK-NEXT:    <VERSION
 ; See if the call to func is registered, using the expected callsite count
 ; and profile count, with value id matching the subsequent value symbol table.
 ; CHECK-NEXT:    <PERMODULE_PROFILE {{.*}} op4=[[FUNCID:[0-9]+]] op5=1 op6=1/>
@@ -17,6 +18,7 @@
 ; CHECK-NEXT:  </VALUE_SYMTAB>
 
 ; COMBINED:       <GLOBALVAL_SUMMARY_BLOCK
+; COMBINED-NEXT:    <VERSION
 ; COMBINED-NEXT:    <COMBINED
 ; See if the call to func is registered, using the expected callsite count
 ; and profile count, with value id matching the subsequent value symbol table.

Modified: llvm/trunk/test/Bitcode/thinlto-function-summary-callgraph.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Bitcode/thinlto-function-summary-callgraph.ll?rev=267318&r1=267317&r2=267318&view=diff
==============================================================================
--- llvm/trunk/test/Bitcode/thinlto-function-summary-callgraph.ll (original)
+++ llvm/trunk/test/Bitcode/thinlto-function-summary-callgraph.ll Sat Apr 23 22:18:11 2016
@@ -6,6 +6,7 @@
 ; RUN: llvm-bcanalyzer -dump %t3.thinlto.bc | FileCheck %s --check-prefix=COMBINED
 
 ; CHECK:       <GLOBALVAL_SUMMARY_BLOCK
+; CHECK-NEXT:    <VERSION
 ; See if the call to func is registered, using the expected callsite count
 ; and value id matching the subsequent value symbol table.
 ; CHECK-NEXT:    <PERMODULE {{.*}} op4=[[FUNCID:[0-9]+]] op5=1/>
@@ -17,6 +18,7 @@
 ; CHECK-NEXT:  </VALUE_SYMTAB>
 
 ; COMBINED:       <GLOBALVAL_SUMMARY_BLOCK
+; COMBINED-NEXT:    <VERSION
 ; COMBINED-NEXT:    <COMBINED
 ; See if the call to func is registered, using the expected callsite count
 ; and value id matching the subsequent value symbol table.

Modified: llvm/trunk/test/Bitcode/thinlto-function-summary-originalnames.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Bitcode/thinlto-function-summary-originalnames.ll?rev=267318&r1=267317&r2=267318&view=diff
==============================================================================
--- llvm/trunk/test/Bitcode/thinlto-function-summary-originalnames.ll (original)
+++ llvm/trunk/test/Bitcode/thinlto-function-summary-originalnames.ll Sat Apr 23 22:18:11 2016
@@ -4,6 +4,7 @@
 ; RUN: llvm-bcanalyzer -dump %t.index.bc | FileCheck %s --check-prefix=COMBINED
 
 ; COMBINED:       <GLOBALVAL_SUMMARY_BLOCK
+; COMBINED-NEXT:    <VERSION
 ; COMBINED-DAG:    <COMBINED
 ; COMBINED-DAG:    <COMBINED_ORIGINAL_NAME op0=6699318081062747564/>
 ; COMBINED-DAG:    <COMBINED_GLOBALVAR_INIT_REFS

Modified: llvm/trunk/test/Bitcode/thinlto-function-summary.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Bitcode/thinlto-function-summary.ll?rev=267318&r1=267317&r2=267318&view=diff
==============================================================================
--- llvm/trunk/test/Bitcode/thinlto-function-summary.ll (original)
+++ llvm/trunk/test/Bitcode/thinlto-function-summary.ll Sat Apr 23 22:18:11 2016
@@ -5,6 +5,7 @@
 ; same in the ValueSumbolTable, to ensure the ordering is stable.
 ; Also check the linkage field on the summary entries.
 ; BC: <GLOBALVAL_SUMMARY_BLOCK
+; BC-NEXT: <VERSION
 ; BC-NEXT: <PERMODULE {{.*}} op0=1 op1=0
 ; BC-NEXT: <PERMODULE {{.*}} op0=2 op1=0
 ; BC-NEXT: <PERMODULE {{.*}} op0=3 op1=3

Modified: llvm/trunk/test/tools/llvm-lto/thinlto.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-lto/thinlto.ll?rev=267318&r1=267317&r2=267318&view=diff
==============================================================================
--- llvm/trunk/test/tools/llvm-lto/thinlto.ll (original)
+++ llvm/trunk/test/tools/llvm-lto/thinlto.ll Sat Apr 23 22:18:11 2016
@@ -10,6 +10,7 @@
 ; COMBINED-NEXT: <ENTRY {{.*}} record string = '{{.*}}thinlto.ll.tmp{{.*}}.o'
 ; COMBINED-NEXT: </MODULE_STRTAB_BLOCK
 ; COMBINED-NEXT: <GLOBALVAL_SUMMARY_BLOCK
+; COMBINED-NEXT: <VERSION
 ; COMBINED-NEXT: <COMBINED
 ; COMBINED-NEXT: <COMBINED
 ; COMBINED-NEXT: </GLOBALVAL_SUMMARY_BLOCK

Modified: llvm/trunk/tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp?rev=267318&r1=267317&r2=267318&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp (original)
+++ llvm/trunk/tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp Sat Apr 23 22:18:11 2016
@@ -309,6 +309,7 @@ static const char *GetCodeName(unsigned
       STRINGIFY_CODE(FS, ALIAS)
       STRINGIFY_CODE(FS, COMBINED_ALIAS)
       STRINGIFY_CODE(FS, COMBINED_ORIGINAL_NAME)
+      STRINGIFY_CODE(FS, VERSION)
     }
   case bitc::METADATA_ATTACHMENT_ID:
     switch(CodeID) {




More information about the llvm-commits mailing list