compiler: add optsize function attr to reduce binary size

This is also added by Clang at -Oz and results in slightly smaller
binaries.
This commit is contained in:
Ayke van Laethem
2018-12-22 17:09:41 +01:00
parent 5ff5873fe6
commit 5a15d4162d
+10
View File
@@ -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()