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).
Этот коммит содержится в:
родитель
d7b7583e83
коммит
7c24925aa7
3 изменённых файлов: 15 добавлений и 5 удалений
|
@ -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
|
||||
|
|
|
@ -180,8 +180,8 @@ func CallGraph(f *elf.File, callsIndirectFunction []string) (map[string][]*CallN
|
|||
// used for getting a function pointer
|
||||
isCall = false
|
||||
case elf.R_ARM_ABS32:
|
||||
// used in the reset vector for pointers
|
||||
isCall = false
|
||||
// when compiling with -Oz (minsize), used for calling
|
||||
isCall = true
|
||||
default:
|
||||
return nil, fmt.Errorf("unknown relocation: %s", relocType)
|
||||
}
|
||||
|
|
|
@ -22,7 +22,10 @@ import (
|
|||
// the -opt= compiler flag.
|
||||
func AddStandardAttributes(fn llvm.Value, config *compileopts.Config) {
|
||||
_, sizeLevel, _ := config.OptLevels()
|
||||
if sizeLevel >= 2 {
|
||||
if sizeLevel >= 1 {
|
||||
fn.AddFunctionAttr(fn.Type().Context().CreateEnumAttribute(llvm.AttributeKindID("optsize"), 0))
|
||||
}
|
||||
if sizeLevel >= 2 {
|
||||
fn.AddFunctionAttr(fn.Type().Context().CreateEnumAttribute(llvm.AttributeKindID("minsize"), 0))
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Создание таблицы
Сослаться в новой задаче