Last active
July 3, 2020 18:46
-
-
Save phipsgabler/006da4e4633f977c88366072e768ac34 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
IRTools.@dynamo function sloppyifs(f, args...) | |
ir = IRTools.IR(f, args...) | |
ir === nothing && return | |
IRTools.recurse!(ir) | |
for block in IRTools.blocks(ir) | |
bblock = IRTools.BasicBlock(block) | |
for b in eachindex(IRTools.branches(bblock)) | |
branch = bblock.branches[b] | |
if IRTools.isconditional(branch) | |
converted = push!(block, IRTools.xcall(:convert, Bool, branch.condition)) | |
bblock.branches[b] = IRTools.Branch(branch; condition=converted) | |
end | |
end | |
end | |
return ir | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Note that this dynamo uses
recurse!
, and thus will convert the branches in all calls down to primitives. If you don't need that, better don't do it, since it can theoretically change behaviour in weird ways.