From 6dba16f28e4a5fb0f0d856309acb3c4ecfbaf3c5 Mon Sep 17 00:00:00 2001 From: Ayke van Laethem Date: Fri, 19 May 2023 15:24:28 +0200 Subject: [PATCH] compiler: only calculate functionInfo once This is a small change that's not really important in itself, but it avoids duplicate errors in a future commit that adds error messages to //go:wasmimport. --- compiler/compiler.go | 16 +++++++++------- compiler/symbol.go | 4 ++++ 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/compiler/compiler.go b/compiler/compiler.go index 453335e9..09f11e61 100644 --- a/compiler/compiler.go +++ b/compiler/compiler.go @@ -82,6 +82,7 @@ type compilerContext struct { uintptrType llvm.Type program *ssa.Program diagnostics []error + functionInfos map[*ssa.Function]functionInfo astComments map[string]*ast.CommentGroup embedGlobals map[string][]*loader.EmbedFile pkg *types.Package @@ -93,13 +94,14 @@ type compilerContext struct { // importantly with a newly created LLVM context and module. func newCompilerContext(moduleName string, machine llvm.TargetMachine, config *Config, dumpSSA bool) *compilerContext { c := &compilerContext{ - Config: config, - DumpSSA: dumpSSA, - difiles: make(map[string]llvm.Metadata), - ditypes: make(map[types.Type]llvm.Metadata), - machine: machine, - targetData: machine.CreateTargetData(), - astComments: map[string]*ast.CommentGroup{}, + Config: config, + DumpSSA: dumpSSA, + difiles: make(map[string]llvm.Metadata), + ditypes: make(map[types.Type]llvm.Metadata), + machine: machine, + targetData: machine.CreateTargetData(), + functionInfos: map[*ssa.Function]functionInfo{}, + astComments: map[string]*ast.CommentGroup{}, } c.ctx = llvm.NewContext() diff --git a/compiler/symbol.go b/compiler/symbol.go index de783817..7d9fcc2f 100644 --- a/compiler/symbol.go +++ b/compiler/symbol.go @@ -239,12 +239,16 @@ func (c *compilerContext) getFunction(fn *ssa.Function) (llvm.Type, llvm.Value) // present in *ssa.Function, such as the link name and whether it should be // exported. func (c *compilerContext) getFunctionInfo(f *ssa.Function) functionInfo { + if info, ok := c.functionInfos[f]; ok { + return info + } info := functionInfo{ // Pick the default linkName. linkName: f.RelString(nil), } // Check for //go: pragmas, which may change the link name (among others). info.parsePragmas(f) + c.functionInfos[f] = info return info }