compiler: run some optimizations after interface lowering
By running these interprocedural optimizations after interface lowering, in particular the heap-to-stack transformation pass, interfaces can be zero cost in some more cases. For example, say you have the following interface: type Writer interface { Write([]byte) (int, error) } and you do something with it: func foo(w io.Writer) { w.Write([]byte("foo")) } this commit enables escape analysis across interface boundaries, which means that the Write call does not cause an allocation if all implementations of io.Writer do not let the slice escape. This enables broader uses of interfaces, as they are now a zero-cost abstraction in more cases.
Этот коммит содержится в:
родитель
5a15d4162d
коммит
18b16fc151
1 изменённых файлов: 9 добавлений и 0 удалений
|
@ -43,6 +43,15 @@ func (c *Compiler) Optimize(optLevel, sizeLevel int, inlinerThreshold uint) erro
|
||||||
c.OptimizeStringToBytes()
|
c.OptimizeStringToBytes()
|
||||||
c.OptimizeAllocs()
|
c.OptimizeAllocs()
|
||||||
c.LowerInterfaces()
|
c.LowerInterfaces()
|
||||||
|
|
||||||
|
// After interfaces are lowered, there are many more opportunities for
|
||||||
|
// interprocedural optimizations. To get them to work, function
|
||||||
|
// attributes have to be updated first.
|
||||||
|
goPasses.Run(c.mod)
|
||||||
|
|
||||||
|
// Run TinyGo-specific interprocedural optimizations.
|
||||||
|
c.OptimizeAllocs()
|
||||||
|
c.OptimizeStringToBytes()
|
||||||
} else {
|
} else {
|
||||||
// Must be run at any optimization level.
|
// Must be run at any optimization level.
|
||||||
c.LowerInterfaces()
|
c.LowerInterfaces()
|
||||||
|
|
Загрузка…
Создание таблицы
Сослаться в новой задаче