var fn *ir.Name
switch call.Op() {
case ir.OCALLFUNC:
+ // If we have a direct call to a closure (not just one we were
+ // able to statically resolve with ir.StaticValue), mark it as
+ // such so batch.outlives can optimize the flow results.
+ if call.X.Op() == ir.OCLOSURE {
+ call.X.(*ir.ClosureExpr).Func.SetClosureCalled(true)
+ }
+
switch v := ir.StaticValue(call.X); v.Op() {
case ir.ONAME:
if v := v.(*ir.Name); v.Class == ir.PFUNC {
// x.Func.Body for iexport and local inlining.
oldfn := x.Func
newfn := ir.NewFunc(oldfn.Pos())
- if oldfn.ClosureCalled() {
- newfn.SetClosureCalled(true)
- }
m.(*ir.ClosureExpr).Func = newfn
newfn.Nname = ir.NewNameAt(oldfn.Nname.Pos(), oldfn.Nname.Sym())
// XXX OK to share fn.Type() ??
// the closure is inlined in a specific function.
newclo := newfn.OClosure
newclo.SetInit(subst.list(n.Init()))
- if oldfn.ClosureCalled() {
- return typecheck.Callee(newclo)
- } else {
- return typecheck.Expr(newclo)
- }
+ return typecheck.Expr(newclo)
}
// node recursively copies a node from the saved pristine body of the
funcExportInline // include inline body in export data
funcInstrumentBody // add race/msan instrumentation during SSA construction
funcOpenCodedDeferDisallowed // can't do open-coded defers
- funcClosureCalled // closure is only immediately called
+ funcClosureCalled // closure is only immediately called; used by escape analysis
)
type SymAndPos struct {
// Add information, now that we know that fun is actually being called.
switch fun := fun.(type) {
- case *ir.ClosureExpr:
- fun.Func.SetClosureCalled(true)
case *ir.SelectorExpr:
if fun.Op() == ir.OMETHVALUE {
op := ir.ODOTMETH
case exprCall:
fun := r.expr()
- if clo, ok := fun.(*ir.ClosureExpr); ok {
- clo.Func.SetClosureCalled(true)
- }
pos := r.pos()
args := r.exprs()
dots := r.bool()
newfn := ir.NewClosureFunc(oldfn.Pos(), subst.newf != nil)
ir.NameClosure(newfn.OClosure, subst.newf)
- newfn.SetClosureCalled(oldfn.ClosureCalled())
-
saveNewf := subst.newf
ir.CurFunc = newfn
subst.newf = newfn
fn.Iota = x
}
- fn.SetClosureCalled(top&ctxCallee != 0)
-
ir.NameClosure(clo, ir.CurFunc)
Func(fn)