-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
x86_64: align loop headers to 64 bytes #5004
Open
pepyakin
wants to merge
1
commit into
bytecodealliance:main
Choose a base branch
from
pepyakin:pep-align-loops
base: main
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.
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 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 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 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 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 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 |
---|---|---|
|
@@ -106,6 +106,8 @@ pub struct BlockLoweringOrder { | |
/// which is used by VCode emission to sink the blocks at the last | ||
/// moment (when we actually emit bytes into the MachBuffer). | ||
cold_blocks: FxHashSet<BlockIndex>, | ||
/// These are loop headers. Used for alignment. | ||
loop_headers: FxHashSet<BlockIndex>, | ||
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. Would it make sense to merge |
||
/// Lowered blocks that are indirect branch targets. | ||
indirect_branch_targets: FxHashSet<BlockIndex>, | ||
} | ||
|
@@ -438,6 +440,7 @@ impl BlockLoweringOrder { | |
// Step 3: now that we have RPO, build the BlockIndex/BB fwd/rev maps. | ||
let mut lowered_order = vec![]; | ||
let mut cold_blocks = FxHashSet::default(); | ||
let mut loop_headers = FxHashSet::default(); | ||
let mut lowered_succ_ranges = vec![]; | ||
let mut lb_to_bindex = FxHashMap::default(); | ||
let mut indirect_branch_targets = FxHashSet::default(); | ||
|
@@ -455,6 +458,10 @@ impl BlockLoweringOrder { | |
cold_blocks.insert(index); | ||
} | ||
|
||
if f.layout.is_loop_header(block) { | ||
loop_headers.insert(index); | ||
} | ||
|
||
if indirect_branch_target_clif_blocks.contains(&block) { | ||
indirect_branch_targets.insert(index); | ||
} | ||
|
@@ -464,6 +471,10 @@ impl BlockLoweringOrder { | |
cold_blocks.insert(index); | ||
} | ||
|
||
if f.layout.is_loop_header(pred) || f.layout.is_loop_header(succ) { | ||
loop_headers.insert(index); | ||
} | ||
|
||
if indirect_branch_target_clif_blocks.contains(&succ) { | ||
indirect_branch_targets.insert(index); | ||
} | ||
|
@@ -491,6 +502,7 @@ impl BlockLoweringOrder { | |
lowered_succ_ranges, | ||
orig_map, | ||
cold_blocks, | ||
loop_headers, | ||
indirect_branch_targets, | ||
}; | ||
trace!("BlockLoweringOrder: {:?}", result); | ||
|
@@ -513,6 +525,11 @@ impl BlockLoweringOrder { | |
self.cold_blocks.contains(&block) | ||
} | ||
|
||
/// Determine whether the given lowered-block index is a loop header. | ||
pub fn is_loop_header(&self, block: BlockIndex) -> bool { | ||
self.loop_headers.contains(&block) | ||
} | ||
|
||
/// Determine whether the given lowered block index is an indirect branch | ||
/// target. | ||
pub fn is_indirect_branch_target(&self, block: BlockIndex) -> bool { | ||
|
This file contains 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 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.
Could you disable this when optimizing for size? Also won't this cause a large blowup when there are a lot of tiny loops in a function with multiple being able to fit in a single cacheline?
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.
Also maybe disable it for cold blocks?