[llvm] r267712 - [ThinLTO] Use valueid instead of bitcode offsets in combined index file

Teresa Johnson via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 27 06:28:40 PDT 2016


Author: tejohnson
Date: Wed Apr 27 08:28:35 2016
New Revision: 267712

URL: http://llvm.org/viewvc/llvm-project?rev=267712&view=rev
Log:
[ThinLTO] Use valueid instead of bitcode offsets in combined index file

Summary:
With the removal of support for lazy parsing of combined index summary
records (e.g. r267344), we no longer need to include the summary record
bitcode offset in the VST entries for definitions. Change the combined
index format to be similar to the per-module index format in using value
ids to cross-reference from the summary record to the VST entry (rather
than the summary record bitcode offset to cross-reference in the other
direction).

The visible changes are:
1) Add the value id to the combined summary records
2) Remove the summary offset from the combined VST records, which has
the following effects:
- No longer need the VST_CODE_COMBINED_GVDEFENTRY record, as all
  combined index VST entries now only contain the value id and
  corresponding GUID.
- No longer have duplicate VST entries in the case where there are
  multiple definitions of a symbol (e.g. weak/linkonce), as they all
  have the same value id and GUID.

An implication of #2 above is that in order to hook up an alias to the
correct aliasee based on the value id of the aliasee recorded in the
combined index alias record, we need to scan the entries in the index
for that GUID to find the one from the same module (i.e. the case where
there are multiple entries for the aliasee). But the reader no longer
has to maintain a special map to hook up the alias/aliasee.

Reviewers: joker.eph

Subscribers: joker.eph, llvm-commits

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

Modified:
    llvm/trunk/include/llvm/Bitcode/LLVMBitCodes.h
    llvm/trunk/include/llvm/IR/ModuleSummaryIndex.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-summary-linkage-types.ll
    llvm/trunk/test/Bitcode/thinlto-summary-section.ll
    llvm/trunk/test/tools/gold/X86/thinlto.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=267712&r1=267711&r2=267712&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Bitcode/LLVMBitCodes.h (original)
+++ llvm/trunk/include/llvm/Bitcode/LLVMBitCodes.h Wed Apr 27 08:28:35 2016
@@ -180,8 +180,6 @@ enum ValueSymtabCodes {
   VST_CODE_ENTRY = 1,   // VST_ENTRY: [valueid, namechar x N]
   VST_CODE_BBENTRY = 2, // VST_BBENTRY: [bbid, namechar x N]
   VST_CODE_FNENTRY = 3, // VST_FNENTRY: [valueid, offset, namechar x N]
-  // VST_COMBINED_GVDEFENTRY: [valueid, sumoffset, guid]
-  VST_CODE_COMBINED_GVDEFENTRY = 4,
   // VST_COMBINED_ENTRY: [valueid, refguid]
   VST_CODE_COMBINED_ENTRY = 5
 };
@@ -204,18 +202,18 @@ enum GlobalValueSummarySymtabCodes {
   FS_PERMODULE_PROFILE = 2,
   // PERMODULE_GLOBALVAR_INIT_REFS: [valueid, flags, n x valueid]
   FS_PERMODULE_GLOBALVAR_INIT_REFS = 3,
-  // COMBINED: [modid, flags, instcount, numrefs, numrefs x valueid,
+  // COMBINED: [valueid, modid, flags, instcount, numrefs, numrefs x valueid,
   //            n x (valueid, callsitecount)]
   FS_COMBINED = 4,
-  // COMBINED_PROFILE: [modid, flags, instcount, numrefs,
+  // COMBINED_PROFILE: [valueid, modid, flags, instcount, numrefs,
   //                    numrefs x valueid,
   //                    n x (valueid, callsitecount, profilecount)]
   FS_COMBINED_PROFILE = 5,
-  // COMBINED_GLOBALVAR_INIT_REFS: [modid, flags, n x valueid]
+  // COMBINED_GLOBALVAR_INIT_REFS: [valueid, modid, flags, n x valueid]
   FS_COMBINED_GLOBALVAR_INIT_REFS = 6,
   // ALIAS: [valueid, flags, valueid]
   FS_ALIAS = 7,
-  // COMBINED_ALIAS: [modid, flags, offset]
+  // COMBINED_ALIAS: [valueid, modid, flags, valueid]
   FS_COMBINED_ALIAS = 8,
   // COMBINED_ORIGINAL_NAME: [original_name_hash]
   FS_COMBINED_ORIGINAL_NAME = 9,

Modified: llvm/trunk/include/llvm/IR/ModuleSummaryIndex.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/ModuleSummaryIndex.h?rev=267712&r1=267711&r2=267712&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/ModuleSummaryIndex.h (original)
+++ llvm/trunk/include/llvm/IR/ModuleSummaryIndex.h Wed Apr 27 08:28:35 2016
@@ -375,6 +375,24 @@ public:
     GlobalValueMap[ValueGUID].push_back(std::move(Summary));
   }
 
+  /// Find the summary for global \p GUID in module \p ModuleId, or nullptr if
+  /// not found.
+  GlobalValueSummary *findSummaryInModule(GlobalValue::GUID ValueGUID,
+                                          StringRef ModuleId) const {
+    auto CalleeInfoList = findGlobalValueSummaryList(ValueGUID);
+    if (CalleeInfoList == end()) {
+      return nullptr; // This function does not have a summary
+    }
+    auto Summary =
+        llvm::find_if(CalleeInfoList->second,
+                      [&](const std::unique_ptr<GlobalValueSummary> &Summary) {
+                        return Summary->modulePath() == ModuleId;
+                      });
+    if (Summary == CalleeInfoList->second.end())
+      return nullptr;
+    return Summary->get();
+  }
+
   /// Returns the first GlobalValueSummary for \p GV, asserting that there
   /// is only one if \p PerModuleIndex.
   GlobalValueSummary *getGlobalValueSummary(const GlobalValue &GV,

Modified: llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp?rev=267712&r1=267711&r2=267712&view=diff
==============================================================================
--- llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp (original)
+++ llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp Wed Apr 27 08:28:35 2016
@@ -492,11 +492,6 @@ class ModuleSummaryIndexBitcodeReader {
   DenseMap<unsigned, std::pair<GlobalValue::GUID, GlobalValue::GUID>>
       ValueIdToCallGraphGUIDMap;
 
-  /// Map to save the association between summary offset in the VST to the
-  /// GUID created when parsing it. Used to add newly parsed summaries to
-  /// the index.
-  DenseMap<uint64_t, GlobalValue::GUID> SummaryOffsetToGUIDMap;
-
   /// Map populated during module path string table parsing, from the
   /// module ID to a string reference owned by the index's module
   /// path string table, used to correlate with combined index
@@ -548,7 +543,6 @@ private:
   std::error_code initLazyStream(std::unique_ptr<DataStreamer> Streamer);
   std::pair<GlobalValue::GUID, GlobalValue::GUID>
   getGUIDFromValueId(unsigned ValueId);
-  GlobalValue::GUID getGUIDFromOffset(uint64_t Offset);
 };
 } // end anonymous namespace
 
@@ -5740,13 +5734,6 @@ ModuleSummaryIndexBitcodeReader::getGUID
   return VGI->second;
 }
 
-GlobalValue::GUID
-ModuleSummaryIndexBitcodeReader::getGUIDFromOffset(uint64_t Offset) {
-  auto I = SummaryOffsetToGUIDMap.find(Offset);
-  assert(I != SummaryOffsetToGUIDMap.end());
-  return I->second;
-}
-
 // Specialized value symbol table parser used when reading module index
 // blocks where we don't actually create global values. The parsed information
 // is saved in the bitcode reader for use when later parsing summaries.
@@ -5832,18 +5819,6 @@ std::error_code ModuleSummaryIndexBitcod
       ValueName.clear();
       break;
     }
-    case bitc::VST_CODE_COMBINED_GVDEFENTRY: {
-      // VST_CODE_COMBINED_GVDEFENTRY: [valueid, offset, guid]
-      unsigned ValueID = Record[0];
-      uint64_t GlobalValSummaryOffset = Record[1];
-      GlobalValue::GUID GlobalValGUID = Record[2];
-      SummaryOffsetToGUIDMap[GlobalValSummaryOffset] = GlobalValGUID;
-      // The "original name", which is the second value of the pair will be
-      // overriden later by a FS_COMBINED_ORIGINAL_NAME in the combined index.
-      ValueIdToCallGraphGUIDMap[ValueID] =
-          std::make_pair(GlobalValGUID, GlobalValGUID);
-      break;
-    }
     case bitc::VST_CODE_COMBINED_ENTRY: {
       // VST_CODE_COMBINED_ENTRY: [valueid, refguid]
       unsigned ValueID = Record[0];
@@ -6030,11 +6005,6 @@ std::error_code ModuleSummaryIndexBitcod
   // "OriginalName" attachement.
   GlobalValueSummary *LastSeenSummary = nullptr;
   bool Combined = false;
-  // For aliases in the combined summary, we need to know which summary
-  // corresponds to the aliasee offset saved in the alias summary. It isn't
-  // sufficient to just map to the aliasee GUID, since in the combined summary
-  // there may be multiple values with the same GUID.
-  DenseMap<uint64_t, GlobalValueSummary *> OffsetToSummaryMap;
   while (1) {
     BitstreamEntry Entry = Stream.advanceSkippingSubblocks();
 
@@ -6067,7 +6037,6 @@ std::error_code ModuleSummaryIndexBitcod
     // in the combined index VST entries). The records also contain
     // information used for ThinLTO renaming and importing.
     Record.clear();
-    uint64_t CurRecordBit = Stream.GetCurrentBitNo();
     auto BitCode = Stream.readRecord(Entry.ID, Record);
     switch (BitCode) {
     default: // Default behavior: ignore.
@@ -6164,27 +6133,29 @@ std::error_code ModuleSummaryIndexBitcod
       TheIndex->addGlobalValueSummary(GUID.first, std::move(FS));
       break;
     }
-    // FS_COMBINED: [modid, flags, instcount, numrefs, numrefs x valueid,
-    //               n x (valueid, callsitecount)]
-    // FS_COMBINED_PROFILE: [modid, flags, instcount, numrefs,
+    // FS_COMBINED: [valueid, modid, flags, instcount, numrefs,
+    //               numrefs x valueid, n x (valueid, callsitecount)]
+    // FS_COMBINED_PROFILE: [valueid, modid, flags, instcount, numrefs,
     //                       numrefs x valueid,
     //                       n x (valueid, callsitecount, profilecount)]
     case bitc::FS_COMBINED:
     case bitc::FS_COMBINED_PROFILE: {
-      uint64_t ModuleId = Record[0];
-      uint64_t RawFlags = Record[1];
-      unsigned InstCount = Record[2];
-      unsigned NumRefs = Record[3];
+      unsigned ValueID = Record[0];
+      uint64_t ModuleId = Record[1];
+      uint64_t RawFlags = Record[2];
+      unsigned InstCount = Record[3];
+      unsigned NumRefs = Record[4];
       auto Flags = getDecodedGVSummaryFlags(RawFlags, Version);
       std::unique_ptr<FunctionSummary> FS =
           llvm::make_unique<FunctionSummary>(Flags, InstCount);
       LastSeenSummary = FS.get();
       FS->setModulePath(ModuleIdMap[ModuleId]);
-      static int RefListStartIndex = 4;
+      static int RefListStartIndex = 5;
       int CallGraphEdgeStartIndex = RefListStartIndex + NumRefs;
       assert(Record.size() >= RefListStartIndex + NumRefs &&
              "Record size inconsistent with number of references");
-      for (unsigned I = 4, E = CallGraphEdgeStartIndex; I != E; ++I) {
+      for (unsigned I = RefListStartIndex, E = CallGraphEdgeStartIndex; I != E;
+           ++I) {
         unsigned RefValueId = Record[I];
         GlobalValue::GUID RefGUID = getGUIDFromValueId(RefValueId).first;
         FS->addRefEdge(RefGUID);
@@ -6199,50 +6170,52 @@ std::error_code ModuleSummaryIndexBitcod
         FS->addCallGraphEdge(CalleeGUID,
                              CalleeInfo(CallsiteCount, ProfileCount));
       }
-      GlobalValue::GUID GUID = getGUIDFromOffset(CurRecordBit);
-      OffsetToSummaryMap[CurRecordBit] = FS.get();
+      GlobalValue::GUID GUID = getGUIDFromValueId(ValueID).first;
       TheIndex->addGlobalValueSummary(GUID, std::move(FS));
       Combined = true;
       break;
     }
-    // FS_COMBINED_ALIAS: [modid, flags, offset]
+    // FS_COMBINED_ALIAS: [valueid, modid, flags, valueid]
     // Aliases must be emitted (and parsed) after all FS_COMBINED entries, as
     // they expect all aliasee summaries to be available.
     case bitc::FS_COMBINED_ALIAS: {
-      uint64_t ModuleId = Record[0];
-      uint64_t RawFlags = Record[1];
-      uint64_t AliaseeSummaryOffset = Record[2];
+      unsigned ValueID = Record[0];
+      uint64_t ModuleId = Record[1];
+      uint64_t RawFlags = Record[2];
+      unsigned AliaseeValueId = Record[3];
       auto Flags = getDecodedGVSummaryFlags(RawFlags, Version);
       std::unique_ptr<AliasSummary> AS = llvm::make_unique<AliasSummary>(Flags);
       LastSeenSummary = AS.get();
       AS->setModulePath(ModuleIdMap[ModuleId]);
 
-      auto *AliaseeSummary = OffsetToSummaryMap[AliaseeSummaryOffset];
-      if (!AliaseeSummary)
+      auto AliaseeGUID = getGUIDFromValueId(AliaseeValueId).first;
+      auto AliaseeInModule =
+          TheIndex->findSummaryInModule(AliaseeGUID, AS->modulePath());
+      if (!AliaseeInModule)
         return error("Alias expects aliasee summary to be parsed");
-      AS->setAliasee(AliaseeSummary);
+      AS->setAliasee(AliaseeInModule);
 
-      GlobalValue::GUID GUID = getGUIDFromOffset(CurRecordBit);
+      GlobalValue::GUID GUID = getGUIDFromValueId(ValueID).first;
       TheIndex->addGlobalValueSummary(GUID, std::move(AS));
       Combined = true;
       break;
     }
-    // FS_COMBINED_GLOBALVAR_INIT_REFS: [modid, flags, n x valueid]
+    // FS_COMBINED_GLOBALVAR_INIT_REFS: [valueid, modid, flags, n x valueid]
     case bitc::FS_COMBINED_GLOBALVAR_INIT_REFS: {
-      uint64_t ModuleId = Record[0];
-      uint64_t RawFlags = Record[1];
+      unsigned ValueID = Record[0];
+      uint64_t ModuleId = Record[1];
+      uint64_t RawFlags = Record[2];
       auto Flags = getDecodedGVSummaryFlags(RawFlags, Version);
       std::unique_ptr<GlobalVarSummary> FS =
           llvm::make_unique<GlobalVarSummary>(Flags);
       LastSeenSummary = FS.get();
       FS->setModulePath(ModuleIdMap[ModuleId]);
-      for (unsigned I = 2, E = Record.size(); I != E; ++I) {
+      for (unsigned I = 3, E = Record.size(); I != E; ++I) {
         unsigned RefValueId = Record[I];
         GlobalValue::GUID RefGUID = getGUIDFromValueId(RefValueId).first;
         FS->addRefEdge(RefGUID);
       }
-      GlobalValue::GUID GUID = getGUIDFromOffset(CurRecordBit);
-      OffsetToSummaryMap[CurRecordBit] = FS.get();
+      GlobalValue::GUID GUID = getGUIDFromValueId(ValueID).first;
       TheIndex->addGlobalValueSummary(GUID, std::move(FS));
       Combined = true;
       break;

Modified: llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp?rev=267712&r1=267711&r2=267712&view=diff
==============================================================================
--- llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp (original)
+++ llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp Wed Apr 27 08:28:35 2016
@@ -270,10 +270,6 @@ class IndexBitcodeWriter : public Bitcod
   /// Tracks the last value id recorded in the GUIDToValueMap.
   unsigned GlobalValueId = 0;
 
-  /// Record the starting offset of each summary entry for use in the VST
-  /// entry, and for any possible alias.
-  DenseMap<const GlobalValueSummary *, uint64_t> SummaryToOffsetMap;
-
 public:
   /// Constructs a IndexBitcodeWriter object for the given combined index,
   /// writing to the provided \p Buffer.
@@ -312,13 +308,6 @@ private:
       return VMI->second;
     }
   }
-  unsigned popValueId(GlobalValue::GUID ValGUID) {
-    const auto &VMI = GUIDToValueIdMap.find(ValGUID);
-    assert(VMI != GUIDToValueIdMap.end());
-    unsigned ValueId = VMI->second;
-    GUIDToValueIdMap.erase(VMI);
-    return ValueId;
-  }
   std::map<GlobalValue::GUID, unsigned> &valueIds() { return GUIDToValueIdMap; }
 };
 
@@ -2629,38 +2618,12 @@ void IndexBitcodeWriter::writeCombinedVa
   Stream.EnterSubblock(bitc::VALUE_SYMTAB_BLOCK_ID, 4);
 
   BitCodeAbbrev *Abbv = new BitCodeAbbrev();
-  Abbv->Add(BitCodeAbbrevOp(bitc::VST_CODE_COMBINED_GVDEFENTRY));
-  Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // valueid
-  Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // sumoffset
-  Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // guid
-  unsigned DefEntryAbbrev = Stream.EmitAbbrev(Abbv);
-
-  Abbv = new BitCodeAbbrev();
   Abbv->Add(BitCodeAbbrevOp(bitc::VST_CODE_COMBINED_ENTRY));
   Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // valueid
   Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // refguid
   unsigned EntryAbbrev = Stream.EmitAbbrev(Abbv);
 
   SmallVector<uint64_t, 64> NameVals;
-
-  for (const auto &GSI : Index) {
-    GlobalValue::GUID ValGUID = GSI.first;
-    unsigned ValueId = popValueId(ValGUID);
-
-    for (const auto &SI : GSI.second) {
-      // VST_CODE_COMBINED_GVDEFENTRY: [valueid, sumoffset, guid]
-      NameVals.push_back(ValueId);
-      auto Offset = SummaryToOffsetMap[SI.get()];
-      assert(Offset);
-      NameVals.push_back(Offset);
-      NameVals.push_back(ValGUID);
-
-      // Emit the finished record.
-      Stream.EmitRecord(bitc::VST_CODE_COMBINED_GVDEFENTRY, NameVals,
-                        DefEntryAbbrev);
-      NameVals.clear();
-    }
-  }
   for (const auto &GVI : valueIds()) {
     // VST_CODE_COMBINED_ENTRY: [valueid, refguid]
     NameVals.push_back(GVI.second);
@@ -3194,6 +3157,7 @@ void IndexBitcodeWriter::writeCombinedGl
   // Abbrev for FS_COMBINED.
   BitCodeAbbrev *Abbv = new BitCodeAbbrev();
   Abbv->Add(BitCodeAbbrevOp(bitc::FS_COMBINED));
+  Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8));   // valueid
   Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8));   // modid
   Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));   // flags
   Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8));   // instcount
@@ -3206,6 +3170,7 @@ void IndexBitcodeWriter::writeCombinedGl
   // Abbrev for FS_COMBINED_PROFILE.
   Abbv = new BitCodeAbbrev();
   Abbv->Add(BitCodeAbbrevOp(bitc::FS_COMBINED_PROFILE));
+  Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8));   // valueid
   Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8));   // modid
   Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));   // flags
   Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8));   // instcount
@@ -3218,6 +3183,7 @@ void IndexBitcodeWriter::writeCombinedGl
   // Abbrev for FS_COMBINED_GLOBALVAR_INIT_REFS.
   Abbv = new BitCodeAbbrev();
   Abbv->Add(BitCodeAbbrevOp(bitc::FS_COMBINED_GLOBALVAR_INIT_REFS));
+  Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8));   // valueid
   Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8));   // modid
   Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));   // flags
   Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));    // valueids
@@ -3227,15 +3193,19 @@ void IndexBitcodeWriter::writeCombinedGl
   // Abbrev for FS_COMBINED_ALIAS.
   Abbv = new BitCodeAbbrev();
   Abbv->Add(BitCodeAbbrevOp(bitc::FS_COMBINED_ALIAS));
+  Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8));   // valueid
   Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8));   // modid
   Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));   // flags
-  Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8));   // offset
+  Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8));   // valueid
   unsigned FSAliasAbbrev = Stream.EmitAbbrev(Abbv);
 
-  // The aliases are emitted as a post-pass, and will point to the summary
-  // offset id of the aliasee. Save them in a vector for post-processing.
+  // The aliases are emitted as a post-pass, and will point to the value
+  // id of the aliasee. Save them in a vector for post-processing.
   SmallVector<AliasSummary *, 64> Aliases;
 
+  // Save the value id for each summary for alias emission.
+  DenseMap<const GlobalValueSummary *, unsigned> SummaryToValueIdMap;
+
   SmallVector<uint64_t, 64> NameVals;
 
   // For local linkage, we also emit the original name separately
@@ -3252,6 +3222,11 @@ void IndexBitcodeWriter::writeCombinedGl
     for (auto &SI : GSI.second) {
       GlobalValueSummary *S = SI.get();
       assert(S);
+
+      assert(hasValueId(GSI.first));
+      unsigned ValueId = getValueId(GSI.first);
+      SummaryToValueIdMap[S] = ValueId;
+
       if (auto *AS = dyn_cast<AliasSummary>(S)) {
         // Will process aliases as a post-pass because the reader wants all
         // global to be loaded first.
@@ -3260,18 +3235,13 @@ void IndexBitcodeWriter::writeCombinedGl
       }
 
       if (auto *VS = dyn_cast<GlobalVarSummary>(S)) {
+        NameVals.push_back(ValueId);
         NameVals.push_back(Index.getModuleId(VS->modulePath()));
         NameVals.push_back(getEncodedGVSummaryFlags(VS->flags()));
         for (auto &RI : VS->refs()) {
           NameVals.push_back(getValueId(RI.getGUID()));
         }
 
-        // Record the starting offset of this summary entry for use in the VST
-        // entry, and for any possible alias. Add the current code size since
-        // the reader will invoke readRecord after the abbrev id read.
-        SummaryToOffsetMap[S] =
-            Stream.GetCurrentBitNo() + Stream.GetAbbrevIDWidth();
-
         // Emit the finished record.
         Stream.EmitRecord(bitc::FS_COMBINED_GLOBALVAR_INIT_REFS, NameVals,
                           FSModRefsAbbrev);
@@ -3281,6 +3251,7 @@ void IndexBitcodeWriter::writeCombinedGl
       }
 
       auto *FS = cast<FunctionSummary>(S);
+      NameVals.push_back(ValueId);
       NameVals.push_back(Index.getModuleId(FS->modulePath()));
       NameVals.push_back(getEncodedGVSummaryFlags(FS->flags()));
       NameVals.push_back(FS->instCount());
@@ -3309,12 +3280,6 @@ void IndexBitcodeWriter::writeCombinedGl
           NameVals.push_back(EI.second.ProfileCount);
       }
 
-      // Record the starting offset of this summary entry for use in the VST
-      // entry, and for any possible alias. Add the current code size since
-      // the reader will invoke readRecord after the abbrev id read.
-      SummaryToOffsetMap[S] =
-          Stream.GetCurrentBitNo() + Stream.GetAbbrevIDWidth();
-
       unsigned FSAbbrev =
           (HasProfileData ? FSCallsProfileAbbrev : FSCallsAbbrev);
       unsigned Code =
@@ -3328,17 +3293,14 @@ void IndexBitcodeWriter::writeCombinedGl
   }
 
   for (auto *AS : Aliases) {
+    auto AliasValueId = SummaryToValueIdMap[AS];
+    assert(AliasValueId);
+    NameVals.push_back(AliasValueId);
     NameVals.push_back(Index.getModuleId(AS->modulePath()));
     NameVals.push_back(getEncodedGVSummaryFlags(AS->flags()));
-    auto AliaseeOffset = SummaryToOffsetMap[&AS->getAliasee()];
-    assert(AliaseeOffset);
-    NameVals.push_back(AliaseeOffset);
-
-    // Record the starting offset of this summary entry for use
-    // in the VST entry. Add the current code size since the
-    // reader will invoke readRecord after the abbrev id read.
-    SummaryToOffsetMap[AS] =
-        Stream.GetCurrentBitNo() + Stream.GetAbbrevIDWidth();
+    auto AliaseeValueId = SummaryToValueIdMap[&AS->getAliasee()];
+    assert(AliaseeValueId);
+    NameVals.push_back(AliaseeValueId);
 
     // Emit the finished record.
     Stream.EmitRecord(bitc::FS_COMBINED_ALIAS, NameVals, FSAliasAbbrev);

Modified: llvm/trunk/test/Bitcode/thinlto-alias.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Bitcode/thinlto-alias.ll?rev=267712&r1=267711&r2=267712&view=diff
==============================================================================
--- llvm/trunk/test/Bitcode/thinlto-alias.ll (original)
+++ llvm/trunk/test/Bitcode/thinlto-alias.ll Wed Apr 27 08:28:35 2016
@@ -21,16 +21,16 @@
 ; 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/>
+; COMBINED-NEXT:    <COMBINED {{.*}} op5=[[ALIASID:[0-9]+]] op6=1/>
 ; Followed by the alias and aliasee
 ; COMBINED-NEXT:    <COMBINED {{.*}}
-; COMBINED-NEXT:    <COMBINED_ALIAS  {{.*}} op2=[[ALIASEEOFFSET:[0-9]+]]
+; COMBINED-NEXT:    <COMBINED_ALIAS  {{.*}} op3=[[ALIASEEID:[0-9]+]]
 ; COMBINED-NEXT:  </GLOBALVAL_SUMMARY_BLOCK
 ; COMBINED-NEXT:  <VALUE_SYMTAB
 ; Entry for function func should have entry with value id ALIASID
-; COMBINED-NEXT:    <COMBINED_GVDEFENTRY {{.*}} op0=[[ALIASID]] {{.*}} op2=-5751648690987223394/>
-; COMBINED-NEXT:    <COMBINED_GVDEFENTRY
-; COMBINED-NEXT:    <COMBINED_GVDEFENTRY  {{.*}} op1=[[ALIASEEOFFSET]] op2=-1039159065113703048/>
+; COMBINED-NEXT:    <COMBINED_ENTRY {{.*}} op0=[[ALIASID]] op1=-5751648690987223394/>
+; COMBINED-NEXT:    <COMBINED
+; COMBINED-NEXT:    <COMBINED_ENTRY {{.*}} op0=[[ALIASEEID]] op1=-1039159065113703048/>
 ; COMBINED-NEXT:  </VALUE_SYMTAB>
 
 ; ModuleID = 'thinlto-function-summary-callgraph.ll'

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=267712&r1=267711&r2=267712&view=diff
==============================================================================
--- llvm/trunk/test/Bitcode/thinlto-function-summary-callgraph-pgo.ll (original)
+++ llvm/trunk/test/Bitcode/thinlto-function-summary-callgraph-pgo.ll Wed Apr 27 08:28:35 2016
@@ -22,12 +22,12 @@
 ; 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.
-; COMBINED-NEXT:    <COMBINED_PROFILE {{.*}} op4=[[FUNCID:[0-9]+]] op5=1 op6=1/>
+; COMBINED-NEXT:    <COMBINED_PROFILE {{.*}} op5=[[FUNCID:[0-9]+]] op6=1 op7=1/>
 ; COMBINED-NEXT:  </GLOBALVAL_SUMMARY_BLOCK>
 ; COMBINED-NEXT:  <VALUE_SYMTAB
 ; Entry for function func should have entry with value id FUNCID
-; COMBINED-NEXT:    <COMBINED_GVDEFENTRY {{.*}} op0=[[FUNCID]] {{.*}} op2=7289175272376759421/>
-; COMBINED-NEXT:    <COMBINED_GVDEFENTRY
+; COMBINED-NEXT:    <COMBINED_ENTRY {{.*}} op0=[[FUNCID]] op1=7289175272376759421/>
+; COMBINED-NEXT:    <COMBINED
 ; COMBINED-NEXT:  </VALUE_SYMTAB>
 
 ; ModuleID = 'thinlto-function-summary-callgraph.ll'

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=267712&r1=267711&r2=267712&view=diff
==============================================================================
--- llvm/trunk/test/Bitcode/thinlto-function-summary-callgraph.ll (original)
+++ llvm/trunk/test/Bitcode/thinlto-function-summary-callgraph.ll Wed Apr 27 08:28:35 2016
@@ -22,12 +22,12 @@
 ; 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.
-; COMBINED-NEXT:    <COMBINED {{.*}} op4=[[FUNCID:[0-9]+]] op5=1/>
+; COMBINED-NEXT:    <COMBINED {{.*}} op5=[[FUNCID:[0-9]+]] op6=1/>
 ; COMBINED-NEXT:  </GLOBALVAL_SUMMARY_BLOCK>
 ; COMBINED-NEXT:  <VALUE_SYMTAB
 ; Entry for function func should have entry with value id FUNCID
-; COMBINED-NEXT:    <COMBINED_GVDEFENTRY {{.*}} op0=[[FUNCID]] {{.*}} op2=7289175272376759421/>
-; COMBINED-NEXT:    <COMBINED_GVDEFENTRY
+; COMBINED-NEXT:    <COMBINED_ENTRY {{.*}} op0=[[FUNCID]] op1=7289175272376759421/>
+; COMBINED-NEXT:    <COMBINED
 ; COMBINED-NEXT:  </VALUE_SYMTAB>
 
 ; ModuleID = 'thinlto-function-summary-callgraph.ll'

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=267712&r1=267711&r2=267712&view=diff
==============================================================================
--- llvm/trunk/test/Bitcode/thinlto-function-summary-originalnames.ll (original)
+++ llvm/trunk/test/Bitcode/thinlto-function-summary-originalnames.ll Wed Apr 27 08:28:35 2016
@@ -13,9 +13,9 @@
 ; COMBINED-DAG:    <COMBINED_ORIGINAL_NAME op0=-4170563161550796836/>
 ; COMBINED-NEXT:  </GLOBALVAL_SUMMARY_BLOCK>
 ; COMBINED-NEXT:  <VALUE_SYMTAB
-; COMBINED-NEXT:   <COMBINED_GVDEFENTRY {{.*}} op2=4947176790635855146/>
-; COMBINED-NEXT:   <COMBINED_GVDEFENTRY {{.*}} op2=-6591587165810580810/>
-; COMBINED-NEXT:   <COMBINED_GVDEFENTRY {{.*}} op2=-4377693495213223786/>
+; COMBINED-NEXT:   <COMBINED_ENTRY {{.*}} op1=4947176790635855146/>
+; COMBINED-NEXT:   <COMBINED_ENTRY {{.*}} op1=-6591587165810580810/>
+; COMBINED-NEXT:   <COMBINED_ENTRY {{.*}} op1=-4377693495213223786/>
 ; COMBINED-NEXT:  </VALUE_SYMTAB>
 
 source_filename = "/path/to/source.c"

Modified: llvm/trunk/test/Bitcode/thinlto-summary-linkage-types.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Bitcode/thinlto-summary-linkage-types.ll?rev=267712&r1=267711&r2=267712&view=diff
==============================================================================
--- llvm/trunk/test/Bitcode/thinlto-summary-linkage-types.ll (original)
+++ llvm/trunk/test/Bitcode/thinlto-summary-linkage-types.ll Wed Apr 27 08:28:35 2016
@@ -6,56 +6,56 @@
 
 define private void @private()
 ; CHECK: <PERMODULE {{.*}} op1=8
-; COMBINED-DAG: <COMBINED {{.*}} op1=8
+; COMBINED-DAG: <COMBINED {{.*}} op2=8
 {
   ret void
 }
 
 define internal void @internal()
 ; CHECK: <PERMODULE {{.*}} op1=7
-; COMBINED-DAG: <COMBINED {{.*}} op1=7
+; COMBINED-DAG: <COMBINED {{.*}} op2=7
 {
   ret void
 }
 
 define available_externally void @available_externally()
 ; CHECK: <PERMODULE {{.*}} op1=1
-; COMBINED-DAG: <COMBINED {{.*}} op1=1
+; COMBINED-DAG: <COMBINED {{.*}} op2=1
 {
   ret void
 }
 
 define linkonce void @linkonce()
 ; CHECK: <PERMODULE {{.*}} op1=2
-; COMBINED-DAG: <COMBINED {{.*}} op1=2
+; COMBINED-DAG: <COMBINED {{.*}} op2=2
 {
   ret void
 }
 
 define weak void @weak()
 ; CHECK: <PERMODULE {{.*}} op1=4
-; COMBINED-DAG: <COMBINED {{.*}} op1=4
+; COMBINED-DAG: <COMBINED {{.*}} op2=4
 {
   ret void
 }
 
 define linkonce_odr void @linkonce_odr()
 ; CHECK: <PERMODULE {{.*}} op1=3
-; COMBINED-DAG: <COMBINED {{.*}} op1=3
+; COMBINED-DAG: <COMBINED {{.*}} op2=3
 {
   ret void
 }
 
 define weak_odr void @weak_odr()
 ; CHECK: <PERMODULE {{.*}} op1=5
-; COMBINED-DAG: <COMBINED {{.*}} op1=5
+; COMBINED-DAG: <COMBINED {{.*}} op2=5
 {
   ret void
 }
 
 define external void @external()
 ; CHECK: <PERMODULE {{.*}} op1=0
-; COMBINED-DAG: <COMBINED {{.*}} op1=0
+; COMBINED-DAG: <COMBINED {{.*}} op2=0
 {
   ret void
 }

Modified: llvm/trunk/test/Bitcode/thinlto-summary-section.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Bitcode/thinlto-summary-section.ll?rev=267712&r1=267711&r2=267712&view=diff
==============================================================================
--- llvm/trunk/test/Bitcode/thinlto-summary-section.ll (original)
+++ llvm/trunk/test/Bitcode/thinlto-summary-section.ll Wed Apr 27 08:28:35 2016
@@ -5,7 +5,7 @@
 ; RUN: llvm-bcanalyzer -dump %t2.thinlto.bc | FileCheck %s --check-prefix=COMBINED
 
 ; CHECK: <PERMODULE {{.*}} op1=16
-; COMBINED-DAG: <COMBINED {{.*}} op1=16
+; COMBINED-DAG: <COMBINED {{.*}} op2=16
 define void @functionWithSection() section "some_section" {
     ret void
 }

Modified: llvm/trunk/test/tools/gold/X86/thinlto.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/gold/X86/thinlto.ll?rev=267712&r1=267711&r2=267712&view=diff
==============================================================================
--- llvm/trunk/test/tools/gold/X86/thinlto.ll (original)
+++ llvm/trunk/test/tools/gold/X86/thinlto.ll Wed Apr 27 08:28:35 2016
@@ -65,8 +65,8 @@
 ; COMBINED-NEXT: <VALUE_SYMTAB
 ; Check that the format is: op0=valueid, op1=offset, op2=funcguid,
 ; where funcguid is the lower 64 bits of the function name MD5.
-; COMBINED-NEXT: <COMBINED_GVDEFENTRY abbrevid={{[0-9]+}} op0={{1|2}} op1={{[0-9]+}} op2={{-3706093650706652785|-5300342847281564238}}
-; COMBINED-NEXT: <COMBINED_GVDEFENTRY abbrevid={{[0-9]+}} op0={{1|2}} op1={{[0-9]+}} op2={{-3706093650706652785|-5300342847281564238}}
+; COMBINED-NEXT: <COMBINED_ENTRY abbrevid={{[0-9]+}} op0={{1|2}} op1={{-3706093650706652785|-5300342847281564238}}
+; COMBINED-NEXT: <COMBINED_ENTRY abbrevid={{[0-9]+}} op0={{1|2}} op1={{-3706093650706652785|-5300342847281564238}}
 ; COMBINED-NEXT: </VALUE_SYMTAB
 
 declare void @g(...)

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=267712&r1=267711&r2=267712&view=diff
==============================================================================
--- llvm/trunk/test/tools/llvm-lto/thinlto.ll (original)
+++ llvm/trunk/test/tools/llvm-lto/thinlto.ll Wed Apr 27 08:28:35 2016
@@ -17,8 +17,8 @@
 ; COMBINED-NEXT: <VALUE_SYMTAB
 ; Check that the format is: op0=valueid, op1=offset, op2=funcguid,
 ; where funcguid is the lower 64 bits of the function name MD5.
-; COMBINED-NEXT: <COMBINED_GVDEFENTRY abbrevid={{[0-9]+}} op0={{1|2}} op1={{[0-9]+}} op2={{-3706093650706652785|-5300342847281564238}}
-; COMBINED-NEXT: <COMBINED_GVDEFENTRY abbrevid={{[0-9]+}} op0={{1|2}} op1={{[0-9]+}} op2={{-3706093650706652785|-5300342847281564238}}
+; COMBINED-NEXT: <COMBINED_ENTRY abbrevid={{[0-9]+}} op0={{1|2}} op1={{-3706093650706652785|-5300342847281564238}}
+; COMBINED-NEXT: <COMBINED_ENTRY abbrevid={{[0-9]+}} op0={{1|2}} op1={{-3706093650706652785|-5300342847281564238}}
 ; COMBINED-NEXT: </VALUE_SYMTAB
 
 define void @f() {

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=267712&r1=267711&r2=267712&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp (original)
+++ llvm/trunk/tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp Wed Apr 27 08:28:35 2016
@@ -288,7 +288,6 @@ static const char *GetCodeName(unsigned
     STRINGIFY_CODE(VST_CODE, ENTRY)
     STRINGIFY_CODE(VST_CODE, BBENTRY)
     STRINGIFY_CODE(VST_CODE, FNENTRY)
-    STRINGIFY_CODE(VST_CODE, COMBINED_GVDEFENTRY)
     STRINGIFY_CODE(VST_CODE, COMBINED_ENTRY)
     }
   case bitc::MODULE_STRTAB_BLOCK_ID:




More information about the llvm-commits mailing list