Re: [C++ coroutines 2/6] Define builtins and internal functions.

2019-11-17 Thread Jeff Law
On 11/17/19 3:24 AM, Iain Sandoe wrote:
> 
> 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  
> 
>   * 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.
This is OK as would be any minor adjustments you may ultimately need due
to other feedback on the kit.

jeff



[C++ coroutines 2/6] Define builtins and internal functions.

2019-11-17 Thread Iain Sandoe


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  

* 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 000..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  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
+.  */
+
+/* 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 t