Remove boolean parameters from instruction builder functions (#5658)

Remove the boolean parameters from the instruction builder functions, as they were only ever used with true. Additionally, change the returns and branches functions to imply terminates_block.
This commit is contained in:
Trevor Elliott
2023-01-30 16:12:05 -08:00
committed by GitHub
parent e4fa355866
commit b5692db7ce
2 changed files with 100 additions and 97 deletions

View File

@@ -171,52 +171,59 @@ impl InstructionBuilder {
self self
} }
#[allow(clippy::wrong_self_convention)] /// Mark this instruction as a block terminator.
pub fn is_terminator(mut self, val: bool) -> Self { pub fn terminates_block(mut self) -> Self {
self.is_terminator = val; self.is_terminator = true;
self self
} }
#[allow(clippy::wrong_self_convention)] /// Mark this instruction as a branch instruction. This also implies that the instruction is a
pub fn is_branch(mut self, val: bool) -> Self { /// block terminator.
self.is_branch = val; pub fn branches(mut self) -> Self {
self.is_branch = true;
self.terminates_block()
}
/// Mark this instruction as a call instruction.
pub fn call(mut self) -> Self {
self.is_call = true;
self self
} }
#[allow(clippy::wrong_self_convention)] /// Mark this instruction as a return instruction. This also implies that the instruction is a
pub fn is_call(mut self, val: bool) -> Self { /// block terminator.
self.is_call = val; pub fn returns(mut self) -> Self {
self.is_return = true;
self.terminates_block()
}
/// Mark this instruction as one that can load from memory.
pub fn can_load(mut self) -> Self {
self.can_load = true;
self self
} }
#[allow(clippy::wrong_self_convention)] /// Mark this instruction as one that can store to memory.
pub fn is_return(mut self, val: bool) -> Self { pub fn can_store(mut self) -> Self {
self.is_return = val; self.can_store = true;
self self
} }
pub fn can_load(mut self, val: bool) -> Self { /// Mark this instruction as possibly trapping.
self.can_load = val; pub fn can_trap(mut self) -> Self {
self.can_trap = true;
self self
} }
pub fn can_store(mut self, val: bool) -> Self { /// Mark this instruction as one that has side-effects.
self.can_store = val; pub fn other_side_effects(mut self) -> Self {
self.other_side_effects = true;
self self
} }
pub fn can_trap(mut self, val: bool) -> Self { /// Mark this instruction as one whose side-effects may be de-duplicated.
self.can_trap = val; pub fn side_effects_idempotent(mut self) -> Self {
self self.side_effects_idempotent = true;
}
pub fn other_side_effects(mut self, val: bool) -> Self {
self.other_side_effects = val;
self
}
pub fn side_effects_idempotent(mut self, val: bool) -> Self {
self.side_effects_idempotent = val;
self self
} }

View File

@@ -34,8 +34,7 @@ fn define_control_flow(
&formats.jump, &formats.jump,
) )
.operands_in(vec![block_call]) .operands_in(vec![block_call])
.is_terminator(true) .branches(),
.is_branch(true),
); );
let ScalarTruthy = &TypeVar::new( let ScalarTruthy = &TypeVar::new(
@@ -60,8 +59,7 @@ fn define_control_flow(
&formats.brif, &formats.brif,
) )
.operands_in(vec![c, block_then, block_else]) .operands_in(vec![c, block_then, block_else])
.is_terminator(true) .branches(),
.is_branch(true),
); );
} }
@@ -96,8 +94,7 @@ fn define_control_flow(
&formats.branch_table, &formats.branch_table,
) )
.operands_in(vec![x, label, JT]) .operands_in(vec![x, label, JT])
.is_terminator(true) .branches(),
.is_branch(true),
); );
} }
@@ -115,9 +112,9 @@ fn define_control_flow(
"#, "#,
&formats.nullary, &formats.nullary,
) )
.other_side_effects(true) .other_side_effects()
.can_load(true) .can_load()
.can_store(true), .can_store(),
); );
{ {
@@ -131,8 +128,8 @@ fn define_control_flow(
&formats.trap, &formats.trap,
) )
.operands_in(vec![code]) .operands_in(vec![code])
.can_trap(true) .can_trap()
.is_terminator(true), .terminates_block(),
); );
let c = &Operand::new("c", ScalarTruthy).with_doc("Controlling value to test"); let c = &Operand::new("c", ScalarTruthy).with_doc("Controlling value to test");
@@ -147,7 +144,7 @@ fn define_control_flow(
&formats.cond_trap, &formats.cond_trap,
) )
.operands_in(vec![c, code]) .operands_in(vec![c, code])
.can_trap(true), .can_trap(),
); );
ig.push( ig.push(
@@ -161,7 +158,7 @@ fn define_control_flow(
&formats.trap, &formats.trap,
) )
.operands_in(vec![code]) .operands_in(vec![code])
.can_trap(true), .can_trap(),
); );
let c = &Operand::new("c", ScalarTruthy).with_doc("Controlling value to test"); let c = &Operand::new("c", ScalarTruthy).with_doc("Controlling value to test");
@@ -176,7 +173,7 @@ fn define_control_flow(
&formats.cond_trap, &formats.cond_trap,
) )
.operands_in(vec![c, code]) .operands_in(vec![c, code])
.can_trap(true), .can_trap(),
); );
ig.push( ig.push(
@@ -190,7 +187,7 @@ fn define_control_flow(
&formats.cond_trap, &formats.cond_trap,
) )
.operands_in(vec![c, code]) .operands_in(vec![c, code])
.can_trap(true), .can_trap(),
); );
} }
@@ -208,8 +205,7 @@ fn define_control_flow(
&formats.multiary, &formats.multiary,
) )
.operands_in(vec![rvals]) .operands_in(vec![rvals])
.is_return(true) .returns(),
.is_terminator(true),
); );
let FN = &Operand::new("FN", &entities.func_ref) let FN = &Operand::new("FN", &entities.func_ref)
@@ -229,7 +225,7 @@ fn define_control_flow(
) )
.operands_in(vec![FN, args]) .operands_in(vec![FN, args])
.operands_out(vec![rvals]) .operands_out(vec![rvals])
.is_call(true), .call(),
); );
let SIG = &Operand::new("SIG", &entities.sig_ref).with_doc("function signature"); let SIG = &Operand::new("SIG", &entities.sig_ref).with_doc("function signature");
@@ -254,7 +250,7 @@ fn define_control_flow(
) )
.operands_in(vec![SIG, callee, args]) .operands_in(vec![SIG, callee, args])
.operands_out(vec![rvals]) .operands_out(vec![rvals])
.is_call(true), .call(),
); );
let FN = &Operand::new("FN", &entities.func_ref) let FN = &Operand::new("FN", &entities.func_ref)
@@ -675,7 +671,7 @@ pub(crate) fn define(
) )
.operands_in(vec![MemFlags, p, Offset]) .operands_in(vec![MemFlags, p, Offset])
.operands_out(vec![a]) .operands_out(vec![a])
.can_load(true), .can_load(),
); );
ig.push( ig.push(
@@ -690,7 +686,7 @@ pub(crate) fn define(
&formats.store, &formats.store,
) )
.operands_in(vec![MemFlags, x, p, Offset]) .operands_in(vec![MemFlags, x, p, Offset])
.can_store(true), .can_store(),
); );
let iExt8 = &TypeVar::new( let iExt8 = &TypeVar::new(
@@ -713,7 +709,7 @@ pub(crate) fn define(
) )
.operands_in(vec![MemFlags, p, Offset]) .operands_in(vec![MemFlags, p, Offset])
.operands_out(vec![a]) .operands_out(vec![a])
.can_load(true), .can_load(),
); );
ig.push( ig.push(
@@ -728,7 +724,7 @@ pub(crate) fn define(
) )
.operands_in(vec![MemFlags, p, Offset]) .operands_in(vec![MemFlags, p, Offset])
.operands_out(vec![a]) .operands_out(vec![a])
.can_load(true), .can_load(),
); );
ig.push( ig.push(
@@ -742,7 +738,7 @@ pub(crate) fn define(
&formats.store, &formats.store,
) )
.operands_in(vec![MemFlags, x, p, Offset]) .operands_in(vec![MemFlags, x, p, Offset])
.can_store(true), .can_store(),
); );
let iExt16 = &TypeVar::new( let iExt16 = &TypeVar::new(
@@ -765,7 +761,7 @@ pub(crate) fn define(
) )
.operands_in(vec![MemFlags, p, Offset]) .operands_in(vec![MemFlags, p, Offset])
.operands_out(vec![a]) .operands_out(vec![a])
.can_load(true), .can_load(),
); );
ig.push( ig.push(
@@ -780,7 +776,7 @@ pub(crate) fn define(
) )
.operands_in(vec![MemFlags, p, Offset]) .operands_in(vec![MemFlags, p, Offset])
.operands_out(vec![a]) .operands_out(vec![a])
.can_load(true), .can_load(),
); );
ig.push( ig.push(
@@ -794,7 +790,7 @@ pub(crate) fn define(
&formats.store, &formats.store,
) )
.operands_in(vec![MemFlags, x, p, Offset]) .operands_in(vec![MemFlags, x, p, Offset])
.can_store(true), .can_store(),
); );
let iExt32 = &TypeVar::new( let iExt32 = &TypeVar::new(
@@ -817,7 +813,7 @@ pub(crate) fn define(
) )
.operands_in(vec![MemFlags, p, Offset]) .operands_in(vec![MemFlags, p, Offset])
.operands_out(vec![a]) .operands_out(vec![a])
.can_load(true), .can_load(),
); );
ig.push( ig.push(
@@ -832,7 +828,7 @@ pub(crate) fn define(
) )
.operands_in(vec![MemFlags, p, Offset]) .operands_in(vec![MemFlags, p, Offset])
.operands_out(vec![a]) .operands_out(vec![a])
.can_load(true), .can_load(),
); );
ig.push( ig.push(
@@ -846,7 +842,7 @@ pub(crate) fn define(
&formats.store, &formats.store,
) )
.operands_in(vec![MemFlags, x, p, Offset]) .operands_in(vec![MemFlags, x, p, Offset])
.can_store(true), .can_store(),
); );
let I16x8 = &TypeVar::new( let I16x8 = &TypeVar::new(
@@ -871,7 +867,7 @@ pub(crate) fn define(
) )
.operands_in(vec![MemFlags, p, Offset]) .operands_in(vec![MemFlags, p, Offset])
.operands_out(vec![a]) .operands_out(vec![a])
.can_load(true), .can_load(),
); );
ig.push( ig.push(
@@ -885,7 +881,7 @@ pub(crate) fn define(
) )
.operands_in(vec![MemFlags, p, Offset]) .operands_in(vec![MemFlags, p, Offset])
.operands_out(vec![a]) .operands_out(vec![a])
.can_load(true), .can_load(),
); );
let I32x4 = &TypeVar::new( let I32x4 = &TypeVar::new(
@@ -910,7 +906,7 @@ pub(crate) fn define(
) )
.operands_in(vec![MemFlags, p, Offset]) .operands_in(vec![MemFlags, p, Offset])
.operands_out(vec![a]) .operands_out(vec![a])
.can_load(true), .can_load(),
); );
ig.push( ig.push(
@@ -924,7 +920,7 @@ pub(crate) fn define(
) )
.operands_in(vec![MemFlags, p, Offset]) .operands_in(vec![MemFlags, p, Offset])
.operands_out(vec![a]) .operands_out(vec![a])
.can_load(true), .can_load(),
); );
let I64x2 = &TypeVar::new( let I64x2 = &TypeVar::new(
@@ -949,7 +945,7 @@ pub(crate) fn define(
) )
.operands_in(vec![MemFlags, p, Offset]) .operands_in(vec![MemFlags, p, Offset])
.operands_out(vec![a]) .operands_out(vec![a])
.can_load(true), .can_load(),
); );
ig.push( ig.push(
@@ -963,7 +959,7 @@ pub(crate) fn define(
) )
.operands_in(vec![MemFlags, p, Offset]) .operands_in(vec![MemFlags, p, Offset])
.operands_out(vec![a]) .operands_out(vec![a])
.can_load(true), .can_load(),
); );
let x = &Operand::new("x", Mem).with_doc("Value to be stored"); let x = &Operand::new("x", Mem).with_doc("Value to be stored");
@@ -988,7 +984,7 @@ pub(crate) fn define(
) )
.operands_in(vec![SS, Offset]) .operands_in(vec![SS, Offset])
.operands_out(vec![a]) .operands_out(vec![a])
.can_load(true), .can_load(),
); );
ig.push( ig.push(
@@ -1007,7 +1003,7 @@ pub(crate) fn define(
&formats.stack_store, &formats.stack_store,
) )
.operands_in(vec![x, SS, Offset]) .operands_in(vec![x, SS, Offset])
.can_store(true), .can_store(),
); );
ig.push( ig.push(
@@ -1039,7 +1035,7 @@ pub(crate) fn define(
) )
.operands_in(vec![DSS]) .operands_in(vec![DSS])
.operands_out(vec![a]) .operands_out(vec![a])
.can_load(true), .can_load(),
); );
ig.push( ig.push(
@@ -1054,7 +1050,7 @@ pub(crate) fn define(
&formats.dynamic_stack_store, &formats.dynamic_stack_store,
) )
.operands_in(vec![x, DSS]) .operands_in(vec![x, DSS])
.can_store(true), .can_store(),
); );
let GV = &Operand::new("GV", &entities.global_value); let GV = &Operand::new("GV", &entities.global_value);
@@ -1123,7 +1119,7 @@ pub(crate) fn define(
&formats.nullary, &formats.nullary,
) )
.operands_out(vec![addr]) .operands_out(vec![addr])
.other_side_effects(true), .other_side_effects(),
); );
ig.push( ig.push(
@@ -1135,7 +1131,7 @@ pub(crate) fn define(
&formats.unary, &formats.unary,
) )
.operands_in(vec![addr]) .operands_in(vec![addr])
.other_side_effects(true), .other_side_effects(),
); );
ig.push( ig.push(
@@ -1379,10 +1375,10 @@ pub(crate) fn define(
) )
.operands_in(vec![c, x, y]) .operands_in(vec![c, x, y])
.operands_out(vec![a]) .operands_out(vec![a])
.other_side_effects(true) .other_side_effects()
// We can de-duplicate spectre selects since the side effect is // We can de-duplicate spectre selects since the side effect is
// idempotent. // idempotent.
.side_effects_idempotent(true), .side_effects_idempotent(),
); );
let c = &Operand::new("c", Any).with_doc("Controlling value to test"); let c = &Operand::new("c", Any).with_doc("Controlling value to test");
@@ -1676,8 +1672,8 @@ pub(crate) fn define(
) )
.operands_in(vec![x, y]) .operands_in(vec![x, y])
.operands_out(vec![a]) .operands_out(vec![a])
.can_trap(true) .can_trap()
.side_effects_idempotent(true), .side_effects_idempotent(),
); );
ig.push( ig.push(
@@ -1695,8 +1691,8 @@ pub(crate) fn define(
) )
.operands_in(vec![x, y]) .operands_in(vec![x, y])
.operands_out(vec![a]) .operands_out(vec![a])
.can_trap(true) .can_trap()
.side_effects_idempotent(true), .side_effects_idempotent(),
); );
ig.push( ig.push(
@@ -1711,8 +1707,8 @@ pub(crate) fn define(
) )
.operands_in(vec![x, y]) .operands_in(vec![x, y])
.operands_out(vec![a]) .operands_out(vec![a])
.can_trap(true) .can_trap()
.side_effects_idempotent(true), .side_effects_idempotent(),
); );
ig.push( ig.push(
@@ -1727,8 +1723,8 @@ pub(crate) fn define(
) )
.operands_in(vec![x, y]) .operands_in(vec![x, y])
.operands_out(vec![a]) .operands_out(vec![a])
.can_trap(true) .can_trap()
.side_effects_idempotent(true), .side_effects_idempotent(),
); );
} }
@@ -1955,8 +1951,8 @@ pub(crate) fn define(
) )
.operands_in(vec![x, y, code]) .operands_in(vec![x, y, code])
.operands_out(vec![a]) .operands_out(vec![a])
.can_trap(true) .can_trap()
.side_effects_idempotent(true), .side_effects_idempotent(),
); );
} }
@@ -3318,8 +3314,8 @@ pub(crate) fn define(
) )
.operands_in(vec![x]) .operands_in(vec![x])
.operands_out(vec![a]) .operands_out(vec![a])
.can_trap(true) .can_trap()
.side_effects_idempotent(true), .side_effects_idempotent(),
); );
ig.push( ig.push(
@@ -3337,8 +3333,8 @@ pub(crate) fn define(
) )
.operands_in(vec![x]) .operands_in(vec![x])
.operands_out(vec![a]) .operands_out(vec![a])
.can_trap(true) .can_trap()
.side_effects_idempotent(true), .side_effects_idempotent(),
); );
let x = &Operand::new("x", Float); let x = &Operand::new("x", Float);
@@ -3514,9 +3510,9 @@ pub(crate) fn define(
) )
.operands_in(vec![MemFlags, AtomicRmwOp, p, x]) .operands_in(vec![MemFlags, AtomicRmwOp, p, x])
.operands_out(vec![a]) .operands_out(vec![a])
.can_load(true) .can_load()
.can_store(true) .can_store()
.other_side_effects(true), .other_side_effects(),
); );
ig.push( ig.push(
@@ -3536,9 +3532,9 @@ pub(crate) fn define(
) )
.operands_in(vec![MemFlags, p, e, x]) .operands_in(vec![MemFlags, p, e, x])
.operands_out(vec![a]) .operands_out(vec![a])
.can_load(true) .can_load()
.can_store(true) .can_store()
.other_side_effects(true), .other_side_effects(),
); );
ig.push( ig.push(
@@ -3556,8 +3552,8 @@ pub(crate) fn define(
) )
.operands_in(vec![MemFlags, p]) .operands_in(vec![MemFlags, p])
.operands_out(vec![a]) .operands_out(vec![a])
.can_load(true) .can_load()
.other_side_effects(true), .other_side_effects(),
); );
ig.push( ig.push(
@@ -3574,8 +3570,8 @@ pub(crate) fn define(
&formats.store_no_offset, &formats.store_no_offset,
) )
.operands_in(vec![MemFlags, x, p]) .operands_in(vec![MemFlags, x, p])
.can_store(true) .can_store()
.other_side_effects(true), .other_side_effects(),
); );
ig.push( ig.push(
@@ -3588,7 +3584,7 @@ pub(crate) fn define(
"#, "#,
&formats.nullary, &formats.nullary,
) )
.other_side_effects(true), .other_side_effects(),
); );
let TxN = &TypeVar::new( let TxN = &TypeVar::new(