main: add -print-allocs flag that lets you print all heap allocations

This flag, if set, is a regexp for function names. If there are heap
allocations in the matching function names, these heap allocations will
be printed with an explanation why the heap allocation exists (and why
the object can't be stack allocated).
This commit is contained in:
Ayke van Laethem
2021-04-19 00:34:57 +02:00
committed by Ron Evans
parent 404b65941a
commit c466465c32
6 changed files with 225 additions and 16 deletions
+6 -2
View File
@@ -3,6 +3,8 @@ package transform
import (
"errors"
"fmt"
"go/token"
"os"
"github.com/tinygo-org/tinygo/compileopts"
"github.com/tinygo-org/tinygo/compiler/ircheck"
@@ -65,7 +67,7 @@ func Optimize(mod llvm.Module, config *compileopts.Config, optLevel, sizeLevel i
OptimizeMaps(mod)
OptimizeStringToBytes(mod)
OptimizeReflectImplements(mod)
OptimizeAllocs(mod)
OptimizeAllocs(mod, nil, nil)
err := LowerInterfaces(mod, sizeLevel)
if err != nil {
return []error{err}
@@ -86,7 +88,9 @@ func Optimize(mod llvm.Module, config *compileopts.Config, optLevel, sizeLevel i
goPasses.Run(mod)
// Run TinyGo-specific interprocedural optimizations.
OptimizeAllocs(mod)
OptimizeAllocs(mod, config.Options.PrintAllocs, func(pos token.Position, msg string) {
fmt.Fprintln(os.Stderr, pos.String()+": "+msg)
})
OptimizeStringToBytes(mod)
OptimizeStringEqual(mod)