Skip to content
This repository has been archived by the owner on Jun 26, 2020. It is now read-only.

Commit

Permalink
Fix review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
bjorn3 committed Sep 7, 2019
1 parent c2c1238 commit 974d23d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
7 changes: 7 additions & 0 deletions cranelift-codegen/meta/src/gen_legalizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ fn unwrap_inst(
fmtln!(fmt, "func.dfg.resolve_aliases(args[{}]),", n);
} else if op.is_varargs() {
let n = inst.imm_opnums.iter().chain(inst.value_opnums.iter()).max().map(|n| n + 1).unwrap_or(0);
// We need to create a `Vec` here, as using a slice would result in a borrowck
// error later on.
fmtln!(fmt, "\
args.iter().skip({}).map(|&arg| func.dfg.resolve_aliases(arg)).collect::<Vec<_>>(),\
", n);
Expand All @@ -115,6 +117,9 @@ fn unwrap_inst(
let name = var_pool
.get(apply.args[i].maybe_var().expect("vararg without name"))
.name;

// Above name is set to an `Vec` representing the varargs. However it is expected to be
// `&[Value]` below, so we borrow it.
fmtln!(fmt, "let {} = &{};", name, name);
}
}
Expand Down Expand Up @@ -419,6 +424,8 @@ fn gen_transform<'a>(
}

if transform.def_pool.get(transform.src).apply.inst.is_branch {
// A branch might have been legalized into multiple branches, so we need to recompute
// the cfg.
fmt.line("cfg.recompute_ebb(pos.func, pos.current_ebb().unwrap());");
}

Expand Down
15 changes: 6 additions & 9 deletions cranelift-codegen/src/legalizer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,11 @@ fn legalize_inst(
match pos.func.dfg.value_def(arg) {
ir::ValueDef::Result(inst, _num) => {
if let ir::InstructionData::Binary {
opcode, args: _, ..
opcode: ir::Opcode::Iconcat,
..
} = pos.func.dfg[inst]
{
if opcode != ir::Opcode::Iconcat {
return LegalizeInstResult::SplitLegalizePending;
}
// `arg` was created by an `iconcat` instruction.
} else {
// `arg` was not created by an `iconcat` instruction. Don't try to resolve it,
// as otherwise `split::isplit` will re-insert the original `isplit`, causing
Expand Down Expand Up @@ -153,7 +152,9 @@ pub fn legalize_function(func: &mut ir::Function, cfg: &mut ControlFlowGraph, is

// Process EBBs in layout order. Some legalization actions may split the current EBB or append
// new ones to the end. We need to make sure we visit those new EBBs too.
while let Some(_ebb) = pos.next_ebb() {
while let Some(ebb) = pos.next_ebb() {
split::split_ebb_params(pos.func, cfg, ebb);

// Keep track of the cursor position before the instruction being processed, so we can
// double back when replacing instructions.
let mut prev_pos = pos.position();
Expand All @@ -176,10 +177,6 @@ pub fn legalize_function(func: &mut ir::Function, cfg: &mut ControlFlowGraph, is
}
}

while let Some(ebb) = pos.next_ebb() {
split::split_ebb_params(pos.func, cfg, ebb);
}

// Try legalizing `isplit` and `vsplit` instructions, which could not previously be legalized.
for inst in pending_splits {
pos.goto_inst(inst);
Expand Down

0 comments on commit 974d23d

Please sign in to comment.