Skip to content
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

[BOLT] Embed cold mapping info into function entry in BAT #76903

Conversation

aaupov
Copy link
Contributor

@aaupov aaupov commented Jan 4, 2024

Reduces BAT section size:

  • large binary: to 12283500 bytes (0.32x original size),
  • medium binary: to 1616020 bytes (0.27x original size),
  • small binary: to 404 bytes (0.28x original size).

Test Plan: Updated bolt/test/X86/bolt-address-translation.test

Created using spr 1.3.4
Created using spr 1.3.4

[skip ci]
Created using spr 1.3.4
Created using spr 1.3.4

[skip ci]
Created using spr 1.3.4
Created using spr 1.3.4

[skip ci]
Created using spr 1.3.4
Created using spr 1.3.4

[skip ci]
Created using spr 1.3.4
@rafaelauler rafaelauler self-assigned this Jan 11, 2024
@@ -160,12 +164,31 @@ std::error_code BoltAddressTranslation::parse(StringRef Buf) {
return make_error_code(llvm::errc::io_error);

Error Err(Error::success());
std::vector<uint64_t> HotFuncs;
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this HotFuncs vector going to be used in another diff of this stack? It looks unused to me atm.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's populated by parseMaps<Hot> and read by parseMaps<Cold>.
Cold functions encode indices of parent hot functions (also delta encoded), hence this vector is required.

@@ -78,10 +79,20 @@ class BoltAddressTranslation {

BoltAddressTranslation() {}

/// Write the serialized address translation table for a function.
template <bool Cold>
Copy link
Contributor

Choose a reason for hiding this comment

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

Move to private: ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

/// Write the serialized address translation tables for each reordered
/// function
void write(const BinaryContext &BC, raw_ostream &OS);

/// Read the serialized address translation table for a function.
/// Return a parse error if failed.
template <bool Cold>
Copy link
Contributor

Choose a reason for hiding this comment

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

private: ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@@ -11,6 +11,7 @@

#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/DataExtractor.h"
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure why was this moved here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

DataExtractor type is used in parseMaps declaration

@@ -119,6 +130,7 @@ class BoltAddressTranslation {
uint64_t FuncAddress);

std::map<uint64_t, MapTy> Maps;
std::map<uint64_t, MapTy> ColdMaps;
Copy link
Contributor

Choose a reason for hiding this comment

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

Kind of weird that this is only used for write(), and not during parsing. There is a lost symmetry between write() and parse() after this diff. Maybe move ColdMaps to live inside write() method then, since it is never used outside of it.

Once we write(), we're not able to call translate(), since we lost cold functions in Maps. Not that this workflow was ever used, but if this class was meant to have any sort of "serialize/deserialize" workflow, now they are out of sync, and design-wise it feels off. So maybe we should use both a private "Maps" / "ColdMaps" during write(), so the code doesn't read as if "translate" depends on either write or parse -- it should depends only on parse. And maybe write() should be a stateless static method.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed the use of ColdMaps.

Created using spr 1.3.4

[skip ci]
Created using spr 1.3.4
@aaupov
Copy link
Contributor Author

aaupov commented Jan 12, 2024

@rafaelauler: addressed the feedback you've added.

However, with template bool parameter (Cold) I don't know if we should replace it with a callback. I'm relying on it in follow-up diffs for other purposes – would it make sense to add several callbacks? If you think it would lead to a cleaner code, I'll do that.

aaupov added a commit that referenced this pull request Jan 12, 2024
Created using spr 1.3.4
aaupov added a commit that referenced this pull request Jan 12, 2024
Created using spr 1.3.4
aaupov added a commit that referenced this pull request Jan 12, 2024
Created using spr 1.3.4
aaupov added a commit that referenced this pull request Jan 12, 2024
Created using spr 1.3.4
aaupov added a commit that referenced this pull request Jan 12, 2024
Created using spr 1.3.4
aaupov added a commit that referenced this pull request Jan 12, 2024
Created using spr 1.3.4
aaupov added a commit that referenced this pull request Jan 12, 2024
Created using spr 1.3.4
aaupov added a commit that referenced this pull request Jan 12, 2024
Created using spr 1.3.4
aaupov added a commit that referenced this pull request Jan 12, 2024
Created using spr 1.3.4
Copy link
Contributor

@rafaelauler rafaelauler left a comment

Choose a reason for hiding this comment

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

Thanks, looks good.

@aaupov aaupov changed the base branch from users/aaupov/spr/main.bolt-embed-cold-mapping-info-into-function-entry-in-bat to main January 12, 2024 21:02
@aaupov aaupov merged commit dcba077 into main Jan 12, 2024
7 checks passed
@aaupov aaupov deleted the users/aaupov/spr/bolt-embed-cold-mapping-info-into-function-entry-in-bat branch January 12, 2024 21:02
justinfargnoli pushed a commit to justinfargnoli/llvm-project that referenced this pull request Jan 28, 2024
Reduces BAT section size:
- large binary: to 12283500 bytes (0.32x original size),
- medium binary: to 1616020 bytes (0.27x original size),
- small binary: to 404 bytes (0.28x original size).

Test Plan: Updated bolt/test/X86/bolt-address-translation.test
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.

None yet

2 participants