Skip to content

[NFCI][BitcodeReader]Read real GUID from VI as opposed to storing it in map #107735

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 2 commits into from
Sep 9, 2024

Conversation

mingmingl-llvm
Copy link
Contributor

@mingmingl-llvm mingmingl-llvm commented Sep 8, 2024

Currently, ValueIdToValueInfoMap [1] stores std::tuple<ValueInfo, GlobalValue::GUID /* original GUID */, GlobalValue::GUID /* real GUID*/ >. This change updates the stored value type to std::pair<ValueInfo, GlobalValue::GUID /* original GUID */>, and reads real GUID from ValueInfo.

When an entry is inserted into ValueIdToValueInfoMap, ValueInfo is created or inserted using real GUID [2]. ValueInfo keeps a pointer to GlobalValueMap [3], using either GUID or {GUID, Name} [4] when reading per-module summaries to create a combined summary.

[1] owned by per module-summary bitcode reader

// The third tuple member is the real GUID of the ValueInfo.
DenseMap<unsigned,
std::tuple<ValueInfo, GlobalValue::GUID, GlobalValue::GUID>>
ValueIdToValueInfoMap;

[2] first, second, third
[3]
GlobalValueSummaryMapTy::value_type *
getOrInsertValuePtr(GlobalValue::GUID GUID) {
return &*GlobalValueMap.emplace(GUID, GlobalValueSummaryInfo(HaveGVs))
.first;
}

[4]
ValueInfo getOrInsertValueInfo(GlobalValue::GUID GUID, StringRef Name) {

and
ValueInfo getOrInsertValueInfo(GlobalValue::GUID GUID) {

@kazutakahirata
Copy link
Contributor

Nice finding! Let me see if I understand things correctly.

  • We always create an instance of ValueInfo with the same GUID as std::get<2>.
  • Once an instance of ValueInfo is created, its pointer portion never changes.
  • The pointer portion of ValueInfo points to an key-value pair of GlobalValueSummaryMapTy, so the key portion, GUID, shouldn't change.

So, std::get<2>(VIAndOriginalGUID) and VIAndOriginalGUID.first.getGUID() must be always the same.

Did I get this right?

@mingmingl-llvm
Copy link
Contributor Author

  • We always create an instance of ValueInfo with the same GUID as std::get<2>.

Yup this is the case for all (first, second, third) insertions.

Once an instance of ValueInfo is created, its pointer portion never changes.
The pointer portion of ValueInfo points to an key-value pair of GlobalValueSummaryMapTy, so the key portion, GUID, shouldn't change.

This is the case as well.

Basically, ValueIdToValueInfoMap is owned and used by the per module-summary bitcode reader, to associate (serialized, per-module) 'value-id' with the (in-memory) value summary (from combined summary).

So the ValueInfo's pointer portion essentially points to the global-value summary entry, which is owned by CombinedIndex.

Since bitcode readers are (reasonably) destructed after the per-module summary content are merged into combined index, this change doesn't help reduce peak memory usage. This change is not complex anyway, so I just thought about sending it out.

Copy link
Contributor

@kazutakahirata kazutakahirata left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. See a comment about "tuple".

@mingmingl-llvm
Copy link
Contributor Author

thanks for the reviews!

@mingmingl-llvm mingmingl-llvm merged commit 7d37172 into llvm:main Sep 9, 2024
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants