This part of the patch series provides the builtin functions used by the standard library code and the internal functions used to implement lowering of the coroutine state machine.
gcc/ChangeLog: 2019-11-17 Iain Sandoe <i...@sandoe.co.uk> * builtin-types.def (BT_FN_BOOL_PTR): New. (BT_FN_PTR_PTR_SIZE_BOOL): New. * builtins.def (DEF_COROUTINE_BUILTIN): New. * coroutine-builtins.def: New file. * internal-fn.c (expand_CO_FRAME): New. (expand_CO_YIELD): New. (expand_CO_SUSPN): New. (expand_CO_ACTOR): New. * internal-fn.def (CO_ACTOR): New. (CO_YIELD): New. (CO_SUSPN): New. (CO_FRAME): New. --- gcc/builtin-types.def | 3 +++ gcc/builtins.def | 9 ++++++++ gcc/coroutine-builtins.def | 52 ++++++++++++++++++++++++++++++++++++++++++++++ gcc/internal-fn.c | 26 +++++++++++++++++++++++ gcc/internal-fn.def | 6 ++++++ 5 files changed, 96 insertions(+) create mode 100644 gcc/coroutine-builtins.def diff --git a/gcc/builtin-types.def b/gcc/builtin-types.def index e5c9e06..6b4875e 100644 --- a/gcc/builtin-types.def +++ b/gcc/builtin-types.def @@ -297,6 +297,7 @@ DEF_FUNCTION_TYPE_1 (BT_FN_UINT32_UINT32, BT_UINT32, BT_UINT32) DEF_FUNCTION_TYPE_1 (BT_FN_UINT64_UINT64, BT_UINT64, BT_UINT64) DEF_FUNCTION_TYPE_1 (BT_FN_UINT64_FLOAT, BT_UINT64, BT_FLOAT) DEF_FUNCTION_TYPE_1 (BT_FN_BOOL_INT, BT_BOOL, BT_INT) +DEF_FUNCTION_TYPE_1 (BT_FN_BOOL_PTR, BT_BOOL, BT_PTR) DEF_FUNCTION_TYPE_1 (BT_FN_PTR_CONST_PTR, BT_PTR, BT_CONST_PTR) DEF_FUNCTION_TYPE_1 (BT_FN_CONST_PTR_CONST_PTR, BT_CONST_PTR, BT_CONST_PTR) DEF_FUNCTION_TYPE_1 (BT_FN_UINT16_UINT32, BT_UINT16, BT_UINT32) @@ -625,6 +626,8 @@ DEF_FUNCTION_TYPE_3 (BT_FN_VOID_UINT32_UINT32_PTR, DEF_FUNCTION_TYPE_3 (BT_FN_VOID_SIZE_SIZE_PTR, BT_VOID, BT_SIZE, BT_SIZE, BT_PTR) DEF_FUNCTION_TYPE_3 (BT_FN_UINT_UINT_PTR_PTR, BT_UINT, BT_UINT, BT_PTR, BT_PTR) +DEF_FUNCTION_TYPE_3 (BT_FN_PTR_PTR_SIZE_BOOL, + BT_PTR, BT_PTR, BT_SIZE, BT_BOOL) DEF_FUNCTION_TYPE_4 (BT_FN_SIZE_CONST_PTR_SIZE_SIZE_FILEPTR, BT_SIZE, BT_CONST_PTR, BT_SIZE, BT_SIZE, BT_FILEPTR) diff --git a/gcc/builtins.def b/gcc/builtins.def index d8233f5..5ad9608 100644 --- a/gcc/builtins.def +++ b/gcc/builtins.def @@ -189,6 +189,12 @@ along with GCC; see the file COPYING3. If not see DEF_BUILTIN (ENUM, NAME, BUILT_IN_NORMAL, BT_LAST, BT_LAST, false, false, \ false, ATTR_LAST, false, false) +/* Builtins used in implementing coroutine support. */ +#undef DEF_COROUTINE_BUILTIN +#define DEF_COROUTINE_BUILTIN(ENUM, NAME, TYPE, ATTRS) \ + DEF_BUILTIN (ENUM, "__builtin_coro_" NAME, BUILT_IN_NORMAL, TYPE, TYPE, \ + true, true, true, ATTRS, true, flag_coroutines) + /* Builtin used by the implementation of OpenACC and OpenMP. Few of these are actually implemented in the compiler; most are in libgomp. */ /* These builtins also need to be enabled in offloading compilers invoked from @@ -1064,6 +1070,9 @@ DEF_GCC_BUILTIN (BUILT_IN_LINE, "LINE", BT_FN_INT, ATTR_NOTHROW_LEAF_LIST) /* Sanitizer builtins. */ #include "sanitizer.def" +/* Coroutine builtins. */ +#include "coroutine-builtins.def" + /* Do not expose the BRIG builtins by default gcc-wide, but only privately in the BRIG FE as long as there are no references for them in the middle end or any of the upstream backends. */ diff --git a/gcc/coroutine-builtins.def b/gcc/coroutine-builtins.def new file mode 100644 index 0000000..2f611e9 --- /dev/null +++ b/gcc/coroutine-builtins.def @@ -0,0 +1,52 @@ +/* This file contains the definitions and documentation for the + coroutines builtins used in GCC. + + Copyright (C) 2018-2019 Free Software Foundation, Inc. + + Contributed by Iain Sandoe <i...@sandoe.co.uk> under contract to Facebook. + +This file is part of GCC. + +GCC is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free +Software Foundation; either version 3, or (at your option) any later +version. + +GCC is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +You should have received a copy of the GNU General Public License +along with GCC; see the file COPYING3. If not see +<http://www.gnu.org/licenses/>. */ + +/* Before including this file, you should define a macro: + + DEF_BUILTIN_STUB(ENUM, NAME) + DEF_COROUTINE_BUILTIN (ENUM, NAME, TYPE, ATTRS) + + See builtins.def for details. + The builtins are created used by library implementations of C++ + coroutines. */ + +/* This has to come before all the coroutine builtins. */ +DEF_BUILTIN_STUB (BEGIN_COROUTINE_BUILTINS, (const char *) 0) + +/* These are the builtins that are externally-visible and used by the + standard library implementation of the coroutine header. */ + +DEF_COROUTINE_BUILTIN (BUILT_IN_CORO_PROMISE, "promise", + BT_FN_PTR_PTR_SIZE_BOOL, ATTR_CONST_NOTHROW_LEAF_LIST) + +DEF_COROUTINE_BUILTIN (BUILT_IN_CORO_RESUME, "resume", BT_FN_VOID_PTR, + ATTR_NULL) + +DEF_COROUTINE_BUILTIN (BUILT_IN_CORO_DESTROY, "destroy", BT_FN_VOID_PTR, + ATTR_NULL) + +DEF_COROUTINE_BUILTIN (BUILT_IN_CORO_DONE, "done", BT_FN_BOOL_PTR, + ATTR_NOTHROW_LEAF_LIST) + +/* This has to come after all the coroutine builtins. */ +DEF_BUILTIN_STUB (END_COROUTINE_BUILTINS, (const char *) 0) diff --git a/gcc/internal-fn.c b/gcc/internal-fn.c index 6a878bd..85bcfee 100644 --- a/gcc/internal-fn.c +++ b/gcc/internal-fn.c @@ -2878,6 +2878,32 @@ expand_NOP (internal_fn, gcall *) /* Nothing. But it shouldn't really prevail. */ } +/* Coroutines, all should have been processed at this stage. */ + +static void +expand_CO_FRAME (internal_fn, gcall *) +{ + gcc_unreachable (); +} + +static void +expand_CO_YIELD (internal_fn, gcall *) +{ + gcc_unreachable (); +} + +static void +expand_CO_SUSPN (internal_fn, gcall *) +{ + gcc_unreachable (); +} + +static void +expand_CO_ACTOR (internal_fn, gcall *) +{ + gcc_unreachable (); +} + /* Expand a call to FN using the operands in STMT. FN has a single output operand and NARGS input operands. */ diff --git a/gcc/internal-fn.def b/gcc/internal-fn.def index a945944..fc54903 100644 --- a/gcc/internal-fn.def +++ b/gcc/internal-fn.def @@ -361,6 +361,12 @@ DEF_INTERNAL_FN (LAUNDER, ECF_LEAF | ECF_NOTHROW | ECF_NOVOPS, NULL) /* Divmod function. */ DEF_INTERNAL_FN (DIVMOD, ECF_CONST | ECF_LEAF, NULL) +/* For coroutines. */ +DEF_INTERNAL_FN (CO_ACTOR, ECF_NOTHROW | ECF_LEAF, NULL) +DEF_INTERNAL_FN (CO_YIELD, ECF_NOTHROW, NULL) +DEF_INTERNAL_FN (CO_SUSPN, ECF_NOTHROW, NULL) +DEF_INTERNAL_FN (CO_FRAME, ECF_PURE | ECF_NOTHROW | ECF_LEAF, NULL) + /* A NOP function with arbitrary arguments and return value. */ DEF_INTERNAL_FN (NOP, ECF_CONST | ECF_LEAF | ECF_NOTHROW, NULL) -- 2.8.1