Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

branch! produces wrong target block numbers? #56

Open
femtomc opened this issue Apr 29, 2020 · 0 comments
Open

branch! produces wrong target block numbers? #56

femtomc opened this issue Apr 29, 2020 · 0 comments

Comments

@femtomc
Copy link

femtomc commented Apr 29, 2020

I'm trying to write a no-op transform:

function block_transform(ir)
    ir = copy(ir)
    n_ir = IR()
    for (i, bb) in enumerate(ir.blocks)
        new_bb = block!(n_ir, i)
        for arg in bb.args
            argument!(new_bb, arg)
        end
        for stmt in bb.stmts
            push!(new_bb, stmt)
        end
        if !isempty(bb.branches)
            for branch in bb.branches
                branch.condition isa Nothing ? branch!(new_bb, branch.block, branch.args...; unless = nothing) : branch!(new_bb, branch.block, branch.args...; unless = branch.condition)
            end
        end
    end
    return n_ir
end

but the result is something weird when I use branch!

--- IR (foo2) ---
1: (%1)
  br 2 (0.0)
2: (%2)
  %3 = Main.BlockManip.Normal(0, 1)
  %4 = Main.BlockManip.rand(%3)
  %5 = %4 > 0.0
  br 4 unless %5
  br 3
3:
  %6 = Main.BlockManip.Normal(0, 1)
  %7 = Main.BlockManip.rand(%6)
  %8 = %2 + %7
  br 2 (%8)
4:
  return %2

--- Transformed ---
1: (%1)
  br 5 (0.0)
2: (%2)
  %3 = Main.BlockManip.Normal(0, 1)
  %4 = Main.BlockManip.rand(%3)
  %5 = %4 > 0.0
  br 6 unless %5
  br 5
3:
  %6 = Main.BlockManip.Normal(0, 1)
  %7 = Main.BlockManip.rand(%6)
  %8 = %2 + %7
  br 2 (%8)
4:
  return %2
5:

i.e. the block numbers produced in the branch statement by branch! seem to be off and I'm not sure where/if I made a mistake.

Edit: I also know this is inefficient, but can I use Pipe here and work with blocks like this?

Edit2: I think I see the crux of the issue - branch.block is referring to a branch in the original IR, not the new IR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant