FluxML / FluxML/IRTools.jl

branch! produces wrong target block numbers?

Open
#56 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Julia
Stars
113
Forks
37
PR merge metrics
No merged PRs in 30d

Description

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.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.