nitgs: add --direct-call-monomorph and --inline-some-methods
authorJean Privat <jean@pryen.org>
Thu, 27 Mar 2014 20:33:56 +0000 (16:33 -0400)
committerJean Privat <jean@pryen.org>
Tue, 1 Apr 2014 15:06:55 +0000 (11:06 -0400)
commitf8ca2a2208339aed2eb8e43b04f92249865be2d7
tree3582e4ec984fbeb45906a2bd0f69ab99085755d4
parent0acee85ca0710b10d98a0454bb41aba8396ed774
nitgs: add --direct-call-monomorph and --inline-some-methods

These code-generation-level global optimizations allow the separate
compiler to:

* first, use a direct call, instead of a VFT call when RTA gives inform
  that a callsite is monomorph (and that the receiver is a nonnull
  non parametric type)
* second, to inline static call when the mmethoddef is tagged accordingly
  (we reuse the `can_inline` service of the global compiler)

**DISCLAMER**
The point of these optimizations is to evaluate some extreme optimizations,
thus to bound the gain of much less aggressive optimizations.
Real direct call and inlining optimizations SHOULD be applied on the AST
or (some intermediate code level) to be combinable with other optimizations.

Some numbers for `nitg --separate nitg.nit`:

# base (no option)
total number of invocations: 45833
invocations by VFT send:     34556 (75.39%)
invocations by direct call:  9955 (21.72%)
invocations by inlinning:    1322 (2.88%)
user time 0m10.2s

# with --direct-call-monomorph
total number of invocations: 45833
invocations by VFT send:     9259 (20.20%)
invocations by direct call:  35199 (76.79%)
invocations by inlinning:    1375 (3.00%)
user 0m10.1s

# with --direct-call-monomorph and --inline-some-methods
total number of invocations: 46657
invocations by VFT send:     9701 (20.79%)
invocations by direct call:  26239 (56.23%)
invocations by inlinning:    10717 (22.96%)
user 0m10.0s

Discussion about the number:
Something is fishy, while there is a high reduction of VFT or direct calls,
there is no real gain in CPU time. Points to investigate:

* the optimized invocations are not in the hot path
  TODO gather dynamic numbers
* my CPU is very efficient when dealing with direct call and indirect calls
  TODO test on pratchett
* some issues with the measurements or with the measurer
  TODO go to sleep

Signed-off-by: Jean Privat <jean@pryen.org>
src/separate_compiler.nit