Options
All
  • Public
  • Public/Protected
  • All
Menu

Module "optimize"

Index

Variables

Const foldNode

foldNode: MultiFn1<Term<any>, void> = defmulti<Term<any>, void>((t) => t.tag)

Functions

Const constantFolding

  • constantFolding(tree: Term<any>): Term<any>
  • Traverses given AST and applies constant folding optimizations where possible. Returns possibly updated tree (mutates original). Currently, only scalar operations are supported / considered.

    example
    const foo = defn("float", "foo", ["float"], (x) => [
      ret(mul(x, add(neg(float(10)), float(42))))]
    )
    
    const prog = scope([foo, foo(add(float(1), float(2)))], true);
    
    // serialized (GLSL)
    glsl(prog);
    
    // float foo(in float _sym0) {
    //   return (_sym0 * (-10.0 + 42.0));
    // };
    // foo((1.0 + 2.0));
    
    // with constant folding
    glsl(constantFolding(prog))
    
    // float foo(in float _sym0) {
    //   return (_sym0 * 32.0);
    // };
    // foo(3.0);

    Parameters

    Returns Term<any>

Const maybeFoldMath

  • maybeFoldMath(op: Operator, l: any, r: any): any

Const replaceNode

  • replaceNode(node: any, next: any): any

Generated using TypeDoc