@@ -428,6 +428,11 @@ class IndexBitcodeWriter : public BitcodeWriterBase {
428
428
// / The combined index to write to bitcode.
429
429
const ModuleSummaryIndex &Index;
430
430
431
+ // / When writing combined summaries, provides the set of global value
432
+ // / summaries for which the value (function, function alias, etc) should be
433
+ // / imported as a declaration.
434
+ const GVSummaryPtrSet *DecSummaries = nullptr ;
435
+
431
436
// / When writing a subset of the index for distributed backends, client
432
437
// / provides a map of modules to the corresponding GUIDs/summaries to write.
433
438
const std::map<std::string, GVSummaryMapTy> *ModuleToSummariesForIndex;
@@ -452,11 +457,16 @@ class IndexBitcodeWriter : public BitcodeWriterBase {
452
457
// / Constructs a IndexBitcodeWriter object for the given combined index,
453
458
// / writing to the provided \p Buffer. When writing a subset of the index
454
459
// / for a distributed backend, provide a \p ModuleToSummariesForIndex map.
460
+ // / If provided, \p ModuleToDecSummaries specifies the set of summaries for
461
+ // / which the corresponding functions or aliased functions should be imported
462
+ // / as a declaration (but not definition) for each module.
455
463
IndexBitcodeWriter (BitstreamWriter &Stream, StringTableBuilder &StrtabBuilder,
456
464
const ModuleSummaryIndex &Index,
465
+ const GVSummaryPtrSet *DecSummaries = nullptr ,
457
466
const std::map<std::string, GVSummaryMapTy>
458
467
*ModuleToSummariesForIndex = nullptr )
459
468
: BitcodeWriterBase(Stream, StrtabBuilder), Index(Index),
469
+ DecSummaries (DecSummaries),
460
470
ModuleToSummariesForIndex(ModuleToSummariesForIndex) {
461
471
// Assign unique value ids to all summaries to be written, for use
462
472
// in writing out the call graph edges. Save the mapping from GUID
@@ -1202,7 +1212,8 @@ static uint64_t getEncodedFFlags(FunctionSummary::FFlags Flags) {
1202
1212
1203
1213
// Decode the flags for GlobalValue in the summary. See getDecodedGVSummaryFlags
1204
1214
// in BitcodeReader.cpp.
1205
- static uint64_t getEncodedGVSummaryFlags (GlobalValueSummary::GVFlags Flags) {
1215
+ static uint64_t getEncodedGVSummaryFlags (GlobalValueSummary::GVFlags Flags,
1216
+ bool ImportAsDecl = false ) {
1206
1217
uint64_t RawFlags = 0 ;
1207
1218
1208
1219
RawFlags |= Flags.NotEligibleToImport ; // bool
@@ -1217,7 +1228,8 @@ static uint64_t getEncodedGVSummaryFlags(GlobalValueSummary::GVFlags Flags) {
1217
1228
1218
1229
RawFlags |= (Flags.Visibility << 8 ); // 2 bits
1219
1230
1220
- RawFlags |= (Flags.ImportType << 10 ); // 1 bit
1231
+ unsigned ImportType = Flags.ImportType | ImportAsDecl;
1232
+ RawFlags |= (ImportType << 10 ); // 1 bit
1221
1233
1222
1234
return RawFlags;
1223
1235
}
@@ -4543,6 +4555,12 @@ void IndexBitcodeWriter::writeCombinedGlobalValueSummary() {
4543
4555
Abbv->Add (BitCodeAbbrevOp (BitCodeAbbrevOp::VBR, 8 ));
4544
4556
unsigned AllocAbbrev = Stream.EmitAbbrev (std::move (Abbv));
4545
4557
4558
+ auto shouldImportValueAsDecl = [&](GlobalValueSummary *GVS) -> bool {
4559
+ if (DecSummaries == nullptr )
4560
+ return false ;
4561
+ return DecSummaries->contains (GVS);
4562
+ };
4563
+
4546
4564
// The aliases are emitted as a post-pass, and will point to the value
4547
4565
// id of the aliasee. Save them in a vector for post-processing.
4548
4566
SmallVector<AliasSummary *, 64 > Aliases;
@@ -4653,7 +4671,8 @@ void IndexBitcodeWriter::writeCombinedGlobalValueSummary() {
4653
4671
NameVals.push_back (*ValueId);
4654
4672
assert (ModuleIdMap.count (FS->modulePath ()));
4655
4673
NameVals.push_back (ModuleIdMap[FS->modulePath ()]);
4656
- NameVals.push_back (getEncodedGVSummaryFlags (FS->flags ()));
4674
+ NameVals.push_back (
4675
+ getEncodedGVSummaryFlags (FS->flags (), shouldImportValueAsDecl (FS)));
4657
4676
NameVals.push_back (FS->instCount ());
4658
4677
NameVals.push_back (getEncodedFFlags (FS->fflags ()));
4659
4678
NameVals.push_back (FS->entryCount ());
@@ -4702,7 +4721,8 @@ void IndexBitcodeWriter::writeCombinedGlobalValueSummary() {
4702
4721
NameVals.push_back (AliasValueId);
4703
4722
assert (ModuleIdMap.count (AS->modulePath ()));
4704
4723
NameVals.push_back (ModuleIdMap[AS->modulePath ()]);
4705
- NameVals.push_back (getEncodedGVSummaryFlags (AS->flags ()));
4724
+ NameVals.push_back (
4725
+ getEncodedGVSummaryFlags (AS->flags (), shouldImportValueAsDecl (AS)));
4706
4726
auto AliaseeValueId = SummaryToValueIdMap[&AS->getAliasee ()];
4707
4727
assert (AliaseeValueId);
4708
4728
NameVals.push_back (AliaseeValueId);
@@ -5036,8 +5056,9 @@ void BitcodeWriter::writeModule(const Module &M,
5036
5056
5037
5057
void BitcodeWriter::writeIndex (
5038
5058
const ModuleSummaryIndex *Index,
5039
- const std::map<std::string, GVSummaryMapTy> *ModuleToSummariesForIndex) {
5040
- IndexBitcodeWriter IndexWriter (*Stream, StrtabBuilder, *Index,
5059
+ const std::map<std::string, GVSummaryMapTy> *ModuleToSummariesForIndex,
5060
+ const GVSummaryPtrSet *DecSummaries) {
5061
+ IndexBitcodeWriter IndexWriter (*Stream, StrtabBuilder, *Index, DecSummaries,
5041
5062
ModuleToSummariesForIndex);
5042
5063
IndexWriter.write ();
5043
5064
}
@@ -5090,12 +5111,13 @@ void IndexBitcodeWriter::write() {
5090
5111
// index for a distributed backend, provide a \p ModuleToSummariesForIndex map.
5091
5112
void llvm::writeIndexToFile (
5092
5113
const ModuleSummaryIndex &Index, raw_ostream &Out,
5093
- const std::map<std::string, GVSummaryMapTy> *ModuleToSummariesForIndex) {
5114
+ const std::map<std::string, GVSummaryMapTy> *ModuleToSummariesForIndex,
5115
+ const GVSummaryPtrSet *DecSummaries) {
5094
5116
SmallVector<char , 0 > Buffer;
5095
5117
Buffer.reserve (256 * 1024 );
5096
5118
5097
5119
BitcodeWriter Writer (Buffer);
5098
- Writer.writeIndex (&Index, ModuleToSummariesForIndex);
5120
+ Writer.writeIndex (&Index, ModuleToSummariesForIndex, DecSummaries );
5099
5121
Writer.writeStrtab ();
5100
5122
5101
5123
Out.write ((char *)&Buffer.front (), Buffer.size ());
0 commit comments