diff options
Diffstat (limited to 'src/cmd/compile/internal/gc/walk.go')
-rw-r--r-- | src/cmd/compile/internal/gc/walk.go | 79 |
1 files changed, 40 insertions, 39 deletions
diff --git a/src/cmd/compile/internal/gc/walk.go b/src/cmd/compile/internal/gc/walk.go index c05aa0c372..d749dff827 100644 --- a/src/cmd/compile/internal/gc/walk.go +++ b/src/cmd/compile/internal/gc/walk.go @@ -22,33 +22,33 @@ import ( const tmpstringbufsize = 32 const zeroValSize = 1024 // must match value of runtime/map.go:maxZero -func walk(fn ir.Node) { +func walk(fn *ir.Func) { Curfn = fn errorsBefore := base.Errors() if base.Flag.W != 0 { - s := fmt.Sprintf("\nbefore walk %v", Curfn.Func().Nname.Sym()) + s := fmt.Sprintf("\nbefore walk %v", Curfn.Sym()) ir.DumpList(s, Curfn.Body()) } lno := base.Pos // Final typecheck for any unused variables. - for i, ln := range fn.Func().Dcl { + for i, ln := range fn.Dcl { if ln.Op() == ir.ONAME && (ln.Class() == ir.PAUTO || ln.Class() == ir.PAUTOHEAP) { - ln = typecheck(ln, ctxExpr|ctxAssign) - fn.Func().Dcl[i] = ln + ln = typecheck(ln, ctxExpr|ctxAssign).(*ir.Name) + fn.Dcl[i] = ln } } // Propagate the used flag for typeswitch variables up to the NONAME in its definition. - for _, ln := range fn.Func().Dcl { + for _, ln := range fn.Dcl { if ln.Op() == ir.ONAME && (ln.Class() == ir.PAUTO || ln.Class() == ir.PAUTOHEAP) && ln.Name().Defn != nil && ln.Name().Defn.Op() == ir.OTYPESW && ln.Name().Used() { ln.Name().Defn.Left().Name().SetUsed(true) } } - for _, ln := range fn.Func().Dcl { + for _, ln := range fn.Dcl { if ln.Op() != ir.ONAME || (ln.Class() != ir.PAUTO && ln.Class() != ir.PAUTOHEAP) || ln.Sym().Name[0] == '&' || ln.Name().Used() { continue } @@ -69,15 +69,15 @@ func walk(fn ir.Node) { } walkstmtlist(Curfn.Body().Slice()) if base.Flag.W != 0 { - s := fmt.Sprintf("after walk %v", Curfn.Func().Nname.Sym()) + s := fmt.Sprintf("after walk %v", Curfn.Sym()) ir.DumpList(s, Curfn.Body()) } zeroResults() heapmoves() - if base.Flag.W != 0 && Curfn.Func().Enter.Len() > 0 { - s := fmt.Sprintf("enter %v", Curfn.Func().Nname.Sym()) - ir.DumpList(s, Curfn.Func().Enter) + if base.Flag.W != 0 && Curfn.Enter.Len() > 0 { + s := fmt.Sprintf("enter %v", Curfn.Sym()) + ir.DumpList(s, Curfn.Enter) } } @@ -87,8 +87,8 @@ func walkstmtlist(s []ir.Node) { } } -func paramoutheap(fn ir.Node) bool { - for _, ln := range fn.Func().Dcl { +func paramoutheap(fn *ir.Func) bool { + for _, ln := range fn.Dcl { switch ln.Class() { case ir.PPARAMOUT: if isParamStackCopy(ln) || ln.Name().Addrtaken() { @@ -209,18 +209,18 @@ func walkstmt(n ir.Node) ir.Node { base.Errorf("case statement out of place") case ir.ODEFER: - Curfn.Func().SetHasDefer(true) - Curfn.Func().NumDefers++ - if Curfn.Func().NumDefers > maxOpenDefers { + Curfn.SetHasDefer(true) + Curfn.NumDefers++ + if Curfn.NumDefers > maxOpenDefers { // Don't allow open-coded defers if there are more than // 8 defers in the function, since we use a single // byte to record active defers. - Curfn.Func().SetOpenCodedDeferDisallowed(true) + Curfn.SetOpenCodedDeferDisallowed(true) } if n.Esc() != EscNever { // If n.Esc is not EscNever, then this defer occurs in a loop, // so open-coded defers cannot be used in this function. - Curfn.Func().SetOpenCodedDeferDisallowed(true) + Curfn.SetOpenCodedDeferDisallowed(true) } fallthrough case ir.OGO: @@ -270,7 +270,7 @@ func walkstmt(n ir.Node) ir.Node { walkstmtlist(n.Rlist().Slice()) case ir.ORETURN: - Curfn.Func().NumReturns++ + Curfn.NumReturns++ if n.List().Len() == 0 { break } @@ -279,12 +279,13 @@ func walkstmt(n ir.Node) ir.Node { // so that reorder3 can fix up conflicts var rl []ir.Node - for _, ln := range Curfn.Func().Dcl { + for _, ln := range Curfn.Dcl { cl := ln.Class() if cl == ir.PAUTO || cl == ir.PAUTOHEAP { break } if cl == ir.PPARAMOUT { + var ln ir.Node = ln if isParamStackCopy(ln) { ln = walkexpr(typecheck(ir.Nod(ir.ODEREF, ln.Name().Heapaddr, nil), ctxExpr), nil) } @@ -800,8 +801,8 @@ opswitch: fromType := n.Left().Type() toType := n.Type() - if !fromType.IsInterface() && !ir.IsBlank(Curfn.Func().Nname) { // skip unnamed functions (func _()) - markTypeUsedInInterface(fromType, Curfn.Func().LSym) + if !fromType.IsInterface() && !ir.IsBlank(Curfn.Nname) { // skip unnamed functions (func _()) + markTypeUsedInInterface(fromType, Curfn.LSym) } // typeword generates the type word of the interface value. @@ -1625,7 +1626,7 @@ func markTypeUsedInInterface(t *types.Type, from *obj.LSym) { func markUsedIfaceMethod(n ir.Node) { ityp := n.Left().Left().Type() tsym := typenamesym(ityp).Linksym() - r := obj.Addrel(Curfn.Func().LSym) + r := obj.Addrel(Curfn.LSym) r.Sym = tsym // n.Left.Xoffset is the method index * Widthptr (the offset of code pointer // in itab). @@ -2448,7 +2449,7 @@ func zeroResults() { v = v.Name().Stackcopy } // Zero the stack location containing f. - Curfn.Func().Enter.Append(ir.NodAt(Curfn.Pos(), ir.OAS, v, nil)) + Curfn.Enter.Append(ir.NodAt(Curfn.Pos(), ir.OAS, v, nil)) } } @@ -2478,9 +2479,9 @@ func heapmoves() { nn := paramstoheap(Curfn.Type().Recvs()) nn = append(nn, paramstoheap(Curfn.Type().Params())...) nn = append(nn, paramstoheap(Curfn.Type().Results())...) - Curfn.Func().Enter.Append(nn...) - base.Pos = Curfn.Func().Endlineno - Curfn.Func().Exit.Append(returnsfromheap(Curfn.Type().Results())...) + Curfn.Enter.Append(nn...) + base.Pos = Curfn.Endlineno + Curfn.Exit.Append(returnsfromheap(Curfn.Type().Results())...) base.Pos = lno } @@ -2781,7 +2782,7 @@ func appendslice(n ir.Node, init *ir.Nodes) ir.Node { nptr2 := l2 - Curfn.Func().SetWBPos(n.Pos()) + Curfn.SetWBPos(n.Pos()) // instantiate typedslicecopy(typ *type, dstPtr *any, dstLen int, srcPtr *any, srcLen int) int fn := syslook("typedslicecopy") @@ -2966,7 +2967,7 @@ func extendslice(n ir.Node, init *ir.Nodes) ir.Node { hasPointers := elemtype.HasPointers() if hasPointers { clrname = "memclrHasPointers" - Curfn.Func().SetWBPos(n.Pos()) + Curfn.SetWBPos(n.Pos()) } var clr ir.Nodes @@ -3100,7 +3101,7 @@ func walkappend(n ir.Node, init *ir.Nodes, dst ir.Node) ir.Node { // func copyany(n ir.Node, init *ir.Nodes, runtimecall bool) ir.Node { if n.Left().Type().Elem().HasPointers() { - Curfn.Func().SetWBPos(n.Pos()) + Curfn.SetWBPos(n.Pos()) fn := writebarrierfn("typedslicecopy", n.Left().Type().Elem(), n.Right().Type().Elem()) n.SetLeft(cheapexpr(n.Left(), init)) ptrL, lenL := backingArrayPtrLen(n.Left()) @@ -3714,9 +3715,9 @@ func usemethod(n ir.Node) { // (including global variables such as numImports - was issue #19028). // Also need to check for reflect package itself (see Issue #38515). if s := res0.Type.Sym; s != nil && s.Name == "Method" && isReflectPkg(s.Pkg) { - Curfn.Func().SetReflectMethod(true) + Curfn.SetReflectMethod(true) // The LSym is initialized at this point. We need to set the attribute on the LSym. - Curfn.Func().LSym.Set(obj.AttrReflectMethod, true) + Curfn.LSym.Set(obj.AttrReflectMethod, true) } } @@ -3765,10 +3766,10 @@ func usefield(n ir.Node) { } sym := tracksym(outer, field) - if Curfn.Func().FieldTrack == nil { - Curfn.Func().FieldTrack = make(map[*types.Sym]struct{}) + if Curfn.FieldTrack == nil { + Curfn.FieldTrack = make(map[*types.Sym]struct{}) } - Curfn.Func().FieldTrack[sym] = struct{}{} + Curfn.FieldTrack[sym] = struct{}{} } func candiscardlist(l ir.Nodes) bool { @@ -3948,12 +3949,12 @@ func wrapCall(n ir.Node, init *ir.Nodes) ir.Node { funcbody() - fn = typecheck(fn, ctxStmt) + typecheckFunc(fn) typecheckslice(fn.Body().Slice(), ctxStmt) xtop = append(xtop, fn) call = ir.Nod(ir.OCALL, nil, nil) - call.SetLeft(fn.Func().Nname) + call.SetLeft(fn.Nname) call.PtrList().Set(n.List().Slice()) call = typecheck(call, ctxStmt) call = walkexpr(call, init) @@ -4091,6 +4092,6 @@ func walkCheckPtrArithmetic(n ir.Node, init *ir.Nodes) ir.Node { // checkPtr reports whether pointer checking should be enabled for // function fn at a given level. See debugHelpFooter for defined // levels. -func checkPtr(fn ir.Node, level int) bool { - return base.Debug.Checkptr >= level && fn.Func().Pragma&ir.NoCheckPtr == 0 +func checkPtr(fn *ir.Func, level int) bool { + return base.Debug.Checkptr >= level && fn.Pragma&ir.NoCheckPtr == 0 } |