blob: fdea1f2fbacca209cf7ef4502405229d4a61e70a [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
Rob Pike24a43e62015-03-05 10:39:23 -080015 BADWIDTH = -1000000000
16 MaxStackVarSize = 10 * 1024 * 1024
17)
18
Russ Cox8c195bd2015-02-13 14:40:36 -050019type Val struct {
Josh Bleecher Snyder13485be2015-05-14 17:57:42 -070020 // U contains one of:
Russ Cox71080fb2015-05-26 22:50:45 -040021 // bool bool when n.ValCtype() == CTBOOL
22 // *Mpint int when n.ValCtype() == CTINT, rune when n.ValCtype() == CTRUNE
23 // *Mpflt float when n.ValCtype() == CTFLT
24 // *Mpcplx pair of floats when n.ValCtype() == CTCPLX
25 // string string when n.ValCtype() == CTSTR
26 // *Nilval when n.ValCtype() == CTNIL
Josh Bleecher Snyder13485be2015-05-14 17:57:42 -070027 U interface{}
Russ Cox8c195bd2015-02-13 14:40:36 -050028}
29
Russ Cox71080fb2015-05-26 22:50:45 -040030type NilVal struct{}
31
Robert Griesemer53d43cb2015-10-26 16:00:59 -070032func (v Val) Ctype() Ctype {
Russ Cox71080fb2015-05-26 22:50:45 -040033 switch x := v.U.(type) {
34 default:
HÃ¥vard Haugen3c9fa382015-08-30 23:10:03 +020035 Fatalf("unexpected Ctype for %T", v.U)
Russ Coxa53710f2015-06-03 14:16:01 -040036 panic("not reached")
37 case nil:
Russ Cox71080fb2015-05-26 22:50:45 -040038 return 0
39 case *NilVal:
40 return CTNIL
41 case bool:
42 return CTBOOL
43 case *Mpint:
44 if x.Rune {
45 return CTRUNE
46 }
47 return CTINT
48 case *Mpflt:
49 return CTFLT
50 case *Mpcplx:
51 return CTCPLX
52 case string:
53 return CTSTR
54 }
55}
56
Russ Cox8c195bd2015-02-13 14:40:36 -050057type Pkg struct {
David Chase8eec2bb2016-03-11 00:10:52 -050058 Name string // package name, e.g. "sys"
59 Path string // string literal used in import statement, e.g. "runtime/internal/sys"
Russ Cox8c195bd2015-02-13 14:40:36 -050060 Pathsym *Sym
Russ Coxcdb7d7d2015-03-05 13:57:36 -050061 Prefix string // escaped path for use in symbol table
Marvin Stengere03c7892015-09-08 05:46:31 +020062 Imported bool // export data of this package was parsed
63 Exported bool // import line written in export data
64 Direct bool // imported directly
Russ Coxcdb7d7d2015-03-05 13:57:36 -050065 Safe bool // whether the package is marked as safe
Russ Coxd0b59de2015-03-02 16:21:15 -050066 Syms map[string]*Sym
Russ Cox8c195bd2015-02-13 14:40:36 -050067}
68
69type Sym struct {
Robert Griesemer37c29722016-03-01 16:37:20 -080070 Flags SymFlags
Matthew Dempsky071e43a2016-02-26 01:37:28 -080071 Link *Sym
Russ Coxcdb7d7d2015-03-05 13:57:36 -050072 Importdef *Pkg // where imported definition was found
73 Linkname string // link name
74
75 // saved and restored by dcopy
Russ Cox8c195bd2015-02-13 14:40:36 -050076 Pkg *Pkg
Russ Coxcdb7d7d2015-03-05 13:57:36 -050077 Name string // variable name
78 Def *Node // definition: ONAME OTYPE OPACK or OLITERAL
Russ Coxcdb7d7d2015-03-05 13:57:36 -050079 Block int32 // blocknumber to catch redeclaration
80 Lastlineno int32 // last declaration for diagnostic
Robert Griesemer157f0692016-03-10 15:07:08 -080081
82 Label *Label // corresponding label (ephemeral)
83 Origpkg *Pkg // original package for . import
84 Lsym *obj.LSym
85 Fsym *Sym // funcsym
Russ Cox8c195bd2015-02-13 14:40:36 -050086}
87
Russ Cox8c195bd2015-02-13 14:40:36 -050088type Label struct {
Robert Griesemerdef9c0b2016-03-10 20:35:27 -080089 Sym *Sym
90 Def *Node
91 Use []*Node
Russ Coxcdb7d7d2015-03-05 13:57:36 -050092
93 // for use during gen
94 Gotopc *obj.Prog // pointer to unresolved gotos
95 Labelpc *obj.Prog // pointer to code
96 Breakpc *obj.Prog // pointer to code
97 Continpc *obj.Prog // pointer to code
Dave Cheney8712e182015-09-07 11:11:14 +100098
99 Used bool
Russ Cox8c195bd2015-02-13 14:40:36 -0500100}
101
Robert Griesemer37c29722016-03-01 16:37:20 -0800102type SymFlags uint8
103
Russ Cox8c195bd2015-02-13 14:40:36 -0500104const (
Robert Griesemer37c29722016-03-01 16:37:20 -0800105 SymExport SymFlags = 1 << iota // to be exported
106 SymPackage
107 SymExported // already written out by export
108 SymUniq
109 SymSiggen
110 SymAsm
111 SymAlgGen
Russ Cox8c195bd2015-02-13 14:40:36 -0500112)
113
114var dclstack *Sym
115
Robert Griesemer53d43cb2015-10-26 16:00:59 -0700116// Ctype describes the constant kind of an "ideal" (untyped) constant.
117type Ctype int8
118
Russ Cox8c195bd2015-02-13 14:40:36 -0500119const (
Robert Griesemer53d43cb2015-10-26 16:00:59 -0700120 CTxxx Ctype = iota
Russ Coxcdb7d7d2015-03-05 13:57:36 -0500121
Russ Cox8c195bd2015-02-13 14:40:36 -0500122 CTINT
123 CTRUNE
124 CTFLT
125 CTCPLX
126 CTSTR
127 CTBOOL
128 CTNIL
129)
130
Brad Fitzpatrick386c0e62016-04-03 22:58:10 +0000131// ChanDir is whether a channel can send, receive, or both.
132type ChanDir uint8
133
134func (c ChanDir) CanRecv() bool { return c&Crecv != 0 }
135func (c ChanDir) CanSend() bool { return c&Csend != 0 }
136
Russ Cox8c195bd2015-02-13 14:40:36 -0500137const (
Jeremy Jackins6327e8d2015-10-22 09:51:12 +0900138 // types of channel
David Crawshawe6d6ad42016-02-16 15:30:32 -0500139 // must match ../../../../reflect/type.go:/ChanDir
Brad Fitzpatrick386c0e62016-04-03 22:58:10 +0000140 Crecv ChanDir = 1 << 0
141 Csend ChanDir = 1 << 1
142 Cboth ChanDir = Crecv | Csend
Russ Cox8c195bd2015-02-13 14:40:36 -0500143)
144
Robert Griesemercd7d7382015-10-26 14:57:36 -0700145// The Class of a variable/function describes the "storage class"
146// of a variable or function. During parsing, storage classes are
147// called declaration contexts.
148type Class uint8
149
Russ Cox8c195bd2015-02-13 14:40:36 -0500150const (
Robert Griesemercd7d7382015-10-26 14:57:36 -0700151 Pxxx Class = iota
152 PEXTERN // global variable
153 PAUTO // local variables
154 PPARAM // input arguments
155 PPARAMOUT // output results
156 PPARAMREF // closure variable reference
157 PFUNC // global function
Russ Coxcdb7d7d2015-03-05 13:57:36 -0500158
159 PDISCARD // discard during parse of duplicate import
160
Robert Griesemercd7d7382015-10-26 14:57:36 -0700161 PHEAP = 1 << 7 // an extra bit to identify an escaped variable
Russ Cox8c195bd2015-02-13 14:40:36 -0500162)
163
164const (
Russ Coxcdb7d7d2015-03-05 13:57:36 -0500165 Etop = 1 << 1 // evaluated at statement level
166 Erv = 1 << 2 // evaluated in value context
Russ Cox8c195bd2015-02-13 14:40:36 -0500167 Etype = 1 << 3
Russ Coxcdb7d7d2015-03-05 13:57:36 -0500168 Ecall = 1 << 4 // call-only expressions are ok
169 Efnstruct = 1 << 5 // multivalue function returns are ok
170 Eiota = 1 << 6 // iota is ok
171 Easgn = 1 << 7 // assigning to expression
172 Eindir = 1 << 8 // indirecting through expression
173 Eaddr = 1 << 9 // taking address of expression
174 Eproc = 1 << 10 // inside a go statement
175 Ecomplit = 1 << 11 // type in composite literal
Russ Cox8c195bd2015-02-13 14:40:36 -0500176)
177
Russ Cox8c195bd2015-02-13 14:40:36 -0500178type Sig struct {
179 name string
180 pkg *Pkg
181 isym *Sym
182 tsym *Sym
183 type_ *Type
184 mtype *Type
185 offset int32
Russ Cox8c195bd2015-02-13 14:40:36 -0500186}
187
Jeremy Jackins6327e8d2015-10-22 09:51:12 +0900188// note this is the runtime representation
189// of the compilers arrays.
190//
191// typedef struct
192// { // must not move anything
193// uchar array[8]; // pointer to data
194// uchar nel[4]; // number of elements
195// uchar cap[4]; // allocated number of elements
196// } Array;
Russ Cox8c195bd2015-02-13 14:40:36 -0500197var Array_array int // runtime offsetof(Array,array) - same for String
198
199var Array_nel int // runtime offsetof(Array,nel) - same for String
200
201var Array_cap int // runtime offsetof(Array,cap)
202
203var sizeof_Array int // runtime sizeof(Array)
204
Jeremy Jackins6327e8d2015-10-22 09:51:12 +0900205// note this is the runtime representation
206// of the compilers strings.
207//
208// typedef struct
209// { // must not move anything
210// uchar array[8]; // pointer to data
211// uchar nel[4]; // number of elements
212// } String;
Russ Cox8c195bd2015-02-13 14:40:36 -0500213var sizeof_String int // runtime sizeof(String)
214
Matthew Dempskye0fa8092016-02-25 16:07:04 -0800215// lexlineno is the line number _after_ the most recently read rune.
216// In particular, it's advanced (or rewound) as newlines are read (or unread).
Russ Cox8c195bd2015-02-13 14:40:36 -0500217var lexlineno int32
218
Matthew Dempskye0fa8092016-02-25 16:07:04 -0800219// lineno is the line number at the start of the most recently lexed token.
Russ Cox8c195bd2015-02-13 14:40:36 -0500220var lineno int32
221
Russ Cox8c195bd2015-02-13 14:40:36 -0500222var pragcgobuf string
223
224var infile string
225
226var outfile string
227
228var bout *obj.Biobuf
229
230var nerrors int
231
232var nsavederrors int
233
234var nsyntaxerrors int
235
Josh Bleecher Snyder2b063bd2015-05-14 19:33:31 -0700236var decldepth int32
Russ Cox8c195bd2015-02-13 14:40:36 -0500237
238var safemode int
239
240var nolocalimports int
241
Russ Cox8c195bd2015-02-13 14:40:36 -0500242var lexbuf bytes.Buffer
243var strbuf bytes.Buffer
Robert Griesemerc8bc7f12015-11-13 14:04:40 -0800244var litbuf string // LLITERAL value for use in syntax error messages
Russ Cox8c195bd2015-02-13 14:40:36 -0500245
246var Debug [256]int
247
248var debugstr string
249
250var Debug_checknil int
Russ Cox4224d812015-03-20 00:06:10 -0400251var Debug_typeassert int
Russ Cox8c195bd2015-02-13 14:40:36 -0500252
Russ Cox8c195bd2015-02-13 14:40:36 -0500253var localpkg *Pkg // package being compiled
254
255var importpkg *Pkg // package being imported
256
Michel Lespinasse859b63c2016-03-18 17:21:33 -0700257var itabpkg *Pkg // fake pkg for itab entries
Michel Lespinassef00bbd52016-03-17 06:18:13 -0700258
259var itablinkpkg *Pkg // fake package for runtime itab entries
260
Russ Cox8c195bd2015-02-13 14:40:36 -0500261var Runtimepkg *Pkg // package runtime
262
263var racepkg *Pkg // package runtime/race
264
Ian Lance Taylor0c69f132015-10-21 07:04:10 -0700265var msanpkg *Pkg // package runtime/msan
266
Russ Cox8c195bd2015-02-13 14:40:36 -0500267var typepkg *Pkg // fake package for runtime type info (headers)
268
269var typelinkpkg *Pkg // fake package for runtime type info (data)
270
Russ Cox8c195bd2015-02-13 14:40:36 -0500271var unsafepkg *Pkg // package unsafe
272
273var trackpkg *Pkg // fake package for field tracking
274
Marvin Stenger8e7a3ea2015-09-24 23:21:18 +0200275var Tptr EType // either TPTR32 or TPTR64
Russ Cox8c195bd2015-02-13 14:40:36 -0500276
277var myimportpath string
278
Russ Cox8c195bd2015-02-13 14:40:36 -0500279var localimport string
280
281var asmhdr string
282
Marvin Stenger8e7a3ea2015-09-24 23:21:18 +0200283var Simtype [NTYPE]EType
Russ Cox8c195bd2015-02-13 14:40:36 -0500284
Josh Bleecher Snyder25da5942015-03-01 07:54:01 +0000285var (
Josh Bleecher Snyder25da5942015-03-01 07:54:01 +0000286 isforw [NTYPE]bool
287 Isint [NTYPE]bool
288 Isfloat [NTYPE]bool
289 Iscomplex [NTYPE]bool
Josh Bleecher Snyder25da5942015-03-01 07:54:01 +0000290 issimple [NTYPE]bool
291)
Russ Cox8c195bd2015-02-13 14:40:36 -0500292
Josh Bleecher Snyder25da5942015-03-01 07:54:01 +0000293var (
294 okforeq [NTYPE]bool
295 okforadd [NTYPE]bool
296 okforand [NTYPE]bool
297 okfornone [NTYPE]bool
298 okforcmp [NTYPE]bool
299 okforbool [NTYPE]bool
300 okforcap [NTYPE]bool
301 okforlen [NTYPE]bool
302 okforarith [NTYPE]bool
303 okforconst [NTYPE]bool
304)
Russ Cox8c195bd2015-02-13 14:40:36 -0500305
Josh Bleecher Snyder25da5942015-03-01 07:54:01 +0000306var (
307 okfor [OEND][]bool
308 iscmp [OEND]bool
309)
Russ Cox8c195bd2015-02-13 14:40:36 -0500310
311var Minintval [NTYPE]*Mpint
312
313var Maxintval [NTYPE]*Mpint
314
315var minfltval [NTYPE]*Mpflt
316
317var maxfltval [NTYPE]*Mpflt
318
Ian Lance Taylorf444b8a2016-03-09 20:29:21 -0800319var xtop []*Node
Russ Cox8c195bd2015-02-13 14:40:36 -0500320
Dave Cheneyd5fe1652015-09-10 15:57:39 +1000321var externdcl []*Node
Russ Cox8c195bd2015-02-13 14:40:36 -0500322
Robert Griesemer3d3bc882015-08-12 14:29:50 -0700323var exportlist []*Node
Russ Cox8c195bd2015-02-13 14:40:36 -0500324
HÃ¥vard Haugen391cc542015-09-06 22:38:49 +0200325var importlist []*Node // imported functions and methods with inlinable bodies
Russ Cox8c195bd2015-02-13 14:40:36 -0500326
Robert Griesemera2119ac2015-10-05 16:33:53 -0700327var funcsyms []*Node
Russ Cox8c195bd2015-02-13 14:40:36 -0500328
Robert Griesemercd7d7382015-10-26 14:57:36 -0700329var dclcontext Class // PEXTERN/PAUTO
Russ Cox8c195bd2015-02-13 14:40:36 -0500330
331var incannedimport int
332
333var statuniqgen int // name generator for static temps
334
Russ Cox8c195bd2015-02-13 14:40:36 -0500335var iota_ int32
336
Ian Lance Taylorf444b8a2016-03-09 20:29:21 -0800337var lastconst []*Node
Russ Cox8c195bd2015-02-13 14:40:36 -0500338
339var lasttype *Node
340
341var Maxarg int64
342
343var Stksize int64 // stack size for current frame
344
345var stkptrsize int64 // prefix of stack containing pointers
346
347var blockgen int32 // max block number
348
349var block int32 // current block number
350
HÃ¥vard Haugen25946642015-09-07 22:19:30 +0200351var hasdefer bool // flag that curfn has defer statement
Russ Cox8c195bd2015-02-13 14:40:36 -0500352
353var Curfn *Node
354
355var Widthptr int
356
357var Widthint int
358
359var Widthreg int
360
Russ Cox8c195bd2015-02-13 14:40:36 -0500361var nblank *Node
362
Dave Cheneye4981812015-03-10 09:58:01 +1100363var Funcdepth int32
Russ Cox8c195bd2015-02-13 14:40:36 -0500364
HÃ¥vard Haugendc3540d2015-08-30 23:56:40 +0200365var typecheckok bool
Russ Cox8c195bd2015-02-13 14:40:36 -0500366
367var compiling_runtime int
368
369var compiling_wrappers int
370
Russ Cox8c195bd2015-02-13 14:40:36 -0500371var use_writebarrier int
372
373var pure_go int
374
375var flag_installsuffix string
376
377var flag_race int
378
Ian Lance Taylor0c69f132015-10-21 07:04:10 -0700379var flag_msan int
380
Russ Cox8c195bd2015-02-13 14:40:36 -0500381var flag_largemodel int
382
Ian Lance Taylor9e902f02015-10-20 10:00:07 -0700383// Whether we are adding any sort of code instrumentation, such as
384// when the race detector is enabled.
385var instrumenting bool
386
Russ Cox8c195bd2015-02-13 14:40:36 -0500387var debuglive int
388
389var Ctxt *obj.Link
390
Russ Cox8c195bd2015-02-13 14:40:36 -0500391var writearchive int
392
393var bstdout obj.Biobuf
394
395var Nacl bool
396
Russ Cox8c195bd2015-02-13 14:40:36 -0500397var continpc *obj.Prog
398
399var breakpc *obj.Prog
400
401var Pc *obj.Prog
402
Russ Cox8c195bd2015-02-13 14:40:36 -0500403var nodfp *Node
404
405var Disable_checknil int
406
Russ Cox8c195bd2015-02-13 14:40:36 -0500407type Flow struct {
Russ Coxcdb7d7d2015-03-05 13:57:36 -0500408 Prog *obj.Prog // actual instruction
409 P1 *Flow // predecessors of this instruction: p1,
410 P2 *Flow // and then p2 linked though p2link.
Russ Cox8c195bd2015-02-13 14:40:36 -0500411 P2link *Flow
Russ Coxcdb7d7d2015-03-05 13:57:36 -0500412 S1 *Flow // successors of this instruction (at most two: s1 and s2).
Russ Cox8c195bd2015-02-13 14:40:36 -0500413 S2 *Flow
Russ Coxcdb7d7d2015-03-05 13:57:36 -0500414 Link *Flow // next instruction in function code
415
416 Active int32 // usable by client
417
418 Id int32 // sequence number in flow graph
419 Rpo int32 // reverse post ordering
420 Loop uint16 // x5 for every loop
Marvin Stenger9ac0fff2015-09-08 03:51:30 +0200421 Refset bool // diagnostic generated
Russ Coxcdb7d7d2015-03-05 13:57:36 -0500422
423 Data interface{} // for use by client
Russ Cox8c195bd2015-02-13 14:40:36 -0500424}
425
426type Graph struct {
427 Start *Flow
428 Num int
Russ Coxcdb7d7d2015-03-05 13:57:36 -0500429
430 // After calling flowrpo, rpo lists the flow nodes in reverse postorder,
431 // and each non-dead Flow node f has g->rpo[f->rpo] == f.
432 Rpo []*Flow
Russ Cox8c195bd2015-02-13 14:40:36 -0500433}
434
Jeremy Jackins6327e8d2015-10-22 09:51:12 +0900435// interface to back end
Russ Cox8c195bd2015-02-13 14:40:36 -0500436
437const (
Russ Coxcdb7d7d2015-03-05 13:57:36 -0500438 // Pseudo-op, like TEXT, GLOBL, TYPE, PCDATA, FUNCDATA.
439 Pseudo = 1 << 1
440
441 // There's nothing to say about the instruction,
442 // but it's still okay to see.
443 OK = 1 << 2
444
445 // Size of right-side write, or right-side read if no write.
446 SizeB = 1 << 3
447 SizeW = 1 << 4
448 SizeL = 1 << 5
449 SizeQ = 1 << 6
450 SizeF = 1 << 7
451 SizeD = 1 << 8
452
453 // Left side (Prog.from): address taken, read, write.
454 LeftAddr = 1 << 9
455 LeftRead = 1 << 10
456 LeftWrite = 1 << 11
457
458 // Register in middle (Prog.reg); only ever read. (arm, ppc64)
Russ Cox8c195bd2015-02-13 14:40:36 -0500459 RegRead = 1 << 12
460 CanRegRead = 1 << 13
Russ Coxcdb7d7d2015-03-05 13:57:36 -0500461
462 // Right side (Prog.to): address taken, read, write.
Russ Cox8c195bd2015-02-13 14:40:36 -0500463 RightAddr = 1 << 14
464 RightRead = 1 << 15
465 RightWrite = 1 << 16
Russ Coxcdb7d7d2015-03-05 13:57:36 -0500466
467 // Instruction kinds
468 Move = 1 << 17 // straight move
469 Conv = 1 << 18 // size conversion
470 Cjmp = 1 << 19 // conditional jump
471 Break = 1 << 20 // breaks control flow (no fallthrough)
472 Call = 1 << 21 // function call
473 Jump = 1 << 22 // jump
474 Skip = 1 << 23 // data instruction
475
476 // Set, use, or kill of carry bit.
477 // Kill means we never look at the carry bit after this kind of instruction.
David Chase8eec2bb2016-03-11 00:10:52 -0500478 // Originally for understanding ADC, RCR, and so on, but now also
479 // tracks set, use, and kill of the zero and overflow bits as well.
480 // TODO rename to {Set,Use,Kill}Flags
Russ Coxcdb7d7d2015-03-05 13:57:36 -0500481 SetCarry = 1 << 24
482 UseCarry = 1 << 25
483 KillCarry = 1 << 26
484
485 // Special cases for register use. (amd64, 386)
486 ShiftCX = 1 << 27 // possible shift by CX
487 ImulAXDX = 1 << 28 // possible multiply into DX:AX
488
489 // Instruction updates whichever of from/to is type D_OREG. (ppc64)
490 PostInc = 1 << 29
Russ Cox8c195bd2015-02-13 14:40:36 -0500491)
492
493type Arch struct {
Russ Coxb115c352015-03-18 17:26:36 -0400494 Thechar int
495 Thestring string
496 Thelinkarch *obj.LinkArch
Russ Coxb115c352015-03-18 17:26:36 -0400497 REGSP int
498 REGCTXT int
499 REGCALLX int // BX
500 REGCALLX2 int // AX
501 REGRETURN int // AX
502 REGMIN int
503 REGMAX int
Dave Cheney888d44d2015-04-09 21:25:48 +1000504 REGZERO int // architectural zero register, if available
Russ Coxb115c352015-03-18 17:26:36 -0400505 FREGMIN int
506 FREGMAX int
507 MAXWIDTH int64
508 ReservedRegs []int
509
510 AddIndex func(*Node, int64, *Node) bool // optional
511 Betypeinit func()
Josh Bleecher Snyder4a7e5bc2015-04-06 19:36:36 -0700512 Bgen_float func(*Node, bool, int, *obj.Prog) // optional
513 Cgen64 func(*Node, *Node) // only on 32-bit systems
Russ Coxb115c352015-03-18 17:26:36 -0400514 Cgenindex func(*Node, *Node, bool) *obj.Prog
Marvin Stenger8e7a3ea2015-09-24 23:21:18 +0200515 Cgen_bmul func(Op, *Node, *Node, *Node) bool
Russ Coxb115c352015-03-18 17:26:36 -0400516 Cgen_float func(*Node, *Node) // optional
517 Cgen_hmul func(*Node, *Node, *Node)
Marvin Stenger8e7a3ea2015-09-24 23:21:18 +0200518 Cgen_shift func(Op, bool, *Node, *Node, *Node)
Russ Coxb115c352015-03-18 17:26:36 -0400519 Clearfat func(*Node)
Marvin Stenger8e7a3ea2015-09-24 23:21:18 +0200520 Cmp64 func(*Node, *Node, Op, int, *obj.Prog) // only on 32-bit systems
Russ Coxb115c352015-03-18 17:26:36 -0400521 Defframe func(*obj.Prog)
Marvin Stenger8e7a3ea2015-09-24 23:21:18 +0200522 Dodiv func(Op, *Node, *Node, *Node)
Russ Coxb115c352015-03-18 17:26:36 -0400523 Excise func(*Flow)
524 Expandchecks func(*obj.Prog)
Russ Cox92c826b2015-04-03 12:23:28 -0400525 Getg func(*Node)
Matthew Dempsky0d9258a2016-03-07 18:00:08 -0800526 Gins func(obj.As, *Node, *Node) *obj.Prog
Russ Coxf8d14fc2015-05-06 12:28:19 -0400527
528 // Ginscmp generates code comparing n1 to n2 and jumping away if op is satisfied.
529 // The returned prog should be Patch'ed with the jump target.
530 // If op is not satisfied, code falls through to the next emitted instruction.
531 // Likely is the branch prediction hint: +1 for likely, -1 for unlikely, 0 for no opinion.
532 //
533 // Ginscmp must be able to handle all kinds of arguments for n1 and n2,
534 // not just simple registers, although it can assume that there are no
Russ Cox6e8bcbb2015-05-15 16:11:25 -0400535 // function calls needed during the evaluation, and on 32-bit systems
536 // the values are guaranteed not to be 64-bit values, so no in-memory
537 // temporaries are necessary.
Marvin Stenger8e7a3ea2015-09-24 23:21:18 +0200538 Ginscmp func(op Op, t *Type, n1, n2 *Node, likely int) *obj.Prog
Russ Coxf8d14fc2015-05-06 12:28:19 -0400539
Josh Bleecher Snyder13cb62c2015-04-08 09:54:15 -0700540 // Ginsboolval inserts instructions to convert the result
541 // of a just-completed comparison to a boolean value.
542 // The first argument is the conditional jump instruction
543 // corresponding to the desired value.
544 // The second argument is the destination.
545 // If not present, Ginsboolval will be emulated with jumps.
Matthew Dempsky0d9258a2016-03-07 18:00:08 -0800546 Ginsboolval func(obj.As, *Node)
Russ Coxf8d14fc2015-05-06 12:28:19 -0400547
Matthew Dempsky0d9258a2016-03-07 18:00:08 -0800548 Ginscon func(obj.As, int64, *Node)
Russ Coxb115c352015-03-18 17:26:36 -0400549 Ginsnop func()
550 Gmove func(*Node, *Node)
551 Igenindex func(*Node, *Node, bool) *obj.Prog
Russ Coxb115c352015-03-18 17:26:36 -0400552 Peep func(*obj.Prog)
553 Proginfo func(*obj.Prog) // fills in Prog.Info
554 Regtyp func(*obj.Addr) bool
555 Sameaddr func(*obj.Addr, *obj.Addr) bool
556 Smallindir func(*obj.Addr, *obj.Addr) bool
557 Stackaddr func(*obj.Addr) bool
Shenghou Mae7dd2882015-04-08 13:34:42 -0400558 Blockcopy func(*Node, *Node, int64, int64, int64)
Matthew Dempsky0d9258a2016-03-07 18:00:08 -0800559 Sudoaddable func(obj.As, *Node, *obj.Addr) bool
Russ Coxb115c352015-03-18 17:26:36 -0400560 Sudoclean func()
561 Excludedregs func() uint64
562 RtoB func(int) uint64
563 FtoB func(int) uint64
564 BtoR func(uint64) int
565 BtoF func(uint64) int
Matthew Dempsky0d9258a2016-03-07 18:00:08 -0800566 Optoas func(Op, *Type) obj.As
Russ Coxb115c352015-03-18 17:26:36 -0400567 Doregbits func(int) uint64
568 Regnames func(*int) []string
Dave Cheney01d005c2015-03-25 09:17:09 +1100569 Use387 bool // should 8g use 387 FP instructions instead of sse2.
Michael Pratta4e31d42016-03-12 14:07:40 -0800570
571 // SSARegToReg maps ssa register numbers to obj register numbers.
572 SSARegToReg []int16
573
574 // SSAMarkMoves marks any MOVXconst ops that need to avoid clobbering flags.
575 SSAMarkMoves func(*SSAGenState, *ssa.Block)
576
577 // SSAGenValue emits Prog(s) for the Value.
578 SSAGenValue func(*SSAGenState, *ssa.Value)
579
580 // SSAGenBlock emits end-of-block Progs. SSAGenValue should be called
581 // for all values in the block before SSAGenBlock.
582 SSAGenBlock func(s *SSAGenState, b, next *ssa.Block)
Russ Cox8c195bd2015-02-13 14:40:36 -0500583}
584
585var pcloc int32
586
587var Thearch Arch
588
589var Newproc *Node
590
591var Deferproc *Node
592
593var Deferreturn *Node
594
595var Panicindex *Node
596
597var panicslice *Node
598
David Chase18559e22015-10-28 13:55:46 -0400599var panicdivide *Node
600
Russ Cox8c195bd2015-02-13 14:40:36 -0500601var throwreturn *Node
Keith Randall8c5bfcc2015-09-18 15:11:30 -0700602
603var growslice *Node
604
Keith Randall5ba31942016-01-25 17:06:54 -0800605var writebarrierptr *Node
606var typedmemmove *Node
Keith Randall8c5bfcc2015-09-18 15:11:30 -0700607
608var panicdottype *Node