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.
8 "cmd/compile/internal/ssa"
9 "cmd/compile/internal/types"
16 BADWIDTH = types.BADWIDTH
20 // maximum size variable which we will allocate on the stack.
21 // This limit is for explicit variable declarations like "var x T" or "x := ...".
22 // Note: the flag smallframes can update this value.
23 maxStackVarSize = int64(10 * 1024 * 1024)
25 // maximum size of implicit variables that we will allocate on the stack.
26 // p := new(T) allocating T on the stack
27 // p := &T{} allocating T on the stack
28 // s := make([]T, n) allocating [n]T on the stack
29 // s := []byte("...") allocating [n]byte on the stack
30 // Note: the flag smallframes can update this value.
31 maxImplicitStackVarSize = int64(64 * 1024)
33 // smallArrayBytes is the maximum size of an array which is considered small.
34 // Small arrays will be initialized directly with a sequence of constant stores.
35 // Large arrays will be initialized by copying from a static temp.
36 // 256 bytes was chosen to minimize generated code + statictmp size.
37 smallArrayBytes = int64(256)
40 // isRuntimePkg reports whether p is package runtime.
41 func isRuntimePkg(p *types.Pkg) bool {
42 if compiling_runtime && p == localpkg {
45 return p.Path == "runtime"
48 // isReflectPkg reports whether p is package reflect.
49 func isReflectPkg(p *types.Pkg) bool {
51 return myimportpath == "reflect"
53 return p.Path == "reflect"
56 // The Class of a variable/function describes the "storage class"
57 // of a variable or function. During parsing, storage classes are
58 // called declaration contexts.
61 //go:generate stringer -type=Class
63 Pxxx Class = iota // no class; used during ssa conversion to indicate pseudo-variables
64 PEXTERN // global variables
65 PAUTO // local variables
66 PAUTOHEAP // local variables or parameters moved to heap
67 PPARAM // input arguments
68 PPARAMOUT // output results
69 PFUNC // global functions
71 // Careful: Class is stored in three bits in Node.flags.
72 _ = uint((1 << 3) - iota) // static assert for iota <= (1 << 3)
75 // Slices in the runtime are represented by three components:
77 // type slice struct {
83 // Strings in the runtime are represented by two components:
85 // type string struct {
90 // These variables are the offsets of fields and sizes of these structs.
100 var pragcgobuf [][]string
105 // nerrors is the number of compiler errors reported
106 // since the last call to saveerrors.
109 // nsavederrors is the total number of compiler errors
110 // reported before the last call to saveerrors.
113 var nsyntaxerrors int
117 var nolocalimports bool
120 type DebugFlags struct {
131 var Debug_checknil int
132 var Debug_typeassert int
134 var localpkg *types.Pkg // package being compiled
136 var inimport bool // set during import
138 var itabpkg *types.Pkg // fake pkg for itab entries
140 var itablinkpkg *types.Pkg // fake package for runtime itab entries
142 var Runtimepkg *types.Pkg // fake package runtime
144 var racepkg *types.Pkg // package runtime/race
146 var msanpkg *types.Pkg // package runtime/msan
148 var unsafepkg *types.Pkg // package unsafe
150 var trackpkg *types.Pkg // fake package for field tracking
152 var mappkg *types.Pkg // fake package for map zero value
154 var gopkg *types.Pkg // pseudo-package for method symbols on anonymous receiver types
158 var myimportpath string
160 var localimport string
164 var simtype [NTYPE]types.EType
169 isComplex [NTYPE]bool
177 okfornone [NTYPE]bool
179 okforbool [NTYPE]bool
182 okforarith [NTYPE]bool
183 okforconst [NTYPE]bool
191 var minintval [NTYPE]*Mpint
193 var maxintval [NTYPE]*Mpint
195 var minfltval [NTYPE]*Mpflt
197 var maxfltval [NTYPE]*Mpflt
201 var exportlist []*Node
203 var importlist []*Node // imported functions and methods with inlinable bodies
206 funcsymsmu sync.Mutex // protects funcsyms and associated package lookups (see func funcsym)
207 funcsyms []*types.Sym
210 var dclcontext Class // PEXTERN/PAUTO
222 var compiling_runtime bool
224 // Compiling the standard library
225 var compiling_std bool
227 var use_writebarrier bool
231 var flag_installsuffix string
239 // Whether we are adding any sort of code instrumentation, such as
240 // when the race detector is enabled.
241 var instrumenting bool
243 // Whether we are tracking lexical scopes for DWARF.
246 // Controls generation of DWARF inlined instance records. Zero
247 // disables, 1 emits inlined routines but suppresses var info,
248 // and 2 emits inlined routines with tracking of formals/locals.
249 var genDwarfInline int
255 var writearchive bool
259 var disable_checknil int
261 var autogeneratedPos src.XPos
263 // interface to back end
266 LinkArch *obj.LinkArch
272 PadFrame func(int64) int64
274 // ZeroRange zeroes a range of memory on stack. It is only inserted
275 // at function entry, and it is ok to clobber registers.
276 ZeroRange func(*Progs, *obj.Prog, int64, int64, *uint32) *obj.Prog
278 Ginsnop func(*Progs) *obj.Prog
279 Ginsnopdefer func(*Progs) *obj.Prog // special ginsnop for deferreturn
281 // SSAMarkMoves marks any MOVXconst ops that need to avoid clobbering flags.
282 SSAMarkMoves func(*SSAGenState, *ssa.Block)
284 // SSAGenValue emits Prog(s) for the Value.
285 SSAGenValue func(*SSAGenState, *ssa.Value)
287 // SSAGenBlock emits end-of-block Progs. SSAGenValue should be called
288 // for all values in the block before SSAGenBlock.
289 SSAGenBlock func(s *SSAGenState, b, next *ssa.Block)
333 zerobaseSym *obj.LSym
335 BoundsCheckFunc [ssa.BoundsKindCount]*obj.LSym
336 ExtendCheckFunc [ssa.BoundsKindCount]*obj.LSym
347 // GCWriteBarrierReg maps from registers to gcWriteBarrier implementation LSyms.
348 var GCWriteBarrierReg map[int16]*obj.LSym