lhmouse/asteria

Optimization techniques

Closed this issue · 4 comments

Optimizer Wish List

  • Tail and Sibling Call Optimization (abbr. mistakenly TCO)
    Note that proper tail calls are a core language feature that cannot be disabled.

  • Dead Code Elimination (abbr. DCE)
    This had been implemented naively but was withdrawn. It can be added back easily. But before that, rather than having individual interfaces for varieties of optimization techniques, I would prefer to have a uniformed interface for cow_vector<AIR_Node>, which may be invoked recursively.

  • Constant Folding
    Ideally this pass should precede DCE. We may also support constant expressions (such as 1+2*3) in the future. Arithmetic overflows (such as 1<<100), if not folded, result in exceptions, so we must not fold such expressions.

  • #137

What is the state of PTC support on mutual recursive calls?

What is the state of PTC support on mutual recursive calls?

A function call is flattened if it occurs in a PTC context, regardless of being recursive or not.

Examples:

func foo() {
  if(something)
    return other(1, 2, 3);  // PTC by value (the result is an rvalue or void)

  if(something)
    return& other(4, 5, 6);  // PTC by reference (the result is forwarded as is)

  if(something) {
    other(true, false);  // PTC by voidification (the result is discarded)
    return;
  }

  other("hello");  // PTC by voidification, too
}

info: According to profiling results by callgrind, the most hot piece of code seems to be copying References.