]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.regabi] cmd/compile: replace ir.Name map with ir.NameSet in inlining
authorBaokun Lee <bk@golangcn.org>
Thu, 21 Jan 2021 06:13:36 +0000 (14:13 +0800)
committerBaokun Lee <bk@golangcn.org>
Thu, 21 Jan 2021 09:55:49 +0000 (09:55 +0000)
As CL 282212 mentioned, we should clean all map[*ir.Name]bool with
ir.NameSet.

Passes toolstash -cmp.

Updates #43819

Change-Id: I1ce5d2055f88539f807dc021cd8e3941b425bc4e
Reviewed-on: https://go-review.googlesource.com/c/go/+/284897
Run-TryBot: Baokun Lee <bk@golangcn.org>
TryBot-Result: Go Bot <gobot@golang.org>
Trust: Baokun Lee <bk@golangcn.org>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
src/cmd/compile/internal/inline/inl.go

index 46f093b1f8fb3f11ee22e13a41d5ee1138a25e2f..83f6740a48d1dc96589b8ae89016a0bec622f62c 100644 (file)
@@ -73,7 +73,7 @@ func InlinePackage() {
        })
 }
 
-// Caninl determines whether fn is inlineable.
+// CanInline determines whether fn is inlineable.
 // If so, CanInline saves fn->nbody in fn->inl and substitutes it with a copy.
 // fn and ->nbody will already have been typechecked.
 func CanInline(fn *ir.Func) {
@@ -169,7 +169,6 @@ func CanInline(fn *ir.Func) {
        visitor := hairyVisitor{
                budget:        inlineMaxBudget,
                extraCallCost: cc,
-               usedLocals:    make(map[*ir.Name]bool),
        }
        if visitor.tooHairy(fn) {
                reason = visitor.reason
@@ -254,7 +253,7 @@ type hairyVisitor struct {
        budget        int32
        reason        string
        extraCallCost int32
-       usedLocals    map[*ir.Name]bool
+       usedLocals    ir.NameSet
        do            func(ir.Node) bool
 }
 
@@ -410,7 +409,7 @@ func (v *hairyVisitor) doNode(n ir.Node) bool {
        case ir.ONAME:
                n := n.(*ir.Name)
                if n.Class == ir.PAUTO {
-                       v.usedLocals[n] = true
+                       v.usedLocals.Add(n)
                }
 
        case ir.OBLOCK:
@@ -1383,7 +1382,7 @@ func pruneUnusedAutos(ll []*ir.Name, vis *hairyVisitor) []*ir.Name {
        s := make([]*ir.Name, 0, len(ll))
        for _, n := range ll {
                if n.Class == ir.PAUTO {
-                       if _, found := vis.usedLocals[n]; !found {
+                       if !vis.usedLocals.Has(n) {
                                continue
                        }
                }