-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Reland "[ThinLTO][Bitcode] Generate import type in bitcode" #97253
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 28 commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
78fa2e0
[ThinLTO]Record import type (declaration or definition) in GlobalValu…
mingmingl-llvm 4b4c33f
[ThinLTO]Generate import type in bitcode writer
mingmingl-llvm cfb63d7
function import changes
mingmingl-llvm b0a4060
'git merge main' and resolve merge conflict
mingmingl-llvm e07d423
Merge branch 'main' into users/minglotus-6/spr/summary1
mingmingl-llvm 175febc
rename Dec to Decl
mingmingl-llvm 8bc4d7a
Merge branch 'main' into users/minglotus-6/spr/summary1
mingmingl-llvm 7252e11
Merge branch 'users/minglotus-6/spr/summary1' into users/minglotus-6/…
mingmingl-llvm 23a3fa4
simplify code
mingmingl-llvm a0277b4
Flag gate the import-declaration change.
mingmingl-llvm 5edeccc
stage changes
mingmingl-llvm a139e4a
Add test coverage for import delcaration
mingmingl-llvm 916dc96
add test coverage for function alias
mingmingl-llvm 248fbfb
llvm-lto test coverage
mingmingl-llvm 5e731ec
add test coverage for debugging log, and a RUN line for internalization
mingmingl-llvm c5e168e
Merge branch 'main' into users/minglotus-6/spr/summary1
mingmingl-llvm 2c38b47
resolve review feedback
mingmingl-llvm 3da9b8b
Merge branch 'users/minglotus-6/spr/summary1' into users/minglotus-6/…
mingmingl-llvm f1d22e1
Diffbase is updated (https://github.com/llvm/llvm-project/pull/87600/…
mingmingl-llvm 86f3f44
resolve review feedback
mingmingl-llvm 001a785
update this patch as the second one
mingmingl-llvm 321f6aa
update stale comment and use 'DAG' for check lines
mingmingl-llvm 31d9bd2
add comment for 'DecSummaries' parameter in FunctionImport.h
mingmingl-llvm ac8e9fa
run 'git merge main'
mingmingl-llvm bde377c
resolve review feedback
mingmingl-llvm 779dcf3
Update regression test:
mingmingl-llvm 41f8e2b
resolve merge conflict
mingmingl-llvm bf4bdeb
use std::unordered_set
mingmingl-llvm 73953c1
resolve comments
mingmingl-llvm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -425,6 +425,11 @@ class IndexBitcodeWriter : public BitcodeWriterBase { | |
/// The combined index to write to bitcode. | ||
const ModuleSummaryIndex &Index; | ||
|
||
/// When writing combined summaries, provides the set of global value | ||
/// summaries for which the value (function, function alias, etc) should be | ||
/// imported as a declaration. | ||
const GVSummaryPtrSet *DecSummaries = nullptr; | ||
|
||
/// When writing a subset of the index for distributed backends, client | ||
/// provides a map of modules to the corresponding GUIDs/summaries to write. | ||
const std::map<std::string, GVSummaryMapTy> *ModuleToSummariesForIndex; | ||
|
@@ -453,11 +458,16 @@ class IndexBitcodeWriter : public BitcodeWriterBase { | |
/// Constructs a IndexBitcodeWriter object for the given combined index, | ||
/// writing to the provided \p Buffer. When writing a subset of the index | ||
/// for a distributed backend, provide a \p ModuleToSummariesForIndex map. | ||
/// If provided, \p ModuleToDecSummaries specifies the set of summaries for | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: DecSummaries? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done. |
||
/// which the corresponding functions or aliased functions should be imported | ||
/// as a declaration (but not definition) for each module. | ||
IndexBitcodeWriter(BitstreamWriter &Stream, StringTableBuilder &StrtabBuilder, | ||
const ModuleSummaryIndex &Index, | ||
const GVSummaryPtrSet *DecSummaries = nullptr, | ||
const std::map<std::string, GVSummaryMapTy> | ||
*ModuleToSummariesForIndex = nullptr) | ||
: BitcodeWriterBase(Stream, StrtabBuilder), Index(Index), | ||
DecSummaries(DecSummaries), | ||
ModuleToSummariesForIndex(ModuleToSummariesForIndex) { | ||
|
||
// See if the StackIdIndex was already added to the StackId map and | ||
|
@@ -1226,7 +1236,8 @@ static uint64_t getEncodedFFlags(FunctionSummary::FFlags Flags) { | |
|
||
// Decode the flags for GlobalValue in the summary. See getDecodedGVSummaryFlags | ||
// in BitcodeReader.cpp. | ||
static uint64_t getEncodedGVSummaryFlags(GlobalValueSummary::GVFlags Flags) { | ||
static uint64_t getEncodedGVSummaryFlags(GlobalValueSummary::GVFlags Flags, | ||
bool ImportAsDecl = false) { | ||
uint64_t RawFlags = 0; | ||
|
||
RawFlags |= Flags.NotEligibleToImport; // bool | ||
|
@@ -1241,7 +1252,8 @@ static uint64_t getEncodedGVSummaryFlags(GlobalValueSummary::GVFlags Flags) { | |
|
||
RawFlags |= (Flags.Visibility << 8); // 2 bits | ||
|
||
RawFlags |= (Flags.ImportType << 10); // 1 bit | ||
unsigned ImportType = Flags.ImportType | ImportAsDecl; | ||
RawFlags |= (ImportType << 10); // 1 bit | ||
|
||
return RawFlags; | ||
} | ||
|
@@ -4568,6 +4580,12 @@ void IndexBitcodeWriter::writeCombinedGlobalValueSummary() { | |
Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); | ||
unsigned AllocAbbrev = Stream.EmitAbbrev(std::move(Abbv)); | ||
|
||
auto shouldImportValueAsDecl = [&](GlobalValueSummary *GVS) -> bool { | ||
if (DecSummaries == nullptr) | ||
return false; | ||
return DecSummaries->count(GVS); | ||
}; | ||
|
||
// 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; | ||
|
@@ -4678,7 +4696,8 @@ void IndexBitcodeWriter::writeCombinedGlobalValueSummary() { | |
NameVals.push_back(*ValueId); | ||
assert(ModuleIdMap.count(FS->modulePath())); | ||
NameVals.push_back(ModuleIdMap[FS->modulePath()]); | ||
NameVals.push_back(getEncodedGVSummaryFlags(FS->flags())); | ||
NameVals.push_back( | ||
getEncodedGVSummaryFlags(FS->flags(), shouldImportValueAsDecl(FS))); | ||
NameVals.push_back(FS->instCount()); | ||
NameVals.push_back(getEncodedFFlags(FS->fflags())); | ||
NameVals.push_back(FS->entryCount()); | ||
|
@@ -4727,7 +4746,8 @@ void IndexBitcodeWriter::writeCombinedGlobalValueSummary() { | |
NameVals.push_back(AliasValueId); | ||
assert(ModuleIdMap.count(AS->modulePath())); | ||
NameVals.push_back(ModuleIdMap[AS->modulePath()]); | ||
NameVals.push_back(getEncodedGVSummaryFlags(AS->flags())); | ||
NameVals.push_back( | ||
getEncodedGVSummaryFlags(AS->flags(), shouldImportValueAsDecl(AS))); | ||
auto AliaseeValueId = SummaryToValueIdMap[&AS->getAliasee()]; | ||
assert(AliaseeValueId); | ||
NameVals.push_back(AliaseeValueId); | ||
|
@@ -5068,8 +5088,9 @@ void BitcodeWriter::writeModule(const Module &M, | |
|
||
void BitcodeWriter::writeIndex( | ||
const ModuleSummaryIndex *Index, | ||
const std::map<std::string, GVSummaryMapTy> *ModuleToSummariesForIndex) { | ||
IndexBitcodeWriter IndexWriter(*Stream, StrtabBuilder, *Index, | ||
const std::map<std::string, GVSummaryMapTy> *ModuleToSummariesForIndex, | ||
const GVSummaryPtrSet *DecSummaries) { | ||
IndexBitcodeWriter IndexWriter(*Stream, StrtabBuilder, *Index, DecSummaries, | ||
ModuleToSummariesForIndex); | ||
IndexWriter.write(); | ||
} | ||
|
@@ -5124,12 +5145,13 @@ void IndexBitcodeWriter::write() { | |
// index for a distributed backend, provide a \p ModuleToSummariesForIndex map. | ||
void llvm::writeIndexToFile( | ||
const ModuleSummaryIndex &Index, raw_ostream &Out, | ||
const std::map<std::string, GVSummaryMapTy> *ModuleToSummariesForIndex) { | ||
const std::map<std::string, GVSummaryMapTy> *ModuleToSummariesForIndex, | ||
const GVSummaryPtrSet *DecSummaries) { | ||
SmallVector<char, 0> Buffer; | ||
Buffer.reserve(256 * 1024); | ||
|
||
BitcodeWriter Writer(Buffer); | ||
Writer.writeIndex(&Index, ModuleToSummariesForIndex); | ||
Writer.writeIndex(&Index, ModuleToSummariesForIndex, DecSummaries); | ||
Writer.writeStrtab(); | ||
|
||
Out.write((char *)&Buffer.front(), Buffer.size()); | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah nice -- interesting that SmallPtrSet also has a big jump when growing at small sizes! (
llvm-project/llvm/lib/Support/SmallPtrSet.cpp
Line 43 in 393eff4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes I corrected the patch description with this link. thanks!