mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
cmd/compile: extract inline related fields into separate Inline type
Inl, Inldcl, and InlCost are only applicable to functions with bodies that can be inlined, so pull them out into a separate Inline type to make understanding them easier. A side benefit is that we can check if a function can be inlined by just checking if n.Func.Inl is non-nil, which simplifies handling of empty function bodies. While here, remove some unnecessary Curfn twiddling, and make imported functions use Inl.Dcl instead of Func.Dcl for consistency for local functions. Passes toolstash-check. Change-Id: Ifd4a80349d85d9e8e4484952b38ec4a63182e81f Reviewed-on: https://go-review.googlesource.com/104756 Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
This commit is contained in:
parent
f2b5f750df
commit
562a199961
7 changed files with 61 additions and 64 deletions
|
|
@ -461,7 +461,6 @@ type Func struct {
|
|||
Exit Nodes
|
||||
Cvars Nodes // closure params
|
||||
Dcl []*Node // autodcl for this func/closure
|
||||
Inldcl Nodes // copy of dcl for use in inlining
|
||||
|
||||
// Parents records the parent scope of each scope within a
|
||||
// function. The root scope (0) has no parent, so the i'th
|
||||
|
|
@ -484,8 +483,7 @@ type Func struct {
|
|||
Nname *Node
|
||||
lsym *obj.LSym
|
||||
|
||||
Inl Nodes // copy of the body for use in inlining
|
||||
InlCost int32
|
||||
Inl *Inline
|
||||
|
||||
Label int32 // largest auto-generated label in this function
|
||||
|
||||
|
|
@ -502,6 +500,15 @@ type Func struct {
|
|||
nwbrCalls *[]nowritebarrierrecCallSym
|
||||
}
|
||||
|
||||
// An Inline holds fields used for function bodies that can be inlined.
|
||||
type Inline struct {
|
||||
Cost int32 // heuristic cost of inlining this function
|
||||
|
||||
// Copies of Func.Dcl and Nbody for use during inlining.
|
||||
Dcl []*Node
|
||||
Body []*Node
|
||||
}
|
||||
|
||||
// A Mark represents a scope boundary.
|
||||
type Mark struct {
|
||||
// Pos is the position of the token that marks the scope
|
||||
|
|
@ -737,6 +744,11 @@ const (
|
|||
// a slice to save space.
|
||||
type Nodes struct{ slice *[]*Node }
|
||||
|
||||
// asNodes returns a slice of *Node as a Nodes value.
|
||||
func asNodes(s []*Node) Nodes {
|
||||
return Nodes{&s}
|
||||
}
|
||||
|
||||
// Slice returns the entries in Nodes as a slice.
|
||||
// Changes to the slice entries (as in s[i] = n) will be reflected in
|
||||
// the Nodes.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue