I am working on an optimizer for Java bytecode and decided to use SSA. However, most optimizations require all operations to be purely functional, so in order to handle side effects, I decided to add an extra opaque state parameter and return value for every operation which could potentially have side effects. This will prevent optimizing away or reordering operations with side effects. For example, ignoring exception handling, you'd get something like this pseudocode.
function arguments: x1, e1
if x1 != 0
x2 = add(x1, 3)
x3, e2 = invoke(foo, x2, e1)
x4 = phi(x1, x3)
e3 = phi(e1, e2)
return x4, e3
Is there a name for what I'm doing? Is it a good approach? I have heard that functional languages have a concept called Monads, which sounds similar but is not the same. Is using monads a better approach? If so, how can I modify this to use monads?