Skip to content

Commit 91ee96e

Browse files
committed
cmd/compile/internal/devirtualize: use typecheck.HaveInlineBody to check if the inliner has concluded imported func is inlinable
1 parent df45919 commit 91ee96e

File tree

1 file changed

+18
-9
lines changed
  • src/cmd/compile/internal/devirtualize

1 file changed

+18
-9
lines changed

src/cmd/compile/internal/devirtualize/pgo.go

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -185,14 +185,18 @@ func shouldPGODevirt(fn *ir.Func) bool {
185185
}()
186186
}
187187

188-
reason = inline.InlineImpossible(fn)
189-
if reason == "no function body" {
190-
// TODO: temp fix. InlineImpossible is confused and/or we seemingly can ignore this complaint.
191-
// If we've reached here, we've already confirmed we have a Dst.AST, which implies
192-
// the destination is visible from this package.
193-
reason = ""
194-
return true
188+
if isImportedFunc(fn) {
189+
if typecheck.HaveInlineBody(fn) {
190+
// The inliner has already determined this is inlinable.
191+
return true
192+
} else {
193+
reason = "imported function that is not inlinable"
194+
return false
195+
}
195196
}
197+
198+
// Local function.
199+
reason = inline.InlineImpossible(fn)
196200
if reason != "" {
197201
return false
198202
}
@@ -364,11 +368,11 @@ func rewriteCondCall(call *ir.CallExpr, curfn, callee *ir.Func, concretetyp *typ
364368
elseBlock.Append(call)
365369
} else {
366370
// Copy slice so edits in one location don't affect another.
367-
thenRet := append([]ir.Node(nil), retvars...)
371+
thenRet := append([]ir.Node(nil), retvars...)
368372
thenAsList := ir.NewAssignListStmt(pos, ir.OAS2, thenRet, []ir.Node{concreteCall})
369373
thenBlock.Append(typecheck.Stmt(thenAsList))
370374

371-
elseRet := append([]ir.Node(nil), retvars...)
375+
elseRet := append([]ir.Node(nil), retvars...)
372376
elseAsList := ir.NewAssignListStmt(pos, ir.OAS2, elseRet, []ir.Node{call})
373377
elseBlock.Append(typecheck.Stmt(elseAsList))
374378
}
@@ -537,3 +541,8 @@ func findHotConcreteCallee(p *pgo.Profile, caller *ir.Func, call *ir.CallExpr) (
537541
}
538542
return hottest.Dst.AST, hottest.Weight
539543
}
544+
545+
func isImportedFunc(fn *ir.Func) bool {
546+
// TODO: what is proper way to check this? does it exist already?
547+
return fn.Sym().Pkg.Path != base.Ctxt.Pkgpath
548+
}

0 commit comments

Comments
 (0)