staticinit

Imports

Imports #

"fmt"
"go/constant"
"go/token"
"os"
"strings"
"cmd/compile/internal/base"
"cmd/compile/internal/ir"
"cmd/compile/internal/reflectdata"
"cmd/compile/internal/staticdata"
"cmd/compile/internal/typecheck"
"cmd/compile/internal/types"
"cmd/internal/obj"
"cmd/internal/objabi"
"cmd/internal/src"

Constants & Variables

MapInitToVar var #

MapInitToVar is the inverse of VarToMapInit; it maintains a mapping from a compiler-generated init function to the map the function is initializing.

var MapInitToVar map[*ir.Func]*ir.Name

mapinitgen var #

mapinitgen is a counter used to uniquify compiler-generated map init functions.

var mapinitgen int

statuniqgen var #

var statuniqgen int

varToMapInit var #

varToMapInit holds book-keeping state for global map initialization; it records the init function created by the compiler to host the initialization code for the map in question.

var varToMapInit map[*ir.Name]*ir.Func

wrapGlobalMapInitSizeThreshold const #

const wrapGlobalMapInitSizeThreshold = 20

Structs

Entry struct #

type Entry struct {
Xoffset int64
Expr ir.Node
}

Plan struct #

type Plan struct {
E []Entry
}

Schedule struct #

An Schedule is used to decompose assignment statements into static and dynamic initialization parts. Static initializations are handled by populating variables' linker symbol data, while dynamic initializations are accumulated to be executed in order.

type Schedule struct {
Out []ir.Node
Plans map[ir.Node]*Plan
Temps map[ir.Node]*ir.Name
seenMutation bool
}

Functions

AddKeepRelocations function #

AddKeepRelocations adds a dummy "R_KEEP" relocation from each global map variable V to its associated outlined init function. These relocation ensure that if the map var itself is determined to be reachable at link time, we also mark the init function as reachable.

func AddKeepRelocations()

AnySideEffects function #

AnySideEffects reports whether n contains any operations that could have observable side effects.

func AnySideEffects(n ir.Node) bool

OutlineMapInits function #

OutlineMapInits replaces global map initializers with outlined calls to separate "map init" functions (where possible and profitable), to facilitate better dead-code elimination by the linker.

func OutlineMapInits(fn *ir.Func)

StaticAssign method #

func (s *Schedule) StaticAssign(l *ir.Name, loff int64, r ir.Node, typ *types.Type) bool

StaticInit method #

StaticInit adds an initialization statement n to the schedule.

func (s *Schedule) StaticInit(n ir.Node)

StaticLoc function #

StaticLoc returns the static address of n, if n has one, or else nil.

func StaticLoc(n ir.Node) (name *ir.Name, offset int64, ok bool)

StaticName function #

StaticName returns a name backed by a (writable) static data symbol.

func StaticName(t *types.Type) *ir.Name

addStr function #

func addStr(n *ir.AddStringExpr) ir.Node

addvalue method #

func (s *Schedule) addvalue(p *Plan, xoffset int64, n ir.Node)

allBlank function #

allBlank reports whether every node in exprs is blank.

func allBlank(exprs []ir.Node) bool

append method #

func (s *Schedule) append(n ir.Node)

canRepeat function #

canRepeat reports whether executing n multiple times has the same effect as assigning n to a single variable and using that variable multiple times.

func canRepeat(n ir.Node) bool

getlit function #

func getlit(lit ir.Node) int

initplan method #

func (s *Schedule) initplan(n ir.Node)

isSideEffect function #

func isSideEffect(n ir.Node) bool

isvaluelit function #

func isvaluelit(n ir.Node) bool

mayModifyPkgVar function #

mayModifyPkgVar reports whether expression n may modify any package-scope variables declared within the current package.

func mayModifyPkgVar(n ir.Node) bool

recordFuncForVar function #

recordFuncForVar establishes a mapping between global map var "v" and outlined init function "fn" (and vice versa); so that we can use the mappings later on to update relocations.

func recordFuncForVar(v *ir.Name, fn *ir.Func)

staticAssignInlinedCall method #

func (s *Schedule) staticAssignInlinedCall(l *ir.Name, loff int64, call *ir.InlinedCallExpr, typ *types.Type) bool

staticcopy method #

like staticassign but we are copying an already initialized value r.

func (s *Schedule) staticcopy(l *ir.Name, loff int64, rn *ir.Name, typ *types.Type) bool

subst function #

func subst(n ir.Node, m map[*ir.Name]ir.Node) (ir.Node, bool)

truncate function #

truncate returns the result of force converting c to type t, truncating its value as needed, like a conversion of a variable. If the conversion is too difficult, truncate returns nil, false.

func truncate(c ir.Node, t *types.Type) (ir.Node, bool)

tryStaticInit method #

tryStaticInit attempts to statically execute an initialization statement and reports whether it succeeded.

func (s *Schedule) tryStaticInit(n ir.Node) bool

tryWrapGlobalInit function #

tryWrapGlobalInit returns a new outlined function to contain global initializer statement n, if possible and worthwhile. Otherwise, it returns nil. Currently, it outlines map assignment statements with large, side-effect-free RHS expressions.

func tryWrapGlobalInit(n ir.Node) *ir.Func

Generated with Arrow