github.com/shogo82148/std@v1.22.1-0.20240327122250-4e474527810c/cmd/compile/internal/staticinit/sched.go (about) 1 // Copyright 2009 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package staticinit 6 7 import ( 8 "github.com/shogo82148/std/cmd/compile/internal/ir" 9 "github.com/shogo82148/std/cmd/compile/internal/types" 10 ) 11 12 type Entry struct { 13 Xoffset int64 14 Expr ir.Node 15 } 16 17 type Plan struct { 18 E []Entry 19 } 20 21 // An Schedule is used to decompose assignment statements into 22 // static and dynamic initialization parts. Static initializations are 23 // handled by populating variables' linker symbol data, while dynamic 24 // initializations are accumulated to be executed in order. 25 type Schedule struct { 26 // Out is the ordered list of dynamic initialization 27 // statements. 28 Out []ir.Node 29 30 Plans map[ir.Node]*Plan 31 Temps map[ir.Node]*ir.Name 32 33 // seenMutation tracks whether we've seen an initialization 34 // expression that may have modified other package-scope variables 35 // within this package. 36 seenMutation bool 37 } 38 39 // StaticInit adds an initialization statement n to the schedule. 40 func (s *Schedule) StaticInit(n ir.Node) 41 42 // MapInitToVar is the inverse of VarToMapInit; it maintains a mapping 43 // from a compiler-generated init function to the map the function is 44 // initializing. 45 var MapInitToVar map[*ir.Func]*ir.Name 46 47 func (s *Schedule) StaticAssign(l *ir.Name, loff int64, r ir.Node, typ *types.Type) bool 48 49 // StaticName returns a name backed by a (writable) static data symbol. 50 // Use readonlystaticname for read-only node. 51 func StaticName(t *types.Type) *ir.Name 52 53 // StaticLoc returns the static address of n, if n has one, or else nil. 54 func StaticLoc(n ir.Node) (name *ir.Name, offset int64, ok bool) 55 56 // AnySideEffects reports whether n contains any operations that could have observable side effects. 57 func AnySideEffects(n ir.Node) bool 58 59 // AddKeepRelocations adds a dummy "R_KEEP" relocation from each 60 // global map variable V to its associated outlined init function. 61 // These relocation ensure that if the map var itself is determined to 62 // be reachable at link time, we also mark the init function as 63 // reachable. 64 func AddKeepRelocations() 65 66 // OutlineMapInits replaces global map initializers with outlined 67 // calls to separate "map init" functions (where possible and 68 // profitable), to facilitate better dead-code elimination by the 69 // linker. 70 func OutlineMapInits(fn *ir.Func)