mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-10 22:13:39 +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
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user