compiler: add optsize function attr to reduce binary size

This is also added by Clang at -Oz and results in slightly smaller
binaries.
Этот коммит содержится в:
Ayke van Laethem 2018-12-22 17:09:41 +01:00
родитель 5ff5873fe6
коммит 5a15d4162d
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: E97FF5335DFDFDED

Просмотреть файл

@ -51,6 +51,16 @@ func (c *Compiler) Optimize(optLevel, sizeLevel int, inlinerThreshold uint) erro
return errors.New("optimizations caused a verification failure") 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. // Run module passes.
modPasses := llvm.NewPassManager() modPasses := llvm.NewPassManager()
defer modPasses.Dispose() defer modPasses.Dispose()