compiler: add optsize function attr to reduce binary size
This is also added by Clang at -Oz and results in slightly smaller binaries.
Этот коммит содержится в:
родитель
5ff5873fe6
коммит
5a15d4162d
1 изменённых файлов: 10 добавлений и 0 удалений
|
@ -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()
|
||||
|
|
Загрузка…
Создание таблицы
Сослаться в новой задаче