mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-08 21:13:39 +00:00
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:
committed by
Ron Evans
parent
404b65941a
commit
c466465c32
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user