Style changes in response to code review.
This commit is contained in:
committed by
Benjamin Bouvier
parent
4d427d7c71
commit
3b1583ebb7
@@ -556,7 +556,9 @@ struct BranchOptInfo {
|
|||||||
/// single `brz` or `brnz`.
|
/// single `brz` or `brnz`.
|
||||||
fn branch_opt(pos: &mut FuncCursor, inst: Inst) {
|
fn branch_opt(pos: &mut FuncCursor, inst: Inst) {
|
||||||
let mut info = if let InstructionData::Branch {
|
let mut info = if let InstructionData::Branch {
|
||||||
opcode, ref args, ..
|
opcode: br_opcode,
|
||||||
|
args: ref br_args,
|
||||||
|
..
|
||||||
} = pos.func.dfg[inst]
|
} = pos.func.dfg[inst]
|
||||||
{
|
{
|
||||||
let first_arg = {
|
let first_arg = {
|
||||||
@@ -564,9 +566,8 @@ fn branch_opt(pos: &mut FuncCursor, inst: Inst) {
|
|||||||
args[0]
|
args[0]
|
||||||
};
|
};
|
||||||
|
|
||||||
let iconst_inst =
|
let icmp_inst = if let ValueDef::Result(icmp_inst, _) = pos.func.dfg.value_def(first_arg) {
|
||||||
if let ValueDef::Result(iconst_inst, _) = pos.func.dfg.value_def(first_arg) {
|
icmp_inst
|
||||||
iconst_inst
|
|
||||||
} else {
|
} else {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
@@ -576,7 +577,7 @@ fn branch_opt(pos: &mut FuncCursor, inst: Inst) {
|
|||||||
arg: cmp_arg,
|
arg: cmp_arg,
|
||||||
cond: cmp_cond,
|
cond: cmp_cond,
|
||||||
imm: cmp_imm,
|
imm: cmp_imm,
|
||||||
} = pos.func.dfg[iconst_inst]
|
} = pos.func.dfg[icmp_inst]
|
||||||
{
|
{
|
||||||
let cmp_imm: i64 = cmp_imm.into();
|
let cmp_imm: i64 = cmp_imm.into();
|
||||||
if cmp_imm != 0 {
|
if cmp_imm != 0 {
|
||||||
@@ -585,7 +586,7 @@ fn branch_opt(pos: &mut FuncCursor, inst: Inst) {
|
|||||||
|
|
||||||
// icmp_imm returns non-zero when the comparison is true. So, if
|
// icmp_imm returns non-zero when the comparison is true. So, if
|
||||||
// we're branching on zero, we need to invert the condition.
|
// we're branching on zero, we need to invert the condition.
|
||||||
let cond = match opcode {
|
let cond = match br_opcode {
|
||||||
Opcode::Brz => cmp_cond.inverse(),
|
Opcode::Brz => cmp_cond.inverse(),
|
||||||
Opcode::Brnz => cmp_cond,
|
Opcode::Brnz => cmp_cond,
|
||||||
_ => return,
|
_ => return,
|
||||||
@@ -600,7 +601,7 @@ fn branch_opt(pos: &mut FuncCursor, inst: Inst) {
|
|||||||
BranchOptInfo {
|
BranchOptInfo {
|
||||||
br_inst: inst,
|
br_inst: inst,
|
||||||
cmp_arg: cmp_arg,
|
cmp_arg: cmp_arg,
|
||||||
args: args.clone(),
|
args: br_args.clone(),
|
||||||
new_opcode: new_opcode,
|
new_opcode: new_opcode,
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -618,16 +619,6 @@ fn branch_opt(pos: &mut FuncCursor, inst: Inst) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct BranchOrderInfo {
|
|
||||||
term_inst: Inst,
|
|
||||||
term_inst_args: ValueList,
|
|
||||||
term_dest: Ebb,
|
|
||||||
cond_inst: Inst,
|
|
||||||
cond_inst_args: ValueList,
|
|
||||||
cond_dest: Ebb,
|
|
||||||
kind: BranchOrderKind,
|
|
||||||
}
|
|
||||||
|
|
||||||
enum BranchOrderKind {
|
enum BranchOrderKind {
|
||||||
BrzToBrnz(Value),
|
BrzToBrnz(Value),
|
||||||
BrnzToBrz(Value),
|
BrnzToBrz(Value),
|
||||||
@@ -640,7 +631,8 @@ enum BranchOrderKind {
|
|||||||
/// branch, this will reorder them if one of them is branching to the next Ebb
|
/// branch, this will reorder them if one of them is branching to the next Ebb
|
||||||
/// layout-wise. The unconditional jump can then become a fallthrough.
|
/// layout-wise. The unconditional jump can then become a fallthrough.
|
||||||
fn branch_order(pos: &mut FuncCursor, cfg: &mut ControlFlowGraph, ebb: Ebb, inst: Inst) {
|
fn branch_order(pos: &mut FuncCursor, cfg: &mut ControlFlowGraph, ebb: Ebb, inst: Inst) {
|
||||||
let info = match pos.func.dfg[inst] {
|
let (term_inst, term_inst_args, term_dest, cond_inst, cond_inst_args, cond_dest, kind) =
|
||||||
|
match pos.func.dfg[inst] {
|
||||||
InstructionData::Jump {
|
InstructionData::Jump {
|
||||||
opcode: Opcode::Jump,
|
opcode: Opcode::Jump,
|
||||||
destination,
|
destination,
|
||||||
@@ -689,15 +681,15 @@ fn branch_order(pos: &mut FuncCursor, cfg: &mut ControlFlowGraph, ebb: Ebb, inst
|
|||||||
_ => panic!("unexpected opcode"),
|
_ => panic!("unexpected opcode"),
|
||||||
};
|
};
|
||||||
|
|
||||||
BranchOrderInfo {
|
(
|
||||||
term_inst: inst,
|
inst,
|
||||||
term_inst_args: args.clone(),
|
args.clone(),
|
||||||
term_dest: destination,
|
destination,
|
||||||
cond_inst: prev_inst,
|
prev_inst,
|
||||||
cond_inst_args: prev_args.clone(),
|
prev_args.clone(),
|
||||||
cond_dest: *cond_dest,
|
*cond_dest,
|
||||||
kind: kind,
|
kind,
|
||||||
}
|
)
|
||||||
}
|
}
|
||||||
InstructionData::BranchIcmp {
|
InstructionData::BranchIcmp {
|
||||||
opcode: Opcode::BrIcmp,
|
opcode: Opcode::BrIcmp,
|
||||||
@@ -709,15 +701,16 @@ fn branch_order(pos: &mut FuncCursor, cfg: &mut ControlFlowGraph, ebb: Ebb, inst
|
|||||||
let args = pos.func.dfg.inst_args(prev_inst);
|
let args = pos.func.dfg.inst_args(prev_inst);
|
||||||
(args[0], args[1])
|
(args[0], args[1])
|
||||||
};
|
};
|
||||||
BranchOrderInfo {
|
|
||||||
term_inst: inst,
|
(
|
||||||
term_inst_args: args.clone(),
|
inst,
|
||||||
term_dest: destination,
|
args.clone(),
|
||||||
cond_inst: prev_inst,
|
destination,
|
||||||
cond_inst_args: prev_args.clone(),
|
prev_inst,
|
||||||
cond_dest: *cond_dest,
|
prev_args.clone(),
|
||||||
kind: BranchOrderKind::InvertIcmpCond(*cond, x_arg, y_arg),
|
*cond_dest,
|
||||||
}
|
BranchOrderKind::InvertIcmpCond(*cond, x_arg, y_arg),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
_ => return,
|
_ => return,
|
||||||
}
|
}
|
||||||
@@ -726,48 +719,40 @@ fn branch_order(pos: &mut FuncCursor, cfg: &mut ControlFlowGraph, ebb: Ebb, inst
|
|||||||
_ => return,
|
_ => return,
|
||||||
};
|
};
|
||||||
|
|
||||||
let cond_args = {
|
let cond_args = { cond_inst_args.as_slice(&pos.func.dfg.value_lists).to_vec() };
|
||||||
info.cond_inst_args
|
let term_args = { term_inst_args.as_slice(&pos.func.dfg.value_lists).to_vec() };
|
||||||
.as_slice(&pos.func.dfg.value_lists)
|
|
||||||
.to_vec()
|
|
||||||
};
|
|
||||||
let term_args = {
|
|
||||||
info.term_inst_args
|
|
||||||
.as_slice(&pos.func.dfg.value_lists)
|
|
||||||
.to_vec()
|
|
||||||
};
|
|
||||||
|
|
||||||
match info.kind {
|
match kind {
|
||||||
BranchOrderKind::BrnzToBrz(cond_arg) => {
|
BranchOrderKind::BrnzToBrz(cond_arg) => {
|
||||||
pos.func
|
pos.func
|
||||||
.dfg
|
.dfg
|
||||||
.replace(info.term_inst)
|
.replace(term_inst)
|
||||||
.jump(info.cond_dest, &cond_args[1..]);
|
.jump(cond_dest, &cond_args[1..]);
|
||||||
pos.func
|
pos.func
|
||||||
.dfg
|
.dfg
|
||||||
.replace(info.cond_inst)
|
.replace(cond_inst)
|
||||||
.brz(cond_arg, info.term_dest, &term_args);
|
.brz(cond_arg, term_dest, &term_args);
|
||||||
}
|
}
|
||||||
BranchOrderKind::BrzToBrnz(cond_arg) => {
|
BranchOrderKind::BrzToBrnz(cond_arg) => {
|
||||||
pos.func
|
pos.func
|
||||||
.dfg
|
.dfg
|
||||||
.replace(info.term_inst)
|
.replace(term_inst)
|
||||||
.jump(info.cond_dest, &cond_args[1..]);
|
.jump(cond_dest, &cond_args[1..]);
|
||||||
pos.func
|
pos.func
|
||||||
.dfg
|
.dfg
|
||||||
.replace(info.cond_inst)
|
.replace(cond_inst)
|
||||||
.brnz(cond_arg, info.term_dest, &term_args);
|
.brnz(cond_arg, term_dest, &term_args);
|
||||||
}
|
}
|
||||||
BranchOrderKind::InvertIcmpCond(cond, x_arg, y_arg) => {
|
BranchOrderKind::InvertIcmpCond(cond, x_arg, y_arg) => {
|
||||||
pos.func
|
pos.func
|
||||||
.dfg
|
.dfg
|
||||||
.replace(info.term_inst)
|
.replace(term_inst)
|
||||||
.jump(info.cond_dest, &cond_args[2..]);
|
.jump(cond_dest, &cond_args[2..]);
|
||||||
pos.func.dfg.replace(info.cond_inst).br_icmp(
|
pos.func.dfg.replace(cond_inst).br_icmp(
|
||||||
cond.inverse(),
|
cond.inverse(),
|
||||||
x_arg,
|
x_arg,
|
||||||
y_arg,
|
y_arg,
|
||||||
info.term_dest,
|
term_dest,
|
||||||
&term_args,
|
&term_args,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user