mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-11 14:33:41 +00:00
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:
committed by
Ron Evans
parent
d7b7583e83
commit
7c24925aa7
+9
-2
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user