mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-18 03:24:00 +00:00
compiler: refactor when the optsize attribute is set
This commit has a few related changes:
* It sets the optsize attribute immediately in the compiler instead of
adding it to each function afterwards in a loop. This seems to me
like the more appropriate way to do it.
* It centralizes setting the optsize attribute in the transform
package, to make later changes easier.
* It sets the optsize in a few more places: to runtime.initAll and to
WebAssembly i64 wrappers.
This commit does not affect the binary size of any of the smoke tests,
so should be risk-free.
This commit is contained in:
committed by
Ron Evans
parent
1869efe954
commit
d7b7583e83
+24
-4
@@ -108,6 +108,7 @@ func (c *compilerContext) getFunction(fn *ssa.Function) llvm.Value {
|
||||
llvmFn.AddFunctionAttr(attr)
|
||||
}
|
||||
}
|
||||
c.addStandardDeclaredAttributes(llvmFn)
|
||||
|
||||
dereferenceableOrNullKind := llvm.AttributeKindID("dereferenceable_or_null")
|
||||
for i, info := range paramInfos {
|
||||
@@ -323,10 +324,23 @@ func getParams(sig *types.Signature) []*types.Var {
|
||||
return params
|
||||
}
|
||||
|
||||
// addStandardAttributes adds the set of attributes that are added to every
|
||||
// function emitted by TinyGo (even thunks/wrappers), possibly depending on the
|
||||
// architecture.
|
||||
func (c *compilerContext) addStandardAttributes(llvmFn llvm.Value) {
|
||||
// addStandardDeclaredAttributes adds attributes that are set for any function,
|
||||
// whether declared or defined.
|
||||
func (c *compilerContext) addStandardDeclaredAttributes(llvmFn llvm.Value) {
|
||||
if c.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)
|
||||
llvmFn.AddFunctionAttr(attr)
|
||||
}
|
||||
}
|
||||
|
||||
// addStandardDefinedAttributes adds the set of attributes that are added to
|
||||
// every function defined by TinyGo (even thunks/wrappers), possibly depending
|
||||
// on the architecture. It does not set attributes only set for declared
|
||||
// functions, use addStandardDeclaredAttributes for this.
|
||||
func (c *compilerContext) addStandardDefinedAttributes(llvmFn llvm.Value) {
|
||||
// TinyGo does not currently raise exceptions, so set the 'nounwind' flag.
|
||||
// This behavior matches Clang when compiling C source files.
|
||||
// It reduces binary size on Linux a little bit on non-x86_64 targets by
|
||||
@@ -338,6 +352,12 @@ func (c *compilerContext) addStandardAttributes(llvmFn llvm.Value) {
|
||||
}
|
||||
}
|
||||
|
||||
// addStandardAttribute adds all attributes added to defined functions.
|
||||
func (c *compilerContext) addStandardAttributes(llvmFn llvm.Value) {
|
||||
c.addStandardDeclaredAttributes(llvmFn)
|
||||
c.addStandardDefinedAttributes(llvmFn)
|
||||
}
|
||||
|
||||
// globalInfo contains some information about a specific global. By default,
|
||||
// linkName is equal to .RelString(nil) on a global and extern is false, but for
|
||||
// some symbols this is different (due to //go:extern for example).
|
||||
|
||||
Reference in New Issue
Block a user