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

[nfc]Make InstrProfSymtab non-copyable and non-movable #86882

Merged
merged 3 commits into from
Mar 28, 2024

Conversation

mingmingl-llvm
Copy link
Contributor

  • The direct use case (in pr 66825) is to add llvm::IntervalMap and the allocator required by IntervalMap ctor to class InstrProfSymtab as owned members. The allocator class doesn't have a move-assignment operator; and it's going to take much effort to implement move-assignment operator for the allocator class such that the enclosing class is movable.
  • There is only one use of compiler-generated move-assignment operator in the repo, which is in CoverageMappingReader.cpp. Luckily it's possible to use std::unique_ptr instead in its surrounding code, so did the change.

- The direct use case (in pr 66825) is to add llvm::IntervalMap and allocator to InstrProfSymtab as class members. The allocator class doesn't have a move-assignment operator; and it's going to take much effort to implement move-assignment operator for the allocator class such that its enclosing class is movable.
- There is only one use of compiler-generated move-assignment operator in the repo, which is in CoverageMappingReader.cpp. Luckily it's possible to use std::unique_ptr<InstrProfSymtab> instead in its surrounding code, so did the change.
1. In create method, return error upon nullptr.
2. Update private constructor of BinaryCoverageReader to take a
   unique_ptr, rather than setting unique_ptr immediately after
   class constructor runs.
@mingmingl-llvm mingmingl-llvm marked this pull request as ready for review March 27, 2024 22:37
Copy link
Contributor

@snehasish snehasish left a comment

Choose a reason for hiding this comment

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

lgtm

// Not copyable or movable.
// Consider std::unique_ptr for move.
// InstrProfSymtab has a few containers as class members, so consider
// std::shared_ptr for read-only copy.
Copy link
Contributor

Choose a reason for hiding this comment

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

std::shared_ptr has (some) overhead and since we aren't using it in this change, lets drop this comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sounds good! I also hesitated about whether to mention shared_ptr and added it mainly for completeness.

"Caller must provide ProfileNames");
std::unique_ptr<BinaryCoverageReader> Reader(new BinaryCoverageReader(
std::move(ProfileNames), std::move(FuncRecords)));
InstrProfSymtab &ProfileNamesRef = *Reader->ProfileNames;
Copy link
Contributor

Choose a reason for hiding this comment

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

Can this be const too?
nit: Also prefer just ProfileNames, IMO the Ref suffix is unnecessary.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can this be const too?

It seems readCoverageMappingData and its callees only callInstrProfSymtab::getFuncName, which could be made const. A couple of places need to be updated for the const reference in this line to compile. I'll just keep it non const as it currently is..

nit: Also prefer just ProfileNames, IMO the Ref suffix is unnecessary.

Sure! I renamed input parameter to ProfileNamesPtr and rename the reference to ProfileNames.

@mingmingl-llvm mingmingl-llvm merged commit 2c7610c into llvm:main Mar 28, 2024
3 of 4 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