-
Notifications
You must be signed in to change notification settings - Fork 120
Add hierarchical discriminator multiplicity support #257
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
Open
kugan-nv
wants to merge
1
commit into
google:master
Choose a base branch
from
kugan-nv:hd1
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+73
−2
Open
Changes from all commits
Commits
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| // Discriminator encoding utilities for AutoFDO | ||
| // Similar to LLVM's discriminator encoding scheme | ||
| // | ||
| // Discriminator format: [Base:8][Multiplicity:7][CopyID:11][Unused:6] | ||
| // - Base discriminator (bits 0-7): Distinguishes instructions at same line | ||
| // - Multiplicity (bits 8-14): Duplication factor for unrolling/vectorization | ||
| // - CopyID (bits 15-25): Unique identifier for code copies | ||
| // - Unused (bits 26-31): Reserved | ||
|
|
||
| #ifndef AUTOFDO_DISCRIMINATOR_ENCODING_H_ | ||
| #define AUTOFDO_DISCRIMINATOR_ENCODING_H_ | ||
|
|
||
| #include <cstdint> | ||
|
|
||
| namespace devtools_crosstool_autofdo { | ||
|
|
||
| // Extract base discriminator (bits 0-7) | ||
| inline uint32_t GetBaseDiscriminator(uint32_t discriminator) { | ||
| return discriminator & 0xFF; | ||
| } | ||
|
|
||
| // Extract multiplicity/duplication factor (bits 8-14) | ||
| // Returns 1 if multiplicity bits are 0 (no duplication) | ||
| inline uint32_t GetMultiplicity(uint32_t discriminator) { | ||
| uint32_t mult = (discriminator >> 8) & 0x7F; | ||
| return (mult == 0) ? 1 : mult; | ||
| } | ||
|
|
||
| // Extract copy ID (bits 15-25) | ||
| inline uint32_t GetCopyID(uint32_t discriminator) { | ||
| return (discriminator >> 15) & 0x7FF; | ||
| } | ||
|
|
||
| // Encode discriminator from components | ||
| inline uint32_t EncodeDiscriminator(uint32_t base, uint32_t multiplicity, | ||
| uint32_t copy_id) { | ||
| // Validate ranges | ||
| if (base > 0xFF || multiplicity > 127 || copy_id > 0x7FF) { | ||
| return base; // Fallback to just base if encoding fails | ||
| } | ||
| return base | (multiplicity << 8) | (copy_id << 15); | ||
| } | ||
|
|
||
| // Check if discriminator has multiplicity encoded | ||
| inline bool HasMultiplicity(uint32_t discriminator) { | ||
| return GetMultiplicity(discriminator) > 1; | ||
| } | ||
|
|
||
| // Check if discriminator has copy ID encoded | ||
| inline bool HasCopyID(uint32_t discriminator) { | ||
| return GetCopyID(discriminator) != 0; | ||
| } | ||
|
|
||
| } // namespace devtools_crosstool_autofdo | ||
|
|
||
| #endif // AUTOFDO_DISCRIMINATOR_ENCODING_H_ | ||
|
|
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
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.
This is not called from anywhere , is it?