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:
Ayke van Laethem
2021-11-01 14:41:52 +01:00
committed by Ron Evans
parent 1869efe954
commit d7b7583e83
12 changed files with 69 additions and 42 deletions
+6 -9
View File
@@ -33,6 +33,7 @@ import (
"sort"
"strings"
"github.com/tinygo-org/tinygo/compileopts"
"tinygo.org/x/go-llvm"
)
@@ -84,7 +85,7 @@ type interfaceInfo struct {
// should be seen as a regular function call (see LowerInterfaces).
type lowerInterfacesPass struct {
mod llvm.Module
sizeLevel int // LLVM optimization size level, 1 means -opt=s and 2 means -opt=z
config *compileopts.Config
builder llvm.Builder
ctx llvm.Context
uintptrType llvm.Type
@@ -97,10 +98,10 @@ type lowerInterfacesPass struct {
// emitted by the compiler as higher-level intrinsics. They need some lowering
// before LLVM can work on them. This is done so that a few cleanup passes can
// run before assigning the final type codes.
func LowerInterfaces(mod llvm.Module, sizeLevel int) error {
func LowerInterfaces(mod llvm.Module, config *compileopts.Config) error {
p := &lowerInterfacesPass{
mod: mod,
sizeLevel: sizeLevel,
config: config,
builder: mod.Context().NewBuilder(),
ctx: mod.Context(),
uintptrType: mod.Context().IntType(llvm.NewTargetData(mod.DataLayout()).PointerSize() * 8),
@@ -343,9 +344,7 @@ func (p *lowerInterfacesPass) defineInterfaceImplementsFunc(fn llvm.Value, itf *
fn.Param(0).SetName("actualType")
fn.SetLinkage(llvm.InternalLinkage)
fn.SetUnnamedAddr(true)
if p.sizeLevel >= 2 {
fn.AddFunctionAttr(p.ctx.CreateEnumAttribute(llvm.AttributeKindID("optsize"), 0))
}
AddStandardAttributes(fn, p.config)
// Start the if/else chain at the entry block.
entry := p.ctx.AddBasicBlock(fn, "entry")
@@ -389,9 +388,7 @@ func (p *lowerInterfacesPass) defineInterfaceMethodFunc(fn llvm.Value, itf *inte
parentHandle.SetName("parentHandle")
fn.SetLinkage(llvm.InternalLinkage)
fn.SetUnnamedAddr(true)
if p.sizeLevel >= 2 {
fn.AddFunctionAttr(p.ctx.CreateEnumAttribute(llvm.AttributeKindID("optsize"), 0))
}
AddStandardAttributes(fn, p.config)
// TODO: debug info