diff options
author | Ayke van Laethem <[email protected]> | 2021-04-04 17:50:47 +0200 |
---|---|---|
committer | Ron Evans <[email protected]> | 2021-04-08 11:40:59 +0200 |
commit | 49ec3eb58e3ae2fd373b1c65883dcd05c588357a (patch) | |
tree | 3fe8230927609f5a5d767a2d6b5bbcb782196b44 /transform/optimizer.go | |
parent | fa6c1b69cea188ab28a9c7871921c9181d532de0 (diff) | |
download | tinygo-49ec3eb58e3ae2fd373b1c65883dcd05c588357a.tar.gz tinygo-49ec3eb58e3ae2fd373b1c65883dcd05c588357a.zip |
builder: add optsize attribute while building the package
This simplifies future changes. While the move itself is very simple, it
required some other changes to a few transforms that create new
functions to add the optsize attribute manually. It also required
abstracting away the optimization level flags (based on the -opt flag)
so that it can easily be retrieved from the config object.
This commit does not impact binary size on baremetal and WebAssembly.
I've seen a few tests on linux/amd64 grow slightly in size, but I'm not
too worried about those.
Diffstat (limited to 'transform/optimizer.go')
-rw-r--r-- | transform/optimizer.go | 18 |
1 files changed, 4 insertions, 14 deletions
diff --git a/transform/optimizer.go b/transform/optimizer.go index e10144b92..108219106 100644 --- a/transform/optimizer.go +++ b/transform/optimizer.go @@ -76,12 +76,12 @@ func Optimize(mod llvm.Module, config *compileopts.Config, optLevel, sizeLevel i OptimizeStringToBytes(mod) OptimizeReflectImplements(mod) OptimizeAllocs(mod) - err := LowerInterfaces(mod) + err := LowerInterfaces(mod, sizeLevel) if err != nil { return []error{err} } - errs := LowerInterrupts(mod) + errs := LowerInterrupts(mod, sizeLevel) if len(errs) > 0 { return errs } @@ -102,14 +102,14 @@ func Optimize(mod llvm.Module, config *compileopts.Config, optLevel, sizeLevel i } else { // Must be run at any optimization level. - err := LowerInterfaces(mod) + err := LowerInterfaces(mod, sizeLevel) if err != nil { return []error{err} } if config.FuncImplementation() == "switch" { LowerFuncValues(mod) } - errs := LowerInterrupts(mod) + errs := LowerInterrupts(mod, sizeLevel) if len(errs) > 0 { return errs } @@ -153,16 +153,6 @@ func Optimize(mod llvm.Module, config *compileopts.Config, optLevel, sizeLevel i return []error{errors.New("optimizations caused a verification failure")} } - if sizeLevel >= 2 { - // Set the "optsize" attribute to make slightly smaller binaries at the - // cost of some performance. - kind := llvm.AttributeKindID("optsize") - attr := mod.Context().CreateEnumAttribute(kind, 0) - for fn := mod.FirstFunction(); !fn.IsNil(); fn = llvm.NextFunction(fn) { - fn.AddFunctionAttr(attr) - } - } - // After TinyGo-specific transforms have finished, undo exporting these functions. for _, name := range getFunctionsUsedInTransforms(config) { fn := mod.NamedFunction(name) |