Type: | Package |
Title: | The R Code Optimizer |
Version: | 1.0.2 |
Maintainer: | Juan Cruz Rodriguez <jcrodriguez@unc.edu.ar> |
Description: | Automatically apply different strategies to optimize R code. 'rco' functions take R code as input, and returns R code as output. |
Depends: | R (≥ 3.6.0) |
License: | GPL-3 |
URL: | https://jcrodriguez1989.github.io/rco/ |
BugReports: | https://github.com/jcrodriguez1989/rco/issues |
Encoding: | UTF-8 |
VignetteBuilder: | knitr |
RoxygenNote: | 7.1.1 |
Suggests: | covr, diffr, ggplot2, httr, knitr, markdown, microbenchmark, rmarkdown, rstudioapi, rvest, shiny, shinythemes, testthat, xml2 |
NeedsCompilation: | no |
Packaged: | 2021-04-17 13:37:11 UTC; jcrodriguez |
Author: | Juan Cruz Rodriguez [aut, cre],
Yihui Xie |
Repository: | CRAN |
Date/Publication: | 2021-04-17 14:00:02 UTC |
All optimizers list.
Description
List of all the optimizer functions:
Constant Folding
opt_constant_folding
Constant Propagation
opt_constant_propagation
Dead Code Elimination
opt_dead_code
Dead Store Elimination
opt_dead_store
Dead Expression Elimination
opt_dead_expr
Common Subexpression Elimination
opt_common_subexpr
Loop-invariant Code Motion
opt_loop_invariant
Usage
all_optimizers
Format
An object of class list
of length 7.
Max optimizers list.
Description
List of all the optimizer functions, with maximum optimization techniques enabled. Note that using this optimizers could change the semantics of the program!
Constant Folding
opt_constant_folding
Constant Propagation
opt_constant_propagation
Dead Code Elimination
opt_dead_code
Dead Store Elimination
opt_dead_store
Dead Expression Elimination
opt_dead_expr
Common Subexpression Elimination
opt_common_subexpr
Loop-invariant Code Motion
opt_loop_invariant
Usage
max_optimizers
Format
An object of class list
of length 7.
Optimizer: Common Subexpression Elimination.
Description
Performs one common subexpression elimination pass. Carefully examine the results after running this function!
Usage
opt_common_subexpr(texts, n_values = 2, in_fun_call = FALSE)
Arguments
texts |
A list of character vectors with the code to optimize. |
n_values |
A numeric indicating the minimum number of values to consider a subexpression. |
in_fun_call |
A logical indicating whether it should propagate in function calls. Note: this could change the semantics of the program. |
Examples
code <- paste(
"a <- b * c + g",
"d = b * c * e",
sep = "\n"
)
cat(opt_common_subexpr(list(code))$codes[[1]])
Optimizer: Constant Folding.
Description
Performs one constant folding pass. Carefully examine the results after running this function!
Usage
opt_constant_folding(texts, fold_floats = FALSE, in_fun_call = FALSE)
Arguments
texts |
A list of character vectors with the code to optimize. |
fold_floats |
A logical indicating if floating-point results should be folded (will reduce precision). |
in_fun_call |
A logical indicating whether it should propagate in function calls. Note: this could change the semantics of the program. |
Examples
code <- paste(
"i <- 320 * 200 * 32",
"x <- i * 20 + 100",
sep = "\n"
)
cat(opt_constant_folding(list(code))$codes[[1]])
Optimizer: Constant Propagation.
Description
Performs one constant propagation pass. Carefully examine the results after running this function!
Usage
opt_constant_propagation(texts, in_fun_call = FALSE)
Arguments
texts |
A list of character vectors with the code to optimize. |
in_fun_call |
A logical indicating whether it should propagate in function calls. Note: this could change the semantics of the program. |
Examples
code <- paste(
"i <- 170",
"x <- -170",
"y <- x + 124",
"z <- i - 124",
sep = "\n"
)
cat(opt_constant_propagation(list(code))$codes[[1]])
Optimizer: Dead Code Elimination.
Description
Performs one dead code elimination pass. Carefully examine the results after running this function!
Usage
opt_dead_code(texts)
Arguments
texts |
A list of character vectors with the code to optimize. |
Examples
code <- paste(
"while (TRUE) {",
" break",
" dead_code()",
"}",
sep = "\n"
)
cat(opt_dead_code(list(code))$codes[[1]])
Optimizer: Dead Expression Elimination.
Description
Performs one dead expression elimination pass. Carefully examine the results after running this function!
Usage
opt_dead_expr(texts)
Arguments
texts |
A list of character vectors with the code to optimize. |
Examples
code <- paste(
"foo <- function(x) {",
" x ^ 3",
" return(x ^ 3)",
"}",
sep = "\n"
)
cat(opt_dead_expr(list(code))$codes[[1]])
Optimizer: Dead Store Elimination.
Description
Performs one dead store elimination pass. Carefully examine the results after running this function!
Usage
opt_dead_store(texts)
Arguments
texts |
A list of character vectors with the code to optimize. |
Examples
code <- paste(
"foo <- function() {",
" x <- 128 ^ 2",
" return(TRUE)",
"}",
sep = "\n"
)
cat(opt_dead_store(list(code))$codes[[1]])
Optimizer: Loop-invariant Code Motion.
Description
Performs one loop-invariant code motion pass. Carefully examine the results after running this function!
Usage
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]])
Optimize '.R' files.
Description
Performs the desired optimization strategies in the files specified. Carefully examine the results after running this function! If several files interact between them (functions from one file use functions from the other), then optimizing all of them together gives more information to rco.
Usage
optimize_files(
files,
optimizers = all_optimizers,
overwrite = FALSE,
iterations = Inf
)
Arguments
files |
A character vector with paths to files to optimize. |
optimizers |
A named list of optimizer functions. |
overwrite |
A logical indicating if files should be overwritten, or saved into new files with "optimized_" prefix. |
iterations |
Numeric indicating the number of times optimizers should pass. If there was no change after current pass, it will stop. |
Optimize a folder with '.R' files.
Description
Performs the desired optimization strategies in all the '.R' in a directory. Carefully examine the results after running this function! If several files interact between them (functions from one file use functions from the other), then optimizing all of them together gives more information to rco.
Usage
optimize_folder(
folder,
optimizers = all_optimizers,
overwrite = FALSE,
iterations = Inf,
pattern = "\\.R$",
recursive = TRUE
)
Arguments
folder |
Path to a directory with files to optimize. |
optimizers |
A named list of optimizer functions. |
overwrite |
A logical indicating if files should be overwritten, or saved into new files with "optimized_" prefix. |
iterations |
Numeric indicating the number of times optimizers should pass. If there was no change after current pass, it will stop. |
pattern |
An optional regular expression. Only file names which match the regular expression will be optimized. |
recursive |
A logical value indicating whether or not files in subdirectories of 'folder' should be optimized as well. |
Optimize text containing code.
Description
Performs the desired optimization strategies in the text. Carefully examine the results after running this function!
Usage
optimize_text(text, optimizers = all_optimizers, iterations = Inf)
Arguments
text |
A character vector with the code to optimize. |
optimizers |
A named list of optimizer functions. |
iterations |
Numeric indicating the number of times optimizers should pass. If there was no change after current pass, it will stop. |
rco GUI selector.
Description
Starts the selected rco Graphical User Interface (GUI).
Usage
rco_gui(option)
Arguments
option |
A character indicating which GUI to open. One from:
|
Examples
## Start the GUI
## Not run:
rco_gui("code_optimizer")
## End(Not run)