Skip to content

Instantly share code, notes, and snippets.

@phipsgabler
Last active July 3, 2020 18:46
Show Gist options
  • Save phipsgabler/006da4e4633f977c88366072e768ac34 to your computer and use it in GitHub Desktop.
Save phipsgabler/006da4e4633f977c88366072e768ac34 to your computer and use it in GitHub Desktop.
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
@phipsgabler
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment