diff options
| author | bors <bors@rust-lang.org> | 2020-10-26 16:31:38 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2020-10-26 16:31:38 +0000 |
| commit | 35debd4c111610317346f46d791f32551d449bd8 (patch) | |
| tree | 00c1dc66606e7721f4dab74a6048c454950ef3fb /compiler/rustc_codegen_cranelift/src/optimize/code_layout.rs | |
| parent | c96e11c781af319199af77347d55f08085e15453 (diff) | |
| parent | ac4f7deb2f3558d2d923fa6ddcbb7210db9c2d52 (diff) | |
| download | rust-35debd4c111610317346f46d791f32551d449bd8.tar.gz rust-35debd4c111610317346f46d791f32551d449bd8.zip | |
Auto merge of #77975 - bjorn3:cg_clif_subtree3, r=Mark-Simulacrum
Add cg_clif as optional codegen backend Rustc_codegen_cranelift is an alternative codegen backend for rustc based on Cranelift. It has the potential to improve compilation times in debug mode. In my experience the compile time improvements over debug mode LLVM for a clean build are about 20-30% in most cases. This PR adds cg_clif as optional codegen backend. By default it is only enabled for `./x.py check`. It can be enabled for `./x.py build` too by adding `cranelift` to the `rust.codegen-backends` array in `config.toml`. MCP: https://github.com/rust-lang/compiler-team/issues/270 r? `@Mark-Simulacrum`
Diffstat (limited to 'compiler/rustc_codegen_cranelift/src/optimize/code_layout.rs')
| -rw-r--r-- | compiler/rustc_codegen_cranelift/src/optimize/code_layout.rs | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/compiler/rustc_codegen_cranelift/src/optimize/code_layout.rs b/compiler/rustc_codegen_cranelift/src/optimize/code_layout.rs new file mode 100644 index 00000000000..f02732014d1 --- /dev/null +++ b/compiler/rustc_codegen_cranelift/src/optimize/code_layout.rs @@ -0,0 +1,40 @@ +//! This optimization moves cold code to the end of the function. +//! +//! Some code is executed much less often than other code. For example panicking or the +//! landingpads for unwinding. By moving this cold code to the end of the function the average +//! amount of jumps is reduced and the code locality is improved. +//! +//! # Undefined behaviour +//! +//! This optimization doesn't assume anything that isn't already assumed by Cranelift itself. + +use crate::prelude::*; + +pub(super) fn optimize_function(ctx: &mut Context, cold_blocks: &EntitySet<Block>) { + // FIXME Move the block in place instead of remove and append once + // bytecodealliance/cranelift#1339 is implemented. + + let mut block_insts = FxHashMap::default(); + for block in cold_blocks + .keys() + .filter(|&block| cold_blocks.contains(block)) + { + let insts = ctx.func.layout.block_insts(block).collect::<Vec<_>>(); + for &inst in &insts { + ctx.func.layout.remove_inst(inst); + } + block_insts.insert(block, insts); + ctx.func.layout.remove_block(block); + } + + // And then append them at the back again. + for block in cold_blocks + .keys() + .filter(|&block| cold_blocks.contains(block)) + { + ctx.func.layout.append_block(block); + for inst in block_insts.remove(&block).unwrap() { + ctx.func.layout.append_inst(inst, block); + } + } +} |
