rustfmt 0.8.1
This commit is contained in:
@@ -65,10 +65,7 @@ impl<'c, 'fc, 'fd> InsertBuilder<'c, 'fc, 'fd> {
|
||||
pub fn new(dfg: &'fd mut DataFlowGraph,
|
||||
pos: &'c mut Cursor<'fc>)
|
||||
-> InsertBuilder<'c, 'fc, 'fd> {
|
||||
InsertBuilder {
|
||||
dfg: dfg,
|
||||
pos: pos,
|
||||
}
|
||||
InsertBuilder { dfg: dfg, pos: pos }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -182,8 +179,9 @@ impl<'f> InstBuilderBase<'f> for ReplaceBuilder<'f> {
|
||||
|
||||
// Normally, make_inst_results() would also set the first result type, but we're not
|
||||
// going to call that, so set it manually.
|
||||
*self.dfg[self.inst].first_type_mut() =
|
||||
self.dfg.compute_result_type(self.inst, 0, ctrl_typevar).unwrap_or_default();
|
||||
*self.dfg[self.inst].first_type_mut() = self.dfg
|
||||
.compute_result_type(self.inst, 0, ctrl_typevar)
|
||||
.unwrap_or_default();
|
||||
}
|
||||
|
||||
(self.inst, self.dfg)
|
||||
|
||||
@@ -356,25 +356,37 @@ 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();
|
||||
let fixed_args = self[inst]
|
||||
.opcode()
|
||||
.constraints()
|
||||
.fixed_value_arguments();
|
||||
&self.inst_args(inst)[..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();
|
||||
let fixed_args = self[inst]
|
||||
.opcode()
|
||||
.constraints()
|
||||
.fixed_value_arguments();
|
||||
&mut self.inst_args_mut(inst)[..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();
|
||||
let fixed_args = self[inst]
|
||||
.opcode()
|
||||
.constraints()
|
||||
.fixed_value_arguments();
|
||||
&self.inst_args(inst)[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();
|
||||
let fixed_args = self[inst]
|
||||
.opcode()
|
||||
.constraints()
|
||||
.fixed_value_arguments();
|
||||
&mut self.inst_args_mut(inst)[fixed_args..]
|
||||
}
|
||||
|
||||
@@ -444,8 +456,8 @@ impl DataFlowGraph {
|
||||
// Update the second_result pointer in `inst`.
|
||||
if head.is_some() {
|
||||
*self.insts[inst]
|
||||
.second_result_mut()
|
||||
.expect("instruction format doesn't allow multiple results") = head.into();
|
||||
.second_result_mut()
|
||||
.expect("instruction format doesn't allow multiple results") = head.into();
|
||||
}
|
||||
*self.insts[inst].first_type_mut() = first_type.unwrap_or_default();
|
||||
|
||||
@@ -505,7 +517,12 @@ impl DataFlowGraph {
|
||||
(inst, 1)
|
||||
}
|
||||
ExpandedValue::Table(idx) => {
|
||||
if let ValueData::Inst { num, inst, ref mut next, .. } = self.extended_values[idx] {
|
||||
if let ValueData::Inst {
|
||||
num,
|
||||
inst,
|
||||
ref mut next,
|
||||
..
|
||||
} = self.extended_values[idx] {
|
||||
assert!(next.is_none(), "last_res is not the last result");
|
||||
*next = res.into();
|
||||
assert!(num < u16::MAX, "Too many arguments to EBB");
|
||||
@@ -518,8 +535,12 @@ impl DataFlowGraph {
|
||||
|
||||
// Now update `res` itself.
|
||||
if let ExpandedValue::Table(idx) = res.expand() {
|
||||
if let ValueData::Inst { ref mut num, ref mut inst, ref mut next, .. } =
|
||||
self.extended_values[idx] {
|
||||
if let ValueData::Inst {
|
||||
ref mut num,
|
||||
ref mut inst,
|
||||
ref mut next,
|
||||
..
|
||||
} = self.extended_values[idx] {
|
||||
*num = res_num;
|
||||
*inst = res_inst;
|
||||
*next = None.into();
|
||||
@@ -565,7 +586,8 @@ impl DataFlowGraph {
|
||||
///
|
||||
/// Returns the new `Inst` reference where the original instruction has been moved.
|
||||
pub fn redefine_first_value(&mut self, pos: &mut Cursor) -> Inst {
|
||||
let orig = pos.current_inst().expect("Cursor must point at an instruction");
|
||||
let orig = pos.current_inst()
|
||||
.expect("Cursor must point at an instruction");
|
||||
let data = self[orig].clone();
|
||||
// After cloning, any secondary values are attached to both copies. Don't do that, we only
|
||||
// want them on the new clone.
|
||||
@@ -630,12 +652,13 @@ impl DataFlowGraph {
|
||||
}
|
||||
|
||||
// Not a fixed result, try to extract a return type from the call signature.
|
||||
self.call_signature(inst).and_then(|sigref| {
|
||||
self.signatures[sigref]
|
||||
.return_types
|
||||
.get(result_idx - fixed_results)
|
||||
.map(|&arg| arg.value_type)
|
||||
})
|
||||
self.call_signature(inst)
|
||||
.and_then(|sigref| {
|
||||
self.signatures[sigref]
|
||||
.return_types
|
||||
.get(result_idx - fixed_results)
|
||||
.map(|&arg| arg.value_type)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -815,8 +838,12 @@ impl DataFlowGraph {
|
||||
// Now update `arg` itself.
|
||||
let arg_ebb = ebb;
|
||||
if let ExpandedValue::Table(idx) = arg.expand() {
|
||||
if let ValueData::Arg { ref mut num, ebb, ref mut next, .. } =
|
||||
self.extended_values[idx] {
|
||||
if let ValueData::Arg {
|
||||
ref mut num,
|
||||
ebb,
|
||||
ref mut next,
|
||||
..
|
||||
} = self.extended_values[idx] {
|
||||
*num = arg_num;
|
||||
*next = None.into();
|
||||
assert_eq!(arg_ebb, ebb, "{} should already belong to EBB", arg);
|
||||
|
||||
@@ -286,14 +286,18 @@ mod tests {
|
||||
assert_eq!(Value::table_with_number(1).unwrap().to_string(), "vx1");
|
||||
|
||||
assert_eq!(Value::direct_with_number(u32::MAX / 2), None);
|
||||
assert_eq!(match Value::direct_with_number(u32::MAX / 2 - 1).unwrap().expand() {
|
||||
assert_eq!(match Value::direct_with_number(u32::MAX / 2 - 1)
|
||||
.unwrap()
|
||||
.expand() {
|
||||
ExpandedValue::Direct(i) => i.index() as u32,
|
||||
_ => u32::MAX,
|
||||
},
|
||||
u32::MAX / 2 - 1);
|
||||
|
||||
assert_eq!(Value::table_with_number(u32::MAX / 2), None);
|
||||
assert_eq!(match Value::table_with_number(u32::MAX / 2 - 1).unwrap().expand() {
|
||||
assert_eq!(match Value::table_with_number(u32::MAX / 2 - 1)
|
||||
.unwrap()
|
||||
.expand() {
|
||||
ExpandedValue::Table(i) => i as u32,
|
||||
_ => u32::MAX,
|
||||
},
|
||||
|
||||
@@ -221,7 +221,8 @@ mod tests {
|
||||
assert_eq!(sig.to_string(), "(i32)");
|
||||
sig.return_types.push(ArgumentType::new(F32));
|
||||
assert_eq!(sig.to_string(), "(i32) -> f32");
|
||||
sig.argument_types.push(ArgumentType::new(I32.by(4).unwrap()));
|
||||
sig.argument_types
|
||||
.push(ArgumentType::new(I32.by(4).unwrap()));
|
||||
assert_eq!(sig.to_string(), "(i32, i32x4) -> f32");
|
||||
sig.return_types.push(ArgumentType::new(B8));
|
||||
assert_eq!(sig.to_string(), "(i32, i32x4) -> f32, b8");
|
||||
|
||||
@@ -304,15 +304,21 @@ impl InstructionData {
|
||||
/// here.
|
||||
pub fn analyze_branch<'a>(&'a self, pool: &'a ValueListPool) -> BranchInfo<'a> {
|
||||
match self {
|
||||
&InstructionData::Jump { destination, ref args, .. } => {
|
||||
BranchInfo::SingleDest(destination, &args.as_slice(pool))
|
||||
}
|
||||
&InstructionData::Branch { destination, ref args, .. } => {
|
||||
BranchInfo::SingleDest(destination, &args.as_slice(pool)[1..])
|
||||
}
|
||||
&InstructionData::BranchIcmp { destination, ref args, .. } => {
|
||||
BranchInfo::SingleDest(destination, &args.as_slice(pool)[2..])
|
||||
}
|
||||
&InstructionData::Jump {
|
||||
destination,
|
||||
ref args,
|
||||
..
|
||||
} => BranchInfo::SingleDest(destination, &args.as_slice(pool)),
|
||||
&InstructionData::Branch {
|
||||
destination,
|
||||
ref args,
|
||||
..
|
||||
} => BranchInfo::SingleDest(destination, &args.as_slice(pool)[1..]),
|
||||
&InstructionData::BranchIcmp {
|
||||
destination,
|
||||
ref args,
|
||||
..
|
||||
} => BranchInfo::SingleDest(destination, &args.as_slice(pool)[2..]),
|
||||
&InstructionData::BranchTable { table, .. } => BranchInfo::Table(table),
|
||||
_ => BranchInfo::NotABranch,
|
||||
}
|
||||
@@ -601,9 +607,21 @@ impl OperandConstraint {
|
||||
Same => Bound(ctrl_type),
|
||||
LaneOf => Bound(ctrl_type.lane_type()),
|
||||
AsBool => Bound(ctrl_type.as_bool()),
|
||||
HalfWidth => Bound(ctrl_type.half_width().expect("invalid type for half_width")),
|
||||
DoubleWidth => Bound(ctrl_type.double_width().expect("invalid type for double_width")),
|
||||
HalfVector => Bound(ctrl_type.half_vector().expect("invalid type for half_vector")),
|
||||
HalfWidth => {
|
||||
Bound(ctrl_type
|
||||
.half_width()
|
||||
.expect("invalid type for half_width"))
|
||||
}
|
||||
DoubleWidth => {
|
||||
Bound(ctrl_type
|
||||
.double_width()
|
||||
.expect("invalid type for double_width"))
|
||||
}
|
||||
HalfVector => {
|
||||
Bound(ctrl_type
|
||||
.half_vector()
|
||||
.expect("invalid type for half_vector"))
|
||||
}
|
||||
DoubleVector => Bound(ctrl_type.by(2).expect("invalid type for double_vector")),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,15 +66,14 @@ impl JumpTableData {
|
||||
///
|
||||
/// This returns an iterator that skips any empty slots in the table.
|
||||
pub fn entries<'a>(&'a self) -> Entries {
|
||||
Entries(self.table
|
||||
.iter()
|
||||
.cloned()
|
||||
.enumerate())
|
||||
Entries(self.table.iter().cloned().enumerate())
|
||||
}
|
||||
|
||||
/// Checks if any of the entries branch to `ebb`.
|
||||
pub fn branches_to(&self, ebb: Ebb) -> bool {
|
||||
self.table.iter().any(|target_ebb| target_ebb.expand() == Some(ebb))
|
||||
self.table
|
||||
.iter()
|
||||
.any(|target_ebb| target_ebb.expand() == Some(ebb))
|
||||
}
|
||||
|
||||
/// Access the whole table as a mutable slice.
|
||||
@@ -109,10 +108,7 @@ impl Display for JumpTableData {
|
||||
Some(first) => write!(fmt, "jump_table {}", first)?,
|
||||
}
|
||||
|
||||
for dest in self.table
|
||||
.iter()
|
||||
.skip(1)
|
||||
.map(|e| e.expand()) {
|
||||
for dest in self.table.iter().skip(1).map(|e| e.expand()) {
|
||||
match dest {
|
||||
None => write!(fmt, ", 0")?,
|
||||
Some(ebb) => write!(fmt, ", {}", ebb)?,
|
||||
|
||||
@@ -125,7 +125,10 @@ impl Layout {
|
||||
/// Get the last sequence number in `ebb`.
|
||||
fn last_ebb_seq(&self, ebb: Ebb) -> SequenceNumber {
|
||||
// Get the seq of the last instruction if it exists, otherwise use the EBB header seq.
|
||||
self.ebbs[ebb].last_inst.map(|inst| self.insts[inst].seq).unwrap_or(self.ebbs[ebb].seq)
|
||||
self.ebbs[ebb]
|
||||
.last_inst
|
||||
.map(|inst| self.insts[inst].seq)
|
||||
.unwrap_or(self.ebbs[ebb].seq)
|
||||
}
|
||||
|
||||
/// Assign a valid sequence number to `ebb` such that the numbers are still monotonic. This may
|
||||
@@ -134,7 +137,10 @@ impl Layout {
|
||||
assert!(self.is_ebb_inserted(ebb));
|
||||
|
||||
// Get the sequence number immediately before `ebb`, or 0.
|
||||
let prev_seq = self.ebbs[ebb].prev.map(|prev_ebb| self.last_ebb_seq(prev_ebb)).unwrap_or(0);
|
||||
let prev_seq = self.ebbs[ebb]
|
||||
.prev
|
||||
.map(|prev_ebb| self.last_ebb_seq(prev_ebb))
|
||||
.unwrap_or(0);
|
||||
|
||||
// Get the sequence number immediately following `ebb`.
|
||||
let next_seq = if let Some(inst) = self.ebbs[ebb].first_inst.expand() {
|
||||
@@ -159,7 +165,8 @@ impl Layout {
|
||||
/// Assign a valid sequence number to `inst` such that the numbers are still monotonic. This may
|
||||
/// require renumbering.
|
||||
fn assign_inst_seq(&mut self, inst: Inst) {
|
||||
let ebb = self.inst_ebb(inst).expect("inst must be inserted before assigning an seq");
|
||||
let ebb = self.inst_ebb(inst)
|
||||
.expect("inst must be inserted before assigning an seq");
|
||||
|
||||
// Get the sequence number immediately before `inst`.
|
||||
let prev_seq = match self.insts[inst].prev.expand() {
|
||||
@@ -436,8 +443,8 @@ impl Layout {
|
||||
/// Insert `inst` before the instruction `before` in the same EBB.
|
||||
pub fn insert_inst(&mut self, inst: Inst, before: Inst) {
|
||||
assert_eq!(self.inst_ebb(inst), None);
|
||||
let ebb =
|
||||
self.inst_ebb(before).expect("Instruction before insertion point not in the layout");
|
||||
let ebb = self.inst_ebb(before)
|
||||
.expect("Instruction before insertion point not in the layout");
|
||||
let after = self.insts[before].prev;
|
||||
{
|
||||
let inst_node = self.insts.ensure(inst);
|
||||
@@ -485,8 +492,8 @@ impl Layout {
|
||||
/// i4
|
||||
/// ```
|
||||
pub fn split_ebb(&mut self, new_ebb: Ebb, before: Inst) {
|
||||
let old_ebb =
|
||||
self.inst_ebb(before).expect("The `before` instruction must be in the layout");
|
||||
let old_ebb = self.inst_ebb(before)
|
||||
.expect("The `before` instruction must be in the layout");
|
||||
assert!(!self.is_ebb_inserted(new_ebb));
|
||||
|
||||
// Insert new_ebb after old_ebb.
|
||||
@@ -786,8 +793,9 @@ impl<'f> Cursor<'f> {
|
||||
self.pos = At(next);
|
||||
Some(next)
|
||||
} else {
|
||||
self.pos =
|
||||
After(self.layout.inst_ebb(inst).expect("current instruction removed?"));
|
||||
self.pos = After(self.layout
|
||||
.inst_ebb(inst)
|
||||
.expect("current instruction removed?"));
|
||||
None
|
||||
}
|
||||
}
|
||||
@@ -837,8 +845,9 @@ impl<'f> Cursor<'f> {
|
||||
self.pos = At(prev);
|
||||
Some(prev)
|
||||
} else {
|
||||
self.pos =
|
||||
Before(self.layout.inst_ebb(inst).expect("current instruction removed?"));
|
||||
self.pos = Before(self.layout
|
||||
.inst_ebb(inst)
|
||||
.expect("current instruction removed?"));
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
@@ -348,12 +348,7 @@ mod tests {
|
||||
assert_eq!(big.bits(), 64 * 256);
|
||||
|
||||
assert_eq!(big.half_vector().unwrap().to_string(), "f64x128");
|
||||
assert_eq!(B1.by(2)
|
||||
.unwrap()
|
||||
.half_vector()
|
||||
.unwrap()
|
||||
.to_string(),
|
||||
"b1");
|
||||
assert_eq!(B1.by(2).unwrap().half_vector().unwrap().to_string(), "b1");
|
||||
assert_eq!(I32.half_vector(), None);
|
||||
assert_eq!(VOID.half_vector(), None);
|
||||
|
||||
@@ -383,12 +378,7 @@ mod tests {
|
||||
assert_eq!(B1.by(8).unwrap().to_string(), "b1x8");
|
||||
assert_eq!(B8.by(1).unwrap().to_string(), "b8");
|
||||
assert_eq!(B16.by(256).unwrap().to_string(), "b16x256");
|
||||
assert_eq!(B32.by(4)
|
||||
.unwrap()
|
||||
.by(2)
|
||||
.unwrap()
|
||||
.to_string(),
|
||||
"b32x8");
|
||||
assert_eq!(B32.by(4).unwrap().by(2).unwrap().to_string(), "b32x8");
|
||||
assert_eq!(B64.by(8).unwrap().to_string(), "b64x8");
|
||||
assert_eq!(I8.by(64).unwrap().to_string(), "i8x64");
|
||||
assert_eq!(F64.by(2).unwrap().to_string(), "f64x2");
|
||||
|
||||
Reference in New Issue
Block a user