2015-03-03 13:38:14 -08:00
// Copyright 2015 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 ssa
[dev.ssa] cmd/compile: enhance command line option processing for SSA
The -d compiler flag can also specify ssa phase and flag,
for example -d=ssa/generic_cse/time,ssa/generic_cse/stats
Spaces in the phase names can be specified with an
underscore. Flags currently parsed (not necessarily
recognized by the phases yet) are:
on, off, mem, time, debug, stats, and test
On, off and time are handled in the harness,
debug, stats, and test are interpreted by the phase itself.
The pass is now attached to the Func being compiled, and a
new method logStats(key, ...value) on *Func to encourage a
semi-standardized format for that output. Output fields
are separated by tabs to ease digestion by awk and
spreadsheets. For example,
if f.pass.stats > 0 {
f.logStat("CSE REWRITES", rewrites)
}
Change-Id: I16db2b5af64c50ca9a47efeb51d961147a903abc
Reviewed-on: https://go-review.googlesource.com/19885
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: Todd Neal <todd@tneal.org>
2016-02-25 13:10:51 -05:00
import (
2016-12-06 17:08:06 -08:00
"cmd/internal/src"
2017-03-15 22:43:40 -07:00
"crypto/sha1"
[dev.ssa] cmd/compile: enhance command line option processing for SSA
The -d compiler flag can also specify ssa phase and flag,
for example -d=ssa/generic_cse/time,ssa/generic_cse/stats
Spaces in the phase names can be specified with an
underscore. Flags currently parsed (not necessarily
recognized by the phases yet) are:
on, off, mem, time, debug, stats, and test
On, off and time are handled in the harness,
debug, stats, and test are interpreted by the phase itself.
The pass is now attached to the Func being compiled, and a
new method logStats(key, ...value) on *Func to encourage a
semi-standardized format for that output. Output fields
are separated by tabs to ease digestion by awk and
spreadsheets. For example,
if f.pass.stats > 0 {
f.logStat("CSE REWRITES", rewrites)
}
Change-Id: I16db2b5af64c50ca9a47efeb51d961147a903abc
Reviewed-on: https://go-review.googlesource.com/19885
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: Todd Neal <todd@tneal.org>
2016-02-25 13:10:51 -05:00
"fmt"
"math"
cmd/compile: rearrange fields between ssa.Func, ssa.Cache, and ssa.Config
This makes ssa.Func, ssa.Cache, and ssa.Config fulfill
the roles laid out for them in CL 38160.
The only non-trivial change in this CL is how cached
values and blocks get IDs. Prior to this CL, their IDs were
assigned as part of resetting the cache, and only modified
IDs were reset. This required knowing how many values and
blocks were modified, which required a tight coupling between
ssa.Func and ssa.Config. To eliminate that coupling,
we now zero values and blocks during reset,
and assign their IDs when they are used.
Since unused values and blocks have ID == 0,
we can efficiently find the last used value/block,
to avoid zeroing everything.
Bulk zeroing is efficient, but not efficient enough
to obviate the need to avoid zeroing everything every time.
As a happy side-effect, ssa.Func.Free is no longer necessary.
DebugHashMatch and friends now belong in func.go.
They have been left in place for clarity and review.
I will move them in a subsequent CL.
Passes toolstash -cmp. No compiler performance impact.
No change in 'go test cmd/compile/internal/ssa' execution time.
Change-Id: I2eb7af58da067ef6a36e815a6f386cfe8634d098
Reviewed-on: https://go-review.googlesource.com/38167
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
2017-03-15 11:15:13 -07:00
"os"
2016-05-11 15:25:17 -04:00
"strings"
[dev.ssa] cmd/compile: enhance command line option processing for SSA
The -d compiler flag can also specify ssa phase and flag,
for example -d=ssa/generic_cse/time,ssa/generic_cse/stats
Spaces in the phase names can be specified with an
underscore. Flags currently parsed (not necessarily
recognized by the phases yet) are:
on, off, mem, time, debug, stats, and test
On, off and time are handled in the harness,
debug, stats, and test are interpreted by the phase itself.
The pass is now attached to the Func being compiled, and a
new method logStats(key, ...value) on *Func to encourage a
semi-standardized format for that output. Output fields
are separated by tabs to ease digestion by awk and
spreadsheets. For example,
if f.pass.stats > 0 {
f.logStat("CSE REWRITES", rewrites)
}
Change-Id: I16db2b5af64c50ca9a47efeb51d961147a903abc
Reviewed-on: https://go-review.googlesource.com/19885
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: Todd Neal <todd@tneal.org>
2016-02-25 13:10:51 -05:00
)
2015-06-25 23:13:57 -05:00
2017-03-14 16:44:48 -07:00
// A Func represents a Go func declaration (or function literal) and its body.
// This package compiles each Func independently.
// Funcs are single-use; a new Func must be created for every compiled function.
2015-03-03 13:38:14 -08:00
type Func struct {
2017-02-03 14:28:32 -08:00
Config * Config // architecture information
cmd/compile: rearrange fields between ssa.Func, ssa.Cache, and ssa.Config
This makes ssa.Func, ssa.Cache, and ssa.Config fulfill
the roles laid out for them in CL 38160.
The only non-trivial change in this CL is how cached
values and blocks get IDs. Prior to this CL, their IDs were
assigned as part of resetting the cache, and only modified
IDs were reset. This required knowing how many values and
blocks were modified, which required a tight coupling between
ssa.Func and ssa.Config. To eliminate that coupling,
we now zero values and blocks during reset,
and assign their IDs when they are used.
Since unused values and blocks have ID == 0,
we can efficiently find the last used value/block,
to avoid zeroing everything.
Bulk zeroing is efficient, but not efficient enough
to obviate the need to avoid zeroing everything every time.
As a happy side-effect, ssa.Func.Free is no longer necessary.
DebugHashMatch and friends now belong in func.go.
They have been left in place for clarity and review.
I will move them in a subsequent CL.
Passes toolstash -cmp. No compiler performance impact.
No change in 'go test cmd/compile/internal/ssa' execution time.
Change-Id: I2eb7af58da067ef6a36e815a6f386cfe8634d098
Reviewed-on: https://go-review.googlesource.com/38167
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
2017-03-15 11:15:13 -07:00
Cache * Cache // re-usable cache
2017-02-03 14:28:32 -08:00
pass * pass // current pass information (name, options, etc.)
Name string // e.g. bytes·Compare
Type Type // type signature of the function.
Blocks [ ] * Block // unordered set of all basic blocks (note: not indexable by ID)
Entry * Block // the entry basic block
bid idAlloc // block ID allocator
vid idAlloc // value ID allocator
2015-03-03 13:38:14 -08:00
cmd/compile: rearrange fields between ssa.Func, ssa.Cache, and ssa.Config
This makes ssa.Func, ssa.Cache, and ssa.Config fulfill
the roles laid out for them in CL 38160.
The only non-trivial change in this CL is how cached
values and blocks get IDs. Prior to this CL, their IDs were
assigned as part of resetting the cache, and only modified
IDs were reset. This required knowing how many values and
blocks were modified, which required a tight coupling between
ssa.Func and ssa.Config. To eliminate that coupling,
we now zero values and blocks during reset,
and assign their IDs when they are used.
Since unused values and blocks have ID == 0,
we can efficiently find the last used value/block,
to avoid zeroing everything.
Bulk zeroing is efficient, but not efficient enough
to obviate the need to avoid zeroing everything every time.
As a happy side-effect, ssa.Func.Free is no longer necessary.
DebugHashMatch and friends now belong in func.go.
They have been left in place for clarity and review.
I will move them in a subsequent CL.
Passes toolstash -cmp. No compiler performance impact.
No change in 'go test cmd/compile/internal/ssa' execution time.
Change-Id: I2eb7af58da067ef6a36e815a6f386cfe8634d098
Reviewed-on: https://go-review.googlesource.com/38167
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
2017-03-15 11:15:13 -07:00
// Given an environment variable used for debug hash match,
// what file (if any) receives the yes/no logging?
logfiles map [ string ] * os . File
HTMLWriter * HTMLWriter // html writer, for debugging
DebugTest bool // default true unless $GOSSAHASH != ""; as a debugging aid, make new code conditional on this and use GOSSAHASH to binary search for failing cases
2015-08-03 12:33:03 -07:00
scheduled bool // Values in Blocks are in final order
2016-11-10 16:03:47 -05:00
NoSplit bool // true if function is marked as nosplit. Used by schedule check pass.
2015-08-03 12:33:03 -07:00
2017-02-10 10:15:10 -05:00
NoWB bool // write barrier is not allowed
WBPos src . XPos // line number of first write barrier
2015-03-03 13:38:14 -08:00
// when register allocation is done, maps value ids to locations
RegAlloc [ ] Location
2015-10-22 14:22:38 -07:00
2015-11-02 08:10:26 -08:00
// map from LocalSlot to set of Values that we want to store in that slot.
NamedValues map [ LocalSlot ] [ ] * Value
2016-03-01 23:21:55 +00:00
// Names is a copy of NamedValues.Keys. We keep a separate list
2015-10-22 14:22:38 -07:00
// of keys to make iteration order deterministic.
2015-11-02 08:10:26 -08:00
Names [ ] LocalSlot
2016-01-28 13:46:30 -08:00
freeValues * Value // free Values linked by argstorage[0]. All other fields except ID are 0/nil.
2016-04-28 16:52:47 -07:00
freeBlocks * Block // free Blocks linked by succstorage[0].b. All other fields except ID are 0/nil.
2016-02-28 15:51:11 -08:00
2016-09-16 13:50:18 -07:00
cachedPostorder [ ] * Block // cached postorder traversal
cachedIdom [ ] * Block // cached immediate dominators
cachedSdom SparseTree // cached dominator tree
cachedLoopnest * loopnest // cached loop nest information
2016-04-11 21:51:29 +02:00
2017-02-09 10:45:35 -08:00
auxmap auxmap // map from aux values to opaque ids used by CSE
2016-02-28 15:51:11 -08:00
constants map [ int64 ] [ ] * Value // constants cache, keyed by constant value; users must check value's Op and Type
2015-03-03 13:38:14 -08:00
}
cmd/compile: rearrange fields between ssa.Func, ssa.Cache, and ssa.Config
This makes ssa.Func, ssa.Cache, and ssa.Config fulfill
the roles laid out for them in CL 38160.
The only non-trivial change in this CL is how cached
values and blocks get IDs. Prior to this CL, their IDs were
assigned as part of resetting the cache, and only modified
IDs were reset. This required knowing how many values and
blocks were modified, which required a tight coupling between
ssa.Func and ssa.Config. To eliminate that coupling,
we now zero values and blocks during reset,
and assign their IDs when they are used.
Since unused values and blocks have ID == 0,
we can efficiently find the last used value/block,
to avoid zeroing everything.
Bulk zeroing is efficient, but not efficient enough
to obviate the need to avoid zeroing everything every time.
As a happy side-effect, ssa.Func.Free is no longer necessary.
DebugHashMatch and friends now belong in func.go.
They have been left in place for clarity and review.
I will move them in a subsequent CL.
Passes toolstash -cmp. No compiler performance impact.
No change in 'go test cmd/compile/internal/ssa' execution time.
Change-Id: I2eb7af58da067ef6a36e815a6f386cfe8634d098
Reviewed-on: https://go-review.googlesource.com/38167
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
2017-03-15 11:15:13 -07:00
// NewFunc returns a new, empty function object.
// Caller must set f.Config and f.Cache before using f.
func NewFunc ( ) * Func {
return & Func { NamedValues : make ( map [ LocalSlot ] [ ] * Value ) }
}
2015-03-03 13:38:14 -08:00
// NumBlocks returns an integer larger than the id of any Block in the Func.
func ( f * Func ) NumBlocks ( ) int {
return f . bid . num ( )
}
// NumValues returns an integer larger than the id of any Value in the Func.
func ( f * Func ) NumValues ( ) int {
return f . vid . num ( )
}
2016-01-28 22:19:46 -06:00
// newSparseSet returns a sparse set that can store at least up to n integers.
func ( f * Func ) newSparseSet ( n int ) * sparseSet {
cmd/compile: rearrange fields between ssa.Func, ssa.Cache, and ssa.Config
This makes ssa.Func, ssa.Cache, and ssa.Config fulfill
the roles laid out for them in CL 38160.
The only non-trivial change in this CL is how cached
values and blocks get IDs. Prior to this CL, their IDs were
assigned as part of resetting the cache, and only modified
IDs were reset. This required knowing how many values and
blocks were modified, which required a tight coupling between
ssa.Func and ssa.Config. To eliminate that coupling,
we now zero values and blocks during reset,
and assign their IDs when they are used.
Since unused values and blocks have ID == 0,
we can efficiently find the last used value/block,
to avoid zeroing everything.
Bulk zeroing is efficient, but not efficient enough
to obviate the need to avoid zeroing everything every time.
As a happy side-effect, ssa.Func.Free is no longer necessary.
DebugHashMatch and friends now belong in func.go.
They have been left in place for clarity and review.
I will move them in a subsequent CL.
Passes toolstash -cmp. No compiler performance impact.
No change in 'go test cmd/compile/internal/ssa' execution time.
Change-Id: I2eb7af58da067ef6a36e815a6f386cfe8634d098
Reviewed-on: https://go-review.googlesource.com/38167
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
2017-03-15 11:15:13 -07:00
for i , scr := range f . Cache . scrSparse {
2016-01-28 22:19:46 -06:00
if scr != nil && scr . cap ( ) >= n {
cmd/compile: rearrange fields between ssa.Func, ssa.Cache, and ssa.Config
This makes ssa.Func, ssa.Cache, and ssa.Config fulfill
the roles laid out for them in CL 38160.
The only non-trivial change in this CL is how cached
values and blocks get IDs. Prior to this CL, their IDs were
assigned as part of resetting the cache, and only modified
IDs were reset. This required knowing how many values and
blocks were modified, which required a tight coupling between
ssa.Func and ssa.Config. To eliminate that coupling,
we now zero values and blocks during reset,
and assign their IDs when they are used.
Since unused values and blocks have ID == 0,
we can efficiently find the last used value/block,
to avoid zeroing everything.
Bulk zeroing is efficient, but not efficient enough
to obviate the need to avoid zeroing everything every time.
As a happy side-effect, ssa.Func.Free is no longer necessary.
DebugHashMatch and friends now belong in func.go.
They have been left in place for clarity and review.
I will move them in a subsequent CL.
Passes toolstash -cmp. No compiler performance impact.
No change in 'go test cmd/compile/internal/ssa' execution time.
Change-Id: I2eb7af58da067ef6a36e815a6f386cfe8634d098
Reviewed-on: https://go-review.googlesource.com/38167
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
2017-03-15 11:15:13 -07:00
f . Cache . scrSparse [ i ] = nil
2016-01-28 22:19:46 -06:00
scr . clear ( )
return scr
}
}
return newSparseSet ( n )
}
2016-02-02 06:35:34 -05:00
// retSparseSet returns a sparse set to the config's cache of sparse sets to be reused by f.newSparseSet.
2016-01-28 22:19:46 -06:00
func ( f * Func ) retSparseSet ( ss * sparseSet ) {
cmd/compile: rearrange fields between ssa.Func, ssa.Cache, and ssa.Config
This makes ssa.Func, ssa.Cache, and ssa.Config fulfill
the roles laid out for them in CL 38160.
The only non-trivial change in this CL is how cached
values and blocks get IDs. Prior to this CL, their IDs were
assigned as part of resetting the cache, and only modified
IDs were reset. This required knowing how many values and
blocks were modified, which required a tight coupling between
ssa.Func and ssa.Config. To eliminate that coupling,
we now zero values and blocks during reset,
and assign their IDs when they are used.
Since unused values and blocks have ID == 0,
we can efficiently find the last used value/block,
to avoid zeroing everything.
Bulk zeroing is efficient, but not efficient enough
to obviate the need to avoid zeroing everything every time.
As a happy side-effect, ssa.Func.Free is no longer necessary.
DebugHashMatch and friends now belong in func.go.
They have been left in place for clarity and review.
I will move them in a subsequent CL.
Passes toolstash -cmp. No compiler performance impact.
No change in 'go test cmd/compile/internal/ssa' execution time.
Change-Id: I2eb7af58da067ef6a36e815a6f386cfe8634d098
Reviewed-on: https://go-review.googlesource.com/38167
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
2017-03-15 11:15:13 -07:00
for i , scr := range f . Cache . scrSparse {
2016-01-28 22:19:46 -06:00
if scr == nil {
cmd/compile: rearrange fields between ssa.Func, ssa.Cache, and ssa.Config
This makes ssa.Func, ssa.Cache, and ssa.Config fulfill
the roles laid out for them in CL 38160.
The only non-trivial change in this CL is how cached
values and blocks get IDs. Prior to this CL, their IDs were
assigned as part of resetting the cache, and only modified
IDs were reset. This required knowing how many values and
blocks were modified, which required a tight coupling between
ssa.Func and ssa.Config. To eliminate that coupling,
we now zero values and blocks during reset,
and assign their IDs when they are used.
Since unused values and blocks have ID == 0,
we can efficiently find the last used value/block,
to avoid zeroing everything.
Bulk zeroing is efficient, but not efficient enough
to obviate the need to avoid zeroing everything every time.
As a happy side-effect, ssa.Func.Free is no longer necessary.
DebugHashMatch and friends now belong in func.go.
They have been left in place for clarity and review.
I will move them in a subsequent CL.
Passes toolstash -cmp. No compiler performance impact.
No change in 'go test cmd/compile/internal/ssa' execution time.
Change-Id: I2eb7af58da067ef6a36e815a6f386cfe8634d098
Reviewed-on: https://go-review.googlesource.com/38167
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
2017-03-15 11:15:13 -07:00
f . Cache . scrSparse [ i ] = ss
2016-01-28 22:19:46 -06:00
return
}
}
cmd/compile: rearrange fields between ssa.Func, ssa.Cache, and ssa.Config
This makes ssa.Func, ssa.Cache, and ssa.Config fulfill
the roles laid out for them in CL 38160.
The only non-trivial change in this CL is how cached
values and blocks get IDs. Prior to this CL, their IDs were
assigned as part of resetting the cache, and only modified
IDs were reset. This required knowing how many values and
blocks were modified, which required a tight coupling between
ssa.Func and ssa.Config. To eliminate that coupling,
we now zero values and blocks during reset,
and assign their IDs when they are used.
Since unused values and blocks have ID == 0,
we can efficiently find the last used value/block,
to avoid zeroing everything.
Bulk zeroing is efficient, but not efficient enough
to obviate the need to avoid zeroing everything every time.
As a happy side-effect, ssa.Func.Free is no longer necessary.
DebugHashMatch and friends now belong in func.go.
They have been left in place for clarity and review.
I will move them in a subsequent CL.
Passes toolstash -cmp. No compiler performance impact.
No change in 'go test cmd/compile/internal/ssa' execution time.
Change-Id: I2eb7af58da067ef6a36e815a6f386cfe8634d098
Reviewed-on: https://go-review.googlesource.com/38167
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
2017-03-15 11:15:13 -07:00
f . Cache . scrSparse = append ( f . Cache . scrSparse , ss )
2016-01-28 22:19:46 -06:00
}
2016-01-28 13:46:30 -08:00
// newValue allocates a new Value with the given fields and places it at the end of b.Values.
2016-12-15 17:17:01 -08:00
func ( f * Func ) newValue ( op Op , t Type , b * Block , pos src . XPos ) * Value {
2016-01-28 13:46:30 -08:00
var v * Value
if f . freeValues != nil {
v = f . freeValues
f . freeValues = v . argstorage [ 0 ]
v . argstorage [ 0 ] = nil
} else {
ID := f . vid . get ( )
cmd/compile: rearrange fields between ssa.Func, ssa.Cache, and ssa.Config
This makes ssa.Func, ssa.Cache, and ssa.Config fulfill
the roles laid out for them in CL 38160.
The only non-trivial change in this CL is how cached
values and blocks get IDs. Prior to this CL, their IDs were
assigned as part of resetting the cache, and only modified
IDs were reset. This required knowing how many values and
blocks were modified, which required a tight coupling between
ssa.Func and ssa.Config. To eliminate that coupling,
we now zero values and blocks during reset,
and assign their IDs when they are used.
Since unused values and blocks have ID == 0,
we can efficiently find the last used value/block,
to avoid zeroing everything.
Bulk zeroing is efficient, but not efficient enough
to obviate the need to avoid zeroing everything every time.
As a happy side-effect, ssa.Func.Free is no longer necessary.
DebugHashMatch and friends now belong in func.go.
They have been left in place for clarity and review.
I will move them in a subsequent CL.
Passes toolstash -cmp. No compiler performance impact.
No change in 'go test cmd/compile/internal/ssa' execution time.
Change-Id: I2eb7af58da067ef6a36e815a6f386cfe8634d098
Reviewed-on: https://go-review.googlesource.com/38167
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
2017-03-15 11:15:13 -07:00
if int ( ID ) < len ( f . Cache . values ) {
v = & f . Cache . values [ ID ]
v . ID = ID
2016-01-28 13:46:30 -08:00
} else {
v = & Value { ID : ID }
}
}
v . Op = op
v . Type = t
v . Block = b
2016-12-07 18:14:35 -08:00
v . Pos = pos
2016-01-28 13:46:30 -08:00
b . Values = append ( b . Values , v )
return v
2015-06-25 23:13:57 -05:00
}
2017-03-07 14:45:46 -05:00
// newValueNoBlock allocates a new Value with the given fields.
// The returned value is not placed in any block. Once the caller
// decides on a block b, it must set b.Block and append
// the returned value to b.Values.
func ( f * Func ) newValueNoBlock ( op Op , t Type , pos src . XPos ) * Value {
var v * Value
if f . freeValues != nil {
v = f . freeValues
f . freeValues = v . argstorage [ 0 ]
v . argstorage [ 0 ] = nil
} else {
ID := f . vid . get ( )
cmd/compile: rearrange fields between ssa.Func, ssa.Cache, and ssa.Config
This makes ssa.Func, ssa.Cache, and ssa.Config fulfill
the roles laid out for them in CL 38160.
The only non-trivial change in this CL is how cached
values and blocks get IDs. Prior to this CL, their IDs were
assigned as part of resetting the cache, and only modified
IDs were reset. This required knowing how many values and
blocks were modified, which required a tight coupling between
ssa.Func and ssa.Config. To eliminate that coupling,
we now zero values and blocks during reset,
and assign their IDs when they are used.
Since unused values and blocks have ID == 0,
we can efficiently find the last used value/block,
to avoid zeroing everything.
Bulk zeroing is efficient, but not efficient enough
to obviate the need to avoid zeroing everything every time.
As a happy side-effect, ssa.Func.Free is no longer necessary.
DebugHashMatch and friends now belong in func.go.
They have been left in place for clarity and review.
I will move them in a subsequent CL.
Passes toolstash -cmp. No compiler performance impact.
No change in 'go test cmd/compile/internal/ssa' execution time.
Change-Id: I2eb7af58da067ef6a36e815a6f386cfe8634d098
Reviewed-on: https://go-review.googlesource.com/38167
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
2017-03-15 11:15:13 -07:00
if int ( ID ) < len ( f . Cache . values ) {
v = & f . Cache . values [ ID ]
v . ID = ID
2017-03-07 14:45:46 -05:00
} else {
v = & Value { ID : ID }
}
}
v . Op = op
v . Type = t
v . Block = nil // caller must fix this.
v . Pos = pos
return v
}
[dev.ssa] cmd/compile: enhance command line option processing for SSA
The -d compiler flag can also specify ssa phase and flag,
for example -d=ssa/generic_cse/time,ssa/generic_cse/stats
Spaces in the phase names can be specified with an
underscore. Flags currently parsed (not necessarily
recognized by the phases yet) are:
on, off, mem, time, debug, stats, and test
On, off and time are handled in the harness,
debug, stats, and test are interpreted by the phase itself.
The pass is now attached to the Func being compiled, and a
new method logStats(key, ...value) on *Func to encourage a
semi-standardized format for that output. Output fields
are separated by tabs to ease digestion by awk and
spreadsheets. For example,
if f.pass.stats > 0 {
f.logStat("CSE REWRITES", rewrites)
}
Change-Id: I16db2b5af64c50ca9a47efeb51d961147a903abc
Reviewed-on: https://go-review.googlesource.com/19885
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: Todd Neal <todd@tneal.org>
2016-02-25 13:10:51 -05:00
// logPassStat writes a string key and int value as a warning in a
// tab-separated format easily handled by spreadsheets or awk.
// file names, lines, and function names are included to provide enough (?)
// context to allow item-by-item comparisons across runs.
// For example:
// awk 'BEGIN {FS="\t"} $3~/TIME/{sum+=$4} END{print "t(ns)=",sum}' t.log
cmd/compile: use sparse algorithm for phis in large program
This adds a sparse method for locating nearest ancestors
in a dominator tree, and checks blocks with more than one
predecessor for differences and inserts phi functions where
there are.
Uses reversed post order to cut number of passes, running
it from first def to last use ("last use" for paramout and
mem is end-of-program; last use for a phi input from a
backedge is the source of the back edge)
Includes a cutover from old algorithm to new to avoid paying
large constant factor for small programs. This keeps normal
builds running at about the same time, while not running
over-long on large machine-generated inputs.
Add "phase" flags for ssa/build -- ssa/build/stats prints
number of blocks, values (before and after linking references
and inserting phis, so expansion can be measured), and their
product; the product governs the cutover, where a good value
seems to be somewhere between 1 and 5 million.
Among the files compiled by make.bash, this is the shape of
the tail of the distribution for #blocks, #vars, and their
product:
#blocks #vars product
max 6171 28180 173,898,780
99.9% 1641 6548 10,401,878
99% 463 1909 873,721
95% 152 639 95,235
90% 84 359 30,021
The old algorithm is indeed usually fastest, for 99%ile
values of usually.
The fix to LookupVarOutgoing
( https://go-review.googlesource.com/#/c/22790/ )
deals with some of the same problems addressed by this CL,
but on at least one bug ( #15537 ) this change is still
a significant help.
With this CL:
/tmp/gopath$ rm -rf pkg bin
/tmp/gopath$ time go get -v -gcflags -memprofile=y.mprof \
github.com/gogo/protobuf/test/theproto3/combos/...
...
real 4m35.200s
user 13m16.644s
sys 0m36.712s
and pprof reports 3.4GB allocated in one of the larger profiles
With tip:
/tmp/gopath$ rm -rf pkg bin
/tmp/gopath$ time go get -v -gcflags -memprofile=y.mprof \
github.com/gogo/protobuf/test/theproto3/combos/...
...
real 10m36.569s
user 25m52.286s
sys 4m3.696s
and pprof reports 8.3GB allocated in the same larger profile
With this CL, most of the compilation time on the benchmarked
input is spent in register/stack allocation (cumulative 53%)
and in the sparse lookup algorithm itself (cumulative 20%).
Fixes #15537.
Change-Id: Ia0299dda6a291534d8b08e5f9883216ded677a00
Reviewed-on: https://go-review.googlesource.com/22342
Reviewed-by: Keith Randall <khr@golang.org>
Run-TryBot: David Chase <drchase@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2016-04-21 13:24:58 -04:00
func ( f * Func ) LogStat ( key string , args ... interface { } ) {
[dev.ssa] cmd/compile: enhance command line option processing for SSA
The -d compiler flag can also specify ssa phase and flag,
for example -d=ssa/generic_cse/time,ssa/generic_cse/stats
Spaces in the phase names can be specified with an
underscore. Flags currently parsed (not necessarily
recognized by the phases yet) are:
on, off, mem, time, debug, stats, and test
On, off and time are handled in the harness,
debug, stats, and test are interpreted by the phase itself.
The pass is now attached to the Func being compiled, and a
new method logStats(key, ...value) on *Func to encourage a
semi-standardized format for that output. Output fields
are separated by tabs to ease digestion by awk and
spreadsheets. For example,
if f.pass.stats > 0 {
f.logStat("CSE REWRITES", rewrites)
}
Change-Id: I16db2b5af64c50ca9a47efeb51d961147a903abc
Reviewed-on: https://go-review.googlesource.com/19885
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: Todd Neal <todd@tneal.org>
2016-02-25 13:10:51 -05:00
value := ""
for _ , a := range args {
value += fmt . Sprintf ( "\t%v" , a )
}
cmd/compile: use sparse algorithm for phis in large program
This adds a sparse method for locating nearest ancestors
in a dominator tree, and checks blocks with more than one
predecessor for differences and inserts phi functions where
there are.
Uses reversed post order to cut number of passes, running
it from first def to last use ("last use" for paramout and
mem is end-of-program; last use for a phi input from a
backedge is the source of the back edge)
Includes a cutover from old algorithm to new to avoid paying
large constant factor for small programs. This keeps normal
builds running at about the same time, while not running
over-long on large machine-generated inputs.
Add "phase" flags for ssa/build -- ssa/build/stats prints
number of blocks, values (before and after linking references
and inserting phis, so expansion can be measured), and their
product; the product governs the cutover, where a good value
seems to be somewhere between 1 and 5 million.
Among the files compiled by make.bash, this is the shape of
the tail of the distribution for #blocks, #vars, and their
product:
#blocks #vars product
max 6171 28180 173,898,780
99.9% 1641 6548 10,401,878
99% 463 1909 873,721
95% 152 639 95,235
90% 84 359 30,021
The old algorithm is indeed usually fastest, for 99%ile
values of usually.
The fix to LookupVarOutgoing
( https://go-review.googlesource.com/#/c/22790/ )
deals with some of the same problems addressed by this CL,
but on at least one bug ( #15537 ) this change is still
a significant help.
With this CL:
/tmp/gopath$ rm -rf pkg bin
/tmp/gopath$ time go get -v -gcflags -memprofile=y.mprof \
github.com/gogo/protobuf/test/theproto3/combos/...
...
real 4m35.200s
user 13m16.644s
sys 0m36.712s
and pprof reports 3.4GB allocated in one of the larger profiles
With tip:
/tmp/gopath$ rm -rf pkg bin
/tmp/gopath$ time go get -v -gcflags -memprofile=y.mprof \
github.com/gogo/protobuf/test/theproto3/combos/...
...
real 10m36.569s
user 25m52.286s
sys 4m3.696s
and pprof reports 8.3GB allocated in the same larger profile
With this CL, most of the compilation time on the benchmarked
input is spent in register/stack allocation (cumulative 53%)
and in the sparse lookup algorithm itself (cumulative 20%).
Fixes #15537.
Change-Id: Ia0299dda6a291534d8b08e5f9883216ded677a00
Reviewed-on: https://go-review.googlesource.com/22342
Reviewed-by: Keith Randall <khr@golang.org>
Run-TryBot: David Chase <drchase@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2016-04-21 13:24:58 -04:00
n := "missing_pass"
if f . pass != nil {
2016-05-11 15:25:17 -04:00
n = strings . Replace ( f . pass . name , " " , "_" , - 1 )
cmd/compile: use sparse algorithm for phis in large program
This adds a sparse method for locating nearest ancestors
in a dominator tree, and checks blocks with more than one
predecessor for differences and inserts phi functions where
there are.
Uses reversed post order to cut number of passes, running
it from first def to last use ("last use" for paramout and
mem is end-of-program; last use for a phi input from a
backedge is the source of the back edge)
Includes a cutover from old algorithm to new to avoid paying
large constant factor for small programs. This keeps normal
builds running at about the same time, while not running
over-long on large machine-generated inputs.
Add "phase" flags for ssa/build -- ssa/build/stats prints
number of blocks, values (before and after linking references
and inserting phis, so expansion can be measured), and their
product; the product governs the cutover, where a good value
seems to be somewhere between 1 and 5 million.
Among the files compiled by make.bash, this is the shape of
the tail of the distribution for #blocks, #vars, and their
product:
#blocks #vars product
max 6171 28180 173,898,780
99.9% 1641 6548 10,401,878
99% 463 1909 873,721
95% 152 639 95,235
90% 84 359 30,021
The old algorithm is indeed usually fastest, for 99%ile
values of usually.
The fix to LookupVarOutgoing
( https://go-review.googlesource.com/#/c/22790/ )
deals with some of the same problems addressed by this CL,
but on at least one bug ( #15537 ) this change is still
a significant help.
With this CL:
/tmp/gopath$ rm -rf pkg bin
/tmp/gopath$ time go get -v -gcflags -memprofile=y.mprof \
github.com/gogo/protobuf/test/theproto3/combos/...
...
real 4m35.200s
user 13m16.644s
sys 0m36.712s
and pprof reports 3.4GB allocated in one of the larger profiles
With tip:
/tmp/gopath$ rm -rf pkg bin
/tmp/gopath$ time go get -v -gcflags -memprofile=y.mprof \
github.com/gogo/protobuf/test/theproto3/combos/...
...
real 10m36.569s
user 25m52.286s
sys 4m3.696s
and pprof reports 8.3GB allocated in the same larger profile
With this CL, most of the compilation time on the benchmarked
input is spent in register/stack allocation (cumulative 53%)
and in the sparse lookup algorithm itself (cumulative 20%).
Fixes #15537.
Change-Id: Ia0299dda6a291534d8b08e5f9883216ded677a00
Reviewed-on: https://go-review.googlesource.com/22342
Reviewed-by: Keith Randall <khr@golang.org>
Run-TryBot: David Chase <drchase@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2016-04-21 13:24:58 -04:00
}
2016-12-07 18:14:35 -08:00
f . Config . Warnl ( f . Entry . Pos , "\t%s\t%s%s\t%s" , n , key , value , f . Name )
[dev.ssa] cmd/compile: enhance command line option processing for SSA
The -d compiler flag can also specify ssa phase and flag,
for example -d=ssa/generic_cse/time,ssa/generic_cse/stats
Spaces in the phase names can be specified with an
underscore. Flags currently parsed (not necessarily
recognized by the phases yet) are:
on, off, mem, time, debug, stats, and test
On, off and time are handled in the harness,
debug, stats, and test are interpreted by the phase itself.
The pass is now attached to the Func being compiled, and a
new method logStats(key, ...value) on *Func to encourage a
semi-standardized format for that output. Output fields
are separated by tabs to ease digestion by awk and
spreadsheets. For example,
if f.pass.stats > 0 {
f.logStat("CSE REWRITES", rewrites)
}
Change-Id: I16db2b5af64c50ca9a47efeb51d961147a903abc
Reviewed-on: https://go-review.googlesource.com/19885
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: Todd Neal <todd@tneal.org>
2016-02-25 13:10:51 -05:00
}
2016-03-01 23:21:55 +00:00
// freeValue frees a value. It must no longer be referenced.
2016-01-28 13:46:30 -08:00
func ( f * Func ) freeValue ( v * Value ) {
2016-01-28 15:54:45 -08:00
if v . Block == nil {
2016-01-28 13:46:30 -08:00
f . Fatalf ( "trying to free an already freed value" )
2015-06-25 23:13:57 -05:00
}
2016-03-15 20:45:50 -07:00
if v . Uses != 0 {
f . Fatalf ( "value %s still has %d uses" , v , v . Uses )
}
2016-01-28 13:46:30 -08:00
// Clear everything but ID (which we reuse).
id := v . ID
2016-03-08 22:13:20 -06:00
2017-03-08 12:50:00 -08:00
// Values with zero arguments and OpOffPtr values might be cached, so remove them there.
2016-03-08 22:13:20 -06:00
nArgs := opcodeTable [ v . Op ] . argLen
2017-03-08 12:50:00 -08:00
if nArgs == 0 || v . Op == OpOffPtr {
2016-03-08 22:13:20 -06:00
vv := f . constants [ v . AuxInt ]
for i , cv := range vv {
if v == cv {
vv [ i ] = vv [ len ( vv ) - 1 ]
2017-03-08 14:48:43 -08:00
vv [ len ( vv ) - 1 ] = nil
2016-03-08 22:13:20 -06:00
f . constants [ v . AuxInt ] = vv [ 0 : len ( vv ) - 1 ]
break
}
}
}
2016-01-28 13:46:30 -08:00
* v = Value { }
v . ID = id
v . argstorage [ 0 ] = f . freeValues
f . freeValues = v
2015-06-25 23:13:57 -05:00
}
2016-01-28 13:46:30 -08:00
// newBlock allocates a new Block of the given kind and places it at the end of f.Blocks.
2015-03-03 13:38:14 -08:00
func ( f * Func ) NewBlock ( kind BlockKind ) * Block {
2016-01-28 13:46:30 -08:00
var b * Block
if f . freeBlocks != nil {
b = f . freeBlocks
2016-04-28 16:52:47 -07:00
f . freeBlocks = b . succstorage [ 0 ] . b
b . succstorage [ 0 ] . b = nil
2016-01-28 13:46:30 -08:00
} else {
ID := f . bid . get ( )
cmd/compile: rearrange fields between ssa.Func, ssa.Cache, and ssa.Config
This makes ssa.Func, ssa.Cache, and ssa.Config fulfill
the roles laid out for them in CL 38160.
The only non-trivial change in this CL is how cached
values and blocks get IDs. Prior to this CL, their IDs were
assigned as part of resetting the cache, and only modified
IDs were reset. This required knowing how many values and
blocks were modified, which required a tight coupling between
ssa.Func and ssa.Config. To eliminate that coupling,
we now zero values and blocks during reset,
and assign their IDs when they are used.
Since unused values and blocks have ID == 0,
we can efficiently find the last used value/block,
to avoid zeroing everything.
Bulk zeroing is efficient, but not efficient enough
to obviate the need to avoid zeroing everything every time.
As a happy side-effect, ssa.Func.Free is no longer necessary.
DebugHashMatch and friends now belong in func.go.
They have been left in place for clarity and review.
I will move them in a subsequent CL.
Passes toolstash -cmp. No compiler performance impact.
No change in 'go test cmd/compile/internal/ssa' execution time.
Change-Id: I2eb7af58da067ef6a36e815a6f386cfe8634d098
Reviewed-on: https://go-review.googlesource.com/38167
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
2017-03-15 11:15:13 -07:00
if int ( ID ) < len ( f . Cache . blocks ) {
b = & f . Cache . blocks [ ID ]
b . ID = ID
2016-01-28 13:46:30 -08:00
} else {
b = & Block { ID : ID }
}
}
2015-06-25 23:13:57 -05:00
b . Kind = kind
b . Func = f
2016-01-28 15:54:45 -08:00
b . Preds = b . predstorage [ : 0 ]
b . Succs = b . succstorage [ : 0 ]
b . Values = b . valstorage [ : 0 ]
2015-03-03 13:38:14 -08:00
f . Blocks = append ( f . Blocks , b )
2016-09-16 13:50:18 -07:00
f . invalidateCFG ( )
2015-03-03 13:38:14 -08:00
return b
}
2016-01-28 13:46:30 -08:00
func ( f * Func ) freeBlock ( b * Block ) {
2016-01-28 15:54:45 -08:00
if b . Func == nil {
f . Fatalf ( "trying to free an already freed block" )
}
2016-01-28 13:46:30 -08:00
// Clear everything but ID (which we reuse).
id := b . ID
* b = Block { }
b . ID = id
2016-04-28 16:52:47 -07:00
b . succstorage [ 0 ] . b = f . freeBlocks
2016-01-28 13:46:30 -08:00
f . freeBlocks = b
}
2015-06-11 21:29:25 -07:00
// NewValue0 returns a new value in the block with no arguments and zero aux values.
2016-12-15 17:17:01 -08:00
func ( b * Block ) NewValue0 ( pos src . XPos , op Op , t Type ) * Value {
2016-12-08 13:49:51 -08:00
v := b . Func . newValue ( op , t , b , pos )
2016-01-28 13:46:30 -08:00
v . AuxInt = 0
2015-03-03 13:38:14 -08:00
v . Args = v . argstorage [ : 0 ]
return v
}
2015-06-11 21:29:25 -07:00
// NewValue returns a new value in the block with no arguments and an auxint value.
2016-12-15 17:17:01 -08:00
func ( b * Block ) NewValue0I ( pos src . XPos , op Op , t Type , auxint int64 ) * Value {
2016-12-08 13:49:51 -08:00
v := b . Func . newValue ( op , t , b , pos )
2016-01-28 13:46:30 -08:00
v . AuxInt = auxint
2015-06-11 21:29:25 -07:00
v . Args = v . argstorage [ : 0 ]
return v
}
// NewValue returns a new value in the block with no arguments and an aux value.
2016-12-15 17:17:01 -08:00
func ( b * Block ) NewValue0A ( pos src . XPos , op Op , t Type , aux interface { } ) * Value {
2015-06-11 21:29:25 -07:00
if _ , ok := aux . ( int64 ) ; ok {
2016-03-01 23:21:55 +00:00
// Disallow int64 aux values. They should be in the auxint field instead.
2015-06-11 21:29:25 -07:00
// Maybe we want to allow this at some point, but for now we disallow it
// to prevent errors like using NewValue1A instead of NewValue1I.
2015-06-24 14:03:39 -07:00
b . Fatalf ( "aux field has int64 type op=%s type=%s aux=%v" , op , t , aux )
2015-06-11 21:29:25 -07:00
}
2016-12-08 13:49:51 -08:00
v := b . Func . newValue ( op , t , b , pos )
2016-01-28 13:46:30 -08:00
v . AuxInt = 0
v . Aux = aux
2015-06-11 21:29:25 -07:00
v . Args = v . argstorage [ : 0 ]
return v
}
// NewValue returns a new value in the block with no arguments and both an auxint and aux values.
2016-12-15 17:17:01 -08:00
func ( b * Block ) NewValue0IA ( pos src . XPos , op Op , t Type , auxint int64 , aux interface { } ) * Value {
2016-12-08 13:49:51 -08:00
v := b . Func . newValue ( op , t , b , pos )
2016-01-28 13:46:30 -08:00
v . AuxInt = auxint
v . Aux = aux
2015-06-11 21:29:25 -07:00
v . Args = v . argstorage [ : 0 ]
return v
}
// NewValue1 returns a new value in the block with one argument and zero aux values.
2016-12-15 17:17:01 -08:00
func ( b * Block ) NewValue1 ( pos src . XPos , op Op , t Type , arg * Value ) * Value {
2016-12-08 13:49:51 -08:00
v := b . Func . newValue ( op , t , b , pos )
2016-01-28 13:46:30 -08:00
v . AuxInt = 0
2015-04-15 15:51:25 -07:00
v . Args = v . argstorage [ : 1 ]
2016-01-28 13:46:30 -08:00
v . argstorage [ 0 ] = arg
2016-03-15 20:45:50 -07:00
arg . Uses ++
2015-04-15 15:51:25 -07:00
return v
}
2015-06-11 21:29:25 -07:00
// NewValue1I returns a new value in the block with one argument and an auxint value.
2016-12-15 17:17:01 -08:00
func ( b * Block ) NewValue1I ( pos src . XPos , op Op , t Type , auxint int64 , arg * Value ) * Value {
2016-12-08 13:49:51 -08:00
v := b . Func . newValue ( op , t , b , pos )
2016-01-28 13:46:30 -08:00
v . AuxInt = auxint
2015-06-11 21:29:25 -07:00
v . Args = v . argstorage [ : 1 ]
2016-01-28 13:46:30 -08:00
v . argstorage [ 0 ] = arg
2016-03-15 20:45:50 -07:00
arg . Uses ++
2015-06-11 21:29:25 -07:00
return v
}
// NewValue1A returns a new value in the block with one argument and an aux value.
2016-12-15 17:17:01 -08:00
func ( b * Block ) NewValue1A ( pos src . XPos , op Op , t Type , aux interface { } , arg * Value ) * Value {
2016-12-08 13:49:51 -08:00
v := b . Func . newValue ( op , t , b , pos )
2016-01-28 13:46:30 -08:00
v . AuxInt = 0
v . Aux = aux
2015-06-11 21:29:25 -07:00
v . Args = v . argstorage [ : 1 ]
2016-01-28 13:46:30 -08:00
v . argstorage [ 0 ] = arg
2016-03-15 20:45:50 -07:00
arg . Uses ++
2015-06-11 21:29:25 -07:00
return v
}
// NewValue1IA returns a new value in the block with one argument and both an auxint and aux values.
2016-12-15 17:17:01 -08:00
func ( b * Block ) NewValue1IA ( pos src . XPos , op Op , t Type , auxint int64 , aux interface { } , arg * Value ) * Value {
2016-12-08 13:49:51 -08:00
v := b . Func . newValue ( op , t , b , pos )
2016-01-28 13:46:30 -08:00
v . AuxInt = auxint
v . Aux = aux
2015-06-11 21:29:25 -07:00
v . Args = v . argstorage [ : 1 ]
2016-01-28 13:46:30 -08:00
v . argstorage [ 0 ] = arg
2016-03-15 20:45:50 -07:00
arg . Uses ++
2015-06-11 21:29:25 -07:00
return v
}
// NewValue2 returns a new value in the block with two arguments and zero aux values.
2016-12-15 17:17:01 -08:00
func ( b * Block ) NewValue2 ( pos src . XPos , op Op , t Type , arg0 , arg1 * Value ) * Value {
2016-12-08 13:49:51 -08:00
v := b . Func . newValue ( op , t , b , pos )
2016-01-28 13:46:30 -08:00
v . AuxInt = 0
2015-04-15 15:51:25 -07:00
v . Args = v . argstorage [ : 2 ]
2016-01-28 13:46:30 -08:00
v . argstorage [ 0 ] = arg0
v . argstorage [ 1 ] = arg1
2016-03-15 20:45:50 -07:00
arg0 . Uses ++
arg1 . Uses ++
2015-04-15 15:51:25 -07:00
return v
}
2015-06-27 15:45:20 +01:00
// NewValue2I returns a new value in the block with two arguments and an auxint value.
2016-12-15 17:17:01 -08:00
func ( b * Block ) NewValue2I ( pos src . XPos , op Op , t Type , auxint int64 , arg0 , arg1 * Value ) * Value {
2016-12-08 13:49:51 -08:00
v := b . Func . newValue ( op , t , b , pos )
2016-01-28 13:46:30 -08:00
v . AuxInt = auxint
2015-06-27 15:45:20 +01:00
v . Args = v . argstorage [ : 2 ]
2016-01-28 13:46:30 -08:00
v . argstorage [ 0 ] = arg0
v . argstorage [ 1 ] = arg1
2016-03-15 20:45:50 -07:00
arg0 . Uses ++
arg1 . Uses ++
2015-06-27 15:45:20 +01:00
return v
}
2015-06-11 21:29:25 -07:00
// NewValue3 returns a new value in the block with three arguments and zero aux values.
2016-12-15 17:17:01 -08:00
func ( b * Block ) NewValue3 ( pos src . XPos , op Op , t Type , arg0 , arg1 , arg2 * Value ) * Value {
2016-12-08 13:49:51 -08:00
v := b . Func . newValue ( op , t , b , pos )
2016-01-28 13:46:30 -08:00
v . AuxInt = 0
2016-04-11 13:17:52 -07:00
v . Args = v . argstorage [ : 3 ]
v . argstorage [ 0 ] = arg0
v . argstorage [ 1 ] = arg1
v . argstorage [ 2 ] = arg2
2016-03-15 20:45:50 -07:00
arg0 . Uses ++
arg1 . Uses ++
arg2 . Uses ++
2015-04-15 15:51:25 -07:00
return v
}
2015-08-14 21:47:20 -07:00
// NewValue3I returns a new value in the block with three arguments and an auxint value.
2016-12-15 17:17:01 -08:00
func ( b * Block ) NewValue3I ( pos src . XPos , op Op , t Type , auxint int64 , arg0 , arg1 , arg2 * Value ) * Value {
2016-12-08 13:49:51 -08:00
v := b . Func . newValue ( op , t , b , pos )
2016-01-28 13:46:30 -08:00
v . AuxInt = auxint
2016-04-11 13:17:52 -07:00
v . Args = v . argstorage [ : 3 ]
v . argstorage [ 0 ] = arg0
v . argstorage [ 1 ] = arg1
v . argstorage [ 2 ] = arg2
2016-03-15 20:45:50 -07:00
arg0 . Uses ++
arg1 . Uses ++
arg2 . Uses ++
2015-08-14 21:47:20 -07:00
return v
}
2017-03-13 21:51:08 -04:00
// NewValue3A returns a new value in the block with three argument and an aux value.
func ( b * Block ) NewValue3A ( pos src . XPos , op Op , t Type , aux interface { } , arg0 , arg1 , arg2 * Value ) * Value {
v := b . Func . newValue ( op , t , b , pos )
v . AuxInt = 0
v . Aux = aux
v . Args = v . argstorage [ : 3 ]
v . argstorage [ 0 ] = arg0
v . argstorage [ 1 ] = arg1
v . argstorage [ 2 ] = arg2
arg0 . Uses ++
arg1 . Uses ++
arg2 . Uses ++
return v
}
2016-08-25 16:02:57 -07:00
// NewValue4 returns a new value in the block with four arguments and zero aux values.
2016-12-15 17:17:01 -08:00
func ( b * Block ) NewValue4 ( pos src . XPos , op Op , t Type , arg0 , arg1 , arg2 , arg3 * Value ) * Value {
2016-12-08 13:49:51 -08:00
v := b . Func . newValue ( op , t , b , pos )
2016-08-25 16:02:57 -07:00
v . AuxInt = 0
v . Args = [ ] * Value { arg0 , arg1 , arg2 , arg3 }
arg0 . Uses ++
arg1 . Uses ++
arg2 . Uses ++
arg3 . Uses ++
return v
}
2016-02-28 15:51:11 -08:00
// constVal returns a constant value for c.
2017-03-08 12:45:12 -08:00
func ( f * Func ) constVal ( pos src . XPos , op Op , t Type , c int64 , setAuxInt bool ) * Value {
2016-02-28 15:51:11 -08:00
if f . constants == nil {
f . constants = make ( map [ int64 ] [ ] * Value )
}
vv := f . constants [ c ]
for _ , v := range vv {
2016-04-03 14:44:29 -07:00
if v . Op == op && v . Type . Compare ( t ) == CMPeq {
2017-03-08 12:45:12 -08:00
if setAuxInt && v . AuxInt != c {
2016-03-08 22:13:20 -06:00
panic ( fmt . Sprintf ( "cached const %s should have AuxInt of %d" , v . LongString ( ) , c ) )
}
2016-02-28 15:51:11 -08:00
return v
}
}
2016-03-06 18:06:09 -08:00
var v * Value
2017-03-08 12:45:12 -08:00
if setAuxInt {
2016-12-08 13:49:51 -08:00
v = f . Entry . NewValue0I ( pos , op , t , c )
2016-03-06 18:06:09 -08:00
} else {
2016-12-08 13:49:51 -08:00
v = f . Entry . NewValue0 ( pos , op , t )
2016-03-06 18:06:09 -08:00
}
2016-02-28 15:51:11 -08:00
f . constants [ c ] = append ( vv , v )
return v
}
2016-03-06 18:06:09 -08:00
// These magic auxint values let us easily cache non-numeric constants
// using the same constants map while making collisions unlikely.
// These values are unlikely to occur in regular code and
// are easy to grep for in case of bugs.
const (
constSliceMagic = 1122334455
constInterfaceMagic = 2233445566
constNilMagic = 3344556677
constEmptyStringMagic = 4455667788
)
2015-03-03 13:38:14 -08:00
// ConstInt returns an int constant representing its argument.
2016-12-15 17:17:01 -08:00
func ( f * Func ) ConstBool ( pos src . XPos , t Type , c bool ) * Value {
2015-09-08 16:52:25 -07:00
i := int64 ( 0 )
if c {
i = 1
}
2016-12-08 13:49:51 -08:00
return f . constVal ( pos , OpConstBool , t , i , true )
2015-09-08 16:52:25 -07:00
}
2016-12-15 17:17:01 -08:00
func ( f * Func ) ConstInt8 ( pos src . XPos , t Type , c int8 ) * Value {
2016-12-08 13:49:51 -08:00
return f . constVal ( pos , OpConst8 , t , int64 ( c ) , true )
2015-07-28 14:19:20 -07:00
}
2016-12-15 17:17:01 -08:00
func ( f * Func ) ConstInt16 ( pos src . XPos , t Type , c int16 ) * Value {
2016-12-08 13:49:51 -08:00
return f . constVal ( pos , OpConst16 , t , int64 ( c ) , true )
2015-07-28 14:19:20 -07:00
}
2016-12-15 17:17:01 -08:00
func ( f * Func ) ConstInt32 ( pos src . XPos , t Type , c int32 ) * Value {
2016-12-08 13:49:51 -08:00
return f . constVal ( pos , OpConst32 , t , int64 ( c ) , true )
2015-07-28 14:19:20 -07:00
}
2016-12-15 17:17:01 -08:00
func ( f * Func ) ConstInt64 ( pos src . XPos , t Type , c int64 ) * Value {
2016-12-08 13:49:51 -08:00
return f . constVal ( pos , OpConst64 , t , c , true )
2015-07-28 14:19:20 -07:00
}
2016-12-15 17:17:01 -08:00
func ( f * Func ) ConstFloat32 ( pos src . XPos , t Type , c float64 ) * Value {
2016-12-08 13:49:51 -08:00
return f . constVal ( pos , OpConst32F , t , int64 ( math . Float64bits ( float64 ( float32 ( c ) ) ) ) , true )
2015-08-12 16:38:11 -04:00
}
2016-12-15 17:17:01 -08:00
func ( f * Func ) ConstFloat64 ( pos src . XPos , t Type , c float64 ) * Value {
2016-12-08 13:49:51 -08:00
return f . constVal ( pos , OpConst64F , t , int64 ( math . Float64bits ( c ) ) , true )
2016-03-06 18:06:09 -08:00
}
2016-12-15 17:17:01 -08:00
func ( f * Func ) ConstSlice ( pos src . XPos , t Type ) * Value {
2016-12-08 13:49:51 -08:00
return f . constVal ( pos , OpConstSlice , t , constSliceMagic , false )
2016-03-06 18:06:09 -08:00
}
2016-12-15 17:17:01 -08:00
func ( f * Func ) ConstInterface ( pos src . XPos , t Type ) * Value {
2016-12-08 13:49:51 -08:00
return f . constVal ( pos , OpConstInterface , t , constInterfaceMagic , false )
2016-03-06 18:06:09 -08:00
}
2016-12-15 17:17:01 -08:00
func ( f * Func ) ConstNil ( pos src . XPos , t Type ) * Value {
2016-12-08 13:49:51 -08:00
return f . constVal ( pos , OpConstNil , t , constNilMagic , false )
2016-03-06 18:06:09 -08:00
}
2016-12-15 17:17:01 -08:00
func ( f * Func ) ConstEmptyString ( pos src . XPos , t Type ) * Value {
2016-12-08 13:49:51 -08:00
v := f . constVal ( pos , OpConstString , t , constEmptyStringMagic , false )
2016-03-06 18:06:09 -08:00
v . Aux = ""
return v
2015-08-12 16:38:11 -04:00
}
2017-03-08 12:50:00 -08:00
func ( f * Func ) ConstOffPtrSP ( pos src . XPos , t Type , c int64 , sp * Value ) * Value {
v := f . constVal ( pos , OpOffPtr , t , c , true )
if len ( v . Args ) == 0 {
v . AddArg ( sp )
}
return v
}
2015-06-12 11:01:13 -07:00
2016-01-13 11:14:57 -08:00
func ( f * Func ) Logf ( msg string , args ... interface { } ) { f . Config . Logf ( msg , args ... ) }
2016-01-29 14:44:15 -05:00
func ( f * Func ) Log ( ) bool { return f . Config . Log ( ) }
2016-12-07 18:14:35 -08:00
func ( f * Func ) Fatalf ( msg string , args ... interface { } ) { f . Config . Fatalf ( f . Entry . Pos , msg , args ... ) }
2016-01-28 13:46:30 -08:00
2016-09-16 13:50:18 -07:00
// postorder returns the reachable blocks in f in a postorder traversal.
func ( f * Func ) postorder ( ) [ ] * Block {
if f . cachedPostorder == nil {
f . cachedPostorder = postorder ( f )
}
return f . cachedPostorder
}
2016-10-09 01:09:52 +09:00
// Idom returns a map from block ID to the immediate dominator of that block.
2016-09-16 13:50:18 -07:00
// f.Entry.ID maps to nil. Unreachable blocks map to nil as well.
2016-10-09 01:09:52 +09:00
func ( f * Func ) Idom ( ) [ ] * Block {
2016-09-16 13:50:18 -07:00
if f . cachedIdom == nil {
f . cachedIdom = dominators ( f )
}
return f . cachedIdom
}
// sdom returns a sparse tree representing the dominator relationships
// among the blocks of f.
func ( f * Func ) sdom ( ) SparseTree {
if f . cachedSdom == nil {
2016-10-09 01:09:52 +09:00
f . cachedSdom = newSparseTree ( f , f . Idom ( ) )
2016-09-16 13:50:18 -07:00
}
return f . cachedSdom
}
// loopnest returns the loop nest information for f.
func ( f * Func ) loopnest ( ) * loopnest {
if f . cachedLoopnest == nil {
f . cachedLoopnest = loopnestfor ( f )
}
return f . cachedLoopnest
}
// invalidateCFG tells f that its CFG has changed.
func ( f * Func ) invalidateCFG ( ) {
f . cachedPostorder = nil
f . cachedIdom = nil
f . cachedSdom = nil
f . cachedLoopnest = nil
}
2017-03-15 22:43:40 -07:00
// DebugHashMatch returns true if environment variable evname
// 1) is empty (this is a special more-quickly implemented case of 3)
// 2) is "y" or "Y"
// 3) is a suffix of the sha1 hash of name
// 4) is a suffix of the environment variable
// fmt.Sprintf("%s%d", evname, n)
// provided that all such variables are nonempty for 0 <= i <= n
// Otherwise it returns false.
// When true is returned the message
// "%s triggered %s\n", evname, name
// is printed on the file named in environment variable
// GSHS_LOGFILE
// or standard out if that is empty or there is an error
// opening the file.
func ( f * Func ) DebugHashMatch ( evname , name string ) bool {
evhash := os . Getenv ( evname )
if evhash == "" {
return true // default behavior with no EV is "on"
}
if evhash == "y" || evhash == "Y" {
f . logDebugHashMatch ( evname , name )
return true
}
if evhash == "n" || evhash == "N" {
return false
}
// Check the hash of the name against a partial input hash.
// We use this feature to do a binary search to
// find a function that is incorrectly compiled.
hstr := ""
for _ , b := range sha1 . Sum ( [ ] byte ( name ) ) {
hstr += fmt . Sprintf ( "%08b" , b )
}
if strings . HasSuffix ( hstr , evhash ) {
f . logDebugHashMatch ( evname , name )
return true
}
// Iteratively try additional hashes to allow tests for multi-point
// failure.
for i := 0 ; true ; i ++ {
ev := fmt . Sprintf ( "%s%d" , evname , i )
evv := os . Getenv ( ev )
if evv == "" {
break
}
if strings . HasSuffix ( hstr , evv ) {
f . logDebugHashMatch ( ev , name )
return true
}
}
return false
}
func ( f * Func ) logDebugHashMatch ( evname , name string ) {
if f . logfiles == nil {
f . logfiles = make ( map [ string ] * os . File )
}
file := f . logfiles [ evname ]
if file == nil {
file = os . Stdout
tmpfile := os . Getenv ( "GSHS_LOGFILE" )
if tmpfile != "" {
var ok error
file , ok = os . Create ( tmpfile )
if ok != nil {
f . Fatalf ( "could not open hash-testing logfile %s" , tmpfile )
}
}
f . logfiles [ evname ] = file
}
s := fmt . Sprintf ( "%s triggered %s\n" , evname , name )
file . WriteString ( s )
file . Sync ( )
}
func DebugNameMatch ( evname , name string ) bool {
return os . Getenv ( evname ) == name
}