Add a branch relaxation pass for #72.

Compute exact EBB header offsets and check that branches are in range.

Not implemented yet: Relax branches that are not in range.

Invoke the relax_branches() pass from the 'test binemit' file tests so
they can verify the proper encoding of branch instructions too.
This commit is contained in:
Jakob Stoklund Olesen
2017-04-05 14:54:17 -07:00
parent eb1052718b
commit b5c74fdc25
6 changed files with 224 additions and 42 deletions

View File

@@ -324,6 +324,19 @@ impl InstructionData {
}
}
/// Get the single destination of this branch instruction, if it is a single destination
/// branch or jump.
///
/// Multi-destination branches like `br_table` return `None`.
pub fn branch_destination(&self) -> Option<Ebb> {
match self {
&InstructionData::Jump { destination, .. } => Some(destination),
&InstructionData::Branch { destination, .. } => Some(destination),
&InstructionData::BranchIcmp { destination, .. } => Some(destination),
_ => None,
}
}
/// Return information about a call instruction.
///
/// Any instruction that can call another function reveals its call signature here.