Prefix fixed_results/fixed_value_arguments with num to indicate they return a usize;

This commit is contained in:
Benjamin Bouvier
2018-11-08 16:48:20 +01:00
committed by Dan Gohman
parent e13b0886dc
commit f896bfb946
7 changed files with 80 additions and 54 deletions

View File

@@ -430,26 +430,38 @@ impl DataFlowGraph {
/// Get the fixed value arguments on `inst` as a slice.
pub fn inst_fixed_args(&self, inst: Inst) -> &[Value] {
let fixed_args = self[inst].opcode().constraints().fixed_value_arguments();
&self.inst_args(inst)[..fixed_args]
let num_fixed_args = self[inst]
.opcode()
.constraints()
.num_fixed_value_arguments();
&self.inst_args(inst)[..num_fixed_args]
}
/// Get the fixed value arguments on `inst` as a mutable slice.
pub fn inst_fixed_args_mut(&mut self, inst: Inst) -> &mut [Value] {
let fixed_args = self[inst].opcode().constraints().fixed_value_arguments();
&mut self.inst_args_mut(inst)[..fixed_args]
let num_fixed_args = self[inst]
.opcode()
.constraints()
.num_fixed_value_arguments();
&mut self.inst_args_mut(inst)[..num_fixed_args]
}
/// Get the variable value arguments on `inst` as a slice.
pub fn inst_variable_args(&self, inst: Inst) -> &[Value] {
let fixed_args = self[inst].opcode().constraints().fixed_value_arguments();
&self.inst_args(inst)[fixed_args..]
let num_fixed_args = self[inst]
.opcode()
.constraints()
.num_fixed_value_arguments();
&self.inst_args(inst)[num_fixed_args..]
}
/// Get the variable value arguments on `inst` as a mutable slice.
pub fn inst_variable_args_mut(&mut self, inst: Inst) -> &mut [Value] {
let fixed_args = self[inst].opcode().constraints().fixed_value_arguments();
&mut self.inst_args_mut(inst)[fixed_args..]
let num_fixed_args = self[inst]
.opcode()
.constraints()
.num_fixed_value_arguments();
&mut self.inst_args_mut(inst)[num_fixed_args..]
}
/// Create result values for an instruction that produces multiple results.
@@ -489,7 +501,10 @@ impl DataFlowGraph {
// Get the call signature if this is a function call.
if let Some(sig) = self.call_signature(inst) {
// Create result values corresponding to the call return types.
debug_assert_eq!(self.insts[inst].opcode().constraints().fixed_results(), 0);
debug_assert_eq!(
self.insts[inst].opcode().constraints().num_fixed_results(),
0
);
let num_results = self.signatures[sig].returns.len();
for res_idx in 0..num_results {
let ty = self.signatures[sig].returns[res_idx].value_type;
@@ -504,7 +519,7 @@ impl DataFlowGraph {
} else {
// Create result values corresponding to the opcode's constraints.
let constraints = self.insts[inst].opcode().constraints();
let num_results = constraints.fixed_results();
let num_results = constraints.num_fixed_results();
for res_idx in 0..num_results {
let ty = constraints.result_type(res_idx, ctrl_typevar);
if let Some(Some(v)) = reuse.next() {
@@ -662,9 +677,9 @@ impl DataFlowGraph {
ctrl_typevar: Type,
) -> Option<Type> {
let constraints = self.insts[inst].opcode().constraints();
let fixed_results = constraints.fixed_results();
let num_fixed_results = constraints.num_fixed_results();
if result_idx < fixed_results {
if result_idx < num_fixed_results {
return Some(constraints.result_type(result_idx, ctrl_typevar));
}
@@ -672,7 +687,7 @@ impl DataFlowGraph {
self.call_signature(inst).and_then(|sigref| {
self.signatures[sigref]
.returns
.get(result_idx - fixed_results)
.get(result_idx - num_fixed_results)
.map(|&arg| arg.value_type)
})
}
@@ -934,7 +949,10 @@ impl DataFlowGraph {
) -> usize {
// Get the call signature if this is a function call.
if let Some(sig) = self.call_signature(inst) {
assert_eq!(self.insts[inst].opcode().constraints().fixed_results(), 0);
assert_eq!(
self.insts[inst].opcode().constraints().num_fixed_results(),
0
);
for res_idx in 0..self.signatures[sig].returns.len() {
let ty = self.signatures[sig].returns[res_idx].value_type;
if let Some(v) = reuse.get(res_idx) {
@@ -943,7 +961,7 @@ impl DataFlowGraph {
}
} else {
let constraints = self.insts[inst].opcode().constraints();
for res_idx in 0..constraints.fixed_results() {
for res_idx in 0..constraints.num_fixed_results() {
let ty = constraints.result_type(res_idx, ctrl_typevar);
if let Some(v) = reuse.get(res_idx) {
self.set_value_type_for_parser(*v, ty);

View File

@@ -335,8 +335,8 @@ pub struct OpcodeConstraints {
typeset_offset: u8,
/// Offset into `OPERAND_CONSTRAINT` table of the descriptors for this opcode. The first
/// `fixed_results()` entries describe the result constraints, then follows constraints for the
/// fixed `Value` input operands. (`fixed_value_arguments()` of them).
/// `num_fixed_results()` entries describe the result constraints, then follows constraints for the
/// fixed `Value` input operands. (`num_fixed_value_arguments()` of them).
constraint_offset: u16,
}
@@ -360,7 +360,7 @@ impl OpcodeConstraints {
/// Get the number of *fixed* result values produced by this opcode.
/// This does not include `variable_args` produced by calls.
pub fn fixed_results(self) -> usize {
pub fn num_fixed_results(self) -> usize {
(self.flags & 0x7) as usize
}
@@ -371,7 +371,7 @@ impl OpcodeConstraints {
/// The number of fixed input values is usually implied by the instruction format, but
/// instruction formats that use a `ValueList` put both fixed and variable arguments in the
/// list. This method returns the *minimum* number of values required in the value list.
pub fn fixed_value_arguments(self) -> usize {
pub fn num_fixed_value_arguments(self) -> usize {
((self.flags >> 5) & 0x7) as usize
}
@@ -394,7 +394,7 @@ impl OpcodeConstraints {
/// Get the value type of result number `n`, having resolved the controlling type variable to
/// `ctrl_type`.
pub fn result_type(self, n: usize, ctrl_type: Type) -> Type {
debug_assert!(n < self.fixed_results(), "Invalid result index");
debug_assert!(n < self.num_fixed_results(), "Invalid result index");
if let ResolvedConstraint::Bound(t) =
OPERAND_CONSTRAINTS[self.constraint_offset() + n].resolve(ctrl_type)
{
@@ -411,10 +411,10 @@ impl OpcodeConstraints {
/// `ValueTypeSet`. This is represented with the `ArgumentConstraint::Free` variant.
pub fn value_argument_constraint(self, n: usize, ctrl_type: Type) -> ResolvedConstraint {
debug_assert!(
n < self.fixed_value_arguments(),
n < self.num_fixed_value_arguments(),
"Invalid value argument index"
);
let offset = self.constraint_offset() + self.fixed_results();
let offset = self.constraint_offset() + self.num_fixed_results();
OPERAND_CONSTRAINTS[offset + n].resolve(ctrl_type)
}
@@ -603,8 +603,8 @@ mod tests {
let a = Opcode::Iadd.constraints();
assert!(a.use_typevar_operand());
assert!(!a.requires_typevar_operand());
assert_eq!(a.fixed_results(), 1);
assert_eq!(a.fixed_value_arguments(), 2);
assert_eq!(a.num_fixed_results(), 1);
assert_eq!(a.num_fixed_value_arguments(), 2);
assert_eq!(a.result_type(0, types::I32), types::I32);
assert_eq!(a.result_type(0, types::I8), types::I8);
assert_eq!(
@@ -619,8 +619,8 @@ mod tests {
let b = Opcode::Bitcast.constraints();
assert!(!b.use_typevar_operand());
assert!(!b.requires_typevar_operand());
assert_eq!(b.fixed_results(), 1);
assert_eq!(b.fixed_value_arguments(), 1);
assert_eq!(b.num_fixed_results(), 1);
assert_eq!(b.num_fixed_value_arguments(), 1);
assert_eq!(b.result_type(0, types::I32), types::I32);
assert_eq!(b.result_type(0, types::I8), types::I8);
match b.value_argument_constraint(0, types::I32) {
@@ -629,18 +629,18 @@ mod tests {
}
let c = Opcode::Call.constraints();
assert_eq!(c.fixed_results(), 0);
assert_eq!(c.fixed_value_arguments(), 0);
assert_eq!(c.num_fixed_results(), 0);
assert_eq!(c.num_fixed_value_arguments(), 0);
let i = Opcode::CallIndirect.constraints();
assert_eq!(i.fixed_results(), 0);
assert_eq!(i.fixed_value_arguments(), 1);
assert_eq!(i.num_fixed_results(), 0);
assert_eq!(i.num_fixed_value_arguments(), 1);
let cmp = Opcode::Icmp.constraints();
assert!(cmp.use_typevar_operand());
assert!(cmp.requires_typevar_operand());
assert_eq!(cmp.fixed_results(), 1);
assert_eq!(cmp.fixed_value_arguments(), 2);
assert_eq!(cmp.num_fixed_results(), 1);
assert_eq!(cmp.num_fixed_value_arguments(), 2);
}
#[test]