Merge: Guard call
authorJean Privat <jean@pryen.org>
Thu, 26 Feb 2015 02:23:36 +0000 (09:23 +0700)
committerJean Privat <jean@pryen.org>
Thu, 26 Feb 2015 02:23:36 +0000 (09:23 +0700)
Add option `--guard-call` as an alternative implementation of the link-time optimization `--substitute-monomorph`

The idea is to have the standard VFT call guarded by a symbol when the call is monomorphic.
So the sequence is independent of any client and is roughly

~~~
if SYMBOL != null then
   SYMBOL(ARGS)
else
   (SELF->VFT[COLOR])(ARGS)
end
~~~

where the value of the SYMBOL is set for each specific program at link-time: null when the call is polymorphic and the address of the single target when the call is monomorphic.

Benches show that, on my computer, there is from 0% to 10% in loss so this alternative implementation is pure overcost :)
Still keep it because, I coded it and works, and it may worth something on other architectures.

The benchs shows some quick results:

* first (sc, red) is default
* second (sl, green) is `--substitute-monomorph`, the previous impl
* third (gc, blue) is `--guard-call``, the new one
* last (cd, purple) is `--direct-call-monomorph0`, the optimal with direct calls directly inserted in a global way

![bench_linkboost](https://cloud.githubusercontent.com/assets/135828/6342973/794b2a92-bc13-11e4-9b22-cc43e6cda473.png)

Even if the result is deceiving, the PR does some cleanup and refactorization, so we got that goin for us,  which is nice.

Pull-Request: #1173
Reviewed-by: Alexandre Terrasa <alexandre@moz-code.org>
Reviewed-by: Lucas Bajolet <r4pass@hotmail.com>

1  2 
benchmarks/bench_engines.sh

@@@ -57,8 -57,7 +57,8 @@@ function run_compiler(
                bench_command "nitc-g" "nitc --global --no-cc ../src/nitls.nit" "./nitc.$title.bin" -v --global --no-cc ../src/nitls.nit
                bench_command "nitc-s" "nitc --separate ../src/nitc.nit" "./nitc.$title.bin" -v --no-cc --separate ../src/nitc.nit
                run_command "$@" ../src/nit.nit -o "nit.$title.bin"
 -              bench_command "nit" "nit ../src/test_parser.nit ../src/nitls.nit" "./nit.$title.bin" -v ../src/test_parser.nit -- -n ../src/nitls.nit
 +              bench_command "nit-queens" "nit queens.nit 8" "./nit.$title.bin" ../lib/ai/examples/queens.nit -q 8
 +              bench_command "nit-nitcc" "nit nitcc.nit calc.sablecc" "./nit.$title.bin" ../contrib/nitcc/src/nitcc.nit ../contrib/nitcc/examples/calc.sablecc
                run_command "$@" ../src/nitdoc.nit -o "nitdoc.$title.bin"
                rm -r out 2> /dev/null
                mkdir out 2> /dev/null
@@@ -73,8 -72,6 +73,8 @@@
                bench_command "queens" "bench_queens 13" "./queens.$title.bin" 13
                run_command "$@" "../lib/ai/examples/puzzle.nit" -o "puzzle.$title.bin"
                bench_command "puzzle" "puzzle 15-hard" "./puzzle.$title.bin" kleg.mondcafjhbi
 +              run_command "$@" "markdown/engines/nitmd/nitmd.nit" -o "nitmd.$title.bin"
 +              bench_command "nitmd" "markdown" "./nitmd.$title.bin" markdown/benches/out/mixed.md 80
        fi
  
        rm -r *.bin .nit_compile out
  # get the bootstrapped nitc
  cp ../bin/nitc .
  
 +if test -z "$fast"; then
 +      make -C markdown/benches
 +      make -C ../contrib/nitcc
 +fi
 +
  ## EFFECTIVE BENCHS ##
  
  function bench_steps()
@@@ -353,12 -345,30 +353,30 @@@ function bench_linkboost(
        run_compiler "nitc-sct" ./nitc --separate --colors-are-symbols --trampoline-call
        prepare_res "$name-nitc-sl.dat" "nitc-sl" "nitc with --separate --link-boost"
        run_compiler "nitc-scts" ./nitc --separate --link-boost
-       prepare_res "$name-nitc-sg.dat" "nitc-sg" "nitc with --separate --semi-global"
-       run_compiler "nitc-sg" ./nitc --separate --semi-global
+       prepare_res "$name-nitc-scgc.dat" "nitc-scgc" "nitc with --separate --colors-are-symbols --guard-call"
+       run_compiler "nitc-scgc" ./nitc --separate --colors-are-symbols --guard-call
+       prepare_res "$name-nitc-scd.dat" "nitc-scd" "nitc with --separate --colors-are-symbols --direct-call-monomorph0"
+       run_compiler "nitc-scd" ./nitc --separate --colors-are-symbols --direct-call-monomorph0
        plot "$name.gnu"
  }
  bench_linkboost
  
+ function bench_call_monomorph()
+ {
+       name="$FUNCNAME"
+       skip_test "$name" && return
+       prepare_res "$name-nitc.dat" "nitc" "nitc with --separate"
+       run_compiler "nitc" ./nitc
+       prepare_res "$name-nitc-d0.dat" "nitc-d0" "nitc with --separate --direct-call-monomorph0"
+       run_compiler "nitc-d0" ./nitc --direct-call-monomorph0
+       prepare_res "$name-nitc-d1.dat" "nitc-d" "nitc with --separate --direct-call-monomorph"
+       run_compiler "nitc-d1" ./nitc --direct-call-monomorph
+       prepare_res "$name-nitc-d2.dat" "nitc-d2" "nitc with --separate --direct-call-monomorph2"
+       run_compiler "nitc-d2" ./nitc --direct-call-monomorph --direct-call-monomorph0
+       plot "$name.gnu"
+ }
+ bench_call_monomorph
  if test -n "$html"; then
        echo >>"$html" "</body></html>"
  fi