diff --git a/compiler/optimizer.go b/compiler/optimizer.go index 08d759b1..cf4b9580 100644 --- a/compiler/optimizer.go +++ b/compiler/optimizer.go @@ -51,6 +51,16 @@ func (c *Compiler) Optimize(optLevel, sizeLevel int, inlinerThreshold uint) erro return 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 := c.ctx.CreateEnumAttribute(kind, 0) + for fn := c.mod.FirstFunction(); !fn.IsNil(); fn = llvm.NextFunction(fn) { + fn.AddFunctionAttr(attr) + } + } + // Run module passes. modPasses := llvm.NewPassManager() defer modPasses.Dispose()