Performs one loop-invariant code motion pass. Carefully examine the results after running this function!

opt_loop_invariant(texts)

Arguments

texts

A list of character vectors with the code to optimize.

Examples

code <- paste( "i <- 0", "while (i < n) {", " x <- y + z", " a[i] <- 6 * i + x * x", " i <- i + 1", "}", sep = "\n" ) cat(opt_loop_invariant(list(code))$codes[[1]])
#> i <- 0 #> if (i < n) { #> x <- y + z #> } #> while (i < n) { #> a[i] <- 6 * i + x * x #> i <- i + 1 #> }