]> Cypherpunks.ru repositories - gostls13.git/commitdiff
cmd/compile: output cost while inlining function with Debug['m'] > 1
authorTennyZhuang <zty0826@gmail.com>
Wed, 29 Jan 2020 03:47:49 +0000 (11:47 +0800)
committerJosh Bleecher Snyder <josharian@gmail.com>
Wed, 26 Feb 2020 14:44:24 +0000 (14:44 +0000)
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 <alb.donizetti@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
src/cmd/compile/internal/gc/inl.go
test/fixedbugs/issue24651a.go
test/fixedbugs/issue24651b.go
test/inline_big.go

index 48c7de327daf75bcfd96217e6fdee0fd27721592..f34193cb321cc5f419cbb3d95ae4368828fa4948 100644 (file)
@@ -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)
        }
index b12b0cce29b1e40aca6ddb55c67fdec5385837fb..6c7bf3090877fcae177cebe06c2462265be27ab5 100644 (file)
@@ -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)
 }
 
index 2420f61fa66e932cf554a073ae7fa4629e314a60..aa88a6787b96bfd7db8f8231dc7f4dccdce4ce50 100644 (file)
@@ -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)
 }
 
index b72ceb7f42b052b439cc20bba432bc0ca798cacb..68e1101d3b0de921e9128f4d2b519e58748ce2ba 100644 (file)
@@ -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]