Cranelift: add support for cold blocks.

This PR adds a flag to each block that can be set via the frontend/builder
interface that indicates that the block will not be frequently
executed. As such, the compiler backend should place the block "out of
line" in the final machine code, so that the ordinary, more frequent
execution path that excludes the block does not have to jump around it.

This is useful for adding handlers for exceptional conditions
(slow-paths, guard violations) in a way that minimizes performance cost.

Fixes #2747.
This commit is contained in:
Chris Fallin
2022-01-18 17:19:08 -08:00
parent e2b37a57dc
commit f489b83835
3 changed files with 36 additions and 1 deletions

View File

@@ -229,6 +229,14 @@ impl<'a> FunctionBuilder<'a> {
block
}
/// Mark a block as "cold".
///
/// This will try to move it out of the ordinary path of execution
/// when lowered to machine code.
pub fn set_cold_block(&mut self, block: Block) {
self.func.layout.set_cold(block);
}
/// Insert `block` in the layout *after* the existing block `after`.
pub fn insert_block_after(&mut self, block: Block, after: Block) {
self.func.layout.insert_block_after(block, after);