compiler: add minsize attribute for -Oz

This matches the behavior of Clang, which uses optsize for -Os and adds
minsize for -Oz.

The code size change is all over the map, but using a hacked together
size comparison tool I've found that there is a slight reduction in
binary size overall (-1.6% with the tinygo smoke tests and -0.8% for the
drivers smoke test).
This commit is contained in:
Ayke van Laethem
2021-11-01 18:37:00 +01:00
committed by Ron Evans
parent d7b7583e83
commit 7c24925aa7
3 changed files with 15 additions and 5 deletions
+9 -2
View File
@@ -327,13 +327,20 @@ func getParams(sig *types.Signature) []*types.Var {
// addStandardDeclaredAttributes adds attributes that are set for any function,
// whether declared or defined.
func (c *compilerContext) addStandardDeclaredAttributes(llvmFn llvm.Value) {
if c.SizeLevel >= 2 {
if c.SizeLevel >= 1 {
// Set the "optsize" attribute to make slightly smaller binaries at the
// cost of some performance.
// cost of minimal performance loss (-Os in Clang).
kind := llvm.AttributeKindID("optsize")
attr := c.ctx.CreateEnumAttribute(kind, 0)
llvmFn.AddFunctionAttr(attr)
}
if c.SizeLevel >= 2 {
// Set the "minsize" attribute to reduce code size even further,
// regardless of performance loss (-Oz in Clang).
kind := llvm.AttributeKindID("minsize")
attr := c.ctx.CreateEnumAttribute(kind, 0)
llvmFn.AddFunctionAttr(attr)
}
}
// addStandardDefinedAttributes adds the set of attributes that are added to