Skip to content

Commit 6e16e58

Browse files
committed
ssa: getAbiTypes use const global data
1 parent cc86a13 commit 6e16e58

File tree

2 files changed

+31
-6
lines changed

2 files changed

+31
-6
lines changed

runtime/internal/runtime/z_type.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,10 @@ func addType(typ *abi.Type) {
583583
rtypeList.addType(typ)
584584
}
585585

586+
func initTypes(typs *[]*abi.Type) {
587+
rtypeList.types = *typs
588+
}
589+
586590
// hashString computes the Fowler–Noll–Vo hash of s.
587591
func hashString(s string) uint32 {
588592
var h uint32

ssa/abitype.go

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -515,9 +515,7 @@ func (b Builder) abiType(t types.Type) Expr {
515515
}), prog.AbiTypePtr()}
516516
}
517517

518-
func (p Package) InitAbiTypes(fname string) Function {
519-
initFn := p.NewFunc(fname, NoArgsNoRet, InC)
520-
b := initFn.MakeBody(1)
518+
func (p Package) getAbiTypes(name string) Expr {
521519
prog := p.Prog
522520
names := make([]string, len(prog.abiSymbol))
523521
n := 0
@@ -526,17 +524,40 @@ func (p Package) InitAbiTypes(fname string) Function {
526524
n++
527525
}
528526
sort.Strings(names)
529-
fn := p.rtFunc("addType")
530-
for _, name := range names {
527+
fields := make([]llvm.Value, len(names))
528+
for i, name := range names {
531529
g := p.doNewVar(name, prog.abiSymbol[name])
532530
g.impl.SetLinkage(llvm.ExternalLinkage)
533531
g.impl.SetGlobalConstant(true)
534532
ptr := Expr{llvm.ConstGEP(g.impl.GlobalValueType(), g.impl, []llvm.Value{
535533
llvm.ConstInt(prog.Int32().ll, 0, false),
536534
llvm.ConstInt(prog.Int32().ll, 0, false),
537535
}), prog.AbiTypePtr()}
538-
b.Call(fn, ptr)
536+
fields[i] = ptr.impl
539537
}
538+
ft := prog.AbiTypePtr()
539+
atyp := prog.rawType(types.NewArray(ft.RawType(), int64(len(names))))
540+
data := Expr{llvm.ConstArray(ft.ll, fields), atyp}
541+
array := p.doNewVar(name+"$array", prog.Pointer(atyp))
542+
array.Init(data)
543+
array.impl.SetGlobalConstant(true)
544+
size := uint64(len(names))
545+
typ := prog.Slice(prog.AbiTypePtr())
546+
g := p.doNewVar(name+"$slice", prog.Pointer(typ))
547+
g.impl.SetInitializer(prog.ctx.ConstStruct([]llvm.Value{
548+
array.impl,
549+
prog.IntVal(size, prog.Int()).impl,
550+
prog.IntVal(size, prog.Int()).impl,
551+
}, false))
552+
g.impl.SetGlobalConstant(true)
553+
return g.Expr
554+
}
555+
556+
func (p Package) InitAbiTypes(fname string) Function {
557+
initFn := p.NewFunc(fname, NoArgsNoRet, InC)
558+
b := initFn.MakeBody(1)
559+
fn := p.rtFunc("initTypes")
560+
b.Call(fn, p.getAbiTypes(fname))
540561
b.Return()
541562
return initFn
542563
}

0 commit comments

Comments
 (0)