mirror of
https://github.com/golang/go
synced 2024-11-13 17:50:23 -07:00
417955d151
This CL refactors mkinlcall by extracting the core InlinedCallExpr construction code into a new "oldInline" function, and adds a new "NewInline" hook point that can be overriden with a new inliner implementation that only needs to worry about the details of constructing the InlinedCallExpr. It also moves the delayretvars optimization check into CanInline, so it's performed just once per inlinable function rather than once for each inlined call. Finally, it skips printing the function body about to be inlined (and updates the couple of regress tests that expected this output). We already report the inline body as it was saved, and this diagnostic is only applicable to the current inliner, which clones existing function body instances. In the unified IR inliner, we'll directly construct inline bodies from the serialized representation. Change-Id: Ibdbe617da83c07665dcbda402cc8d4d4431dde2f Reviewed-on: https://go-review.googlesource.com/c/go/+/323290 Trust: Matthew Dempsky <mdempsky@google.com> Trust: Dan Scales <danscales@google.com> Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Dan Scales <danscales@google.com>
25 lines
800 B
Go
25 lines
800 B
Go
//errorcheck -0 -m -m
|
|
|
|
// Copyright 2018 The Go Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package main
|
|
|
|
//go:norace
|
|
func Foo(x int) int { // ERROR "can inline Foo with cost .* as: func\(int\) int { return x \* \(x \+ 1\) \* \(x \+ 2\) }$"
|
|
return x * (x + 1) * (x + 2)
|
|
}
|
|
|
|
func Bar(x int) int { // ERROR "can inline Bar with cost .* as: func\(int\) int { return x \* \(x \+ 1\) \* \(x \+ 2\) }$"
|
|
return x * (x + 1) * (x + 2)
|
|
}
|
|
|
|
var x = 5
|
|
|
|
//go:noinline Provide a clean, constant reason for not inlining main
|
|
func main() { // ERROR "cannot inline main: marked go:noinline$"
|
|
println("Foo(", x, ")=", Foo(x)) // ERROR "inlining call to Foo"
|
|
println("Bar(", x, ")=", Bar(x)) // ERROR "inlining call to Bar"
|
|
}
|