public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r10-10005] d: Compile-time reflection for supported built-ins (PR101127)
@ 2021-07-28 11:50 Iain Buclaw
  0 siblings, 0 replies; only message in thread
From: Iain Buclaw @ 2021-07-28 11:50 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:4ae456dc2fcc5f12caa8abb5e5781839e2a0c7f7

commit r10-10005-g4ae456dc2fcc5f12caa8abb5e5781839e2a0c7f7
Author: Iain Buclaw <ibuclaw@gdcproject.org>
Date:   Sun Jul 25 23:19:36 2021 +0200

    d: Compile-time reflection for supported built-ins (PR101127)
    
    In order to allow user-code to determine whether a back-end builtin is
    available without error, LANG_HOOKS_BUILTIN_FUNCTION_EXT_SCOPE has been
    defined to delay putting back-end builtin functions until the ISA that
    defines them has been declared.
    
    However in D, there is no global namespace.  All builtins get pushed
    into the `gcc.builtins' module, which is constructed during the semantic
    analysis pass, which has already finished by the time target attributes
    are evaluated.  So builtins are not pushed by the new langhook because
    they would be ultimately ignored.  Builtins exposed to D code then can
    now only be altered by the command-line.
    
            PR d/101127
    
    gcc/d/ChangeLog:
    
            * d-builtins.cc (d_builtin_function_ext_scope): New function.
            * d-lang.cc (LANG_HOOKS_BUILTIN_FUNCTION_EXT_SCOPE): Define.
            * d-tree.h (d_builtin_function_ext_scope): Declare.
    
    gcc/testsuite/ChangeLog:
    
            * gdc.dg/pr101127a.d: New test.
            * gdc.dg/pr101127b.d: New test.
    
    (cherry picked from commit b2f6e1de242fff5713763cd3146dcf3f9dee51ca)

Diff:
---
 gcc/d/d-builtins.cc              | 15 +++++++++++++++
 gcc/d/d-lang.cc                  |  2 ++
 gcc/d/d-tree.h                   |  1 +
 gcc/testsuite/gdc.dg/pr101127a.d |  8 ++++++++
 gcc/testsuite/gdc.dg/pr101127b.d |  7 +++++++
 5 files changed, 33 insertions(+)

diff --git a/gcc/d/d-builtins.cc b/gcc/d/d-builtins.cc
index 1cb5407f8a9..0ca65a34153 100644
--- a/gcc/d/d-builtins.cc
+++ b/gcc/d/d-builtins.cc
@@ -1211,5 +1211,20 @@ d_builtin_function (tree decl)
   return decl;
 }
 
+/* Same as d_builtin_function, but used to delay putting in back-end builtin
+   functions until the ISA that defines the builtin has been declared.
+   However in D, there is no global namespace.  All builtins get pushed into the
+   `gcc.builtins' module, which is constructed during the semantic analysis
+   pass, which has already finished by the time target attributes are evaluated.
+   So builtins are not pushed because they would be ultimately ignored.
+   The purpose of having this function then is to improve compile-time
+   reflection support to allow user-code to determine whether a given back end
+   function is enabled by the ISA.  */
+
+tree
+d_builtin_function_ext_scope (tree decl)
+{
+  return decl;
+}
 
 #include "gt-d-d-builtins.h"
diff --git a/gcc/d/d-lang.cc b/gcc/d/d-lang.cc
index 4f1bf4a6e6a..5850dace181 100644
--- a/gcc/d/d-lang.cc
+++ b/gcc/d/d-lang.cc
@@ -1825,6 +1825,7 @@ d_build_eh_runtime_type (tree type)
 #undef LANG_HOOKS_GET_ALIAS_SET
 #undef LANG_HOOKS_TYPES_COMPATIBLE_P
 #undef LANG_HOOKS_BUILTIN_FUNCTION
+#undef LANG_HOOKS_BUILTIN_FUNCTION_EXT_SCOPE
 #undef LANG_HOOKS_REGISTER_BUILTIN_TYPE
 #undef LANG_HOOKS_FINISH_INCOMPLETE_DECL
 #undef LANG_HOOKS_GIMPLIFY_EXPR
@@ -1855,6 +1856,7 @@ d_build_eh_runtime_type (tree type)
 #define LANG_HOOKS_GET_ALIAS_SET	    d_get_alias_set
 #define LANG_HOOKS_TYPES_COMPATIBLE_P	    d_types_compatible_p
 #define LANG_HOOKS_BUILTIN_FUNCTION	    d_builtin_function
+#define LANG_HOOKS_BUILTIN_FUNCTION_EXT_SCOPE d_builtin_function_ext_scope
 #define LANG_HOOKS_REGISTER_BUILTIN_TYPE    d_register_builtin_type
 #define LANG_HOOKS_FINISH_INCOMPLETE_DECL   d_finish_incomplete_decl
 #define LANG_HOOKS_GIMPLIFY_EXPR	    d_gimplify_expr
diff --git a/gcc/d/d-tree.h b/gcc/d/d-tree.h
index 7d2e100a5c6..813786e5dc6 100644
--- a/gcc/d/d-tree.h
+++ b/gcc/d/d-tree.h
@@ -491,6 +491,7 @@ extern const attribute_spec d_langhook_attribute_table[];
 extern const attribute_spec d_langhook_common_attribute_table[];
 
 extern tree d_builtin_function (tree);
+extern tree d_builtin_function_ext_scope (tree);
 extern void d_init_builtins (void);
 extern void d_register_builtin_type (tree, const char *);
 extern void d_build_builtins_module (Module *);
diff --git a/gcc/testsuite/gdc.dg/pr101127a.d b/gcc/testsuite/gdc.dg/pr101127a.d
new file mode 100644
index 00000000000..b56398e1929
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/pr101127a.d
@@ -0,0 +1,8 @@
+// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101127
+// { dg-do compile { target i?86*-*-* x86_64-*-* } }
+// { dg-additional-options "-mavx" }
+
+import gcc.builtins;
+
+static assert(__traits(compiles, __builtin_ia32_andps256));
+static assert(__traits(compiles, __builtin_ia32_pmulhrsw128));
diff --git a/gcc/testsuite/gdc.dg/pr101127b.d b/gcc/testsuite/gdc.dg/pr101127b.d
new file mode 100644
index 00000000000..b462d75c424
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/pr101127b.d
@@ -0,0 +1,7 @@
+// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101127
+// { dg-do compile { target i?86*-*-* x86_64-*-* } }
+
+import gcc.builtins;
+
+static assert(!__traits(compiles, __builtin_ia32_andps256));
+static assert(!__traits(compiles, __builtin_ia32_pmulhrsw128));


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-07-28 11:50 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-28 11:50 [gcc r10-10005] d: Compile-time reflection for supported built-ins (PR101127) Iain Buclaw

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).