machinst: Avoid a full instructions traversal of all the blocks when computing the final block ordering;

This commit is contained in:
Benjamin Bouvier
2020-05-05 18:58:47 +02:00
parent 162fcd3d75
commit 1d90751ba9
3 changed files with 22 additions and 18 deletions

View File

@@ -18,8 +18,7 @@
//! backend pipeline.
use crate::entity::SecondaryMap;
use crate::ir;
use crate::ir::SourceLoc;
use crate::ir::{self, Block, SourceLoc};
use crate::machinst::*;
use crate::settings;
@@ -101,6 +100,9 @@ pub struct VCode<I: VCodeInst> {
/// ABI object.
abi: Box<dyn ABIBody<I = I>>,
/// The block targeted by fallthrough_returns, if there's one.
pub fallthrough_return_block: Option<BlockIndex>,
}
/// A builder for a VCode function body. This builder is designed for the
@@ -153,6 +155,16 @@ impl<I: VCodeInst> VCodeBuilder<I> {
&mut *self.vcode.abi
}
/// Set the fallthrough_return target block for this function. There must be at most once per
/// function.
pub fn set_fallthrough_return_block(&mut self, bb: Block) {
debug_assert!(
self.vcode.fallthrough_return_block.is_none(),
"a function must have at most one fallthrough-return instruction"
);
self.vcode.fallthrough_return_block = Some(self.bb_to_bindex(bb));
}
/// Set the type of a VReg.
pub fn set_vreg_type(&mut self, vreg: VirtualReg, ty: Type) {
while self.vcode.vreg_types.len() <= vreg.get_index() {
@@ -315,6 +327,7 @@ impl<I: VCodeInst> VCode<I> {
final_block_offsets: vec![],
code_size: 0,
abi,
fallthrough_return_block: None,
}
}