]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/go/gofrontend/runtime.def
compiler: recognize and optimize array range clear
[thirdparty/gcc.git] / gcc / go / gofrontend / runtime.def
CommitLineData
9581e91d 1// runtime.def -- runtime functions called by generated code. -*- C++ -*-
2
3// Copyright 2011 The Go Authors. All rights reserved.
4// Use of this source code is governed by a BSD-style
5// license that can be found in the LICENSE file.
6
7// Definitions for the Go runtime functions.
8
9// Parameter type helper macros.
10#define ABFT6(T1, T2, T3, T4, T5, T6) \
11 { RFT_ ## T1, RFT_ ## T2, RFT_ ## T3, RFT_ ## T4, RFT_ ## T5, RFT_ ## T6 }
12#define P0() ABFT6(VOID, VOID, VOID, VOID, VOID, VOID)
13#define P1(T) ABFT6(T, VOID, VOID, VOID, VOID, VOID)
14#define P2(T1, T2) ABFT6(T1, T2, VOID, VOID, VOID, VOID)
15#define P3(T1, T2, T3) ABFT6(T1, T2, T3, VOID, VOID, VOID)
16#define P4(T1, T2, T3, T4) ABFT6(T1, T2, T3, T4, VOID, VOID)
17#define P5(T1, T2, T3, T4, T5) ABFT6(T1, T2, T3, T4, T5, VOID)
18#define P6(T1,T2,T3,T4,T5,T6) ABFT6(T1, T2, T3, T4, T5, T6)
19
20// Result type helper macros.
21#define ABFT2(T1, T2) { RFT_ ## T1, RFT_ ## T2 }
22#define R0() ABFT2(VOID, VOID)
23#define R1(T) ABFT2(T, VOID)
24#define R2(T1, T2) ABFT2(T1, T2)
25
26// Define all the Go runtime functions. The first parameter is the
27// enum code used to refer to the function. The second parameter is
28// the name. The third is the parameter types and the fourth is the
29// result types.
30
e9d3367e 31// The standard C memcmp function, used for struct comparisons.
0b6b034c 32DEF_GO_RUNTIME(MEMCMP, "__go_memcmp", P3(POINTER, POINTER, UINTPTR), R1(INT))
e9d3367e 33
ccea2b36 34// Decode a non-ASCII rune from a string.
35DEF_GO_RUNTIME(DECODERUNE, "runtime.decoderune", P2(STRING, INT),
36 R2(RUNE, INT))
9581e91d 37
736a16ba 38// Concatenate strings.
39DEF_GO_RUNTIME(CONCATSTRINGS, "runtime.concatstrings", P2(POINTER, SLICE),
40 R1(STRING))
41DEF_GO_RUNTIME(CONCATSTRING2, "runtime.concatstring2",
42 P2(POINTER, ARRAY2STRING), R1(STRING))
43DEF_GO_RUNTIME(CONCATSTRING3, "runtime.concatstring3",
44 P2(POINTER, ARRAY3STRING), R1(STRING))
45DEF_GO_RUNTIME(CONCATSTRING4, "runtime.concatstring4",
46 P2(POINTER, ARRAY4STRING), R1(STRING))
47DEF_GO_RUNTIME(CONCATSTRING5, "runtime.concatstring5",
48 P2(POINTER, ARRAY5STRING), R1(STRING))
9581e91d 49
6098d6cb 50// Compare two strings for equality.
51DEF_GO_RUNTIME(EQSTRING, "runtime.eqstring", P2(STRING, STRING), R1(BOOL))
52
9581e91d 53// Compare two strings.
6098d6cb 54DEF_GO_RUNTIME(CMPSTRING, "runtime.cmpstring", P2(STRING, STRING), R1(INT))
9581e91d 55
56// Take a slice of a string.
57DEF_GO_RUNTIME(STRING_SLICE, "__go_string_slice", P3(STRING, INT, INT),
58 R1(STRING))
59
60// Convert an integer to a string.
736a16ba 61DEF_GO_RUNTIME(INTSTRING, "runtime.intstring", P2(POINTER, INT64), R1(STRING))
9581e91d 62
736a16ba 63// Convert a []byte to a string.
64DEF_GO_RUNTIME(SLICEBYTETOSTRING, "runtime.slicebytetostring",
65 P2(POINTER, SLICE), R1(STRING))
9581e91d 66
736a16ba 67// Convert a []rune to a string.
68DEF_GO_RUNTIME(SLICERUNETOSTRING, "runtime.slicerunetostring",
69 P2(POINTER, SLICE), R1(STRING))
9581e91d 70
736a16ba 71// Convert a string to a []byte.
72DEF_GO_RUNTIME(STRINGTOSLICEBYTE, "runtime.stringtoslicebyte",
73 P2(POINTER, STRING), R1(SLICE))
9581e91d 74
736a16ba 75// Convert a string to a []rune.
76DEF_GO_RUNTIME(STRINGTOSLICERUNE, "runtime.stringtoslicerune",
77 P2(POINTER, STRING), R1(SLICE))
9581e91d 78
79
1850e20c 80// Complex division.
81DEF_GO_RUNTIME(COMPLEX64_DIV, "__go_complex64_div",
82 P2(COMPLEX64, COMPLEX64), R1(COMPLEX64))
83DEF_GO_RUNTIME(COMPLEX128_DIV, "__go_complex128_div",
84 P2(COMPLEX128, COMPLEX128), R1(COMPLEX128))
85
a9182619 86// Make a slice.
ccea2b36 87DEF_GO_RUNTIME(MAKESLICE, "runtime.makeslice", P3(TYPE, INT, INT),
d633d0fb 88 R1(POINTER))
ccea2b36 89
90DEF_GO_RUNTIME(MAKESLICE64, "runtime.makeslice64", P3(TYPE, INT64, INT64),
d633d0fb 91 R1(POINTER))
a9182619 92
93
33d1d391 94// Make a map with a hint and an (optional, unused) map structure.
95DEF_GO_RUNTIME(MAKEMAP, "runtime.makemap", P3(TYPE, INT, POINTER),
96 R1(MAP))
97DEF_GO_RUNTIME(MAKEMAP64, "runtime.makemap64", P3(TYPE, INT64, POINTER),
98 R1(MAP))
99
100// Make a map with no hint, or a small constant hint.
101DEF_GO_RUNTIME(MAKEMAP_SMALL, "runtime.makemap_small", P0(), R1(MAP))
9581e91d 102
103// Build a map from a composite literal.
104DEF_GO_RUNTIME(CONSTRUCT_MAP, "__go_construct_map",
0d5530d9 105 P5(POINTER, UINTPTR, UINTPTR, UINTPTR, POINTER),
9581e91d 106 R1(MAP))
107
9581e91d 108// Look up a key in a map.
0d5530d9 109DEF_GO_RUNTIME(MAPACCESS1, "runtime.mapaccess1", P3(TYPE, MAP, POINTER),
9581e91d 110 R1(POINTER))
111
0d5530d9 112// Look up a key in a map when the value is large.
113DEF_GO_RUNTIME(MAPACCESS1_FAT, "runtime.mapaccess1_fat",
114 P4(TYPE, MAP, POINTER, POINTER), R1(POINTER))
9581e91d 115
0d5530d9 116// Look up a key in a map returning the value and whether it is
117// present.
118DEF_GO_RUNTIME(MAPACCESS2, "runtime.mapaccess2", P3(TYPE, MAP, POINTER),
119 R2(POINTER, BOOL))
9581e91d 120
0d5530d9 121// Look up a key in a map, returning the value and whether it is
122// present, when the value is large.
123DEF_GO_RUNTIME(MAPACCESS2_FAT, "runtime.mapaccess2_fat",
124 P4(TYPE, MAP, POINTER, POINTER), R2(POINTER, BOOL))
1cce762f 125
0d5530d9 126// Assignment to a key in a map.
ccea2b36 127DEF_GO_RUNTIME(MAPASSIGN, "runtime.mapassign", P3(TYPE, MAP, POINTER),
128 R1(POINTER))
9581e91d 129
0d5530d9 130// Delete a key from a map.
131DEF_GO_RUNTIME(MAPDELETE, "runtime.mapdelete", P3(TYPE, MAP, POINTER), R0())
9581e91d 132
0d5530d9 133// Begin a range over a map.
134DEF_GO_RUNTIME(MAPITERINIT, "runtime.mapiterinit", P3(TYPE, MAP, POINTER),
9581e91d 135 R0())
136
137// Range over a map, moving to the next map entry.
0d5530d9 138DEF_GO_RUNTIME(MAPITERNEXT, "runtime.mapiternext", P1(POINTER), R0())
9581e91d 139
b52ffd74 140// Clear a map.
141DEF_GO_RUNTIME(MAPCLEAR, "runtime.mapclear", P2(TYPE, MAP), R0())
142
9581e91d 143
144// Make a channel.
1423c90a 145DEF_GO_RUNTIME(MAKECHAN, "runtime.makechan", P2(TYPE, INT), R1(CHAN))
146DEF_GO_RUNTIME(MAKECHAN64, "runtime.makechan64", P2(TYPE, INT64), R1(CHAN))
9581e91d 147
132ed071 148// Send a value on a channel.
e36a5ff5 149DEF_GO_RUNTIME(CHANSEND, "runtime.chansend1", P2(CHAN, POINTER), R0())
9581e91d 150
2c809f8f 151// Receive a value from a channel.
e36a5ff5 152DEF_GO_RUNTIME(CHANRECV1, "runtime.chanrecv1", P2(CHAN, POINTER), R0())
9581e91d 153
154// Receive a value from a channel returning whether it is closed.
e36a5ff5 155DEF_GO_RUNTIME(CHANRECV2, "runtime.chanrecv2", P2(CHAN, POINTER), R1(BOOL))
f24f10bb 156
157
86a71ed0 158// Run a select, returning the index of the selected clause and
159// whether that channel received a value.
160DEF_GO_RUNTIME(SELECTGO, "runtime.selectgo", P3(POINTER, POINTER, INT),
161 R2(INT, BOOL))
9581e91d 162
163
164// Panic.
03ac9de4 165DEF_GO_RUNTIME(GOPANIC, "runtime.gopanic", P1(EFACE), R0())
9581e91d 166
167// Recover.
03ac9de4 168DEF_GO_RUNTIME(GORECOVER, "runtime.gorecover", P0(), R1(EFACE))
9581e91d 169
170// Recover when called directly from defer.
03ac9de4 171DEF_GO_RUNTIME(DEFERREDRECOVER, "runtime.deferredrecover", P0(), R1(EFACE))
9581e91d 172
173// Decide whether this function can call recover.
81487fff 174DEF_GO_RUNTIME(CANRECOVER, "runtime.canrecover", P1(UINTPTR), R1(BOOL))
9581e91d 175
176// Set the return address for defer in a defer thunk.
81487fff 177DEF_GO_RUNTIME(SETDEFERRETADDR, "runtime.setdeferretaddr", P1(UINTPTR),
9581e91d 178 R1(BOOL))
179
180// Check for a deferred function in an exception handler.
03ac9de4 181DEF_GO_RUNTIME(CHECKDEFER, "runtime.checkdefer", P1(BOOLPTR), R0())
9581e91d 182
183// Run deferred functions.
03ac9de4 184DEF_GO_RUNTIME(DEFERRETURN, "runtime.deferreturn", P1(BOOLPTR), R0())
9581e91d 185
186// Panic with a runtime error.
1b1f2abf 187DEF_GO_RUNTIME(RUNTIME_ERROR, "__go_runtime_error", P1(INT32), R0())
9581e91d 188
189
190// Close.
132ed071 191DEF_GO_RUNTIME(CLOSE, "runtime.closechan", P1(CHAN), R0())
9581e91d 192
193
194// Copy.
321e5ad2 195DEF_GO_RUNTIME(SLICECOPY, "runtime.slicecopy", P3(SLICE, SLICE, UINTPTR),
196 R1(INT))
9581e91d 197
321e5ad2 198// Copy from string.
199DEF_GO_RUNTIME(SLICESTRINGCOPY, "runtime.slicestringcopy", P2(SLICE, STRING),
200 R1(INT))
201
202// Copy of value containing pointers.
203DEF_GO_RUNTIME(TYPEDSLICECOPY, "runtime.typedslicecopy",
204 P3(TYPE, SLICE, SLICE), R1(INT))
205
206
207// Grow a slice for append.
16c9b8e5 208DEF_GO_RUNTIME(GROWSLICE, "runtime.growslice",
209 P5(TYPE, POINTER, INT, INT, INT), R1(SLICE))
9581e91d 210
211
212// Register roots (global variables) for the garbage collector.
03118c21 213DEF_GO_RUNTIME(REGISTER_GC_ROOTS, "runtime.registerGCRoots", P1(POINTER), R0())
9581e91d 214
215
216// Allocate memory.
03118c21 217DEF_GO_RUNTIME(NEW, "runtime.newobject", P1(TYPE), R1(POINTER))
9581e91d 218
9581e91d 219// Start a new goroutine.
81487fff 220DEF_GO_RUNTIME(GO, "__go_go", P2(UINTPTR, POINTER), R1(POINTER))
9581e91d 221
9581e91d 222// Defer a function.
81487fff 223DEF_GO_RUNTIME(DEFERPROC, "runtime.deferproc", P3(BOOLPTR, UINTPTR, POINTER),
03ac9de4 224 R0())
9581e91d 225
226
9581e91d 227// Convert an empty interface to an empty interface, returning ok.
228DEF_GO_RUNTIME(IFACEE2E2, "runtime.ifaceE2E2", P1(EFACE), R2(EFACE, BOOL))
229
230// Convert a non-empty interface to an empty interface, returning ok.
231DEF_GO_RUNTIME(IFACEI2E2, "runtime.ifaceI2E2", P1(IFACE), R2(EFACE, BOOL))
232
233// Convert an empty interface to a non-empty interface, returning ok.
234DEF_GO_RUNTIME(IFACEE2I2, "runtime.ifaceE2I2", P2(TYPE, EFACE),
235 R2(IFACE, BOOL))
236
237// Convert a non-empty interface to a non-empty interface, returning ok.
238DEF_GO_RUNTIME(IFACEI2I2, "runtime.ifaceI2I2", P2(TYPE, IFACE),
239 R2(IFACE, BOOL))
240
241// Convert an empty interface to a pointer type, returning ok.
242DEF_GO_RUNTIME(IFACEE2T2P, "runtime.ifaceE2T2P", P2(TYPE, EFACE),
243 R2(POINTER, BOOL))
244
245// Convert a non-empty interface to a pointer type, return ok.
246DEF_GO_RUNTIME(IFACEI2T2P, "runtime.ifaceI2T2P", P2(TYPE, IFACE),
247 R2(POINTER, BOOL))
248
249// Convert an empty interface to a non-pointer type, returning ok.
250DEF_GO_RUNTIME(IFACEE2T2, "runtime.ifaceE2T2", P3(TYPE, EFACE, POINTER),
251 R1(BOOL))
252
253// Convert a non-empty interface to a non-pointer type, returning ok.
254DEF_GO_RUNTIME(IFACEI2T2, "runtime.ifaceI2T2", P3(TYPE, IFACE, POINTER),
255 R1(BOOL))
256
6098d6cb 257// Return the interface method table for the second type converted to
258// the first type which is a (possibly empty) interface type. Panics
259// if the second type is nil (indicating a nil interface value) or if
260// the conversion is not possible. Used for type assertions. This is
261// like REQUIREITAB, but for type assertions.
262DEF_GO_RUNTIME(ASSERTITAB, "runtime.assertitab", P2(TYPE, TYPE), R1(POINTER))
263
264// Return the interface method table for the second type converted to
265// the first type, which is a non-empty interface type. Return nil if
266// the second type is nil, indicating a nil interface value. Panics
267// if the conversion is not possible. Used for assignments. This is
268// like ASSERTITAB, but for assignments.
269DEF_GO_RUNTIME(REQUIREITAB, "runtime.requireitab", P2(TYPE, TYPE),
9581e91d 270 R1(POINTER))
271
272// Check whether an interface type may be converted to a
273// non-interface type.
6098d6cb 274DEF_GO_RUNTIME(ASSERTI2T, "runtime.assertI2T", P3(TYPE, TYPE, TYPE), R0())
9581e91d 275
6098d6cb 276// Return whether we can convert a type to an interface type.
277DEF_GO_RUNTIME(IFACET2IP, "runtime.ifaceT2Ip", P2(TYPE, TYPE), R1(BOOL))
9581e91d 278
279// Get the type descriptor of an empty interface.
280DEF_GO_RUNTIME(EFACETYPE, "runtime.efacetype", P1(EFACE), R1(TYPE))
281
282// Get the type descriptor of a non-empty interface.
283DEF_GO_RUNTIME(IFACETYPE, "runtime.ifacetype", P1(IFACE), R1(TYPE))
284
285
286// Compare two type descriptors for equality.
287DEF_GO_RUNTIME(IFACETYPEEQ, "runtime.ifacetypeeq", P2(TYPE, TYPE), R1(BOOL))
288
289// Compare two empty interface values.
6098d6cb 290DEF_GO_RUNTIME(EFACEEQ, "runtime.efaceeq", P2(EFACE, EFACE), R1(BOOL))
9581e91d 291
292// Compare an empty interface value to a non-interface value.
6098d6cb 293DEF_GO_RUNTIME(EFACEVALEQ, "runtime.efacevaleq", P3(EFACE, TYPE, POINTER),
294 R1(BOOL))
9581e91d 295
296// Compare two non-empty interface values.
6098d6cb 297DEF_GO_RUNTIME(IFACEEQ, "runtime.ifaceeq", P2(IFACE, IFACE), R1(BOOL))
9581e91d 298
299// Compare a non-empty interface value to a non-interface value.
6098d6cb 300DEF_GO_RUNTIME(IFACEVALEQ, "runtime.ifacevaleq", P3(IFACE, TYPE, POINTER),
301 R1(BOOL))
9581e91d 302
303// Compare a non-empty interface value to an interface value.
6098d6cb 304DEF_GO_RUNTIME(IFACEEFACEEQ, "runtime.ifaceefaceeq", P2(IFACE, EFACE),
305 R1(BOOL))
9581e91d 306
307
03118c21 308// Set *dst = src where dst is a pointer to a pointer and src is a pointer.
96942f21 309DEF_GO_RUNTIME(GCWRITEBARRIER, "runtime.gcWriteBarrier",
81487fff 310 P2(POINTER, UINTPTR), R0())
03118c21 311
312// Set *dst = *src for an arbitrary type.
313DEF_GO_RUNTIME(TYPEDMEMMOVE, "runtime.typedmemmove",
314 P3(TYPE, POINTER, POINTER), R0())
315
d2199dbc 316// Clear memory that contains no pointer.
317DEF_GO_RUNTIME(MEMCLRNOPTR, "runtime.memclrNoHeapPointers",
318 P2(POINTER, UINTPTR), R0())
319
320// Clear memory that contains pointer.
321DEF_GO_RUNTIME(MEMCLRHASPTR, "runtime.memclrHasPointers",
322 P2(POINTER, UINTPTR), R0())
323
03118c21 324
88b03a70 325// Lock the printer (for print/println).
326DEF_GO_RUNTIME(PRINTLOCK, "runtime.printlock", P0(), R0())
327
328// Unlock the printer (for print/println).
329DEF_GO_RUNTIME(PRINTUNLOCK, "runtime.printunlock", P0(), R0())
330
9581e91d 331// Print a string (for print/println).
88b03a70 332DEF_GO_RUNTIME(PRINTSTRING, "runtime.printstring", P1(STRING), R0())
9581e91d 333
334// Print a uint64 (for print/println).
88b03a70 335DEF_GO_RUNTIME(PRINTUINT, "runtime.printuint", P1(UINT64), R0())
9581e91d 336
337// Print a int64 (for print/println).
88b03a70 338DEF_GO_RUNTIME(PRINTINT, "runtime.printint", P1(INT64), R0())
9581e91d 339
340// Print a float64 (for print/println).
88b03a70 341DEF_GO_RUNTIME(PRINTFLOAT, "runtime.printfloat", P1(FLOAT64), R0())
9581e91d 342
343// Print a complex128 (for print/println).
88b03a70 344DEF_GO_RUNTIME(PRINTCOMPLEX, "runtime.printcomplex", P1(COMPLEX128), R0())
9581e91d 345
346// Print a bool (for print/println).
88b03a70 347DEF_GO_RUNTIME(PRINTBOOL, "runtime.printbool", P1(BOOL), R0())
9581e91d 348
349// Print a pointer/map/channel/function (for print/println).
88b03a70 350DEF_GO_RUNTIME(PRINTPOINTER, "runtime.printpointer", P1(POINTER), R0())
9581e91d 351
352// Print an empty interface (for print/println).
88b03a70 353DEF_GO_RUNTIME(PRINTEFACE, "runtime.printeface", P1(EFACE), R0())
9581e91d 354
355// Print a non-empty interface (for print/println).
88b03a70 356DEF_GO_RUNTIME(PRINTIFACE, "runtime.printiface", P1(IFACE), R0())
9581e91d 357
358// Print a slice (for print/println).
88b03a70 359DEF_GO_RUNTIME(PRINTSLICE, "runtime.printslice", P1(SLICE), R0())
9581e91d 360
361// Print a space (for println).
88b03a70 362DEF_GO_RUNTIME(PRINTSP, "runtime.printsp", P0(), R0())
9581e91d 363
364// Print a newline (for println).
88b03a70 365DEF_GO_RUNTIME(PRINTNL, "runtime.printnl", P0(), R0())
9581e91d 366
367
149eabc5 368// Used for field tracking for data analysis.
369DEF_GO_RUNTIME(FIELDTRACK, "__go_fieldtrack", P1(POINTER), R0())
370
371
8ac0f767 372// Unreachable code.
373DEF_GO_RUNTIME(UNREACHABLE, "__builtin_unreachable", P0(), R0())
374
9581e91d 375// Remove helper macros.
376#undef ABFT6
377#undef ABFT2
378#undef P0
379#undef P1
380#undef P2
381#undef P3
382#undef P4
383#undef P5
384#undef P6
385#undef R0
386#undef R1
387#undef R2