Граф коммитов

10 коммитов

Автор SHA1 Сообщение Дата
Ayke van Laethem
b4c90f3677
compiler: lower interfaces in a separate pass
This commit changes many things:

  * Most interface-related operations are moved into an optimization
    pass for more modularity. IR construction creates pseudo-calls which
    are lowered in this pass.
  * Type codes are assigned in this interface lowering pass, after DCE.
  * Type codes are sorted by usage: types more often used in type
    asserts are assigned lower numbers to ease jump table construction
    during machine code generation.
  * Interface assertions are optimized: they are replaced by constant
    false, comparison against a constant, or a typeswitch with only
    concrete types in the general case.
  * Interface calls are replaced with unreachable, direct calls, or a
    concrete type switch with direct calls depending on the number of
    implementing types. This hopefully makes some interface patterns
    zero-cost.

These changes lead to a ~0.5K reduction in code size on Cortex-M for
testdata/interface.go. It appears that a major cause for this is the
replacement of function pointers with direct calls, which are far more
susceptible to optimization. Also, not having a fixed global array of
function pointers greatly helps dead code elimination.

This change also makes future optimizations easier, like optimizations
on interface value comparisons.
2018-12-01 13:26:06 +01:00
Ayke van Laethem
100901574b
compiler: let escape analysis look across bitcasts
This is necessary to avoid memory allocation in the math packages in
some functions.
2018-11-16 23:03:38 +01:00
Ayke van Laethem
317b12b8c0
compiler: remove println statement
I forgot to remove this debug print after I wrote the code...
2018-10-29 18:18:23 +01:00
Ayke van Laethem
2a5c331516
compiler: assume external functions don't let pointers escape
Assume any external function won't let pointers live longer than the
call itself. This is true in the vast majority of cases (apparently
everywhere currently) but might not always be true.

TODO: add a //go:noescape (or maybe //go:escape) to handle this, instead
of this assumption.
2018-10-29 14:04:55 +01:00
Ayke van Laethem
cb0a148cd7
compiler: fix map optimization
Not all uses of a map are call instructions. Don't assume they are.
TODO: investigate these uses and see whether they might be eliminated?
2018-10-24 12:37:47 +02:00
Ayke van Laethem
52199f4a14
compiler: eliminate created but never used maps 2018-10-12 17:00:39 +02:00
Ayke van Laethem
25e73a5439
compiler: align and zero-initialize stack allocated values 2018-10-12 16:57:17 +02:00
Ayke van Laethem
ec73bd6a26
compiler: optimize runtime.stringToBytes calls
This optimization makes sure the following pattern doesn't do a heap
allocation (assuming Write doesn't modify the slice):

    var w *machine.UART = ...
    w.Write([]byte("foo"))

As long as Write doesn't modify the slice and LLVM can detect this, a
call to runtime.stringToBytes with the necessary allocation + copy is
avoided.
2018-10-09 14:18:12 +02:00
Ayke van Laethem
4219652535
compiler: add basic heap-to-stack optimization 2018-10-09 14:14:52 +02:00
Ayke van Laethem
5db43e8d04
compiler: move Optimize() function to a separate file
In the future, there will be more optimizations. Let's keep them in a
separate file for separation of concerns.
2018-10-06 19:57:41 +02:00