@@ -713,11 +713,20 @@ class ModuleSummaryIndexBitcodeReader : public BitcodeReaderBase {
713
713
// / Original source file name recorded in a bitcode record.
714
714
std::string SourceFileName;
715
715
716
+ // / The string identifier given to this module by the client, normally the
717
+ // / path to the bitcode file.
718
+ StringRef ModulePath;
719
+
720
+ // / For per-module summary indexes, the unique numerical identifier given to
721
+ // / this module by the client.
722
+ unsigned ModuleId;
723
+
716
724
public:
717
725
ModuleSummaryIndexBitcodeReader (BitstreamCursor Stream, StringRef Strtab,
718
- ModuleSummaryIndex &TheIndex);
726
+ ModuleSummaryIndex &TheIndex,
727
+ StringRef ModulePath, unsigned ModuleId);
719
728
720
- Error parseModule (StringRef ModulePath );
729
+ Error parseModule ();
721
730
722
731
private:
723
732
void setValueGUID (uint64_t ValueID, StringRef ValueName,
@@ -730,11 +739,13 @@ class ModuleSummaryIndexBitcodeReader : public BitcodeReaderBase {
730
739
std::vector<FunctionSummary::EdgeTy> makeCallList (ArrayRef<uint64_t > Record,
731
740
bool IsOldProfileFormat,
732
741
bool HasProfile);
733
- Error parseEntireSummary (StringRef ModulePath );
742
+ Error parseEntireSummary ();
734
743
Error parseModuleStringTable ();
735
744
736
745
std::pair<GlobalValue::GUID, GlobalValue::GUID>
737
746
getGUIDFromValueId (unsigned ValueId);
747
+
748
+ ModulePathStringTableTy::iterator addThisModulePath ();
738
749
};
739
750
740
751
} // end anonymous namespace
@@ -4676,8 +4687,15 @@ std::vector<StructType *> BitcodeReader::getIdentifiedStructTypes() const {
4676
4687
}
4677
4688
4678
4689
ModuleSummaryIndexBitcodeReader::ModuleSummaryIndexBitcodeReader (
4679
- BitstreamCursor Cursor, StringRef Strtab, ModuleSummaryIndex &TheIndex)
4680
- : BitcodeReaderBase(std::move(Cursor), Strtab), TheIndex(TheIndex) {}
4690
+ BitstreamCursor Cursor, StringRef Strtab, ModuleSummaryIndex &TheIndex,
4691
+ StringRef ModulePath, unsigned ModuleId)
4692
+ : BitcodeReaderBase(std::move(Cursor), Strtab), TheIndex(TheIndex),
4693
+ ModulePath(ModulePath), ModuleId(ModuleId) {}
4694
+
4695
+ ModulePathStringTableTy::iterator
4696
+ ModuleSummaryIndexBitcodeReader::addThisModulePath () {
4697
+ return TheIndex.addModulePath (ModulePath, ModuleId);
4698
+ }
4681
4699
4682
4700
std::pair<GlobalValue::GUID, GlobalValue::GUID>
4683
4701
ModuleSummaryIndexBitcodeReader::getGUIDFromValueId (unsigned ValueId) {
@@ -4787,7 +4805,7 @@ Error ModuleSummaryIndexBitcodeReader::parseValueSymbolTable(
4787
4805
// Parse just the blocks needed for building the index out of the module.
4788
4806
// At the end of this routine the module Index is populated with a map
4789
4807
// from global value id to GlobalValueSummary objects.
4790
- Error ModuleSummaryIndexBitcodeReader::parseModule (StringRef ModulePath ) {
4808
+ Error ModuleSummaryIndexBitcodeReader::parseModule () {
4791
4809
if (Stream.EnterSubBlock (bitc::MODULE_BLOCK_ID))
4792
4810
return error (" Invalid record" );
4793
4811
@@ -4838,7 +4856,7 @@ Error ModuleSummaryIndexBitcodeReader::parseModule(StringRef ModulePath) {
4838
4856
SeenValueSymbolTable = true ;
4839
4857
}
4840
4858
SeenGlobalValSummary = true ;
4841
- if (Error Err = parseEntireSummary (ModulePath ))
4859
+ if (Error Err = parseEntireSummary ())
4842
4860
return Err;
4843
4861
break ;
4844
4862
case bitc::MODULE_STRTAB_BLOCK_ID:
@@ -4871,12 +4889,7 @@ Error ModuleSummaryIndexBitcodeReader::parseModule(StringRef ModulePath) {
4871
4889
case bitc::MODULE_CODE_HASH: {
4872
4890
if (Record.size () != 5 )
4873
4891
return error (" Invalid hash length " + Twine (Record.size ()).str ());
4874
- if (TheIndex.modulePaths ().empty ())
4875
- // We always seed the index with the module.
4876
- TheIndex.addModulePath (ModulePath, 0 );
4877
- if (TheIndex.modulePaths ().size () != 1 )
4878
- return error (" Don't expect multiple modules defined?" );
4879
- auto &Hash = TheIndex.modulePaths ().begin ()->second .second ;
4892
+ auto &Hash = addThisModulePath ()->second .second ;
4880
4893
int Pos = 0 ;
4881
4894
for (auto &Val : Record) {
4882
4895
assert (!(Val >> 32 ) && " Unexpected high bits set" );
@@ -4951,8 +4964,7 @@ std::vector<FunctionSummary::EdgeTy> ModuleSummaryIndexBitcodeReader::makeCallLi
4951
4964
4952
4965
// Eagerly parse the entire summary block. This populates the GlobalValueSummary
4953
4966
// objects in the index.
4954
- Error ModuleSummaryIndexBitcodeReader::parseEntireSummary (
4955
- StringRef ModulePath) {
4967
+ Error ModuleSummaryIndexBitcodeReader::parseEntireSummary () {
4956
4968
if (Stream.EnterSubBlock (bitc::GLOBALVAL_SUMMARY_BLOCK_ID))
4957
4969
return error (" Invalid record" );
4958
4970
SmallVector<uint64_t , 64 > Record;
@@ -5057,7 +5069,7 @@ Error ModuleSummaryIndexBitcodeReader::parseEntireSummary(
5057
5069
PendingTypeTestAssumeConstVCalls.clear ();
5058
5070
PendingTypeCheckedLoadConstVCalls.clear ();
5059
5071
auto GUID = getGUIDFromValueId (ValueID);
5060
- FS->setModulePath (TheIndex. addModulePath (ModulePath, 0 )->first ());
5072
+ FS->setModulePath (addThisModulePath ( )->first ());
5061
5073
FS->setOriginalName (GUID.second );
5062
5074
TheIndex.addGlobalValueSummary (GUID.first , std::move (FS));
5063
5075
break ;
@@ -5077,13 +5089,14 @@ Error ModuleSummaryIndexBitcodeReader::parseEntireSummary(
5077
5089
// string table section in the per-module index, we create a single
5078
5090
// module path string table entry with an empty (0) ID to take
5079
5091
// ownership.
5080
- AS->setModulePath (TheIndex. addModulePath (ModulePath, 0 )->first ());
5092
+ AS->setModulePath (addThisModulePath ( )->first ());
5081
5093
5082
5094
GlobalValue::GUID AliaseeGUID = getGUIDFromValueId (AliaseeID).first ;
5083
- auto *AliaseeSummary = TheIndex.getGlobalValueSummary (AliaseeGUID);
5084
- if (!AliaseeSummary)
5095
+ auto AliaseeInModule =
5096
+ TheIndex.findSummaryInModule (AliaseeGUID, ModulePath);
5097
+ if (!AliaseeInModule)
5085
5098
return error (" Alias expects aliasee summary to be parsed" );
5086
- AS->setAliasee (AliaseeSummary );
5099
+ AS->setAliasee (AliaseeInModule );
5087
5100
5088
5101
auto GUID = getGUIDFromValueId (ValueID);
5089
5102
AS->setOriginalName (GUID.second );
@@ -5098,7 +5111,7 @@ Error ModuleSummaryIndexBitcodeReader::parseEntireSummary(
5098
5111
std::vector<ValueInfo> Refs =
5099
5112
makeRefList (ArrayRef<uint64_t >(Record).slice (2 ));
5100
5113
auto FS = llvm::make_unique<GlobalVarSummary>(Flags, std::move (Refs));
5101
- FS->setModulePath (TheIndex. addModulePath (ModulePath, 0 )->first ());
5114
+ FS->setModulePath (addThisModulePath ( )->first ());
5102
5115
auto GUID = getGUIDFromValueId (ValueID);
5103
5116
FS->setOriginalName (GUID.second );
5104
5117
TheIndex.addGlobalValueSummary (GUID.first , std::move (FS));
@@ -5482,15 +5495,31 @@ BitcodeModule::getLazyModule(LLVMContext &Context, bool ShouldLazyLoadMetadata,
5482
5495
return getModuleImpl (Context, false , ShouldLazyLoadMetadata, IsImporting);
5483
5496
}
5484
5497
5498
+ // Parse the specified bitcode buffer and merge the index into CombinedIndex.
5499
+ Error BitcodeModule::readSummary (ModuleSummaryIndex &CombinedIndex,
5500
+ unsigned ModuleId) {
5501
+ BitstreamCursor Stream (Buffer);
5502
+ Stream.JumpToBit (ModuleBit);
5503
+
5504
+ ModuleSummaryIndexBitcodeReader R (std::move (Stream), Strtab, CombinedIndex,
5505
+ ModuleIdentifier, ModuleId);
5506
+
5507
+ if (Error Err = R.parseModule ())
5508
+ return std::move (Err);
5509
+
5510
+ return Error::success ();
5511
+ }
5512
+
5485
5513
// Parse the specified bitcode buffer, returning the function info index.
5486
5514
Expected<std::unique_ptr<ModuleSummaryIndex>> BitcodeModule::getSummary () {
5487
5515
BitstreamCursor Stream (Buffer);
5488
5516
Stream.JumpToBit (ModuleBit);
5489
5517
5490
5518
auto Index = llvm::make_unique<ModuleSummaryIndex>();
5491
- ModuleSummaryIndexBitcodeReader R (std::move (Stream), Strtab, *Index);
5519
+ ModuleSummaryIndexBitcodeReader R (std::move (Stream), Strtab, *Index,
5520
+ ModuleIdentifier, 0 );
5492
5521
5493
- if (Error Err = R.parseModule (ModuleIdentifier ))
5522
+ if (Error Err = R.parseModule ())
5494
5523
return std::move (Err);
5495
5524
5496
5525
return std::move (Index);
@@ -5600,6 +5629,16 @@ Expected<std::string> llvm::getBitcodeProducerString(MemoryBufferRef Buffer) {
5600
5629
return readIdentificationCode (*StreamOrErr);
5601
5630
}
5602
5631
5632
+ Error llvm::readModuleSummaryIndex (MemoryBufferRef Buffer,
5633
+ ModuleSummaryIndex &CombinedIndex,
5634
+ unsigned ModuleId) {
5635
+ Expected<BitcodeModule> BM = getSingleModule (Buffer);
5636
+ if (!BM)
5637
+ return BM.takeError ();
5638
+
5639
+ return BM->readSummary (CombinedIndex, ModuleId);
5640
+ }
5641
+
5603
5642
Expected<std::unique_ptr<ModuleSummaryIndex>>
5604
5643
llvm::getModuleSummaryIndex (MemoryBufferRef Buffer) {
5605
5644
Expected<BitcodeModule> BM = getSingleModule (Buffer);
0 commit comments