* Manually rename BasicBlock to BlockPredecessor BasicBlock is a pair of (Ebb, Inst) that is used to represent the basic block subcomponent of an Ebb that is a predecessor to an Ebb. Eventually we will be able to remove this struct, but for now it makes sense to give it a non-conflicting name so that we can start to transition Ebb to represent a basic block. I have not updated any comments that refer to BasicBlock, as eventually we will remove BlockPredecessor and replace with Block, which is a basic block, so the comments will become correct. * Manually rename SSABuilder block types to avoid conflict SSABuilder has its own Block and BlockData types. These along with associated identifier will cause conflicts in a later commit, so they are renamed to be more verbose here. * Automatically rename 'Ebb' to 'Block' in *.rs * Automatically rename 'EBB' to 'block' in *.rs * Automatically rename 'ebb' to 'block' in *.rs * Automatically rename 'extended basic block' to 'basic block' in *.rs * Automatically rename 'an basic block' to 'a basic block' in *.rs * Manually update comment for `Block` `Block`'s wikipedia article required an update. * Automatically rename 'an `Block`' to 'a `Block`' in *.rs * Automatically rename 'extended_basic_block' to 'basic_block' in *.rs * Automatically rename 'ebb' to 'block' in *.clif * Manually rename clif constant that contains 'ebb' as substring to avoid conflict * Automatically rename filecheck uses of 'EBB' to 'BB' 'regex: EBB' -> 'regex: BB' '$EBB' -> '$BB' * Automatically rename 'EBB' 'Ebb' to 'block' in *.clif * Automatically rename 'an block' to 'a block' in *.clif * Fix broken testcase when function name length increases Test function names are limited to 16 characters. This causes the new longer name to be truncated and fail a filecheck test. An outdated comment was also fixed.
74 lines
3.0 KiB
Rust
74 lines
3.0 KiB
Rust
//! Instruction shrinking.
|
|
//!
|
|
//! Sometimes there are multiple valid encodings for a given instruction. Cranelift often initially
|
|
//! chooses the largest one, because this typically provides the register allocator the most
|
|
//! flexibility. However, once register allocation is done, this is no longer important, and we
|
|
//! can switch to smaller encodings when possible.
|
|
|
|
use crate::ir::instructions::InstructionData;
|
|
use crate::ir::Function;
|
|
use crate::isa::TargetIsa;
|
|
use crate::regalloc::RegDiversions;
|
|
use crate::timing;
|
|
use log::debug;
|
|
|
|
/// Pick the smallest valid encodings for instructions.
|
|
pub fn shrink_instructions(func: &mut Function, isa: &dyn TargetIsa) {
|
|
let _tt = timing::shrink_instructions();
|
|
|
|
let encinfo = isa.encoding_info();
|
|
let mut divert = RegDiversions::new();
|
|
|
|
for block in func.layout.blocks() {
|
|
// Load diversions from predecessors.
|
|
divert.at_block(&func.entry_diversions, block);
|
|
|
|
for inst in func.layout.block_insts(block) {
|
|
let enc = func.encodings[inst];
|
|
if enc.is_legal() {
|
|
// regmove/regfill/regspill are special instructions with register immediates
|
|
// that represented as normal operands, so the normal predicates below don't
|
|
// handle them correctly.
|
|
//
|
|
// Also, they need to be presented to the `RegDiversions` to update the
|
|
// location tracking.
|
|
//
|
|
// TODO: Eventually, we want the register allocator to avoid leaving these special
|
|
// instructions behind, but for now, just temporarily avoid trying to shrink them.
|
|
let inst_data = &func.dfg[inst];
|
|
match inst_data {
|
|
InstructionData::RegMove { .. }
|
|
| InstructionData::RegFill { .. }
|
|
| InstructionData::RegSpill { .. } => {
|
|
divert.apply(inst_data);
|
|
continue;
|
|
}
|
|
_ => (),
|
|
}
|
|
|
|
let ctrl_type = func.dfg.ctrl_typevar(inst);
|
|
|
|
// Pick the last encoding with constraints that are satisfied.
|
|
let best_enc = isa
|
|
.legal_encodings(func, &func.dfg[inst], ctrl_type)
|
|
.filter(|e| encinfo.constraints[e.recipe()].satisfied(inst, &divert, &func))
|
|
.min_by_key(|e| encinfo.byte_size(*e, inst, &divert, &func))
|
|
.unwrap();
|
|
|
|
if best_enc != enc {
|
|
func.encodings[inst] = best_enc;
|
|
|
|
debug!(
|
|
"Shrunk [{}] to [{}] in {}, reducing the size from {} to {}",
|
|
encinfo.display(enc),
|
|
encinfo.display(best_enc),
|
|
func.dfg.display_inst(inst, isa),
|
|
encinfo.byte_size(enc, inst, &divert, &func),
|
|
encinfo.byte_size(best_enc, inst, &divert, &func)
|
|
);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|