Something went wrong. Try again.
🌱 A minimal programming language and compiler. git.urbach.dev/cli/q
high-performance programming-language compiler
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132package optimizer
import ( "git.urbach.dev/cli/q/src/ssa")
// Fold evaluates binary operations at compile time and replaces them with constants.func Fold(ir ssa.IR) map[ssa.Value]struct{} { var folded map[ssa.Value]struct{}
for _, block := range ir.Blocks { for _, value := range block.Instructions { switch op := value.(type) { case *ssa.BinaryOp: folded = foldBinaryOp(ir, block, op, folded) case *ssa.UnaryOp: folded = foldUnaryOp(ir, block, op, folded) } } }
for _, block := range ir.Blocks { for _, value := range block.Instructions { switch op := value.(type) { case *ssa.BinaryOp: folded = foldPowerOfTwo(block, op, folded) } } }
return folded}