@@ -425,6 +425,11 @@ class IndexBitcodeWriter : public BitcodeWriterBase {
425
425
// / The combined index to write to bitcode.
426
426
const ModuleSummaryIndex &Index;
427
427
428
+ // / When writing combined summaries, provides the set of global value
429
+ // / summaries for which the value (function, function alias, etc) should be
430
+ // / imported as a declaration.
431
+ const GVSummaryPtrSet *DecSummaries = nullptr ;
432
+
428
433
// / When writing a subset of the index for distributed backends, client
429
434
// / provides a map of modules to the corresponding GUIDs/summaries to write.
430
435
const std::map<std::string, GVSummaryMapTy> *ModuleToSummariesForIndex;
@@ -453,11 +458,16 @@ class IndexBitcodeWriter : public BitcodeWriterBase {
453
458
// / Constructs a IndexBitcodeWriter object for the given combined index,
454
459
// / writing to the provided \p Buffer. When writing a subset of the index
455
460
// / for a distributed backend, provide a \p ModuleToSummariesForIndex map.
461
+ // / If provided, \p ModuleToDecSummaries specifies the set of summaries for
462
+ // / which the corresponding functions or aliased functions should be imported
463
+ // / as a declaration (but not definition) for each module.
456
464
IndexBitcodeWriter (BitstreamWriter &Stream, StringTableBuilder &StrtabBuilder,
457
465
const ModuleSummaryIndex &Index,
466
+ const GVSummaryPtrSet *DecSummaries = nullptr ,
458
467
const std::map<std::string, GVSummaryMapTy>
459
468
*ModuleToSummariesForIndex = nullptr )
460
469
: BitcodeWriterBase(Stream, StrtabBuilder), Index(Index),
470
+ DecSummaries (DecSummaries),
461
471
ModuleToSummariesForIndex(ModuleToSummariesForIndex) {
462
472
463
473
// See if the StackIdIndex was already added to the StackId map and
@@ -1226,7 +1236,8 @@ static uint64_t getEncodedFFlags(FunctionSummary::FFlags Flags) {
1226
1236
1227
1237
// Decode the flags for GlobalValue in the summary. See getDecodedGVSummaryFlags
1228
1238
// in BitcodeReader.cpp.
1229
- static uint64_t getEncodedGVSummaryFlags (GlobalValueSummary::GVFlags Flags) {
1239
+ static uint64_t getEncodedGVSummaryFlags (GlobalValueSummary::GVFlags Flags,
1240
+ bool ImportAsDecl = false ) {
1230
1241
uint64_t RawFlags = 0 ;
1231
1242
1232
1243
RawFlags |= Flags.NotEligibleToImport ; // bool
@@ -1241,7 +1252,8 @@ static uint64_t getEncodedGVSummaryFlags(GlobalValueSummary::GVFlags Flags) {
1241
1252
1242
1253
RawFlags |= (Flags.Visibility << 8 ); // 2 bits
1243
1254
1244
- RawFlags |= (Flags.ImportType << 10 ); // 1 bit
1255
+ unsigned ImportType = Flags.ImportType | ImportAsDecl;
1256
+ RawFlags |= (ImportType << 10 ); // 1 bit
1245
1257
1246
1258
return RawFlags;
1247
1259
}
@@ -4568,6 +4580,12 @@ void IndexBitcodeWriter::writeCombinedGlobalValueSummary() {
4568
4580
Abbv->Add (BitCodeAbbrevOp (BitCodeAbbrevOp::VBR, 8 ));
4569
4581
unsigned AllocAbbrev = Stream.EmitAbbrev (std::move (Abbv));
4570
4582
4583
+ auto shouldImportValueAsDecl = [&](GlobalValueSummary *GVS) -> bool {
4584
+ if (DecSummaries == nullptr )
4585
+ return false ;
4586
+ return DecSummaries->contains (GVS);
4587
+ };
4588
+
4571
4589
// The aliases are emitted as a post-pass, and will point to the value
4572
4590
// id of the aliasee. Save them in a vector for post-processing.
4573
4591
SmallVector<AliasSummary *, 64 > Aliases;
@@ -4678,7 +4696,8 @@ void IndexBitcodeWriter::writeCombinedGlobalValueSummary() {
4678
4696
NameVals.push_back (*ValueId);
4679
4697
assert (ModuleIdMap.count (FS->modulePath ()));
4680
4698
NameVals.push_back (ModuleIdMap[FS->modulePath ()]);
4681
- NameVals.push_back (getEncodedGVSummaryFlags (FS->flags ()));
4699
+ NameVals.push_back (
4700
+ getEncodedGVSummaryFlags (FS->flags (), shouldImportValueAsDecl (FS)));
4682
4701
NameVals.push_back (FS->instCount ());
4683
4702
NameVals.push_back (getEncodedFFlags (FS->fflags ()));
4684
4703
NameVals.push_back (FS->entryCount ());
@@ -4727,7 +4746,8 @@ void IndexBitcodeWriter::writeCombinedGlobalValueSummary() {
4727
4746
NameVals.push_back (AliasValueId);
4728
4747
assert (ModuleIdMap.count (AS->modulePath ()));
4729
4748
NameVals.push_back (ModuleIdMap[AS->modulePath ()]);
4730
- NameVals.push_back (getEncodedGVSummaryFlags (AS->flags ()));
4749
+ NameVals.push_back (
4750
+ getEncodedGVSummaryFlags (AS->flags (), shouldImportValueAsDecl (AS)));
4731
4751
auto AliaseeValueId = SummaryToValueIdMap[&AS->getAliasee ()];
4732
4752
assert (AliaseeValueId);
4733
4753
NameVals.push_back (AliaseeValueId);
@@ -5068,8 +5088,9 @@ void BitcodeWriter::writeModule(const Module &M,
5068
5088
5069
5089
void BitcodeWriter::writeIndex (
5070
5090
const ModuleSummaryIndex *Index,
5071
- const std::map<std::string, GVSummaryMapTy> *ModuleToSummariesForIndex) {
5072
- IndexBitcodeWriter IndexWriter (*Stream, StrtabBuilder, *Index,
5091
+ const std::map<std::string, GVSummaryMapTy> *ModuleToSummariesForIndex,
5092
+ const GVSummaryPtrSet *DecSummaries) {
5093
+ IndexBitcodeWriter IndexWriter (*Stream, StrtabBuilder, *Index, DecSummaries,
5073
5094
ModuleToSummariesForIndex);
5074
5095
IndexWriter.write ();
5075
5096
}
@@ -5124,12 +5145,13 @@ void IndexBitcodeWriter::write() {
5124
5145
// index for a distributed backend, provide a \p ModuleToSummariesForIndex map.
5125
5146
void llvm::writeIndexToFile (
5126
5147
const ModuleSummaryIndex &Index, raw_ostream &Out,
5127
- const std::map<std::string, GVSummaryMapTy> *ModuleToSummariesForIndex) {
5148
+ const std::map<std::string, GVSummaryMapTy> *ModuleToSummariesForIndex,
5149
+ const GVSummaryPtrSet *DecSummaries) {
5128
5150
SmallVector<char , 0 > Buffer;
5129
5151
Buffer.reserve (256 * 1024 );
5130
5152
5131
5153
BitcodeWriter Writer (Buffer);
5132
- Writer.writeIndex (&Index, ModuleToSummariesForIndex);
5154
+ Writer.writeIndex (&Index, ModuleToSummariesForIndex, DecSummaries );
5133
5155
Writer.writeStrtab ();
5134
5156
5135
5157
Out.write ((char *)&Buffer.front (), Buffer.size ());
0 commit comments