blob: 5317648ff5535c8bae8963bf613f9634ef337cc7 [file] [log] [blame]
Russ Cox8c195bd2015-02-13 14:40:36 -05001// 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
5package gc
6
7import (
8 "bytes"
Michael Pratta4e31d42016-03-12 14:07:40 -08009 "cmd/compile/internal/ssa"
Russ Cox8c195bd2015-02-13 14:40:36 -050010 "cmd/internal/obj"
Russ Cox8c195bd2015-02-13 14:40:36 -050011)
12
Russ Cox8c195bd2015-02-13 14:40:36 -050013const (
Rob Pike24a43e62015-03-05 10:39:23 -080014 UINF = 100
15 PRIME1 = 3
16 BADWIDTH = -1000000000
17 MaxStackVarSize = 10 * 1024 * 1024
18)
19
Russ Cox8c195bd2015-02-13 14:40:36 -050020type Val struct {
Josh Bleecher Snyder13485be2015-05-14 17:57:42 -070021 // U contains one of:
Russ Cox71080fb2015-05-26 22:50:45 -040022 // bool bool when n.ValCtype() == CTBOOL
23 // *Mpint int when n.ValCtype() == CTINT, rune when n.ValCtype() == CTRUNE
24 // *Mpflt float when n.ValCtype() == CTFLT
25 // *Mpcplx pair of floats when n.ValCtype() == CTCPLX
26 // string string when n.ValCtype() == CTSTR
27 // *Nilval when n.ValCtype() == CTNIL
Josh Bleecher Snyder13485be2015-05-14 17:57:42 -070028 U interface{}
Russ Cox8c195bd2015-02-13 14:40:36 -050029}
30
Russ Cox71080fb2015-05-26 22:50:45 -040031type NilVal struct{}
32
Robert Griesemer53d43cb2015-10-26 16:00:59 -070033func (v Val) Ctype() Ctype {
Russ Cox71080fb2015-05-26 22:50:45 -040034 switch x := v.U.(type) {
35 default:
HÃ¥vard Haugen3c9fa382015-08-30 23:10:03 +020036 Fatalf("unexpected Ctype for %T", v.U)
Russ Coxa53710f2015-06-03 14:16:01 -040037 panic("not reached")
38 case nil:
Russ Cox71080fb2015-05-26 22:50:45 -040039 return 0
40 case *NilVal:
41 return CTNIL
42 case bool:
43 return CTBOOL
44 case *Mpint:
45 if x.Rune {
46 return CTRUNE
47 }
48 return CTINT
49 case *Mpflt:
50 return CTFLT
51 case *Mpcplx:
52 return CTCPLX
53 case string:
54 return CTSTR
55 }
56}
57
Russ Cox8c195bd2015-02-13 14:40:36 -050058type Pkg struct {
Russ Coxcdb7d7d2015-03-05 13:57:36 -050059 Name string // package name
60 Path string // string literal used in import statement
Russ Cox8c195bd2015-02-13 14:40:36 -050061 Pathsym *Sym
Russ Coxcdb7d7d2015-03-05 13:57:36 -050062 Prefix string // escaped path for use in symbol table
Marvin Stengere03c7892015-09-08 05:46:31 +020063 Imported bool // export data of this package was parsed
64 Exported bool // import line written in export data
65 Direct bool // imported directly
Russ Coxcdb7d7d2015-03-05 13:57:36 -050066 Safe bool // whether the package is marked as safe
Russ Coxd0b59de2015-03-02 16:21:15 -050067 Syms map[string]*Sym
Russ Cox8c195bd2015-02-13 14:40:36 -050068}
69
70type Sym struct {
Robert Griesemer37c29722016-03-01 16:37:20 -080071 Flags SymFlags
Matthew Dempsky071e43a2016-02-26 01:37:28 -080072 Link *Sym
Russ Coxcdb7d7d2015-03-05 13:57:36 -050073 Importdef *Pkg // where imported definition was found
74 Linkname string // link name
75
76 // saved and restored by dcopy
Russ Cox8c195bd2015-02-13 14:40:36 -050077 Pkg *Pkg
Russ Coxcdb7d7d2015-03-05 13:57:36 -050078 Name string // variable name
79 Def *Node // definition: ONAME OTYPE OPACK or OLITERAL
Russ Coxcdb7d7d2015-03-05 13:57:36 -050080 Block int32 // blocknumber to catch redeclaration
81 Lastlineno int32 // last declaration for diagnostic
Robert Griesemer157f0692016-03-10 15:07:08 -080082
83 Label *Label // corresponding label (ephemeral)
84 Origpkg *Pkg // original package for . import
85 Lsym *obj.LSym
86 Fsym *Sym // funcsym
Russ Cox8c195bd2015-02-13 14:40:36 -050087}
88
Russ Cox8c195bd2015-02-13 14:40:36 -050089type Label struct {
Robert Griesemerdef9c0b2016-03-10 20:35:27 -080090 Sym *Sym
91 Def *Node
92 Use []*Node
Russ Coxcdb7d7d2015-03-05 13:57:36 -050093
94 // for use during gen
95 Gotopc *obj.Prog // pointer to unresolved gotos
96 Labelpc *obj.Prog // pointer to code
97 Breakpc *obj.Prog // pointer to code
98 Continpc *obj.Prog // pointer to code
Dave Cheney8712e182015-09-07 11:11:14 +100099
100 Used bool
Russ Cox8c195bd2015-02-13 14:40:36 -0500101}
102
Robert Griesemer37c29722016-03-01 16:37:20 -0800103type SymFlags uint8
104
Russ Cox8c195bd2015-02-13 14:40:36 -0500105const (
Robert Griesemer37c29722016-03-01 16:37:20 -0800106 SymExport SymFlags = 1 << iota // to be exported
107 SymPackage
108 SymExported // already written out by export
109 SymUniq
110 SymSiggen
111 SymAsm
112 SymAlgGen
Russ Cox8c195bd2015-02-13 14:40:36 -0500113)
114
115var dclstack *Sym
116
Robert Griesemer53d43cb2015-10-26 16:00:59 -0700117// Ctype describes the constant kind of an "ideal" (untyped) constant.
118type Ctype int8
119
Russ Cox8c195bd2015-02-13 14:40:36 -0500120const (
Robert Griesemer53d43cb2015-10-26 16:00:59 -0700121 CTxxx Ctype = iota
Russ Coxcdb7d7d2015-03-05 13:57:36 -0500122
Russ Cox8c195bd2015-02-13 14:40:36 -0500123 CTINT
124 CTRUNE
125 CTFLT
126 CTCPLX
127 CTSTR
128 CTBOOL
129 CTNIL
130)
131
132const (
Jeremy Jackins6327e8d2015-10-22 09:51:12 +0900133 // types of channel
David Crawshawe6d6ad42016-02-16 15:30:32 -0500134 // must match ../../../../reflect/type.go:/ChanDir
Russ Cox8c195bd2015-02-13 14:40:36 -0500135 Crecv = 1 << 0
136 Csend = 1 << 1
137 Cboth = Crecv | Csend
138)
139
Robert Griesemercd7d7382015-10-26 14:57:36 -0700140// The Class of a variable/function describes the "storage class"
141// of a variable or function. During parsing, storage classes are
142// called declaration contexts.
143type Class uint8
144
Russ Cox8c195bd2015-02-13 14:40:36 -0500145const (
Robert Griesemercd7d7382015-10-26 14:57:36 -0700146 Pxxx Class = iota
147 PEXTERN // global variable
148 PAUTO // local variables
149 PPARAM // input arguments
150 PPARAMOUT // output results
151 PPARAMREF // closure variable reference
152 PFUNC // global function
Russ Coxcdb7d7d2015-03-05 13:57:36 -0500153
154 PDISCARD // discard during parse of duplicate import
155
Robert Griesemercd7d7382015-10-26 14:57:36 -0700156 PHEAP = 1 << 7 // an extra bit to identify an escaped variable
Russ Cox8c195bd2015-02-13 14:40:36 -0500157)
158
159const (
Russ Coxcdb7d7d2015-03-05 13:57:36 -0500160 Etop = 1 << 1 // evaluated at statement level
161 Erv = 1 << 2 // evaluated in value context
Russ Cox8c195bd2015-02-13 14:40:36 -0500162 Etype = 1 << 3
Russ Coxcdb7d7d2015-03-05 13:57:36 -0500163 Ecall = 1 << 4 // call-only expressions are ok
164 Efnstruct = 1 << 5 // multivalue function returns are ok
165 Eiota = 1 << 6 // iota is ok
166 Easgn = 1 << 7 // assigning to expression
167 Eindir = 1 << 8 // indirecting through expression
168 Eaddr = 1 << 9 // taking address of expression
169 Eproc = 1 << 10 // inside a go statement
170 Ecomplit = 1 << 11 // type in composite literal
Russ Cox8c195bd2015-02-13 14:40:36 -0500171)
172
Russ Cox8c195bd2015-02-13 14:40:36 -0500173type Sig struct {
174 name string
175 pkg *Pkg
176 isym *Sym
177 tsym *Sym
178 type_ *Type
179 mtype *Type
180 offset int32
Russ Cox8c195bd2015-02-13 14:40:36 -0500181}
182
Jeremy Jackins6327e8d2015-10-22 09:51:12 +0900183// note this is the runtime representation
184// of the compilers arrays.
185//
186// typedef struct
187// { // must not move anything
188// uchar array[8]; // pointer to data
189// uchar nel[4]; // number of elements
190// uchar cap[4]; // allocated number of elements
191// } Array;
Russ Cox8c195bd2015-02-13 14:40:36 -0500192var Array_array int // runtime offsetof(Array,array) - same for String
193
194var Array_nel int // runtime offsetof(Array,nel) - same for String
195
196var Array_cap int // runtime offsetof(Array,cap)
197
198var sizeof_Array int // runtime sizeof(Array)
199
Jeremy Jackins6327e8d2015-10-22 09:51:12 +0900200// note this is the runtime representation
201// of the compilers strings.
202//
203// typedef struct
204// { // must not move anything
205// uchar array[8]; // pointer to data
206// uchar nel[4]; // number of elements
207// } String;
Russ Cox8c195bd2015-02-13 14:40:36 -0500208var sizeof_String int // runtime sizeof(String)
209
Matthew Dempskye0fa8092016-02-25 16:07:04 -0800210// lexlineno is the line number _after_ the most recently read rune.
211// In particular, it's advanced (or rewound) as newlines are read (or unread).
Russ Cox8c195bd2015-02-13 14:40:36 -0500212var lexlineno int32
213
Matthew Dempskye0fa8092016-02-25 16:07:04 -0800214// lineno is the line number at the start of the most recently lexed token.
Russ Cox8c195bd2015-02-13 14:40:36 -0500215var lineno int32
216
Russ Cox8c195bd2015-02-13 14:40:36 -0500217var pragcgobuf string
218
219var infile string
220
221var outfile string
222
223var bout *obj.Biobuf
224
225var nerrors int
226
227var nsavederrors int
228
229var nsyntaxerrors int
230
Josh Bleecher Snyder2b063bd2015-05-14 19:33:31 -0700231var decldepth int32
Russ Cox8c195bd2015-02-13 14:40:36 -0500232
233var safemode int
234
235var nolocalimports int
236
Russ Cox8c195bd2015-02-13 14:40:36 -0500237var lexbuf bytes.Buffer
238var strbuf bytes.Buffer
Robert Griesemerc8bc7f12015-11-13 14:04:40 -0800239var litbuf string // LLITERAL value for use in syntax error messages
Russ Cox8c195bd2015-02-13 14:40:36 -0500240
241var Debug [256]int
242
243var debugstr string
244
245var Debug_checknil int
Russ Cox4224d812015-03-20 00:06:10 -0400246var Debug_typeassert int
Russ Cox8c195bd2015-02-13 14:40:36 -0500247
Russ Cox8c195bd2015-02-13 14:40:36 -0500248var localpkg *Pkg // package being compiled
249
250var importpkg *Pkg // package being imported
251
Russ Cox8c195bd2015-02-13 14:40:36 -0500252var gostringpkg *Pkg // fake pkg for Go strings
253
254var itabpkg *Pkg // fake pkg for itab cache
255
256var Runtimepkg *Pkg // package runtime
257
258var racepkg *Pkg // package runtime/race
259
Ian Lance Taylor0c69f132015-10-21 07:04:10 -0700260var msanpkg *Pkg // package runtime/msan
261
Russ Cox8c195bd2015-02-13 14:40:36 -0500262var typepkg *Pkg // fake package for runtime type info (headers)
263
264var typelinkpkg *Pkg // fake package for runtime type info (data)
265
Russ Cox8c195bd2015-02-13 14:40:36 -0500266var unsafepkg *Pkg // package unsafe
267
268var trackpkg *Pkg // fake package for field tracking
269
Marvin Stenger8e7a3ea2015-09-24 23:21:18 +0200270var Tptr EType // either TPTR32 or TPTR64
Russ Cox8c195bd2015-02-13 14:40:36 -0500271
272var myimportpath string
273
Russ Cox8c195bd2015-02-13 14:40:36 -0500274var localimport string
275
276var asmhdr string
277
Marvin Stenger8e7a3ea2015-09-24 23:21:18 +0200278var Simtype [NTYPE]EType
Russ Cox8c195bd2015-02-13 14:40:36 -0500279
Josh Bleecher Snyder25da5942015-03-01 07:54:01 +0000280var (
281 Isptr [NTYPE]bool
282 isforw [NTYPE]bool
283 Isint [NTYPE]bool
284 Isfloat [NTYPE]bool
285 Iscomplex [NTYPE]bool
286 Issigned [NTYPE]bool
287 issimple [NTYPE]bool
288)
Russ Cox8c195bd2015-02-13 14:40:36 -0500289
Josh Bleecher Snyder25da5942015-03-01 07:54:01 +0000290var (
291 okforeq [NTYPE]bool
292 okforadd [NTYPE]bool
293 okforand [NTYPE]bool
294 okfornone [NTYPE]bool
295 okforcmp [NTYPE]bool
296 okforbool [NTYPE]bool
297 okforcap [NTYPE]bool
298 okforlen [NTYPE]bool
299 okforarith [NTYPE]bool
300 okforconst [NTYPE]bool
301)
Russ Cox8c195bd2015-02-13 14:40:36 -0500302
Josh Bleecher Snyder25da5942015-03-01 07:54:01 +0000303var (
304 okfor [OEND][]bool
305 iscmp [OEND]bool
306)
Russ Cox8c195bd2015-02-13 14:40:36 -0500307
308var Minintval [NTYPE]*Mpint
309
310var Maxintval [NTYPE]*Mpint
311
312var minfltval [NTYPE]*Mpflt
313
314var maxfltval [NTYPE]*Mpflt
315
Ian Lance Taylorf444b8a2016-03-09 20:29:21 -0800316var xtop []*Node
Russ Cox8c195bd2015-02-13 14:40:36 -0500317
Dave Cheneyd5fe1652015-09-10 15:57:39 +1000318var externdcl []*Node
Russ Cox8c195bd2015-02-13 14:40:36 -0500319
Robert Griesemer3d3bc882015-08-12 14:29:50 -0700320var exportlist []*Node
Russ Cox8c195bd2015-02-13 14:40:36 -0500321
HÃ¥vard Haugen391cc542015-09-06 22:38:49 +0200322var importlist []*Node // imported functions and methods with inlinable bodies
Russ Cox8c195bd2015-02-13 14:40:36 -0500323
Robert Griesemera2119ac2015-10-05 16:33:53 -0700324var funcsyms []*Node
Russ Cox8c195bd2015-02-13 14:40:36 -0500325
Robert Griesemercd7d7382015-10-26 14:57:36 -0700326var dclcontext Class // PEXTERN/PAUTO
Russ Cox8c195bd2015-02-13 14:40:36 -0500327
328var incannedimport int
329
330var statuniqgen int // name generator for static temps
331
Russ Cox8c195bd2015-02-13 14:40:36 -0500332var iota_ int32
333
Ian Lance Taylorf444b8a2016-03-09 20:29:21 -0800334var lastconst []*Node
Russ Cox8c195bd2015-02-13 14:40:36 -0500335
336var lasttype *Node
337
338var Maxarg int64
339
340var Stksize int64 // stack size for current frame
341
342var stkptrsize int64 // prefix of stack containing pointers
343
344var blockgen int32 // max block number
345
346var block int32 // current block number
347
HÃ¥vard Haugen25946642015-09-07 22:19:30 +0200348var hasdefer bool // flag that curfn has defer statement
Russ Cox8c195bd2015-02-13 14:40:36 -0500349
350var Curfn *Node
351
352var Widthptr int
353
354var Widthint int
355
356var Widthreg int
357
Russ Cox8c195bd2015-02-13 14:40:36 -0500358var nblank *Node
359
Dave Cheneye4981812015-03-10 09:58:01 +1100360var Funcdepth int32
Russ Cox8c195bd2015-02-13 14:40:36 -0500361
HÃ¥vard Haugendc3540d2015-08-30 23:56:40 +0200362var typecheckok bool
Russ Cox8c195bd2015-02-13 14:40:36 -0500363
364var compiling_runtime int
365
366var compiling_wrappers int
367
Russ Cox8c195bd2015-02-13 14:40:36 -0500368var use_writebarrier int
369
370var pure_go int
371
372var flag_installsuffix string
373
374var flag_race int
375
Ian Lance Taylor0c69f132015-10-21 07:04:10 -0700376var flag_msan int
377
Russ Cox8c195bd2015-02-13 14:40:36 -0500378var flag_largemodel int
379
Ian Lance Taylor9e902f02015-10-20 10:00:07 -0700380// Whether we are adding any sort of code instrumentation, such as
381// when the race detector is enabled.
382var instrumenting bool
383
Russ Cox8c195bd2015-02-13 14:40:36 -0500384var debuglive int
385
386var Ctxt *obj.Link
387
Russ Cox8c195bd2015-02-13 14:40:36 -0500388var writearchive int
389
390var bstdout obj.Biobuf
391
392var Nacl bool
393
Russ Cox8c195bd2015-02-13 14:40:36 -0500394var continpc *obj.Prog
395
396var breakpc *obj.Prog
397
398var Pc *obj.Prog
399
Russ Cox8c195bd2015-02-13 14:40:36 -0500400var nodfp *Node
401
402var Disable_checknil int
403
Russ Cox8c195bd2015-02-13 14:40:36 -0500404type Flow struct {
Russ Coxcdb7d7d2015-03-05 13:57:36 -0500405 Prog *obj.Prog // actual instruction
406 P1 *Flow // predecessors of this instruction: p1,
407 P2 *Flow // and then p2 linked though p2link.
Russ Cox8c195bd2015-02-13 14:40:36 -0500408 P2link *Flow
Russ Coxcdb7d7d2015-03-05 13:57:36 -0500409 S1 *Flow // successors of this instruction (at most two: s1 and s2).
Russ Cox8c195bd2015-02-13 14:40:36 -0500410 S2 *Flow
Russ Coxcdb7d7d2015-03-05 13:57:36 -0500411 Link *Flow // next instruction in function code
412
413 Active int32 // usable by client
414
415 Id int32 // sequence number in flow graph
416 Rpo int32 // reverse post ordering
417 Loop uint16 // x5 for every loop
Marvin Stenger9ac0fff2015-09-08 03:51:30 +0200418 Refset bool // diagnostic generated
Russ Coxcdb7d7d2015-03-05 13:57:36 -0500419
420 Data interface{} // for use by client
Russ Cox8c195bd2015-02-13 14:40:36 -0500421}
422
423type Graph struct {
424 Start *Flow
425 Num int
Russ Coxcdb7d7d2015-03-05 13:57:36 -0500426
427 // After calling flowrpo, rpo lists the flow nodes in reverse postorder,
428 // and each non-dead Flow node f has g->rpo[f->rpo] == f.
429 Rpo []*Flow
Russ Cox8c195bd2015-02-13 14:40:36 -0500430}
431
Jeremy Jackins6327e8d2015-10-22 09:51:12 +0900432// interface to back end
Russ Cox8c195bd2015-02-13 14:40:36 -0500433
434const (
Russ Coxcdb7d7d2015-03-05 13:57:36 -0500435 // Pseudo-op, like TEXT, GLOBL, TYPE, PCDATA, FUNCDATA.
436 Pseudo = 1 << 1
437
438 // There's nothing to say about the instruction,
439 // but it's still okay to see.
440 OK = 1 << 2
441
442 // Size of right-side write, or right-side read if no write.
443 SizeB = 1 << 3
444 SizeW = 1 << 4
445 SizeL = 1 << 5
446 SizeQ = 1 << 6
447 SizeF = 1 << 7
448 SizeD = 1 << 8
449
450 // Left side (Prog.from): address taken, read, write.
451 LeftAddr = 1 << 9
452 LeftRead = 1 << 10
453 LeftWrite = 1 << 11
454
455 // Register in middle (Prog.reg); only ever read. (arm, ppc64)
Russ Cox8c195bd2015-02-13 14:40:36 -0500456 RegRead = 1 << 12
457 CanRegRead = 1 << 13
Russ Coxcdb7d7d2015-03-05 13:57:36 -0500458
459 // Right side (Prog.to): address taken, read, write.
Russ Cox8c195bd2015-02-13 14:40:36 -0500460 RightAddr = 1 << 14
461 RightRead = 1 << 15
462 RightWrite = 1 << 16
Russ Coxcdb7d7d2015-03-05 13:57:36 -0500463
464 // Instruction kinds
465 Move = 1 << 17 // straight move
466 Conv = 1 << 18 // size conversion
467 Cjmp = 1 << 19 // conditional jump
468 Break = 1 << 20 // breaks control flow (no fallthrough)
469 Call = 1 << 21 // function call
470 Jump = 1 << 22 // jump
471 Skip = 1 << 23 // data instruction
472
473 // Set, use, or kill of carry bit.
474 // Kill means we never look at the carry bit after this kind of instruction.
475 SetCarry = 1 << 24
476 UseCarry = 1 << 25
477 KillCarry = 1 << 26
478
479 // Special cases for register use. (amd64, 386)
480 ShiftCX = 1 << 27 // possible shift by CX
481 ImulAXDX = 1 << 28 // possible multiply into DX:AX
482
483 // Instruction updates whichever of from/to is type D_OREG. (ppc64)
484 PostInc = 1 << 29
Russ Cox8c195bd2015-02-13 14:40:36 -0500485)
486
487type Arch struct {
Russ Coxb115c352015-03-18 17:26:36 -0400488 Thechar int
489 Thestring string
490 Thelinkarch *obj.LinkArch
Russ Coxb115c352015-03-18 17:26:36 -0400491 REGSP int
492 REGCTXT int
493 REGCALLX int // BX
494 REGCALLX2 int // AX
495 REGRETURN int // AX
496 REGMIN int
497 REGMAX int
Dave Cheney888d44d2015-04-09 21:25:48 +1000498 REGZERO int // architectural zero register, if available
Russ Coxb115c352015-03-18 17:26:36 -0400499 FREGMIN int
500 FREGMAX int
501 MAXWIDTH int64
502 ReservedRegs []int
503
504 AddIndex func(*Node, int64, *Node) bool // optional
505 Betypeinit func()
Josh Bleecher Snyder4a7e5bc2015-04-06 19:36:36 -0700506 Bgen_float func(*Node, bool, int, *obj.Prog) // optional
507 Cgen64 func(*Node, *Node) // only on 32-bit systems
Russ Coxb115c352015-03-18 17:26:36 -0400508 Cgenindex func(*Node, *Node, bool) *obj.Prog
Marvin Stenger8e7a3ea2015-09-24 23:21:18 +0200509 Cgen_bmul func(Op, *Node, *Node, *Node) bool
Russ Coxb115c352015-03-18 17:26:36 -0400510 Cgen_float func(*Node, *Node) // optional
511 Cgen_hmul func(*Node, *Node, *Node)
Marvin Stenger8e7a3ea2015-09-24 23:21:18 +0200512 Cgen_shift func(Op, bool, *Node, *Node, *Node)
Russ Coxb115c352015-03-18 17:26:36 -0400513 Clearfat func(*Node)
Marvin Stenger8e7a3ea2015-09-24 23:21:18 +0200514 Cmp64 func(*Node, *Node, Op, int, *obj.Prog) // only on 32-bit systems
Russ Coxb115c352015-03-18 17:26:36 -0400515 Defframe func(*obj.Prog)
Marvin Stenger8e7a3ea2015-09-24 23:21:18 +0200516 Dodiv func(Op, *Node, *Node, *Node)
Russ Coxb115c352015-03-18 17:26:36 -0400517 Excise func(*Flow)
518 Expandchecks func(*obj.Prog)
Russ Cox92c826b2015-04-03 12:23:28 -0400519 Getg func(*Node)
Matthew Dempsky0d9258a2016-03-07 18:00:08 -0800520 Gins func(obj.As, *Node, *Node) *obj.Prog
Russ Coxf8d14fc2015-05-06 12:28:19 -0400521
522 // Ginscmp generates code comparing n1 to n2 and jumping away if op is satisfied.
523 // The returned prog should be Patch'ed with the jump target.
524 // If op is not satisfied, code falls through to the next emitted instruction.
525 // Likely is the branch prediction hint: +1 for likely, -1 for unlikely, 0 for no opinion.
526 //
527 // Ginscmp must be able to handle all kinds of arguments for n1 and n2,
528 // not just simple registers, although it can assume that there are no
Russ Cox6e8bcbb2015-05-15 16:11:25 -0400529 // function calls needed during the evaluation, and on 32-bit systems
530 // the values are guaranteed not to be 64-bit values, so no in-memory
531 // temporaries are necessary.
Marvin Stenger8e7a3ea2015-09-24 23:21:18 +0200532 Ginscmp func(op Op, t *Type, n1, n2 *Node, likely int) *obj.Prog
Russ Coxf8d14fc2015-05-06 12:28:19 -0400533
Josh Bleecher Snyder13cb62c2015-04-08 09:54:15 -0700534 // Ginsboolval inserts instructions to convert the result
535 // of a just-completed comparison to a boolean value.
536 // The first argument is the conditional jump instruction
537 // corresponding to the desired value.
538 // The second argument is the destination.
539 // If not present, Ginsboolval will be emulated with jumps.
Matthew Dempsky0d9258a2016-03-07 18:00:08 -0800540 Ginsboolval func(obj.As, *Node)
Russ Coxf8d14fc2015-05-06 12:28:19 -0400541
Matthew Dempsky0d9258a2016-03-07 18:00:08 -0800542 Ginscon func(obj.As, int64, *Node)
Russ Coxb115c352015-03-18 17:26:36 -0400543 Ginsnop func()
544 Gmove func(*Node, *Node)
545 Igenindex func(*Node, *Node, bool) *obj.Prog
546 Linkarchinit func()
547 Peep func(*obj.Prog)
548 Proginfo func(*obj.Prog) // fills in Prog.Info
549 Regtyp func(*obj.Addr) bool
550 Sameaddr func(*obj.Addr, *obj.Addr) bool
551 Smallindir func(*obj.Addr, *obj.Addr) bool
552 Stackaddr func(*obj.Addr) bool
Shenghou Mae7dd2882015-04-08 13:34:42 -0400553 Blockcopy func(*Node, *Node, int64, int64, int64)
Matthew Dempsky0d9258a2016-03-07 18:00:08 -0800554 Sudoaddable func(obj.As, *Node, *obj.Addr) bool
Russ Coxb115c352015-03-18 17:26:36 -0400555 Sudoclean func()
556 Excludedregs func() uint64
557 RtoB func(int) uint64
558 FtoB func(int) uint64
559 BtoR func(uint64) int
560 BtoF func(uint64) int
Matthew Dempsky0d9258a2016-03-07 18:00:08 -0800561 Optoas func(Op, *Type) obj.As
Russ Coxb115c352015-03-18 17:26:36 -0400562 Doregbits func(int) uint64
563 Regnames func(*int) []string
Dave Cheney01d005c2015-03-25 09:17:09 +1100564 Use387 bool // should 8g use 387 FP instructions instead of sse2.
Michael Pratta4e31d42016-03-12 14:07:40 -0800565
566 // SSARegToReg maps ssa register numbers to obj register numbers.
567 SSARegToReg []int16
568
569 // SSAMarkMoves marks any MOVXconst ops that need to avoid clobbering flags.
570 SSAMarkMoves func(*SSAGenState, *ssa.Block)
571
572 // SSAGenValue emits Prog(s) for the Value.
573 SSAGenValue func(*SSAGenState, *ssa.Value)
574
575 // SSAGenBlock emits end-of-block Progs. SSAGenValue should be called
576 // for all values in the block before SSAGenBlock.
577 SSAGenBlock func(s *SSAGenState, b, next *ssa.Block)
Russ Cox8c195bd2015-02-13 14:40:36 -0500578}
579
580var pcloc int32
581
582var Thearch Arch
583
584var Newproc *Node
585
586var Deferproc *Node
587
588var Deferreturn *Node
589
590var Panicindex *Node
591
592var panicslice *Node
593
David Chase18559e22015-10-28 13:55:46 -0400594var panicdivide *Node
595
Russ Cox8c195bd2015-02-13 14:40:36 -0500596var throwreturn *Node
Keith Randall8c5bfcc2015-09-18 15:11:30 -0700597
598var growslice *Node
599
Keith Randall5ba31942016-01-25 17:06:54 -0800600var writebarrierptr *Node
601var typedmemmove *Node
Keith Randall8c5bfcc2015-09-18 15:11:30 -0700602
603var panicdottype *Node