]> Cypherpunks.ru repositories - gostls13.git/blob - src/cmd/compile/internal/gc/go.go
[dev.typeparams] merge master into dev.typeparams
[gostls13.git] / src / cmd / compile / internal / gc / go.go
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 gc
6
7 import (
8         "cmd/compile/internal/ssa"
9         "cmd/compile/internal/types"
10         "cmd/internal/obj"
11         "cmd/internal/src"
12         "sync"
13 )
14
15 const (
16         BADWIDTH = types.BADWIDTH
17 )
18
19 var (
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)
24
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)
32
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)
38 )
39
40 // isRuntimePkg reports whether p is package runtime.
41 func isRuntimePkg(p *types.Pkg) bool {
42         if compiling_runtime && p == localpkg {
43                 return true
44         }
45         return p.Path == "runtime"
46 }
47
48 // isReflectPkg reports whether p is package reflect.
49 func isReflectPkg(p *types.Pkg) bool {
50         if p == localpkg {
51                 return myimportpath == "reflect"
52         }
53         return p.Path == "reflect"
54 }
55
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.
59 type Class uint8
60
61 //go:generate stringer -type=Class
62 const (
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
70
71         // Careful: Class is stored in three bits in Node.flags.
72         _ = uint((1 << 3) - iota) // static assert for iota <= (1 << 3)
73 )
74
75 // Slices in the runtime are represented by three components:
76 //
77 // type slice struct {
78 //      ptr unsafe.Pointer
79 //      len int
80 //      cap int
81 // }
82 //
83 // Strings in the runtime are represented by two components:
84 //
85 // type string struct {
86 //      ptr unsafe.Pointer
87 //      len int
88 // }
89 //
90 // These variables are the offsets of fields and sizes of these structs.
91 var (
92         slicePtrOffset int64
93         sliceLenOffset int64
94         sliceCapOffset int64
95
96         sizeofSlice  int64
97         sizeofString int64
98 )
99
100 var pragcgobuf [][]string
101
102 var outfile string
103 var linkobj string
104
105 // nerrors is the number of compiler errors reported
106 // since the last call to saveerrors.
107 var nerrors int
108
109 // nsavederrors is the total number of compiler errors
110 // reported before the last call to saveerrors.
111 var nsavederrors int
112
113 var nsyntaxerrors int
114
115 var decldepth int32
116
117 var nolocalimports bool
118
119 // gc debug flags
120 type DebugFlags struct {
121         P, B, C, E, G,
122         K, L, N, S,
123         W, e, h, j,
124         l, m, r, w int
125 }
126
127 var Debug DebugFlags
128
129 var debugstr string
130
131 var Debug_checknil int
132 var Debug_typeassert int
133
134 var localpkg *types.Pkg // package being compiled
135
136 var inimport bool // set during import
137
138 var itabpkg *types.Pkg // fake pkg for itab entries
139
140 var itablinkpkg *types.Pkg // fake package for runtime itab entries
141
142 var Runtimepkg *types.Pkg // fake package runtime
143
144 var racepkg *types.Pkg // package runtime/race
145
146 var msanpkg *types.Pkg // package runtime/msan
147
148 var unsafepkg *types.Pkg // package unsafe
149
150 var trackpkg *types.Pkg // fake package for field tracking
151
152 var mappkg *types.Pkg // fake package for map zero value
153
154 var gopkg *types.Pkg // pseudo-package for method symbols on anonymous receiver types
155
156 var zerosize int64
157
158 var myimportpath string
159
160 var localimport string
161
162 var asmhdr string
163
164 var simtype [NTYPE]types.EType
165
166 var (
167         isInt     [NTYPE]bool
168         isFloat   [NTYPE]bool
169         isComplex [NTYPE]bool
170         issimple  [NTYPE]bool
171 )
172
173 var (
174         okforeq    [NTYPE]bool
175         okforadd   [NTYPE]bool
176         okforand   [NTYPE]bool
177         okfornone  [NTYPE]bool
178         okforcmp   [NTYPE]bool
179         okforbool  [NTYPE]bool
180         okforcap   [NTYPE]bool
181         okforlen   [NTYPE]bool
182         okforarith [NTYPE]bool
183         okforconst [NTYPE]bool
184 )
185
186 var (
187         okfor [OEND][]bool
188         iscmp [OEND]bool
189 )
190
191 var minintval [NTYPE]*Mpint
192
193 var maxintval [NTYPE]*Mpint
194
195 var minfltval [NTYPE]*Mpflt
196
197 var maxfltval [NTYPE]*Mpflt
198
199 var xtop []*Node
200
201 var exportlist []*Node
202
203 var importlist []*Node // imported functions and methods with inlinable bodies
204
205 var (
206         funcsymsmu sync.Mutex // protects funcsyms and associated package lookups (see func funcsym)
207         funcsyms   []*types.Sym
208 )
209
210 var dclcontext Class // PEXTERN/PAUTO
211
212 var Curfn *Node
213
214 var Widthptr int
215
216 var Widthreg int
217
218 var nblank *Node
219
220 var typecheckok bool
221
222 var compiling_runtime bool
223
224 // Compiling the standard library
225 var compiling_std bool
226
227 var use_writebarrier bool
228
229 var pure_go bool
230
231 var flag_installsuffix string
232
233 var flag_race bool
234
235 var flag_msan bool
236
237 var flagDWARF bool
238
239 // Whether we are adding any sort of code instrumentation, such as
240 // when the race detector is enabled.
241 var instrumenting bool
242
243 // Whether we are tracking lexical scopes for DWARF.
244 var trackScopes bool
245
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
250
251 var debuglive int
252
253 var Ctxt *obj.Link
254
255 var writearchive bool
256
257 var nodfp *Node
258
259 var disable_checknil int
260
261 var autogeneratedPos src.XPos
262
263 // interface to back end
264
265 type Arch struct {
266         LinkArch *obj.LinkArch
267
268         REGSP     int
269         MAXWIDTH  int64
270         SoftFloat bool
271
272         PadFrame func(int64) int64
273
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
277
278         Ginsnop      func(*Progs) *obj.Prog
279         Ginsnopdefer func(*Progs) *obj.Prog // special ginsnop for deferreturn
280
281         // SSAMarkMoves marks any MOVXconst ops that need to avoid clobbering flags.
282         SSAMarkMoves func(*SSAGenState, *ssa.Block)
283
284         // SSAGenValue emits Prog(s) for the Value.
285         SSAGenValue func(*SSAGenState, *ssa.Value)
286
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)
290 }
291
292 var thearch Arch
293
294 var (
295         staticuint64s,
296         zerobase *Node
297
298         assertE2I,
299         assertE2I2,
300         assertI2I,
301         assertI2I2,
302         deferproc,
303         deferprocStack,
304         Deferreturn,
305         Duffcopy,
306         Duffzero,
307         gcWriteBarrier,
308         goschedguarded,
309         growslice,
310         msanread,
311         msanwrite,
312         newobject,
313         newproc,
314         panicdivide,
315         panicshift,
316         panicdottypeE,
317         panicdottypeI,
318         panicnildottype,
319         panicoverflow,
320         raceread,
321         racereadrange,
322         racewrite,
323         racewriterange,
324         x86HasPOPCNT,
325         x86HasSSE41,
326         x86HasFMA,
327         armHasVFPv4,
328         arm64HasATOMICS,
329         typedmemclr,
330         typedmemmove,
331         Udiv,
332         writeBarrier,
333         zerobaseSym *obj.LSym
334
335         BoundsCheckFunc [ssa.BoundsKindCount]*obj.LSym
336         ExtendCheckFunc [ssa.BoundsKindCount]*obj.LSym
337
338         // Wasm
339         WasmMove,
340         WasmZero,
341         WasmDiv,
342         WasmTruncS,
343         WasmTruncU,
344         SigPanic *obj.LSym
345 )
346
347 // GCWriteBarrierReg maps from registers to gcWriteBarrier implementation LSyms.
348 var GCWriteBarrierReg map[int16]*obj.LSym