mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-09 13:33:39 +00:00
builder: add optsize attribute while building the package
This simplifies future changes. While the move itself is very simple, it required some other changes to a few transforms that create new functions to add the optsize attribute manually. It also required abstracting away the optimization level flags (based on the -opt flag) so that it can easily be retrieved from the config object. This commit does not impact binary size on baremetal and WebAssembly. I've seen a few tests on linux/amd64 grow slightly in size, but I'm not too worried about those.
This commit is contained in:
committed by
Ron Evans
parent
fa6c1b69ce
commit
49ec3eb58e
@@ -133,6 +133,7 @@ func (itf *interfaceInfo) id() string {
|
||||
// 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
|
||||
builder llvm.Builder
|
||||
ctx llvm.Context
|
||||
uintptrType llvm.Type
|
||||
@@ -145,9 +146,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) error {
|
||||
func LowerInterfaces(mod llvm.Module, sizeLevel int) error {
|
||||
p := &lowerInterfacesPass{
|
||||
mod: mod,
|
||||
sizeLevel: sizeLevel,
|
||||
builder: mod.Context().NewBuilder(),
|
||||
ctx: mod.Context(),
|
||||
uintptrType: mod.Context().IntType(llvm.NewTargetData(mod.DataLayout()).PointerSize() * 8),
|
||||
@@ -594,6 +596,9 @@ func (p *lowerInterfacesPass) createInterfaceImplementsFunc(itf *interfaceInfo)
|
||||
fn := itf.assertFunc
|
||||
fn.SetLinkage(llvm.InternalLinkage)
|
||||
fn.SetUnnamedAddr(true)
|
||||
if p.sizeLevel >= 2 {
|
||||
fn.AddFunctionAttr(p.ctx.CreateEnumAttribute(llvm.AttributeKindID("optsize"), 0))
|
||||
}
|
||||
|
||||
// TODO: debug info
|
||||
|
||||
@@ -653,6 +658,9 @@ func (p *lowerInterfacesPass) createInterfaceMethodFunc(itf *interfaceInfo, sign
|
||||
fn := itf.methodFuncs[signature]
|
||||
fn.SetLinkage(llvm.InternalLinkage)
|
||||
fn.SetUnnamedAddr(true)
|
||||
if p.sizeLevel >= 2 {
|
||||
fn.AddFunctionAttr(p.ctx.CreateEnumAttribute(llvm.AttributeKindID("optsize"), 0))
|
||||
}
|
||||
|
||||
// TODO: debug info
|
||||
|
||||
|
||||
Reference in New Issue
Block a user