From ee46f135a92c982d1dfcfd742729df372d70a69c Mon Sep 17 00:00:00 2001 From: TennyZhuang Date: Wed, 29 Jan 2020 11:47:49 +0800 Subject: [PATCH] cmd/compile: output cost while inlining function with Debug['m'] > 1 The existing implementation outputs inline cost iff function cannot be inlined with Debug['m'] > 1, the cost info is also useful if the function is inlineable. Fixes #36780 Change-Id: Ic96f6baf96aee25fb4b33d31d4d644dc2310e536 Reviewed-on: https://go-review.googlesource.com/c/go/+/216778 Run-TryBot: Alberto Donizetti TryBot-Result: Gobot Gobot Reviewed-by: Josh Bleecher Snyder --- src/cmd/compile/internal/gc/inl.go | 2 +- test/fixedbugs/issue24651a.go | 2 +- test/fixedbugs/issue24651b.go | 4 ++-- test/inline_big.go | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/cmd/compile/internal/gc/inl.go b/src/cmd/compile/internal/gc/inl.go index 48c7de327d..f34193cb32 100644 --- a/src/cmd/compile/internal/gc/inl.go +++ b/src/cmd/compile/internal/gc/inl.go @@ -225,7 +225,7 @@ func caninl(fn *Node) { fn.Type.FuncType().Nname = asTypesNode(n) if Debug['m'] > 1 { - fmt.Printf("%v: can inline %#v as: %#v { %#v }\n", fn.Line(), n, fn.Type, asNodes(n.Func.Inl.Body)) + fmt.Printf("%v: can inline %#v with cost %d as: %#v { %#v }\n", fn.Line(), n, inlineMaxBudget-visitor.budget, fn.Type, asNodes(n.Func.Inl.Body)) } else if Debug['m'] != 0 { fmt.Printf("%v: can inline %v\n", fn.Line(), n) } diff --git a/test/fixedbugs/issue24651a.go b/test/fixedbugs/issue24651a.go index b12b0cce29..6c7bf30908 100644 --- a/test/fixedbugs/issue24651a.go +++ b/test/fixedbugs/issue24651a.go @@ -12,7 +12,7 @@ func Foo(x int) int { // ERROR "cannot inline Foo: marked go:norace with -race c return x * (x + 1) * (x + 2) } -func Bar(x int) int { // ERROR "can inline Bar as: func\(int\) int { 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) } diff --git a/test/fixedbugs/issue24651b.go b/test/fixedbugs/issue24651b.go index 2420f61fa6..aa88a6787b 100644 --- a/test/fixedbugs/issue24651b.go +++ b/test/fixedbugs/issue24651b.go @@ -7,11 +7,11 @@ package main //go:norace -func Foo(x int) int { // ERROR "can inline Foo as: func\(int\) int { return x \* \(x \+ 1\) \* \(x \+ 2\) }$" +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 as: func\(int\) int { 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) } diff --git a/test/inline_big.go b/test/inline_big.go index b72ceb7f42..68e1101d3b 100644 --- a/test/inline_big.go +++ b/test/inline_big.go @@ -9,12 +9,12 @@ package foo -func small(a []int) int { // ERROR "can inline small as:.*" "a does not escape" +func small(a []int) int { // ERROR "can inline small with cost .* as:.*" "a does not escape" // Cost 16 body (need cost < 20). // See cmd/compile/internal/gc/inl.go:inlineBigFunction* return a[0] + a[1] + a[2] + a[3] } -func medium(a []int) int { // ERROR "can inline medium as:.*" "a does not escape" +func medium(a []int) int { // ERROR "can inline medium with cost .* as:.*" "a does not escape" // Cost 32 body (need cost > 20 and cost < 80). // See cmd/compile/internal/gc/inl.go:inlineBigFunction* return a[0] + a[1] + a[2] + a[3] + a[4] + a[5] + a[6] + a[7]