Merge: Nitgs optims
authorJean Privat <jean@pryen.org>
Thu, 3 Apr 2014 20:06:32 +0000 (16:06 -0400)
committerJean Privat <jean@pryen.org>
Thu, 3 Apr 2014 20:06:32 +0000 (16:06 -0400)
Some optimizations on the nitg-s side (low level).

Some use the new call-graph mechanism.

Pull-Request: #372
Reviewed-by: Alexis Laferrière <alexis.laf@xymus.net>

1  2 
src/abstract_compiler.nit
src/model/model.nit
src/separate_compiler.nit

Simple merge
Simple merge
@@@ -1078,12 -1104,51 +1104,51 @@@ class SeparateCompilerVisito
                                else
                                        self.add("{res} = 1; /* arg is null and recv is not */")
                                end
-                               if maybenull then
-                                       self.add("\}")
-                               end
-                               return res
+                               self.add("\}") # closes the null case
+                               self.add("if (0) \{") # what follow is useless, CC will drop it
                        end
                end
+               return res
+       end
+       private fun table_send(mmethod: MMethod, arguments: Array[RuntimeVariable], const_color: String): nullable RuntimeVariable
+       do
+               compiler.modelbuilder.nb_invok_by_tables += 1
+               if compiler.modelbuilder.toolcontext.opt_invocation_metrics.value then add("count_invoke_by_tables++;")
+               assert arguments.length == mmethod.intro.msignature.arity + 1 else debug("Invalid arity for {mmethod}. {arguments.length} arguments given.")
+               var recv = arguments.first
+               var res0 = before_send(mmethod, arguments)
+               var res: nullable RuntimeVariable
+               var msignature = mmethod.intro.msignature.resolve_for(mmethod.intro.mclassdef.bound_mtype, mmethod.intro.mclassdef.bound_mtype, mmethod.intro.mclassdef.mmodule, true)
+               var ret = msignature.return_mtype
+               if mmethod.is_new then
+                       ret = arguments.first.mtype
+                       res = self.new_var(ret)
+               else if ret == null then
+                       res = null
+               else
+                       res = self.new_var(ret)
+               end
 -              var s = new Buffer
 -              var ss = new Buffer
++              var s = new FlatBuffer
++              var ss = new FlatBuffer
+               s.append("val*")
+               ss.append("{recv}")
+               for i in [0..msignature.arity[ do
+                       var a = arguments[i+1]
+                       var t = msignature.mparameters[i].mtype
+                       if i == msignature.vararg_rank then
+                               t = arguments[i+1].mcasttype
+                       end
+                       s.append(", {t.ctype}")
+                       a = self.autobox(a, t)
+                       ss.append(", {a}")
+               end
  
                var r
                if ret == null then r = "void" else r = ret.ctype