Mass rename Ebb and relatives to Block (#1365)
* 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.
This commit is contained in:
@@ -23,13 +23,13 @@ type EntryIndex = u64;
|
||||
/// # let mut func = Function::with_name_signature(ExternalName::user(0, 0), sig);
|
||||
/// # let mut builder = FunctionBuilder::new(&mut func, &mut fn_builder_ctx);
|
||||
/// #
|
||||
/// # let entry = builder.create_ebb();
|
||||
/// # let entry = builder.create_block();
|
||||
/// # builder.switch_to_block(entry);
|
||||
/// #
|
||||
/// let block0 = builder.create_ebb();
|
||||
/// let block1 = builder.create_ebb();
|
||||
/// let block2 = builder.create_ebb();
|
||||
/// let fallback = builder.create_ebb();
|
||||
/// let block0 = builder.create_block();
|
||||
/// let block1 = builder.create_block();
|
||||
/// let block2 = builder.create_block();
|
||||
/// let fallback = builder.create_block();
|
||||
///
|
||||
/// let val = builder.ins().iconst(I32, 1);
|
||||
///
|
||||
@@ -41,7 +41,7 @@ type EntryIndex = u64;
|
||||
/// ```
|
||||
#[derive(Debug, Default)]
|
||||
pub struct Switch {
|
||||
cases: HashMap<EntryIndex, Ebb>,
|
||||
cases: HashMap<EntryIndex, Block>,
|
||||
}
|
||||
|
||||
impl Switch {
|
||||
@@ -53,8 +53,8 @@ impl Switch {
|
||||
}
|
||||
|
||||
/// Set a switch entry
|
||||
pub fn set_entry(&mut self, index: EntryIndex, ebb: Ebb) {
|
||||
let prev = self.cases.insert(index, ebb);
|
||||
pub fn set_entry(&mut self, index: EntryIndex, block: Block) {
|
||||
let prev = self.cases.insert(index, block);
|
||||
assert!(
|
||||
prev.is_none(),
|
||||
"Tried to set the same entry {} twice",
|
||||
@@ -63,7 +63,7 @@ impl Switch {
|
||||
}
|
||||
|
||||
/// Get a reference to all existing entries
|
||||
pub fn entries(&self) -> &HashMap<EntryIndex, Ebb> {
|
||||
pub fn entries(&self) -> &HashMap<EntryIndex, Block> {
|
||||
&self.cases
|
||||
}
|
||||
|
||||
@@ -82,7 +82,7 @@ impl Switch {
|
||||
|
||||
let mut contiguous_case_ranges: Vec<ContiguousCaseRange> = vec![];
|
||||
let mut last_index = None;
|
||||
for (index, ebb) in cases {
|
||||
for (index, block) in cases {
|
||||
match last_index {
|
||||
None => contiguous_case_ranges.push(ContiguousCaseRange::new(index)),
|
||||
Some(last_index) => {
|
||||
@@ -91,7 +91,11 @@ impl Switch {
|
||||
}
|
||||
}
|
||||
}
|
||||
contiguous_case_ranges.last_mut().unwrap().ebbs.push(ebb);
|
||||
contiguous_case_ranges
|
||||
.last_mut()
|
||||
.unwrap()
|
||||
.blocks
|
||||
.push(block);
|
||||
last_index = Some(index);
|
||||
}
|
||||
|
||||
@@ -107,10 +111,10 @@ impl Switch {
|
||||
fn build_search_tree(
|
||||
bx: &mut FunctionBuilder,
|
||||
val: Value,
|
||||
otherwise: Ebb,
|
||||
otherwise: Block,
|
||||
contiguous_case_ranges: Vec<ContiguousCaseRange>,
|
||||
) -> Vec<(EntryIndex, Ebb, Vec<Ebb>)> {
|
||||
let mut cases_and_jt_ebbs = Vec::new();
|
||||
) -> Vec<(EntryIndex, Block, Vec<Block>)> {
|
||||
let mut cases_and_jt_blocks = Vec::new();
|
||||
|
||||
// Avoid allocation in the common case
|
||||
if contiguous_case_ranges.len() <= 3 {
|
||||
@@ -119,17 +123,17 @@ impl Switch {
|
||||
val,
|
||||
otherwise,
|
||||
contiguous_case_ranges,
|
||||
&mut cases_and_jt_ebbs,
|
||||
&mut cases_and_jt_blocks,
|
||||
);
|
||||
return cases_and_jt_ebbs;
|
||||
return cases_and_jt_blocks;
|
||||
}
|
||||
|
||||
let mut stack: Vec<(Option<Ebb>, Vec<ContiguousCaseRange>)> = Vec::new();
|
||||
let mut stack: Vec<(Option<Block>, Vec<ContiguousCaseRange>)> = Vec::new();
|
||||
stack.push((None, contiguous_case_ranges));
|
||||
|
||||
while let Some((ebb, contiguous_case_ranges)) = stack.pop() {
|
||||
if let Some(ebb) = ebb {
|
||||
bx.switch_to_block(ebb);
|
||||
while let Some((block, contiguous_case_ranges)) = stack.pop() {
|
||||
if let Some(block) = block {
|
||||
bx.switch_to_block(block);
|
||||
}
|
||||
|
||||
if contiguous_case_ranges.len() <= 3 {
|
||||
@@ -138,64 +142,68 @@ impl Switch {
|
||||
val,
|
||||
otherwise,
|
||||
contiguous_case_ranges,
|
||||
&mut cases_and_jt_ebbs,
|
||||
&mut cases_and_jt_blocks,
|
||||
);
|
||||
} else {
|
||||
let split_point = contiguous_case_ranges.len() / 2;
|
||||
let mut left = contiguous_case_ranges;
|
||||
let right = left.split_off(split_point);
|
||||
|
||||
let left_ebb = bx.create_ebb();
|
||||
let right_ebb = bx.create_ebb();
|
||||
let left_block = bx.create_block();
|
||||
let right_block = bx.create_block();
|
||||
|
||||
let should_take_right_side = bx.ins().icmp_imm(
|
||||
IntCC::UnsignedGreaterThanOrEqual,
|
||||
val,
|
||||
right[0].first_index as i64,
|
||||
);
|
||||
bx.ins().brnz(should_take_right_side, right_ebb, &[]);
|
||||
bx.ins().jump(left_ebb, &[]);
|
||||
bx.ins().brnz(should_take_right_side, right_block, &[]);
|
||||
bx.ins().jump(left_block, &[]);
|
||||
|
||||
stack.push((Some(left_ebb), left));
|
||||
stack.push((Some(right_ebb), right));
|
||||
stack.push((Some(left_block), left));
|
||||
stack.push((Some(right_block), right));
|
||||
}
|
||||
}
|
||||
|
||||
cases_and_jt_ebbs
|
||||
cases_and_jt_blocks
|
||||
}
|
||||
|
||||
/// Linear search for the right `ContiguousCaseRange`.
|
||||
fn build_search_branches(
|
||||
bx: &mut FunctionBuilder,
|
||||
val: Value,
|
||||
otherwise: Ebb,
|
||||
otherwise: Block,
|
||||
contiguous_case_ranges: Vec<ContiguousCaseRange>,
|
||||
cases_and_jt_ebbs: &mut Vec<(EntryIndex, Ebb, Vec<Ebb>)>,
|
||||
cases_and_jt_blocks: &mut Vec<(EntryIndex, Block, Vec<Block>)>,
|
||||
) {
|
||||
let mut was_branch = false;
|
||||
let ins_fallthrough_jump = |was_branch: bool, bx: &mut FunctionBuilder| {
|
||||
if was_branch {
|
||||
let ebb = bx.create_ebb();
|
||||
bx.ins().jump(ebb, &[]);
|
||||
bx.switch_to_block(ebb);
|
||||
let block = bx.create_block();
|
||||
bx.ins().jump(block, &[]);
|
||||
bx.switch_to_block(block);
|
||||
}
|
||||
};
|
||||
for ContiguousCaseRange { first_index, ebbs } in contiguous_case_ranges.into_iter().rev() {
|
||||
match (ebbs.len(), first_index) {
|
||||
for ContiguousCaseRange {
|
||||
first_index,
|
||||
blocks,
|
||||
} in contiguous_case_ranges.into_iter().rev()
|
||||
{
|
||||
match (blocks.len(), first_index) {
|
||||
(1, 0) => {
|
||||
ins_fallthrough_jump(was_branch, bx);
|
||||
bx.ins().brz(val, ebbs[0], &[]);
|
||||
bx.ins().brz(val, blocks[0], &[]);
|
||||
}
|
||||
(1, _) => {
|
||||
ins_fallthrough_jump(was_branch, bx);
|
||||
let is_good_val = bx.ins().icmp_imm(IntCC::Equal, val, first_index as i64);
|
||||
bx.ins().brnz(is_good_val, ebbs[0], &[]);
|
||||
bx.ins().brnz(is_good_val, blocks[0], &[]);
|
||||
}
|
||||
(_, 0) => {
|
||||
// if `first_index` is 0, then `icmp_imm uge val, first_index` is trivially true
|
||||
let jt_ebb = bx.create_ebb();
|
||||
bx.ins().jump(jt_ebb, &[]);
|
||||
cases_and_jt_ebbs.push((first_index, jt_ebb, ebbs));
|
||||
let jt_block = bx.create_block();
|
||||
bx.ins().jump(jt_block, &[]);
|
||||
cases_and_jt_blocks.push((first_index, jt_block, blocks));
|
||||
// `jump otherwise` below must not be hit, because the current block has been
|
||||
// filled above. This is the last iteration anyway, as 0 is the smallest
|
||||
// unsigned int, so just return here.
|
||||
@@ -203,14 +211,14 @@ impl Switch {
|
||||
}
|
||||
(_, _) => {
|
||||
ins_fallthrough_jump(was_branch, bx);
|
||||
let jt_ebb = bx.create_ebb();
|
||||
let jt_block = bx.create_block();
|
||||
let is_good_val = bx.ins().icmp_imm(
|
||||
IntCC::UnsignedGreaterThanOrEqual,
|
||||
val,
|
||||
first_index as i64,
|
||||
);
|
||||
bx.ins().brnz(is_good_val, jt_ebb, &[]);
|
||||
cases_and_jt_ebbs.push((first_index, jt_ebb, ebbs));
|
||||
bx.ins().brnz(is_good_val, jt_block, &[]);
|
||||
cases_and_jt_blocks.push((first_index, jt_block, blocks));
|
||||
}
|
||||
}
|
||||
was_branch = true;
|
||||
@@ -219,21 +227,21 @@ impl Switch {
|
||||
bx.ins().jump(otherwise, &[]);
|
||||
}
|
||||
|
||||
/// For every item in `cases_and_jt_ebbs` this will create a jump table in the specified ebb.
|
||||
/// For every item in `cases_and_jt_blocks` this will create a jump table in the specified block.
|
||||
fn build_jump_tables(
|
||||
bx: &mut FunctionBuilder,
|
||||
val: Value,
|
||||
otherwise: Ebb,
|
||||
cases_and_jt_ebbs: Vec<(EntryIndex, Ebb, Vec<Ebb>)>,
|
||||
otherwise: Block,
|
||||
cases_and_jt_blocks: Vec<(EntryIndex, Block, Vec<Block>)>,
|
||||
) {
|
||||
for (first_index, jt_ebb, ebbs) in cases_and_jt_ebbs.into_iter().rev() {
|
||||
for (first_index, jt_block, blocks) in cases_and_jt_blocks.into_iter().rev() {
|
||||
let mut jt_data = JumpTableData::new();
|
||||
for ebb in ebbs {
|
||||
jt_data.push_entry(ebb);
|
||||
for block in blocks {
|
||||
jt_data.push_entry(block);
|
||||
}
|
||||
let jump_table = bx.create_jump_table(jt_data);
|
||||
|
||||
bx.switch_to_block(jt_ebb);
|
||||
bx.switch_to_block(jt_block);
|
||||
let discr = if first_index == 0 {
|
||||
val
|
||||
} else {
|
||||
@@ -249,8 +257,8 @@ impl Switch {
|
||||
///
|
||||
/// * The function builder to emit to
|
||||
/// * The value to switch on
|
||||
/// * The default ebb
|
||||
pub fn emit(self, bx: &mut FunctionBuilder, val: Value, otherwise: Ebb) {
|
||||
/// * The default block
|
||||
pub fn emit(self, bx: &mut FunctionBuilder, val: Value, otherwise: Block) {
|
||||
// FIXME icmp(_imm) doesn't have encodings for i8 and i16 on x86(_64) yet
|
||||
let val = match bx.func.dfg.value_type(val) {
|
||||
types::I8 | types::I16 => bx.ins().uextend(types::I32, val),
|
||||
@@ -258,19 +266,20 @@ impl Switch {
|
||||
};
|
||||
|
||||
let contiguous_case_ranges = self.collect_contiguous_case_ranges();
|
||||
let cases_and_jt_ebbs = Self::build_search_tree(bx, val, otherwise, contiguous_case_ranges);
|
||||
Self::build_jump_tables(bx, val, otherwise, cases_and_jt_ebbs);
|
||||
let cases_and_jt_blocks =
|
||||
Self::build_search_tree(bx, val, otherwise, contiguous_case_ranges);
|
||||
Self::build_jump_tables(bx, val, otherwise, cases_and_jt_blocks);
|
||||
}
|
||||
}
|
||||
|
||||
/// This represents a contiguous range of cases to switch on.
|
||||
///
|
||||
/// For example 10 => ebb1, 11 => ebb2, 12 => ebb7 will be represented as:
|
||||
/// For example 10 => block1, 11 => block2, 12 => block7 will be represented as:
|
||||
///
|
||||
/// ```plain
|
||||
/// ContiguousCaseRange {
|
||||
/// first_index: 10,
|
||||
/// ebbs: vec![Ebb::from_u32(1), Ebb::from_u32(2), Ebb::from_u32(7)]
|
||||
/// blocks: vec![Block::from_u32(1), Block::from_u32(2), Block::from_u32(7)]
|
||||
/// }
|
||||
/// ```
|
||||
#[derive(Debug)]
|
||||
@@ -278,15 +287,15 @@ struct ContiguousCaseRange {
|
||||
/// The entry index of the first case. Eg. 10 when the entry indexes are 10, 11, 12 and 13.
|
||||
first_index: EntryIndex,
|
||||
|
||||
/// The ebbs to jump to sorted in ascending order of entry index.
|
||||
ebbs: Vec<Ebb>,
|
||||
/// The blocks to jump to sorted in ascending order of entry index.
|
||||
blocks: Vec<Block>,
|
||||
}
|
||||
|
||||
impl ContiguousCaseRange {
|
||||
fn new(first_index: EntryIndex) -> Self {
|
||||
Self {
|
||||
first_index,
|
||||
ebbs: Vec::new(),
|
||||
blocks: Vec::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -304,15 +313,15 @@ mod tests {
|
||||
let mut func_ctx = FunctionBuilderContext::new();
|
||||
{
|
||||
let mut bx = FunctionBuilder::new(&mut func, &mut func_ctx);
|
||||
let ebb = bx.create_ebb();
|
||||
bx.switch_to_block(ebb);
|
||||
let block = bx.create_block();
|
||||
bx.switch_to_block(block);
|
||||
let val = bx.ins().iconst(types::I8, 0);
|
||||
let mut switch = Switch::new();
|
||||
$(
|
||||
let ebb = bx.create_ebb();
|
||||
switch.set_entry($index, ebb);
|
||||
let block = bx.create_block();
|
||||
switch.set_entry($index, block);
|
||||
)*
|
||||
switch.emit(&mut bx, val, Ebb::with_number($default).unwrap());
|
||||
switch.emit(&mut bx, val, Block::with_number($default).unwrap());
|
||||
}
|
||||
func
|
||||
.to_string()
|
||||
@@ -327,11 +336,11 @@ mod tests {
|
||||
let func = setup!(0, [0,]);
|
||||
assert_eq!(
|
||||
func,
|
||||
"ebb0:
|
||||
"block0:
|
||||
v0 = iconst.i8 0
|
||||
v1 = uextend.i32 v0
|
||||
brz v1, ebb1
|
||||
jump ebb0"
|
||||
brz v1, block1
|
||||
jump block0"
|
||||
);
|
||||
}
|
||||
|
||||
@@ -340,12 +349,12 @@ mod tests {
|
||||
let func = setup!(0, [1,]);
|
||||
assert_eq!(
|
||||
func,
|
||||
"ebb0:
|
||||
"block0:
|
||||
v0 = iconst.i8 0
|
||||
v1 = uextend.i32 v0
|
||||
v2 = icmp_imm eq v1, 1
|
||||
brnz v2, ebb1
|
||||
jump ebb0"
|
||||
brnz v2, block1
|
||||
jump block0"
|
||||
);
|
||||
}
|
||||
|
||||
@@ -354,15 +363,15 @@ mod tests {
|
||||
let func = setup!(0, [0, 1,]);
|
||||
assert_eq!(
|
||||
func,
|
||||
" jt0 = jump_table [ebb1, ebb2]
|
||||
" jt0 = jump_table [block1, block2]
|
||||
|
||||
ebb0:
|
||||
block0:
|
||||
v0 = iconst.i8 0
|
||||
v1 = uextend.i32 v0
|
||||
jump ebb3
|
||||
jump block3
|
||||
|
||||
ebb3:
|
||||
br_table.i32 v1, ebb0, jt0"
|
||||
block3:
|
||||
br_table.i32 v1, block0, jt0"
|
||||
);
|
||||
}
|
||||
|
||||
@@ -371,16 +380,16 @@ ebb3:
|
||||
let func = setup!(0, [0, 2,]);
|
||||
assert_eq!(
|
||||
func,
|
||||
"ebb0:
|
||||
"block0:
|
||||
v0 = iconst.i8 0
|
||||
v1 = uextend.i32 v0
|
||||
v2 = icmp_imm eq v1, 2
|
||||
brnz v2, ebb2
|
||||
jump ebb3
|
||||
brnz v2, block2
|
||||
jump block3
|
||||
|
||||
ebb3:
|
||||
brz.i32 v1, ebb1
|
||||
jump ebb0"
|
||||
block3:
|
||||
brz.i32 v1, block1
|
||||
jump block0"
|
||||
);
|
||||
}
|
||||
|
||||
@@ -389,37 +398,37 @@ ebb3:
|
||||
let func = setup!(0, [0, 1, 5, 7, 10, 11, 12,]);
|
||||
assert_eq!(
|
||||
func,
|
||||
" jt0 = jump_table [ebb1, ebb2]
|
||||
jt1 = jump_table [ebb5, ebb6, ebb7]
|
||||
" jt0 = jump_table [block1, block2]
|
||||
jt1 = jump_table [block5, block6, block7]
|
||||
|
||||
ebb0:
|
||||
block0:
|
||||
v0 = iconst.i8 0
|
||||
v1 = uextend.i32 v0
|
||||
v2 = icmp_imm uge v1, 7
|
||||
brnz v2, ebb9
|
||||
jump ebb8
|
||||
brnz v2, block9
|
||||
jump block8
|
||||
|
||||
ebb9:
|
||||
block9:
|
||||
v3 = icmp_imm.i32 uge v1, 10
|
||||
brnz v3, ebb10
|
||||
jump ebb11
|
||||
brnz v3, block10
|
||||
jump block11
|
||||
|
||||
ebb11:
|
||||
block11:
|
||||
v4 = icmp_imm.i32 eq v1, 7
|
||||
brnz v4, ebb4
|
||||
jump ebb0
|
||||
brnz v4, block4
|
||||
jump block0
|
||||
|
||||
ebb8:
|
||||
block8:
|
||||
v5 = icmp_imm.i32 eq v1, 5
|
||||
brnz v5, ebb3
|
||||
jump ebb12
|
||||
brnz v5, block3
|
||||
jump block12
|
||||
|
||||
ebb12:
|
||||
br_table.i32 v1, ebb0, jt0
|
||||
block12:
|
||||
br_table.i32 v1, block0, jt0
|
||||
|
||||
ebb10:
|
||||
block10:
|
||||
v6 = iadd_imm.i32 v1, -10
|
||||
br_table v6, ebb0, jt1"
|
||||
br_table v6, block0, jt1"
|
||||
);
|
||||
}
|
||||
|
||||
@@ -428,17 +437,17 @@ ebb10:
|
||||
let func = setup!(0, [::core::i64::MIN as u64, 1,]);
|
||||
assert_eq!(
|
||||
func,
|
||||
"ebb0:
|
||||
"block0:
|
||||
v0 = iconst.i8 0
|
||||
v1 = uextend.i32 v0
|
||||
v2 = icmp_imm eq v1, 0x8000_0000_0000_0000
|
||||
brnz v2, ebb1
|
||||
jump ebb3
|
||||
brnz v2, block1
|
||||
jump block3
|
||||
|
||||
ebb3:
|
||||
block3:
|
||||
v3 = icmp_imm.i32 eq v1, 1
|
||||
brnz v3, ebb2
|
||||
jump ebb0"
|
||||
brnz v3, block2
|
||||
jump block0"
|
||||
);
|
||||
}
|
||||
|
||||
@@ -447,17 +456,17 @@ ebb3:
|
||||
let func = setup!(0, [::core::i64::MAX as u64, 1,]);
|
||||
assert_eq!(
|
||||
func,
|
||||
"ebb0:
|
||||
"block0:
|
||||
v0 = iconst.i8 0
|
||||
v1 = uextend.i32 v0
|
||||
v2 = icmp_imm eq v1, 0x7fff_ffff_ffff_ffff
|
||||
brnz v2, ebb1
|
||||
jump ebb3
|
||||
brnz v2, block1
|
||||
jump block3
|
||||
|
||||
ebb3:
|
||||
block3:
|
||||
v3 = icmp_imm.i32 eq v1, 1
|
||||
brnz v3, ebb2
|
||||
jump ebb0"
|
||||
brnz v3, block2
|
||||
jump block0"
|
||||
)
|
||||
}
|
||||
|
||||
@@ -466,17 +475,17 @@ ebb3:
|
||||
let func = setup!(0, [-1i64 as u64, 0, 1,]);
|
||||
assert_eq!(
|
||||
func,
|
||||
" jt0 = jump_table [ebb2, ebb3]
|
||||
" jt0 = jump_table [block2, block3]
|
||||
|
||||
ebb0:
|
||||
block0:
|
||||
v0 = iconst.i8 0
|
||||
v1 = uextend.i32 v0
|
||||
v2 = icmp_imm eq v1, -1
|
||||
brnz v2, ebb1
|
||||
jump ebb4
|
||||
brnz v2, block1
|
||||
jump block4
|
||||
|
||||
ebb4:
|
||||
br_table.i32 v1, ebb0, jt0"
|
||||
block4:
|
||||
br_table.i32 v1, block0, jt0"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user