[gcc r15-1699] libgccjit: Add ability to get the alignment of a type

2024-06-27 Thread Antoni Boucher via Gcc-cvs
https://gcc.gnu.org/g:445c62ee492b363e7ad86260c7a91a7fdf984f50

commit r15-1699-g445c62ee492b363e7ad86260c7a91a7fdf984f50
Author: Antoni Boucher 
Date:   Thu Apr 4 18:57:07 2024 -0400

libgccjit: Add ability to get the alignment of a type

gcc/jit/ChangeLog:

* docs/topics/compatibility.rst (LIBGCCJIT_ABI_28): New ABI tag.
* docs/topics/expressions.rst: Document gcc_jit_context_new_alignof.
* jit-playback.cc (new_alignof): New method.
* jit-playback.h: New method.
* jit-recording.cc (recording::context::new_alignof): New
method.
(recording::memento_of_sizeof::replay_into,
recording::memento_of_typeinfo::replay_into,
recording::memento_of_sizeof::make_debug_string,
recording::memento_of_typeinfo::make_debug_string,
recording::memento_of_sizeof::write_reproducer,
recording::memento_of_typeinfo::write_reproducer): Rename.
* jit-recording.h (enum type_info_type): New enum.
(class memento_of_sizeof class memento_of_typeinfo): Rename.
* libgccjit.cc (gcc_jit_context_new_alignof): New function.
* libgccjit.h (gcc_jit_context_new_alignof): New function.
* libgccjit.map: New function.

gcc/testsuite/ChangeLog:

* jit.dg/all-non-failing-tests.h: New test.
* jit.dg/test-alignof.c: New test.

Diff:
---
 gcc/jit/docs/topics/compatibility.rst|  7 +++
 gcc/jit/docs/topics/expressions.rst  | 14 ++
 gcc/jit/jit-playback.cc  | 11 +
 gcc/jit/jit-playback.h   |  3 ++
 gcc/jit/jit-recording.cc | 67 ++-
 gcc/jit/jit-recording.h  | 19 ++--
 gcc/jit/libgccjit.cc | 18 
 gcc/jit/libgccjit.h  | 13 ++
 gcc/jit/libgccjit.map|  5 ++
 gcc/testsuite/jit.dg/all-non-failing-tests.h | 10 
 gcc/testsuite/jit.dg/test-alignof.c  | 69 
 11 files changed, 221 insertions(+), 15 deletions(-)

diff --git a/gcc/jit/docs/topics/compatibility.rst 
b/gcc/jit/docs/topics/compatibility.rst
index 9cfb054f653..92c3ed24c89 100644
--- a/gcc/jit/docs/topics/compatibility.rst
+++ b/gcc/jit/docs/topics/compatibility.rst
@@ -397,3 +397,10 @@ on functions and variables:
 
 ``LIBGCCJIT_ABI_27`` covers the addition of
 :func:`gcc_jit_context_new_sizeof`
+
+.. _LIBGCCJIT_ABI_28:
+
+``LIBGCCJIT_ABI_28``
+
+``LIBGCCJIT_ABI_28`` covers the addition of
+:func:`gcc_jit_context_new_alignof`
diff --git a/gcc/jit/docs/topics/expressions.rst 
b/gcc/jit/docs/topics/expressions.rst
index d83d95fe9e0..5734f0e5f7e 100644
--- a/gcc/jit/docs/topics/expressions.rst
+++ b/gcc/jit/docs/topics/expressions.rst
@@ -140,6 +140,20 @@ Simple expressions
 
  sizeof (type)
 
+.. function:: gcc_jit_rvalue *\
+  gcc_jit_context_new_alignof (gcc_jit_context *ctxt, \
+   gcc_jit_type *type)
+
+   Generate an rvalue that is equal to the alignment of ``type``.
+
+   The parameter ``type`` must be non-NULL.
+
+   This is equivalent to this C code:
+
+   .. code-block:: c
+
+ _Alignof (type)
+
 Constructor expressions
 ***
 
diff --git a/gcc/jit/jit-playback.cc b/gcc/jit/jit-playback.cc
index 6baa838af10..b3f54da24ab 100644
--- a/gcc/jit/jit-playback.cc
+++ b/gcc/jit/jit-playback.cc
@@ -1120,6 +1120,17 @@ new_sizeof (type *type)
 
 /* Construct a playback::rvalue instance (wrapping a tree).  */
 
+playback::rvalue *
+playback::context::
+new_alignof (type *type)
+{
+  int alignment = TYPE_ALIGN (type->as_tree ()) / BITS_PER_UNIT;
+  tree inner = build_int_cst (integer_type_node, alignment);
+  return new rvalue (this, inner);
+}
+
+/* Construct a playback::rvalue instance (wrapping a tree).  */
+
 playback::rvalue *
 playback::context::
 new_string_literal (const char *value)
diff --git a/gcc/jit/jit-playback.h b/gcc/jit/jit-playback.h
index aa6a086613c..6e97b389cbb 100644
--- a/gcc/jit/jit-playback.h
+++ b/gcc/jit/jit-playback.h
@@ -165,6 +165,9 @@ public:
   rvalue *
   new_sizeof (type *type);
 
+  rvalue *
+  new_alignof (type *type);
+
   rvalue *
   new_string_literal (const char *value);
 
diff --git a/gcc/jit/jit-recording.cc b/gcc/jit/jit-recording.cc
index 5e9ef40f3b7..f68d01fff55 100644
--- a/gcc/jit/jit-recording.cc
+++ b/gcc/jit/jit-recording.cc
@@ -1077,7 +1077,7 @@ recording::context::new_global_init_rvalue (lvalue 
*variable,
   gbl->set_rvalue_init (init); /* Needed by the global for write dump.  */
 }
 
-/* Create a recording::memento_of_sizeof instance and add it
+/* Create a recording::memento_of_typeinfo instance and add it
to this context's list of mementos.
 
Implements the post-error-checking part of
@@ -1087,7 +1087,22 @@ recording::rvalue *
 reco

[gcc r15-1863] libgccjit: Add support for the type bfloat16

2024-07-05 Thread Antoni Boucher via Gcc-cvs
https://gcc.gnu.org/g:1c314247aab43aaa278ecc51d666f8c5896d8bbb

commit r15-1863-g1c314247aab43aaa278ecc51d666f8c5896d8bbb
Author: Antoni Boucher 
Date:   Thu Nov 16 10:59:22 2023 -0500

libgccjit: Add support for the type bfloat16

gcc/jit/ChangeLog:

PR jit/112574
* docs/topics/types.rst: Document GCC_JIT_TYPE_BFLOAT16.
* jit-common.h: Update NUM_GCC_JIT_TYPES.
* jit-playback.cc (get_tree_node_for_type): Support bfloat16.
* jit-recording.cc (recording::memento_of_get_type::get_size,
recording::memento_of_get_type::dereference,
recording::memento_of_get_type::is_int,
recording::memento_of_get_type::is_signed,
recording::memento_of_get_type::is_float,
recording::memento_of_get_type::is_bool): Support bfloat16.
* libgccjit.h (enum gcc_jit_types): Add GCC_JIT_TYPE_BFLOAT16.

gcc/testsuite/ChangeLog:

PR jit/112574
* jit.dg/all-non-failing-tests.h: New test test-bfloat16.c.
* jit.dg/test-types.c: Test GCC_JIT_TYPE_BFLOAT16.
* jit.dg/test-bfloat16.c: New test.

Diff:
---
 gcc/jit/docs/topics/types.rst|  2 ++
 gcc/jit/jit-common.h |  2 +-
 gcc/jit/jit-playback.cc  |  6 +
 gcc/jit/jit-recording.cc | 11 +
 gcc/jit/libgccjit.h  |  4 ++-
 gcc/testsuite/jit.dg/all-non-failing-tests.h |  3 +++
 gcc/testsuite/jit.dg/test-bfloat16.c | 37 
 gcc/testsuite/jit.dg/test-types.c|  4 +++
 8 files changed, 67 insertions(+), 2 deletions(-)

diff --git a/gcc/jit/docs/topics/types.rst b/gcc/jit/docs/topics/types.rst
index bb51f037b7e..6a7a35280ed 100644
--- a/gcc/jit/docs/topics/types.rst
+++ b/gcc/jit/docs/topics/types.rst
@@ -113,6 +113,8 @@ Standard types
- C99's ``__int128_t``
  * - :c:data:`GCC_JIT_TYPE_FLOAT`
-
+ * - :c:data:`GCC_JIT_TYPE_BFLOAT16`
+   - C's ``__bfloat16``
  * - :c:data:`GCC_JIT_TYPE_DOUBLE`
-
  * - :c:data:`GCC_JIT_TYPE_LONG_DOUBLE`
diff --git a/gcc/jit/jit-common.h b/gcc/jit/jit-common.h
index 1e335878b56..afb41763e46 100644
--- a/gcc/jit/jit-common.h
+++ b/gcc/jit/jit-common.h
@@ -36,7 +36,7 @@ along with GCC; see the file COPYING3.  If not see
 #endif
 #endif
 
-const int NUM_GCC_JIT_TYPES = GCC_JIT_TYPE_INT128_T + 1;
+const int NUM_GCC_JIT_TYPES = GCC_JIT_TYPE_BFLOAT16 + 1;
 
 /* This comment is included by the docs.
 
diff --git a/gcc/jit/jit-playback.cc b/gcc/jit/jit-playback.cc
index b3f54da24ab..1b5445d6101 100644
--- a/gcc/jit/jit-playback.cc
+++ b/gcc/jit/jit-playback.cc
@@ -281,6 +281,12 @@ get_tree_node_for_type (enum gcc_jit_types type_)
 
 case GCC_JIT_TYPE_FLOAT:
   return float_type_node;
+case GCC_JIT_TYPE_BFLOAT16:
+#ifndef HAVE_BFmode
+  add_error (NULL, "gcc_jit_types value unsupported on this target: %i",
+type_);
+#endif
+  return bfloat16_type_node;
 case GCC_JIT_TYPE_DOUBLE:
   return double_type_node;
 case GCC_JIT_TYPE_LONG_DOUBLE:
diff --git a/gcc/jit/jit-recording.cc b/gcc/jit/jit-recording.cc
index 43a6795f8f3..cc7f529c9e8 100644
--- a/gcc/jit/jit-recording.cc
+++ b/gcc/jit/jit-recording.cc
@@ -2418,6 +2418,10 @@ recording::memento_of_get_type::get_size ()
   m = targetm.c.mode_for_floating_type (TI_FLOAT_TYPE);
   size = GET_MODE_PRECISION (m).to_constant ();
   break;
+#ifdef HAVE_BFmode
+case GCC_JIT_TYPE_BFLOAT16:
+  return GET_MODE_UNIT_SIZE (BFmode);
+#endif
 case GCC_JIT_TYPE_DOUBLE:
   m = targetm.c.mode_for_floating_type (TI_DOUBLE_TYPE);
   size = GET_MODE_PRECISION (m).to_constant ();
@@ -2479,6 +2483,7 @@ recording::memento_of_get_type::dereference ()
 case GCC_JIT_TYPE_INT64_T:
 case GCC_JIT_TYPE_INT128_T:
 case GCC_JIT_TYPE_FLOAT:
+case GCC_JIT_TYPE_BFLOAT16:
 case GCC_JIT_TYPE_DOUBLE:
 case GCC_JIT_TYPE_LONG_DOUBLE:
 case GCC_JIT_TYPE_COMPLEX_FLOAT:
@@ -2543,6 +2548,7 @@ recording::memento_of_get_type::is_int () const
   return true;
 
 case GCC_JIT_TYPE_FLOAT:
+case GCC_JIT_TYPE_BFLOAT16:
 case GCC_JIT_TYPE_DOUBLE:
 case GCC_JIT_TYPE_LONG_DOUBLE:
   return false;
@@ -2601,6 +2607,7 @@ recording::memento_of_get_type::is_signed () const
 case GCC_JIT_TYPE_UINT128_T:
 
 case GCC_JIT_TYPE_FLOAT:
+case GCC_JIT_TYPE_BFLOAT16:
 case GCC_JIT_TYPE_DOUBLE:
 case GCC_JIT_TYPE_LONG_DOUBLE:
 
@@ -2660,6 +2667,7 @@ recording::memento_of_get_type::is_float () const
   return false;
 
 case GCC_JIT_TYPE_FLOAT:
+case GCC_JIT_TYPE_BFLOAT16:
 case GCC_JIT_TYPE_DOUBLE:
 case GCC_JIT_TYPE_LONG_DOUBLE:
   return true;
@@ -2723,6 +2731,7 @@ recording::memento_of_get_type::is_bool () const
   return false;
 
 case GCC_JIT_TYPE_FLOAT:
+case GCC_JIT_TYPE_BFLOAT16:
 case GCC_JIT_TYPE_DOUBLE:
 

[gcc r15-1864] libgccjit: Allow comparing array types

2024-07-05 Thread Antoni Boucher via Gcc-cvs
https://gcc.gnu.org/g:533f807e17034b20c586eeb480c989a42869bb36

commit r15-1864-g533f807e17034b20c586eeb480c989a42869bb36
Author: Antoni Boucher 
Date:   Tue Jan 2 16:04:10 2024 -0500

libgccjit: Allow comparing array types

gcc/jit/ChangeLog:

* jit-common.h: Add array_type class.
* jit-recording.h (type::dyn_cast_array_type,
memento_of_get_aligned::dyn_cast_array_type,
array_type::dyn_cast_array_type, array_type::is_same_type_as):
New methods.

gcc/testsuite/ChangeLog:

* jit.dg/test-types.c: Add array type comparison to the test.

Diff:
---
 gcc/jit/jit-common.h  |  1 +
 gcc/jit/jit-recording.h   | 17 +
 gcc/testsuite/jit.dg/test-types.c |  5 +
 3 files changed, 23 insertions(+)

diff --git a/gcc/jit/jit-common.h b/gcc/jit/jit-common.h
index afb41763e46..655d94e0bab 100644
--- a/gcc/jit/jit-common.h
+++ b/gcc/jit/jit-common.h
@@ -118,6 +118,7 @@ namespace recording {
 class struct_;
class union_;
   class vector_type;
+  class array_type;
 class field;
   class bitfield;
 class fields;
diff --git a/gcc/jit/jit-recording.h b/gcc/jit/jit-recording.h
index cce25f1fc07..abd4f6f8bb3 100644
--- a/gcc/jit/jit-recording.h
+++ b/gcc/jit/jit-recording.h
@@ -560,6 +560,7 @@ public:
   virtual function_type *as_a_function_type() { gcc_unreachable (); return 
NULL; }
   virtual struct_ *dyn_cast_struct () { return NULL; }
   virtual vector_type *dyn_cast_vector_type () { return NULL; }
+  virtual array_type *dyn_cast_array_type () { return NULL; }
 
   /* Is it typesafe to copy to this type from rtype?  */
   virtual bool accepts_writes_from (type *rtype)
@@ -829,6 +830,11 @@ public:
 
   void replay_into (replayer *) final override;
 
+  array_type *dyn_cast_array_type () final override
+  {
+return m_other_type->dyn_cast_array_type ();
+  }
+
 private:
   string * make_debug_string () final override;
   void write_reproducer (reproducer &r) final override;
@@ -895,6 +901,17 @@ class array_type : public type
 
   type *dereference () final override;
 
+  bool is_same_type_as (type *other) final override
+  {
+array_type *other_array_type = other->dyn_cast_array_type ();
+if (!other_array_type)
+  return false;
+return m_num_elements == other_array_type->m_num_elements
+  && m_element_type->is_same_type_as (other_array_type->m_element_type);
+  }
+
+  array_type *dyn_cast_array_type () final override { return this; }
+
   bool is_int () const final override { return false; }
   bool is_float () const final override { return false; }
   bool is_bool () const final override { return false; }
diff --git a/gcc/testsuite/jit.dg/test-types.c 
b/gcc/testsuite/jit.dg/test-types.c
index f51252e0da0..bfdb76383c5 100644
--- a/gcc/testsuite/jit.dg/test-types.c
+++ b/gcc/testsuite/jit.dg/test-types.c
@@ -496,4 +496,9 @@ verify_code (gcc_jit_context *ctxt, gcc_jit_result *result)
 #ifdef HAVE_BFmode
   CHECK_VALUE (gcc_jit_type_get_size (gcc_jit_context_get_type (ctxt, 
GCC_JIT_TYPE_BFLOAT16)), sizeof (__bfloat16));
 #endif
+
+  gcc_jit_type *int_type = gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_INT);
+  gcc_jit_type *array_type1 = gcc_jit_context_new_array_type (ctxt, NULL, 
int_type, 2);
+  gcc_jit_type *array_type2 = gcc_jit_context_new_array_type (ctxt, NULL, 
int_type, 2);
+  CHECK (gcc_jit_compatible_types (array_type1, array_type2));
 }


[gcc r15-4888] target: Fix asm codegen for vfpclasss* and vcvtph2* instructions

2024-11-04 Thread Antoni Boucher via Gcc-cvs
https://gcc.gnu.org/g:9141bfdd483e2838f5dce767f1c1657710ef2daf

commit r15-4888-g9141bfdd483e2838f5dce767f1c1657710ef2daf
Author: Antoni Boucher 
Date:   Mon Sep 23 18:58:47 2024 -0400

target: Fix asm codegen for vfpclasss* and vcvtph2* instructions

This only happens when using -masm=intel.

gcc/ChangeLog:
PR target/116725
* config/i386/sse.md: Fix asm generation.

gcc/testsuite/ChangeLog:
PR target/116725
* gcc.target/i386/pr116725.c: Add test using those AVX builtins.

Diff:
---
 gcc/config/i386/sse.md   | 10 ++--
 gcc/testsuite/gcc.target/i386/pr116725.c | 40 
 2 files changed, 48 insertions(+), 2 deletions(-)

diff --git a/gcc/config/i386/sse.md b/gcc/config/i386/sse.md
index 22c6c817dd75..15ed8ff99cbd 100644
--- a/gcc/config/i386/sse.md
+++ b/gcc/config/i386/sse.md
@@ -1312,6 +1312,12 @@
(V8HF "w") (V8BF "w") (V4SF "k") (V2DF "q")
(HF "w") (BF "w") (SF "k") (DF "q")])
 
+;; Pointer size override for 16-bit upper-convert modes (Intel asm dialect)
+(define_mode_attr iptrh
+ [(V32HI "") (V16SI "") (V8DI "")
+  (V16HI "") (V8SI "") (V4DI "q")
+  (V8HI "") (V4SI "q") (V2DI "k")])
+
 ;; Mapping of vector modes to VPTERNLOG suffix
 (define_mode_attr ternlogsuffix
   [(V8DI "q") (V4DI "q") (V2DI "q")
@@ -7606,7 +7612,7 @@
   [(match_operand: 1 "" 
"")]
   UNSPEC_US_FIX_NOTRUNC))]
   "TARGET_AVX512FP16 && "
-  "vcvtph2\t{%1, 
%0|%0, %1}"
+  "vcvtph2\t{%1, 
%0|%0, %1}"
   [(set_attr "type" "ssecvt")
(set_attr "prefix" "evex")
(set_attr "mode" "")])
@@ -29840,7 +29846,7 @@
UNSPEC_FPCLASS)
  (const_int 1)))]
"TARGET_AVX512DQ || VALID_AVX512FP16_REG_MODE(mode)"
-   "vfpclass\t{%2, %1, 
%0|%0, %1, %2}";
+   "vfpclass\t{%2, %1, 
%0|%0, %1, %2}";
   [(set_attr "type" "sse")
(set_attr "length_immediate" "1")
(set_attr "prefix" "evex")
diff --git a/gcc/testsuite/gcc.target/i386/pr116725.c 
b/gcc/testsuite/gcc.target/i386/pr116725.c
new file mode 100644
index ..9e5070e16e71
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr116725.c
@@ -0,0 +1,40 @@
+/* PR gcc/116725 */
+/* { dg-do assemble } */
+/* { dg-options "-masm=intel -mavx512dq -mavx512fp16 -mavx512vl" } */
+/* { dg-require-effective-target masm_intel } */
+
+#include 
+
+typedef double __m128d __attribute__ ((__vector_size__ (16)));
+typedef float __m128f __attribute__ ((__vector_size__ (16)));
+typedef int __v16si __attribute__ ((__vector_size__ (64)));
+typedef _Float16 __m256h __attribute__ ((__vector_size__ (32)));
+typedef long long __m512i __attribute__((__vector_size__(64)));
+typedef _Float16 __m128h __attribute__ ((__vector_size__ (16), __may_alias__));
+typedef int __v4si __attribute__ ((__vector_size__ (16)));
+typedef long long __m128i __attribute__ ((__vector_size__ (16)));
+
+int main(void) {
+__m128d vec = {1.0, 2.0};
+char res = __builtin_ia32_fpclasssd_mask(vec, 1, 1);
+printf("%d\n", res);
+
+__m128f vec2 = {1.0, 2.0, 3.0, 4.0};
+char res2 = __builtin_ia32_fpcla_mask(vec2, 1, 1);
+printf("%d\n", res2);
+
+__m128h vec3 = {2.0, 1.0, 3.0};
+__v4si vec4 = {};
+__v4si res3 = __builtin_ia32_vcvtph2dq128_mask(vec3, vec4, -1);
+printf("%d\n", res3[0]);
+
+__v4si res4 = __builtin_ia32_vcvtph2udq128_mask(vec3, vec4, -1);
+printf("%d\n", res4[0]);
+
+__m128i vec5 = {};
+__m128i res5 = __builtin_ia32_vcvtph2qq128_mask(vec3, vec5, -1);
+printf("%d\n", res5[0]);
+
+__m128i res6 = __builtin_ia32_vcvtph2uqq128_mask(vec3, vec5, -1);
+printf("%d\n", res6[0]);
+}


[gcc r15-4928] libgccjit: Add count zeroes builtins to ensure_optimization_builtins_exist

2024-11-04 Thread Antoni Boucher via Gcc-cvs
https://gcc.gnu.org/g:56acc9498ebce94f902dccd82eefdac36f08fc38

commit r15-4928-g56acc9498ebce94f902dccd82eefdac36f08fc38
Author: Antoni Boucher 
Date:   Thu Feb 8 21:48:27 2024 -0500

libgccjit: Add count zeroes builtins to ensure_optimization_builtins_exist

gcc/jit/ChangeLog:

* jit-builtins.cc (ensure_optimization_builtins_exist): Add
missing builtins.

Diff:
---
 gcc/jit/jit-builtins.cc | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/gcc/jit/jit-builtins.cc b/gcc/jit/jit-builtins.cc
index e0bb24738ddf..0c13c8db5860 100644
--- a/gcc/jit/jit-builtins.cc
+++ b/gcc/jit/jit-builtins.cc
@@ -612,6 +612,12 @@ builtins_manager::ensure_optimization_builtins_exist ()
   (void)get_builtin_function_by_id (BUILT_IN_POPCOUNT);
   (void)get_builtin_function_by_id (BUILT_IN_POPCOUNTL);
   (void)get_builtin_function_by_id (BUILT_IN_POPCOUNTLL);
+  (void)get_builtin_function_by_id (BUILT_IN_CLZ);
+  (void)get_builtin_function_by_id (BUILT_IN_CTZ);
+  (void)get_builtin_function_by_id (BUILT_IN_CLZL);
+  (void)get_builtin_function_by_id (BUILT_IN_CTZL);
+  (void)get_builtin_function_by_id (BUILT_IN_CLZLL);
+  (void)get_builtin_function_by_id (BUILT_IN_CTZLL);
 }
 
 /* Playback support.  */


[gcc r15-4933] libgccjit: Add gcc_jit_global_set_readonly

2024-11-04 Thread Antoni Boucher via Gcc-cvs
https://gcc.gnu.org/g:7bb75a5edc1b3c90500e2a78124feac7beefacad

commit r15-4933-g7bb75a5edc1b3c90500e2a78124feac7beefacad
Author: Antoni Boucher 
Date:   Tue May 24 17:45:01 2022 -0400

libgccjit: Add gcc_jit_global_set_readonly

gcc/jit/ChangeLog:

* docs/topics/compatibility.rst (LIBGCCJIT_ABI_29): New ABI tag.
* docs/topics/expressions.rst: Document gcc_jit_global_set_readonly.
* jit-playback.cc (global_new_decl, new_global,
new_global_initialized): New parameter readonly.
* jit-playback.h (global_new_decl, new_global,
new_global_initialized): New parameter readonly.
* jit-recording.cc (recording::global::replay_into): Use
m_readonly.
(recording::global::write_reproducer): Dump reproducer for
gcc_jit_global_set_readonly.
* jit-recording.h (get_readonly, set_readonly): New methods.
(m_readonly): New attribute.
* libgccjit.cc (gcc_jit_global_set_readonly): New function.
(gcc_jit_block_add_assignment): Check that we don't assign to a
readonly variable.
* libgccjit.h (gcc_jit_global_set_readonly): New function.
(LIBGCCJIT_HAVE_gcc_jit_global_set_readonly): New define.
* libgccjit.map: New function.

gcc/testsuite/ChangeLog:

* jit.dg/all-non-failing-tests.h: Mention test-readonly.c.
* jit.dg/test-error-assign-readonly.c: New test.
* jit.dg/test-readonly.c: New test.

Diff:
---
 gcc/jit/docs/topics/compatibility.rst |  7 +++
 gcc/jit/docs/topics/expressions.rst   | 12 +
 gcc/jit/jit-playback.cc   | 15 +++---
 gcc/jit/jit-playback.h|  9 ++--
 gcc/jit/jit-recording.cc  |  9 +++-
 gcc/jit/jit-recording.h   | 11 
 gcc/jit/libgccjit.cc  | 22 
 gcc/jit/libgccjit.h   |  5 ++
 gcc/jit/libgccjit.map |  5 ++
 gcc/testsuite/jit.dg/all-non-failing-tests.h  |  3 ++
 gcc/testsuite/jit.dg/test-error-assign-readonly.c | 62 +++
 gcc/testsuite/jit.dg/test-readonly.c  | 38 ++
 12 files changed, 187 insertions(+), 11 deletions(-)

diff --git a/gcc/jit/docs/topics/compatibility.rst 
b/gcc/jit/docs/topics/compatibility.rst
index 92c3ed24c892..96adc03fed4d 100644
--- a/gcc/jit/docs/topics/compatibility.rst
+++ b/gcc/jit/docs/topics/compatibility.rst
@@ -404,3 +404,10 @@ on functions and variables:
 
 ``LIBGCCJIT_ABI_28`` covers the addition of
 :func:`gcc_jit_context_new_alignof`
+
+.. _LIBGCCJIT_ABI_29:
+
+``LIBGCCJIT_ABI_29``
+
+``LIBGCCJIT_ABI_29`` covers the addition of
+:func:`gcc_jit_global_set_readonly`
diff --git a/gcc/jit/docs/topics/expressions.rst 
b/gcc/jit/docs/topics/expressions.rst
index 5734f0e5f7e5..2aabbb82a6bc 100644
--- a/gcc/jit/docs/topics/expressions.rst
+++ b/gcc/jit/docs/topics/expressions.rst
@@ -989,6 +989,18 @@ Variables
 
   #ifdef LIBGCCJIT_HAVE_ATTRIBUTES
 
+.. function:: void\
+  gcc_jit_global_set_readonly (gcc_jit_lvalue *global)
+
+   Set the global variable as read-only, meaning you cannot assign to this 
variable.
+
+   This entrypoint was added in :ref:`LIBGCCJIT_ABI_29`; you can test for its
+   presence using:
+
+   .. code-block:: c
+
+  #ifdef LIBGCCJIT_HAVE_gcc_jit_global_set_readonly
+
 Working with pointers, structs and unions
 -
 
diff --git a/gcc/jit/jit-playback.cc b/gcc/jit/jit-playback.cc
index 8dd77e4d5871..f0f01648ac19 100644
--- a/gcc/jit/jit-playback.cc
+++ b/gcc/jit/jit-playback.cc
@@ -723,7 +723,8 @@ global_new_decl (location *loc,
 const char *name,
 enum global_var_flags flags,
 const std::vector> &attributes)
+std::string>> &attributes,
+bool readonly)
 {
   gcc_assert (type);
   gcc_assert (name);
@@ -762,7 +763,7 @@ global_new_decl (location *loc,
   break;
 }
 
-  if (TYPE_READONLY (type_tree))
+  if (TYPE_READONLY (type_tree) || readonly)
 TREE_READONLY (inner) = 1;
 
   if (loc)
@@ -815,10 +816,11 @@ new_global (location *loc,
const char *name,
enum global_var_flags flags,
const std::vector> &attributes)
+   std::string>> &attributes,
+   bool readonly)
 {
   tree inner =
-global_new_decl (loc, kind, type, name, flags, attributes);
+global_new_decl (loc, kind, type, name, flags, attributes, readonly);
 
   return global_finalize_lvalue (inner);
 }
@@ -965,9 +967,10 @@ new_global_initialized (location *loc,
const char *name,
enum global_var_flags flags,
c

[gcc r15-4936] libgccjit: Add convert vector

2024-11-04 Thread Antoni Boucher via Gcc-cvs
https://gcc.gnu.org/g:fe97ac43e05a8da8a12fbad2208a1ebb19d2d6c9

commit r15-4936-gfe97ac43e05a8da8a12fbad2208a1ebb19d2d6c9
Author: Antoni Boucher 
Date:   Sat May 14 17:24:29 2022 -0400

libgccjit: Add convert vector

gcc/jit/ChangeLog:

* docs/topics/compatibility.rst (LIBGCCJIT_ABI_30): New ABI tag.
* docs/topics/expressions.rst: Document 
gcc_jit_context_convert_vector.
* jit-playback.cc (convert_vector): New method.
* jit-playback.h: New method.
* jit-recording.cc (recording::context::new_convert_vector,
recording::convert_vector::replay_into,
recording::convert_vector::visit_children,
recording::convert_vector::make_debug_string,
recording::convert_vector::write_reproducer): New methods.
* jit-recording.h (class convert_vector): New class.
(context::new_convert_vector): New method.
* libgccjit.cc (gcc_jit_context_convert_vector): New function.
* libgccjit.h (gcc_jit_context_convert_vector): New function.
* libgccjit.map: New function.

gcc/testsuite/ChangeLog:

* jit.dg/all-non-failing-tests.h: New test.
* jit.dg/test-convert-vector.c: New test.

Diff:
---
 gcc/jit/docs/topics/compatibility.rst|  7 +++
 gcc/jit/docs/topics/expressions.rst  | 19 
 gcc/jit/jit-playback.cc  | 28 +++
 gcc/jit/jit-playback.h   |  5 ++
 gcc/jit/jit-recording.cc | 72 
 gcc/jit/jit-recording.h  | 34 +
 gcc/jit/libgccjit.cc | 36 ++
 gcc/jit/libgccjit.h  | 10 
 gcc/jit/libgccjit.map|  5 ++
 gcc/testsuite/jit.dg/all-non-failing-tests.h | 10 
 gcc/testsuite/jit.dg/test-convert-vector.c   | 60 +++
 11 files changed, 286 insertions(+)

diff --git a/gcc/jit/docs/topics/compatibility.rst 
b/gcc/jit/docs/topics/compatibility.rst
index 96adc03fed4d..33fa763d0213 100644
--- a/gcc/jit/docs/topics/compatibility.rst
+++ b/gcc/jit/docs/topics/compatibility.rst
@@ -411,3 +411,10 @@ on functions and variables:
 
 ``LIBGCCJIT_ABI_29`` covers the addition of
 :func:`gcc_jit_global_set_readonly`
+
+.. _LIBGCCJIT_ABI_30:
+
+``LIBGCCJIT_ABI_30``
+
+``LIBGCCJIT_ABI_30`` covers the addition of
+:func:`gcc_jit_context_convert_vector`
diff --git a/gcc/jit/docs/topics/expressions.rst 
b/gcc/jit/docs/topics/expressions.rst
index 2aabbb82a6bc..ca923e7f60c2 100644
--- a/gcc/jit/docs/topics/expressions.rst
+++ b/gcc/jit/docs/topics/expressions.rst
@@ -727,6 +727,25 @@ Type-coercion
 
   #ifdef LIBGCCJIT_HAVE_gcc_jit_context_new_bitcast
 
+.. function:: gcc_jit_rvalue *
+  gcc_jit_context_convert_vector (gcc_jit_context *ctxt, \
+  gcc_jit_location *loc, \
+  gcc_jit_rvalue *vector, \
+  gcc_jit_type *type)
+
+   Given a vector rvalue, cast it to the type ``type``, doing an element-wise
+   conversion.
+
+   The number of elements in ``vector`` and ``type`` must match.
+   The ``type`` must be a vector type.
+
+   This entrypoint was added in :ref:`LIBGCCJIT_ABI_30`; you can test for
+   its presence using
+
+   .. code-block:: c
+
+  #ifdef LIBGCCJIT_HAVE_gcc_jit_context_convert_vector
+
 Lvalues
 ---
 
diff --git a/gcc/jit/jit-playback.cc b/gcc/jit/jit-playback.cc
index f0f01648ac19..e32e837f2fea 100644
--- a/gcc/jit/jit-playback.cc
+++ b/gcc/jit/jit-playback.cc
@@ -1694,6 +1694,34 @@ new_array_access (location *loc,
 }
 }
 
+/* Construct a playback::rvalue instance (wrapping a tree) for a
+   vector conversion.  */
+
+playback::rvalue *
+playback::context::
+convert_vector (location *loc,
+  rvalue *vector,
+  type *type)
+{
+  gcc_assert (vector);
+  gcc_assert (type);
+
+  /* For comparison, see:
+   c/c-common.cc: c_build_vec_convert
+  */
+
+  tree t_vector = vector->as_tree ();
+
+  tree t_result =
+build_call_expr_internal_loc (UNKNOWN_LOCATION, IFN_VEC_CONVERT,
+  type->as_tree (), 1, t_vector);
+
+  if (loc)
+set_tree_location (t_result, loc);
+
+  return new rvalue (this, t_result);
+}
+
 /* Construct a tree for a field access.  */
 
 tree
diff --git a/gcc/jit/jit-playback.h b/gcc/jit/jit-playback.h
index 212f0b2662df..97ad62ccd6a3 100644
--- a/gcc/jit/jit-playback.h
+++ b/gcc/jit/jit-playback.h
@@ -222,6 +222,11 @@ public:
rvalue *ptr,
rvalue *index);
 
+  rvalue *
+  convert_vector (location *loc,
+ rvalue *vector,
+ type *type);
+
   void
   set_str_option (enum gcc_jit_str_option opt,
  const char *value);
diff --git a/gcc/jit/jit-recordi

[gcc r15-5531] libgccjit: Add support for setting the comment ident

2024-11-20 Thread Antoni Boucher via Gcc-cvs
https://gcc.gnu.org/g:cf544af03a8b51b3dea1667ea2525dc6a6b4ae08

commit r15-5531-gcf544af03a8b51b3dea1667ea2525dc6a6b4ae08
Author: Antoni Boucher 
Date:   Fri Oct 27 17:36:03 2023 -0400

libgccjit: Add support for setting the comment ident

gcc/jit/ChangeLog:

* docs/topics/compatibility.rst (LIBGCCJIT_ABI_34): New ABI tag.
* docs/topics/contexts.rst: Document 
gcc_jit_context_set_output_ident.
* jit-playback.cc (set_output_ident): New method.
* jit-playback.h (set_output_ident): New method.
* jit-recording.cc (recording::context::set_output_ident,
recording::output_ident::output_ident,
recording::output_ident::~output_ident,
recording::output_ident::replay_into,
recording::output_ident::make_debug_string,
recording::output_ident::write_reproducer): New methods.
* jit-recording.h (class output_ident): New class.
* libgccjit.cc (gcc_jit_context_set_output_ident): New function.
* libgccjit.h (gcc_jit_context_set_output_ident): New function.
* libgccjit.map: New function.

gcc/testsuite/ChangeLog:

* jit.dg/all-non-failing-tests.h: New test.
* jit.dg/test-output-ident.c: New test.

Diff:
---
 gcc/jit/docs/topics/compatibility.rst|  8 +
 gcc/jit/docs/topics/contexts.rst | 29 +++
 gcc/jit/jit-playback.cc  |  7 
 gcc/jit/jit-playback.h   |  3 ++
 gcc/jit/jit-recording.cc | 53 
 gcc/jit/jit-recording.h  | 22 
 gcc/jit/libgccjit.cc | 16 +
 gcc/jit/libgccjit.h  |  6 
 gcc/jit/libgccjit.map|  5 +++
 gcc/testsuite/jit.dg/all-non-failing-tests.h |  3 ++
 gcc/testsuite/jit.dg/test-output-ident.c | 23 
 11 files changed, 175 insertions(+)

diff --git a/gcc/jit/docs/topics/compatibility.rst 
b/gcc/jit/docs/topics/compatibility.rst
index 34c9b740a9a8..f48c52b21795 100644
--- a/gcc/jit/docs/topics/compatibility.rst
+++ b/gcc/jit/docs/topics/compatibility.rst
@@ -445,3 +445,11 @@ on functions and variables:
 temporary variable:
 
   * :func:`gcc_jit_function_new_temp`
+
+.. _LIBGCCJIT_ABI_34:
+
+``LIBGCCJIT_ABI_34``
+
+``LIBGCCJIT_ABI_34`` covers the addition of
+
+ * :func:`gcc_jit_context_set_output_ident`
diff --git a/gcc/jit/docs/topics/contexts.rst b/gcc/jit/docs/topics/contexts.rst
index ba075cd71d35..29e634e71f37 100644
--- a/gcc/jit/docs/topics/contexts.rst
+++ b/gcc/jit/docs/topics/contexts.rst
@@ -604,3 +604,32 @@ Additional command-line options
.. code-block:: c
 
   #ifdef LIBGCCJIT_HAVE_gcc_jit_context_add_driver_option
+
+Output options
+**
+
+.. function:: void gcc_jit_context_set_output_ident (gcc_jit_context *ctxt,\
+ const char* output_ident)
+
+   Set the identifier to write in the .comment section of the output file to
+   ``output_ident``.
+
+   The parameter ``output_ident`` must be non-NULL.
+
+   This only works on some target, as you can see here:
+   https://gcc.gnu.org/onlinedocs/cpp/Other-Directives.html
+
+   Analogous to:
+
+   .. code-block:: c
+
+  #ident "My comment"
+
+   in C.
+
+   This entrypoint was added in :ref:`LIBGCCJIT_ABI_34`; you can test for
+   its presence using
+
+   .. code-block:: c
+
+  #ifdef LIBGCCJIT_HAVE_gcc_jit_context_set_output_ident
diff --git a/gcc/jit/jit-playback.cc b/gcc/jit/jit-playback.cc
index 7530b0d84775..d5bd0407afd1 100644
--- a/gcc/jit/jit-playback.cc
+++ b/gcc/jit/jit-playback.cc
@@ -329,6 +329,13 @@ get_type (enum gcc_jit_types type_)
   return new type (type_node);
 }
 
+void
+playback::context::
+set_output_ident (const char* ident)
+{
+  targetm.asm_out.output_ident (ident);
+}
+
 /* Construct a playback::type instance (wrapping a tree) for the given
array type.  */
 
diff --git a/gcc/jit/jit-playback.h b/gcc/jit/jit-playback.h
index 2f5e41155674..e29100423bac 100644
--- a/gcc/jit/jit-playback.h
+++ b/gcc/jit/jit-playback.h
@@ -77,6 +77,9 @@ public:
   type *
   get_type (enum gcc_jit_types type);
 
+  void
+  set_output_ident (const char* ident);
+
   type *
   new_array_type (location *loc,
  type *element_type,
diff --git a/gcc/jit/jit-recording.cc b/gcc/jit/jit-recording.cc
index 4a0f8e6dff75..e39a10bacc33 100644
--- a/gcc/jit/jit-recording.cc
+++ b/gcc/jit/jit-recording.cc
@@ -1486,6 +1486,13 @@ recording::context::get_str_option (enum 
gcc_jit_str_option opt)
   return m_str_options[opt];
 }
 
+void
+recording::context::set_output_ident (const char *ident)
+{
+  recording::output_ident *memento = new output_ident (this, ident);
+  record (memento);
+}
+
 /* Set the given integer option for this context, or add an error if
it's not recognized.
 
@@ -23

[gcc r15-5528] libgccjit: Add support for machine-dependent builtins

2024-11-20 Thread Antoni Boucher via Gcc-cvs
https://gcc.gnu.org/g:87f0136fa46c9b0352aa47f637d2f6678b8beb5b

commit r15-5528-g87f0136fa46c9b0352aa47f637d2f6678b8beb5b
Author: Antoni Boucher 
Date:   Mon Jan 23 17:21:15 2023 -0500

libgccjit: Add support for machine-dependent builtins

gcc/jit/ChangeLog:
PR jit/108762
* docs/topics/compatibility.rst (LIBGCCJIT_ABI_32): New ABI tag.
* docs/topics/functions.rst: Add documentation for the function
gcc_jit_context_get_target_builtin_function.
* dummy-frontend.cc: Include headers target.h, jit-recording.h,
print-tree.h, unordered_map and string, new variables 
(target_builtins,
target_function_types, and target_builtins_ctxt), new function
(tree_type_to_jit_type).
* jit-builtins.cc: Specify that the function types are not from
target builtins.
* jit-playback.cc: New argument is_target_builtin to new_function.
* jit-playback.h: New argument is_target_builtin to
new_function.
* jit-recording.cc: New argument is_target_builtin to
new_function_type, function_type constructor and function
constructor, new function
(get_target_builtin_function).
* jit-recording.h: Include headers string and unordered_map, new
variable target_function_types, new argument is_target_builtin
to new_function_type, function_type and function, new functions
(get_target_builtin_function, copy).
* libgccjit.cc: New function
(gcc_jit_context_get_target_builtin_function).
* libgccjit.h: New function
(gcc_jit_context_get_target_builtin_function).
* libgccjit.map: New functions
(gcc_jit_context_get_target_builtin_function).

gcc/testsuite:
PR jit/108762
* jit.dg/all-non-failing-tests.h: New test test-target-builtins.c.
* jit.dg/test-target-builtins.c: New test.

Diff:
---
 gcc/jit/docs/topics/compatibility.rst|  10 +-
 gcc/jit/docs/topics/functions.rst|  19 +++
 gcc/jit/dummy-frontend.cc| 205 ++-
 gcc/jit/jit-builtins.cc  |   6 +-
 gcc/jit/jit-playback.cc  |  12 +-
 gcc/jit/jit-playback.h   |   5 +-
 gcc/jit/jit-recording.cc |  76 --
 gcc/jit/jit-recording.h  | 110 +-
 gcc/jit/libgccjit.cc |  18 +++
 gcc/jit/libgccjit.h  |  13 ++
 gcc/jit/libgccjit.map|   5 +
 gcc/testsuite/jit.dg/all-non-failing-tests.h |   3 +
 gcc/testsuite/jit.dg/test-target-builtins.c  |  77 ++
 13 files changed, 538 insertions(+), 21 deletions(-)

diff --git a/gcc/jit/docs/topics/compatibility.rst 
b/gcc/jit/docs/topics/compatibility.rst
index 77b4c5df9979..bfef40afc2a0 100644
--- a/gcc/jit/docs/topics/compatibility.rst
+++ b/gcc/jit/docs/topics/compatibility.rst
@@ -418,7 +418,6 @@ on functions and variables:
 
 ``LIBGCCJIT_ABI_30`` covers the addition of
 :func:`gcc_jit_context_convert_vector`
-===
 
 .. _LIBGCCJIT_ABI_31:
 
@@ -428,3 +427,12 @@ on functions and variables:
 
   * :func:`gcc_jit_context_new_rvalue_vector_perm`
   * :func:`gcc_jit_context_new_vector_access`
+
+.. _LIBGCCJIT_ABI_32:
+
+``LIBGCCJIT_ABI_32``
+
+
+``LIBGCCJIT_ABI_32`` covers the addition of a function to get target builtins:
+
+  * :func:`gcc_jit_context_get_target_builtin_function`
diff --git a/gcc/jit/docs/topics/functions.rst 
b/gcc/jit/docs/topics/functions.rst
index 804605ea9398..16e82a34c21f 100644
--- a/gcc/jit/docs/topics/functions.rst
+++ b/gcc/jit/docs/topics/functions.rst
@@ -140,6 +140,25 @@ Functions
   uses such a parameter will lead to an error being emitted within
   the context.
 
+.. function::  gcc_jit_function *\
+   gcc_jit_context_get_target_builtin_function (gcc_jit_context 
*ctxt,\
+const char *name)
+
+   Get the :type:`gcc_jit_function` for the built-in function (sometimes called
+   intrinsic functions) with the given name.  For example:
+
+   .. code-block:: c
+
+  gcc_jit_function *fn
+= gcc_jit_context_get_target_builtin_function (ctxt, 
"__builtin_ia32_pmuldq512_mask");
+
+   .. note:: Due to technical limitations with how libgccjit interacts with
+  the insides of GCC, not all built-in functions are supported.  More
+  precisely, not all types are supported for parameters of built-in
+  functions from libgccjit.  Attempts to get a built-in function that
+  uses such a parameter will lead to an error being emitted within
+  the context.
+
 .. function::  gcc_jit_object *\
gcc_jit_function_as_object (gcc_jit_function *func)
 
diff --git a/gcc/jit/dummy-fronten

[gcc r15-5530] libgccjit: Add support for creating temporary variables

2024-11-20 Thread Antoni Boucher via Gcc-cvs
https://gcc.gnu.org/g:d8cf8917ed3d7e0708da3ac3d82456da28d1cdb5

commit r15-5530-gd8cf8917ed3d7e0708da3ac3d82456da28d1cdb5
Author: Antoni Boucher 
Date:   Thu Jan 18 17:54:59 2024 -0500

libgccjit: Add support for creating temporary variables

gcc/jit/ChangeLog:

* docs/topics/compatibility.rst (LIBGCCJIT_ABI_33): New ABI tag.
* docs/topics/functions.rst: Document gcc_jit_function_new_temp.
* jit-playback.cc (new_local): Add support for temporary
variables.
* jit-recording.cc (recording::function::new_temp): New method.
(recording::local::write_reproducer): Support temporary
variables.
* jit-recording.h (new_temp): New method.
* libgccjit.cc (gcc_jit_function_new_temp): New function.
* libgccjit.h (gcc_jit_function_new_temp): New function.
* libgccjit.map: New function.

gcc/testsuite/ChangeLog:

* jit.dg/all-non-failing-tests.h: Mention test-temp.c.
* jit.dg/test-temp.c: New test.

Diff:
---
 gcc/jit/docs/topics/compatibility.rst|  9 +
 gcc/jit/docs/topics/functions.rst| 20 ++
 gcc/jit/jit-playback.cc  | 15 +++-
 gcc/jit/jit-recording.cc | 47 ++-
 gcc/jit/jit-recording.h  | 11 +-
 gcc/jit/libgccjit.cc | 31 +++
 gcc/jit/libgccjit.h  |  7 
 gcc/jit/libgccjit.map|  5 +++
 gcc/testsuite/jit.dg/all-non-failing-tests.h |  3 ++
 gcc/testsuite/jit.dg/test-temp.c | 56 
 10 files changed, 191 insertions(+), 13 deletions(-)

diff --git a/gcc/jit/docs/topics/compatibility.rst 
b/gcc/jit/docs/topics/compatibility.rst
index bfef40afc2a0..34c9b740a9a8 100644
--- a/gcc/jit/docs/topics/compatibility.rst
+++ b/gcc/jit/docs/topics/compatibility.rst
@@ -436,3 +436,12 @@ on functions and variables:
 ``LIBGCCJIT_ABI_32`` covers the addition of a function to get target builtins:
 
   * :func:`gcc_jit_context_get_target_builtin_function`
+
+.. _LIBGCCJIT_ABI_33:
+
+``LIBGCCJIT_ABI_33``
+
+``LIBGCCJIT_ABI_33`` covers the addition of a function to create a new
+temporary variable:
+
+  * :func:`gcc_jit_function_new_temp`
diff --git a/gcc/jit/docs/topics/functions.rst 
b/gcc/jit/docs/topics/functions.rst
index 16e82a34c21f..d986439de131 100644
--- a/gcc/jit/docs/topics/functions.rst
+++ b/gcc/jit/docs/topics/functions.rst
@@ -190,6 +190,26 @@ Functions
underlying string, so it is valid to pass in a pointer to an on-stack
buffer.
 
+.. function:: gcc_jit_lvalue *\
+  gcc_jit_function_new_temp (gcc_jit_function *func,\
+ gcc_jit_location *loc,\
+ gcc_jit_type *type)
+
+   Create a new local variable within the function, of the given type.
+   This function is similar to :func:`gcc_jit_function_new_local`, but
+   it is to be used for compiler-generated variables (as opposed to
+   user-defined variables in the language to be compiled) and these
+   variables won't show up in the debug info.
+
+   The parameter ``type`` must be non-`void`.
+
+   This entrypoint was added in :ref:`LIBGCCJIT_ABI_33`; you can test
+   for its presence using
+
+   .. code-block:: c
+
+  #ifdef LIBGCCJIT_HAVE_gcc_jit_function_new_temp
+
 .. function::  size_t \
gcc_jit_function_get_param_count (gcc_jit_function *func)
 
diff --git a/gcc/jit/jit-playback.cc b/gcc/jit/jit-playback.cc
index e8887e96c8e0..7530b0d84775 100644
--- a/gcc/jit/jit-playback.cc
+++ b/gcc/jit/jit-playback.cc
@@ -32,6 +32,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "toplev.h"
 #include "tree-cfg.h"
 #include "convert.h"
+#include "gimple-expr.h"
 #include "stor-layout.h"
 #include "print-tree.h"
 #include "gimplify.h"
@@ -2167,10 +2168,20 @@ new_local (location *loc,
   std::string>> &attributes)
 {
   gcc_assert (type);
-  gcc_assert (name);
-  tree inner = build_decl (UNKNOWN_LOCATION, VAR_DECL,
+  tree inner;
+  if (name)
+inner = build_decl (UNKNOWN_LOCATION, VAR_DECL,
   get_identifier (name),
   type->as_tree ());
+  else
+  {
+inner = build_decl (UNKNOWN_LOCATION, VAR_DECL,
+   create_tmp_var_name ("JITTMP"),
+   type->as_tree ());
+DECL_ARTIFICIAL (inner) = 1;
+DECL_IGNORED_P (inner) = 1;
+DECL_NAMELESS (inner) = 1;
+  }
   DECL_CONTEXT (inner) = this->m_inner_fndecl;
 
   /* Prepend to BIND_EXPR_VARS: */
diff --git a/gcc/jit/jit-recording.cc b/gcc/jit/jit-recording.cc
index 7c1b3fdde410..4a0f8e6dff75 100644
--- a/gcc/jit/jit-recording.cc
+++ b/gcc/jit/jit-recording.cc
@@ -4356,6 +4356,23 @@ recording::function::new_local (recording::location *loc,
   ret

[gcc r15-5512] libgccjit: Add type checks in gcc_jit_block_add_assignment_op

2024-11-20 Thread Antoni Boucher via Gcc-cvs
https://gcc.gnu.org/g:efdc80a8bfea63433d8959e7913c9864208c630e

commit r15-5512-gefdc80a8bfea63433d8959e7913c9864208c630e
Author: Antoni Boucher 
Date:   Wed Oct 18 18:33:18 2023 -0400

libgccjit: Add type checks in gcc_jit_block_add_assignment_op

gcc/jit/ChangeLog:

* libgccjit.cc (RETURN_IF_FAIL_PRINTF3): New macro.
(gcc_jit_block_add_assignment_op): Add numeric checks.

gcc/testsuite/ChangeLog:

* jit.dg/test-error-bad-assignment-op.c: New test.

Diff:
---
 gcc/jit/libgccjit.cc   | 21 
 .../jit.dg/test-error-bad-assignment-op.c  | 57 ++
 2 files changed, 78 insertions(+)

diff --git a/gcc/jit/libgccjit.cc b/gcc/jit/libgccjit.cc
index 664180177fea..398a0ff2d35c 100644
--- a/gcc/jit/libgccjit.cc
+++ b/gcc/jit/libgccjit.cc
@@ -267,6 +267,16 @@ struct gcc_jit_extended_asm : public 
gcc::jit::recording::extended_asm
   }\
   JIT_END_STMT
 
+#define RETURN_IF_FAIL_PRINTF3(TEST_EXPR, CTXT, LOC, ERR_FMT, A0, A1, A2) \
+  JIT_BEGIN_STMT   \
+if (!(TEST_EXPR))  \
+  {\
+   jit_error ((CTXT), (LOC), "%s: " ERR_FMT,   \
+  __func__, (A0), (A1), (A2)); \
+   return; \
+  }\
+  JIT_END_STMT
+
 #define RETURN_IF_FAIL_PRINTF4(TEST_EXPR, CTXT, LOC, ERR_FMT, A0, A1, A2, A3) \
   JIT_BEGIN_STMT   \
 if (!(TEST_EXPR))  \
@@ -2984,6 +2994,17 @@ gcc_jit_block_add_assignment_op (gcc_jit_block *block,
 lvalue->get_type ()->get_debug_string (),
 rvalue->get_debug_string (),
 rvalue->get_type ()->get_debug_string ());
+  // TODO: check if it is a numeric vector?
+  RETURN_IF_FAIL_PRINTF3 (
+lvalue->get_type ()->is_numeric (), ctxt, loc,
+"gcc_jit_block_add_assignment_op %s has non-numeric lvalue %s (type: %s)",
+gcc::jit::binary_op_reproducer_strings[op],
+lvalue->get_debug_string (), lvalue->get_type ()->get_debug_string ());
+  RETURN_IF_FAIL_PRINTF3 (
+rvalue->get_type ()->is_numeric (), ctxt, loc,
+"gcc_jit_block_add_assignment_op %s has non-numeric rvalue %s (type: %s)",
+gcc::jit::binary_op_reproducer_strings[op],
+rvalue->get_debug_string (), rvalue->get_type ()->get_debug_string ());
 
   gcc::jit::recording::statement *stmt = block->add_assignment_op (loc, 
lvalue, op, rvalue);
 
diff --git a/gcc/testsuite/jit.dg/test-error-bad-assignment-op.c 
b/gcc/testsuite/jit.dg/test-error-bad-assignment-op.c
new file mode 100644
index ..683ebbfb1fed
--- /dev/null
+++ b/gcc/testsuite/jit.dg/test-error-bad-assignment-op.c
@@ -0,0 +1,57 @@
+#include 
+#include 
+
+#include "libgccjit.h"
+
+#include "harness.h"
+
+void
+create_code (gcc_jit_context *ctxt, void *user_data)
+{
+  /* Let's try to inject the equivalent of:
+
+ void
+ test_fn ()
+ {
+const char *variable;
+variable += "test";
+ }
+
+ and verify that the API complains about the mismatching types
+ in the assignments.
+  */
+  gcc_jit_type *void_type =
+gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_VOID);
+  gcc_jit_type *const_char_ptr_type =
+gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_CONST_CHAR_PTR);
+
+  gcc_jit_function *func =
+gcc_jit_context_new_function (ctxt, NULL,
+  GCC_JIT_FUNCTION_EXPORTED,
+  void_type,
+  "test_fn",
+  0, NULL,
+  0);
+
+  gcc_jit_lvalue *variable = gcc_jit_function_new_local (func, NULL, 
const_char_ptr_type, "variable");
+  gcc_jit_block *initial =
+gcc_jit_function_new_block (func, "initial");
+  gcc_jit_rvalue *string =
+gcc_jit_context_new_string_literal (ctxt, "test");
+  gcc_jit_block_add_assignment_op (initial, NULL, variable, 
GCC_JIT_BINARY_OP_PLUS, string);
+
+  gcc_jit_block_end_with_void_return (initial, NULL);
+}
+
+void
+verify_code (gcc_jit_context *ctxt, gcc_jit_result *result)
+{
+  CHECK_VALUE (result, NULL);
+
+  /* Verify that the correct error messages were emitted.  */
+  CHECK_STRING_VALUE (gcc_jit_context_get_first_error (ctxt),
+ "gcc_jit_block_add_assignment_op:"
+  " gcc_jit_block_add_assignment_op GCC_JIT_BINARY_OP_PLUS"
+  " has non-numeric lvalue variable (type: const char *)");
+}
+


[gcc r15-5514] libgccjit: Fix float playback for cross-compilation

2024-11-20 Thread Antoni Boucher via Gcc-cvs
https://gcc.gnu.org/g:fa720364e4ed3154b7f2dd8f4c2c71f890990552

commit r15-5514-gfa720364e4ed3154b7f2dd8f4c2c71f890990552
Author: Antoni Boucher 
Date:   Sat Oct 21 11:20:46 2023 -0400

libgccjit: Fix float playback for cross-compilation

gcc/jit/ChangeLog:
PR jit/113343
* jit-playback.cc (new_rvalue_from_const): Fix to have the
correct value when cross-compiling.

Diff:
---
 gcc/jit/jit-playback.cc | 21 -
 1 file changed, 8 insertions(+), 13 deletions(-)

diff --git a/gcc/jit/jit-playback.cc b/gcc/jit/jit-playback.cc
index e32e837f2fea..88513a6ba70d 100644
--- a/gcc/jit/jit-playback.cc
+++ b/gcc/jit/jit-playback.cc
@@ -43,6 +43,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "gcc.h"
 #include "diagnostic.h"
 #include "stmt.h"
+#include "realmpfr.h"
 
 #include "jit-playback.h"
 #include "jit-result.h"
@@ -1078,22 +1079,16 @@ new_rvalue_from_const  (type *type,
   // FIXME: type-checking, or coercion?
   tree inner_type = type->as_tree ();
 
+  mpfr_t mpf_value;
+
+  mpfr_init2 (mpf_value, 64);
+  mpfr_set_d (mpf_value, value, MPFR_RNDN);
+
   /* We have a "double", we want a REAL_VALUE_TYPE.
 
- real.cc:real_from_target appears to require the representation to be
- split into 32-bit values, and then sent as an pair of host long
- ints.  */
+ realmpfr.cc:real_from_mpfr.  */
   REAL_VALUE_TYPE real_value;
-  union
-  {
-double as_double;
-uint32_t as_uint32s[2];
-  } u;
-  u.as_double = value;
-  long int as_long_ints[2];
-  as_long_ints[0] = u.as_uint32s[0];
-  as_long_ints[1] = u.as_uint32s[1];
-  real_from_target (&real_value, as_long_ints, DFmode);
+  real_from_mpfr (&real_value, mpf_value, inner_type, MPFR_RNDN);
   tree inner = build_real (inner_type, real_value);
   return new rvalue (this, inner);
 }


[gcc r15-5511] libgccjit: Support signed char flag

2024-11-20 Thread Antoni Boucher via Gcc-cvs
https://gcc.gnu.org/g:04b67ac1e8ae4e918a804197dfff8e69b0ccf955

commit r15-5511-g04b67ac1e8ae4e918a804197dfff8e69b0ccf955
Author: Antoni Boucher 
Date:   Mon Oct 3 19:11:39 2022 -0400

libgccjit: Support signed char flag

gcc/jit/ChangeLog:

* dummy-frontend.cc (jit_langhook_init): Send flag_signed_char
argument to build_common_tree_nodes.

gcc/testsuite/ChangeLog:

* jit.dg/all-non-failing-tests.h: Add test-signed-char.c.
* jit.dg/test-signed-char.c: New test.

Diff:
---
 gcc/jit/dummy-frontend.cc|  2 +-
 gcc/testsuite/jit.dg/all-non-failing-tests.h | 10 ++
 gcc/testsuite/jit.dg/test-signed-char.c  | 52 
 3 files changed, 63 insertions(+), 1 deletion(-)

diff --git a/gcc/jit/dummy-frontend.cc b/gcc/jit/dummy-frontend.cc
index 35475b5ad05d..327e8de4f94a 100644
--- a/gcc/jit/dummy-frontend.cc
+++ b/gcc/jit/dummy-frontend.cc
@@ -1077,7 +1077,7 @@ jit_langhook_init (void)
  *gcc::jit::active_playback_ctxt);
   global_dc->set_output_format (std::move (sink));
 
-  build_common_tree_nodes (false);
+  build_common_tree_nodes (flag_signed_char);
 
   build_common_builtin_nodes ();
 
diff --git a/gcc/testsuite/jit.dg/all-non-failing-tests.h 
b/gcc/testsuite/jit.dg/all-non-failing-tests.h
index 32ca70da4374..7b8cf624bbaa 100644
--- a/gcc/testsuite/jit.dg/all-non-failing-tests.h
+++ b/gcc/testsuite/jit.dg/all-non-failing-tests.h
@@ -373,6 +373,13 @@
 /* test-setting-alignment.c: This can't be in the testcases array as it
is target-specific.  */
 
+/* test-signed-char.c */
+#define create_code create_code_signed_char
+#define verify_code verify_code_signed_char
+#include "test-signed-char.c"
+#undef create_code
+#undef verify_code
+
 /* test-sizeof.c */
 #define create_code create_code_sizeof
 #define verify_code verify_code_sizeof
@@ -586,6 +593,9 @@ const struct testcase testcases[] = {
   {"reflection",
create_code_reflection ,
verify_code_reflection },
+  {"signed-char",
+   create_code_signed_char,
+   verify_code_signed_char},
   {"sizeof",
create_code_sizeof,
verify_code_sizeof},
diff --git a/gcc/testsuite/jit.dg/test-signed-char.c 
b/gcc/testsuite/jit.dg/test-signed-char.c
new file mode 100644
index ..c12b41d92cc3
--- /dev/null
+++ b/gcc/testsuite/jit.dg/test-signed-char.c
@@ -0,0 +1,52 @@
+#include 
+#include 
+#include 
+
+#include "libgccjit.h"
+
+#include "harness.h"
+
+void
+create_code (gcc_jit_context *ctxt, void *user_data)
+{
+  /* Let's try to inject the equivalent of:
+int test_signed_char ()
+{
+char val = -2;
+return (int) val;
+}
+*/
+  gcc_jit_type *char_type =
+gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_CHAR);
+  gcc_jit_type *int_type =
+gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_INT);
+
+  gcc_jit_function *test_fn =
+gcc_jit_context_new_function (ctxt, NULL,
+ GCC_JIT_FUNCTION_EXPORTED,
+ int_type,
+ "test_signed_char",
+ 0, NULL,
+ 0);
+
+  gcc_jit_block *block = gcc_jit_function_new_block(test_fn, "entry");
+
+  gcc_jit_rvalue *val = gcc_jit_context_new_rvalue_from_int (ctxt,
+char_type, -2);
+  gcc_jit_rvalue *return_value = gcc_jit_context_new_cast (
+ctxt, NULL, val, int_type);
+
+  gcc_jit_block_end_with_return (block, NULL, return_value);
+}
+
+void
+verify_code (gcc_jit_context *ctxt, gcc_jit_result *result)
+{
+  CHECK_NON_NULL (result);
+
+  typedef int (*fn_type) ();
+  fn_type test_signed_char =
+(fn_type)gcc_jit_result_get_code (result, "test_signed_char");
+  CHECK_NON_NULL (test_signed_char);
+  CHECK_VALUE (test_signed_char (), -2);
+}


[gcc r15-5522] libgccjit: Allow comparing aligned int types

2024-11-20 Thread Antoni Boucher via Gcc-cvs
https://gcc.gnu.org/g:16cf1c010dbee4e411f0d1289830bfb6ed5c7807

commit r15-5522-g16cf1c010dbee4e411f0d1289830bfb6ed5c7807
Author: Antoni Boucher 
Date:   Sun Oct 8 09:12:12 2023 -0400

libgccjit: Allow comparing aligned int types

gcc/jit/ChangeLog:

* jit-common.h: Add forward declaration of memento_of_get_aligned.
* jit-recording.h (type::is_same_type_as): Compare integer
types.
(dyn_cast_aligned_type): New method.
(type::is_aligned, memento_of_get_aligned::is_same_type_as,
memento_of_get_aligned::is_aligned): new methods.

gcc/testsuite/ChangeLog:

* jit.dg/test-types.c: Add checks comparing aligned types.

Diff:
---
 gcc/jit/jit-common.h  |  1 +
 gcc/jit/jit-recording.h   | 34 +++---
 gcc/testsuite/jit.dg/test-types.c | 11 ---
 3 files changed, 36 insertions(+), 10 deletions(-)

diff --git a/gcc/jit/jit-common.h b/gcc/jit/jit-common.h
index 655d94e0bab4..6ab96223e1e0 100644
--- a/gcc/jit/jit-common.h
+++ b/gcc/jit/jit-common.h
@@ -134,6 +134,7 @@ namespace recording {
 class statement;
   class extended_asm;
 class case_;
+class memento_of_get_aligned;
   class top_level_asm;
 
   /* End of recording types. */
diff --git a/gcc/jit/jit-recording.h b/gcc/jit/jit-recording.h
index 13c2ea735027..ab4b0ff35b65 100644
--- a/gcc/jit/jit-recording.h
+++ b/gcc/jit/jit-recording.h
@@ -580,6 +580,7 @@ public:
   virtual struct_ *dyn_cast_struct () { return NULL; }
   virtual vector_type *dyn_cast_vector_type () { return NULL; }
   virtual array_type *dyn_cast_array_type () { return NULL; }
+  virtual memento_of_get_aligned *dyn_cast_aligned_type () { return NULL; }
 
   /* Is it typesafe to copy to this type from rtype?  */
   virtual bool accepts_writes_from (type *rtype)
@@ -590,6 +591,14 @@ public:
 
   virtual bool is_same_type_as (type *other)
   {
+if (is_int ()
+&& other->is_int ()
+&& get_size () == other->get_size ()
+&& is_signed () == other->is_signed ())
+{
+  /* LHS (this) is an integer of the same size and sign as rtype.  */
+  return true;
+}
 return this == other;
   }
 
@@ -607,6 +616,7 @@ public:
   virtual type *is_volatile () { return NULL; }
   virtual type *is_restrict () { return NULL; }
   virtual type *is_const () { return NULL; }
+  virtual type *is_aligned () { return NULL; }
   virtual type *is_array () = 0;
   virtual struct_ *is_struct () { return NULL; }
   virtual bool is_union () const { return false; }
@@ -661,13 +671,6 @@ public:
   accept it:  */
return true;
  }
-  } else if (is_int ()
-&& rtype->is_int ()
-&& get_size () == rtype->get_size ()
-&& is_signed () == rtype->is_signed ())
-  {
-   /* LHS (this) is an integer of the same size and sign as rtype.  */
-   return true;
   }
 
 return type::accepts_writes_from (rtype);
@@ -844,10 +847,27 @@ public:
   : decorated_type (other_type),
 m_alignment_in_bytes (alignment_in_bytes) {}
 
+  bool is_same_type_as (type *other) final override
+  {
+if (!other->is_aligned ())
+{
+  return m_other_type->is_same_type_as (other);
+}
+return m_alignment_in_bytes
+   == other->dyn_cast_aligned_type ()->m_alignment_in_bytes
+   && m_other_type->is_same_type_as (other->is_aligned ());
+  }
+
+  type *is_aligned () final override { return m_other_type; }
+
   /* Strip off the alignment, giving the underlying type.  */
   type *unqualified () final override { return m_other_type; }
 
   void replay_into (replayer *) final override;
+  memento_of_get_aligned *dyn_cast_aligned_type () final override 
+  {
+return this;
+  }
 
   array_type *dyn_cast_array_type () final override
   {
diff --git a/gcc/testsuite/jit.dg/test-types.c 
b/gcc/testsuite/jit.dg/test-types.c
index bfdb76383c55..8573711cf8eb 100644
--- a/gcc/testsuite/jit.dg/test-types.c
+++ b/gcc/testsuite/jit.dg/test-types.c
@@ -486,10 +486,10 @@ verify_code (gcc_jit_context *ctxt, gcc_jit_result 
*result)
 
   CHECK_VALUE (z.m_FILE_ptr, stderr);
 
+  gcc_jit_type *long_type = gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_LONG);
+  gcc_jit_type *int64_type = gcc_jit_context_get_type (ctxt, 
GCC_JIT_TYPE_INT64_T);
   if (sizeof(long) == 8)
-CHECK (gcc_jit_compatible_types (
-  gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_LONG),
-  gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_INT64_T)));
+CHECK (gcc_jit_compatible_types (long_type, int64_type));
 
   CHECK_VALUE (gcc_jit_type_get_size (gcc_jit_context_get_type (ctxt, 
GCC_JIT_TYPE_FLOAT)), sizeof (float));
   CHECK_VALUE (gcc_jit_type_get_size (gcc_jit_context_get_type (ctxt, 
GCC_JIT_TYPE_DOUBLE)), sizeof (double));
@@ -501,4 +501,9 @@ verify_code (gcc_jit_context *ctxt, gcc_jit_result *result)
   gcc_jit_type *array_type1 = gcc_jit_co

[gcc r15-5520] libgccjit: Add vector permutation and vector access operations

2024-11-20 Thread Antoni Boucher via Gcc-cvs
https://gcc.gnu.org/g:452abe143e8b9254139f188fce7a674700a10d98

commit r15-5520-g452abe143e8b9254139f188fce7a674700a10d98
Author: Antoni Boucher 
Date:   Fri Nov 17 17:23:28 2023 -0500

libgccjit: Add vector permutation and vector access operations

gcc/jit/ChangeLog:
PR jit/112602
* docs/topics/compatibility.rst (LIBGCCJIT_ABI_31): New ABI tag.
* docs/topics/expressions.rst: Document
gcc_jit_context_new_rvalue_vector_perm and
gcc_jit_context_new_vector_access.
* jit-playback.cc (playback::context::new_rvalue_vector_perm,
common_mark_addressable_vec,
gnu_vector_type_p,
lvalue_p,
convert_vector_to_array_for_subscript,
new_vector_access): new functions.
* jit-playback.h (new_rvalue_vector_perm, new_vector_access):
New functions.
* jit-recording.cc (recording::context::new_rvalue_vector_perm,
recording::context::new_vector_access,
memento_of_new_rvalue_vector_perm,
recording::memento_of_new_rvalue_vector_perm::replay_into,
recording::memento_of_new_rvalue_vector_perm::visit_children,
recording::memento_of_new_rvalue_vector_perm::make_debug_string,
recording::memento_of_new_rvalue_vector_perm::write_reproducer,
recording::vector_access::replay_into,
recording::vector_access::visit_children,
recording::vector_access::make_debug_string,
recording::vector_access::write_reproducer): New methods.
* jit-recording.h (class memento_of_new_rvalue_vector_perm,
class vector_access): New classes.
* libgccjit.cc (gcc_jit_context_new_vector_access,
gcc_jit_context_new_rvalue_vector_perm): New functions.
* libgccjit.h (gcc_jit_context_new_rvalue_vector_perm,
gcc_jit_context_new_vector_access): New functions.
* libgccjit.map: New functions.

gcc/testsuite/ChangeLog:
PR jit/112602
* jit.dg/all-non-failing-tests.h: New test test-vector-perm.c.
* jit.dg/test-vector-perm.c: New test.

Diff:
---
 gcc/jit/docs/topics/compatibility.rst|  10 ++
 gcc/jit/docs/topics/expressions.rst  |  53 +
 gcc/jit/jit-playback.cc  | 150 
 gcc/jit/jit-playback.h   |  10 ++
 gcc/jit/jit-recording.cc | 166 +++
 gcc/jit/jit-recording.h  |  72 
 gcc/jit/libgccjit.cc | 112 ++
 gcc/jit/libgccjit.h  |  29 +
 gcc/jit/libgccjit.map|   6 +
 gcc/testsuite/jit.dg/all-non-failing-tests.h |  12 +-
 gcc/testsuite/jit.dg/test-vector-perm.c  |  96 
 11 files changed, 715 insertions(+), 1 deletion(-)

diff --git a/gcc/jit/docs/topics/compatibility.rst 
b/gcc/jit/docs/topics/compatibility.rst
index 33fa763d0213..77b4c5df9979 100644
--- a/gcc/jit/docs/topics/compatibility.rst
+++ b/gcc/jit/docs/topics/compatibility.rst
@@ -418,3 +418,13 @@ on functions and variables:
 
 ``LIBGCCJIT_ABI_30`` covers the addition of
 :func:`gcc_jit_context_convert_vector`
+===
+
+.. _LIBGCCJIT_ABI_31:
+
+``LIBGCCJIT_ABI_31``
+
+``LIBGCCJIT_ABI_31`` covers the addition of functions to manipulate vectors:
+
+  * :func:`gcc_jit_context_new_rvalue_vector_perm`
+  * :func:`gcc_jit_context_new_vector_access`
diff --git a/gcc/jit/docs/topics/expressions.rst 
b/gcc/jit/docs/topics/expressions.rst
index ca923e7f60c2..2b6e71d5b1bc 100644
--- a/gcc/jit/docs/topics/expressions.rst
+++ b/gcc/jit/docs/topics/expressions.rst
@@ -323,6 +323,35 @@ Vector expressions
 
   #ifdef LIBGCCJIT_HAVE_gcc_jit_context_new_rvalue_from_vector
 
+.. function:: gcc_jit_rvalue * \
+  gcc_jit_context_new_rvalue_vector_perm (gcc_jit_context *ctxt, \
+  gcc_jit_location *loc, \
+  gcc_jit_rvalue 
*elements1, \
+  gcc_jit_rvalue 
*elements2, \
+  gcc_jit_rvalue *mask);
+
+   Build a permutation of two vectors.
+
+   "elements1" and "elements2" should have the same type.
+   The length of "mask" and "elements1" should be the same.
+   The element type of "mask" should be integral.
+   The size of the element type of "mask" and "elements1" should be the same.
+
+   This entrypoint was added in :ref:`LIBGCCJIT_ABI_31`; you can test for
+   its presence using
+
+   .. code-block:: c
+
+  #ifdef LIBGCCJIT_HAVE_VECTOR_OPERATIONS
+
+Analogous to:
+
+.. code-block:: c
+
+   __builtin_shuffle (elements1, elements2, mask)
+
+in C.
+
 Unary Operations
 **

[gcc r15-5521] libgccjit: Add option to allow special characters in function names

2024-11-20 Thread Antoni Boucher via Gcc-cvs
https://gcc.gnu.org/g:ede14092bc33e182ee6c811c335bf9aac789d7be

commit r15-5521-gede14092bc33e182ee6c811c335bf9aac789d7be
Author: Antoni Boucher 
Date:   Thu Feb 15 17:03:22 2024 -0500

libgccjit: Add option to allow special characters in function names

gcc/jit/ChangeLog:

* docs/topics/contexts.rst: Add documentation for new option.
* jit-recording.cc (recording::context::get_str_option): New
method.
* jit-recording.h (get_str_option): New method.
* libgccjit.cc (gcc_jit_context_new_function): Allow special
characters in function names.
* libgccjit.h (enum gcc_jit_str_option): New option.

gcc/testsuite/ChangeLog:

* jit.dg/test-special-chars.c: New test.

Diff:
---
 gcc/jit/docs/topics/contexts.rst  |  9 +--
 gcc/jit/jit-recording.cc  | 17 +++--
 gcc/jit/jit-recording.h   |  3 +++
 gcc/jit/libgccjit.cc  |  8 --
 gcc/jit/libgccjit.h   |  3 +++
 gcc/testsuite/jit.dg/test-special-chars.c | 41 +++
 6 files changed, 75 insertions(+), 6 deletions(-)

diff --git a/gcc/jit/docs/topics/contexts.rst b/gcc/jit/docs/topics/contexts.rst
index 10a0e50f9f62..ba075cd71d35 100644
--- a/gcc/jit/docs/topics/contexts.rst
+++ b/gcc/jit/docs/topics/contexts.rst
@@ -317,13 +317,18 @@ String Options
copy of the underlying string, so it is valid to pass in a pointer to
an on-stack buffer.
 
-   There is just one string option specified this way:
-
.. macro:: GCC_JIT_STR_OPTION_PROGNAME
 
   The name of the program, for use as a prefix when printing error
   messages to stderr.  If `NULL`, or default, "libgccjit.so" is used.
 
+  .. macro:: GCC_JIT_STR_OPTION_SPECIAL_CHARS_IN_FUNC_NAMES
+
+  Alphabetic ASCII characters and underscores are always valid. Numeric
+  ASCII characters are always valid after the initial character of the
+  string. Use this entrypoint to specify additional ASCII characters that
+  are valid throughout function names (ex.: ".$").
+
 Boolean options
 ***
 
diff --git a/gcc/jit/jit-recording.cc b/gcc/jit/jit-recording.cc
index 7cbe383c79db..90ac5bdafffc 100644
--- a/gcc/jit/jit-recording.cc
+++ b/gcc/jit/jit-recording.cc
@@ -1424,6 +1424,18 @@ recording::context::set_str_option (enum 
gcc_jit_str_option opt,
   log_str_option (opt);
 }
 
+const char*
+recording::context::get_str_option (enum gcc_jit_str_option opt)
+{
+  if (opt < 0 || opt >= GCC_JIT_NUM_STR_OPTIONS)
+{
+  add_error (NULL,
+"unrecognized (enum gcc_jit_str_option) value: %i", opt);
+  return NULL;
+}
+  return m_str_options[opt];
+}
+
 /* Set the given integer option for this context, or add an error if
it's not recognized.
 
@@ -1765,7 +1777,8 @@ recording::context::dump_to_file (const char *path, bool 
update_locations)
 
 static const char * const
  str_option_reproducer_strings[GCC_JIT_NUM_STR_OPTIONS] = {
-  "GCC_JIT_STR_OPTION_PROGNAME"
+  "GCC_JIT_STR_OPTION_PROGNAME",
+  "GCC_JIT_STR_OPTION_SPECIAL_CHARS_IN_FUNC_NAMES",
 };
 
 static const char * const
@@ -1782,7 +1795,7 @@ static const char * const
   "GCC_JIT_BOOL_OPTION_DUMP_SUMMARY",
   "GCC_JIT_BOOL_OPTION_DUMP_EVERYTHING",
   "GCC_JIT_BOOL_OPTION_SELFCHECK_GC",
-  "GCC_JIT_BOOL_OPTION_KEEP_INTERMEDIATES"
+  "GCC_JIT_BOOL_OPTION_KEEP_INTERMEDIATES",
 };
 
 static const char * const
diff --git a/gcc/jit/jit-recording.h b/gcc/jit/jit-recording.h
index e5a920fac499..13c2ea735027 100644
--- a/gcc/jit/jit-recording.h
+++ b/gcc/jit/jit-recording.h
@@ -255,6 +255,9 @@ public:
   set_str_option (enum gcc_jit_str_option opt,
  const char *value);
 
+  const char*
+  get_str_option (enum gcc_jit_str_option opt);
+
   void
   set_int_option (enum gcc_jit_int_option opt,
  int value);
diff --git a/gcc/jit/libgccjit.cc b/gcc/jit/libgccjit.cc
index 63dee7049af9..3a7a4e26931f 100644
--- a/gcc/jit/libgccjit.cc
+++ b/gcc/jit/libgccjit.cc
@@ -1201,10 +1201,13 @@ gcc_jit_context_new_function (gcc_jit_context *ctxt,
  Eventually we'll need some way to interact with e.g. C++ name
  mangling.  */
   {
+const char* special_chars_allowed
+  = ctxt->get_str_option (GCC_JIT_STR_OPTION_SPECIAL_CHARS_IN_FUNC_NAMES);
 /* Leading char: */
 char ch = *name;
 RETURN_NULL_IF_FAIL_PRINTF2 (
-   ISALPHA (ch) || ch == '_',
+   ISALPHA (ch) || ch == '_' || (special_chars_allowed
+ && strchr (special_chars_allowed, ch)),
ctxt, loc,
"name \"%s\" contains invalid character: '%c'",
name, ch);
@@ -1212,7 +1215,8 @@ gcc_jit_context_new_function (gcc_jit_context *ctxt,
 for (const char *ptr = name + 1; (ch = *ptr); ptr++)
   {
RETURN_NULL_IF_FAIL_PRINTF2 (
- ISALNUM (ch) || ch == '_',
+ ISALNUM (ch) || ch == '_' || (special_chars_allowed
+   && strchr (spec

[gcc r15-6070] aarch64: Fix ICE happening in SET_TYPE_VECTOR_SUBPARTS with libgccjit

2024-12-09 Thread Antoni Boucher via Gcc-cvs
https://gcc.gnu.org/g:62fa2e434b60558a7c3b4c578fda744bde96

commit r15-6070-g62fa2e434b60558a7c3b4c578fda744bde96
Author: Antoni Boucher 
Date:   Wed Dec 4 20:59:53 2024 -0500

aarch64: Fix ICE happening in SET_TYPE_VECTOR_SUBPARTS with libgccjit

The structure aarch64_simd_type_info was split in 2 because we do not
want to reset the static members of aarch64_simd_type_info to their
default value. We only want the tree types to be GC-ed. This is
necessary for libgccjit which can run multiple times in the same
process. If the static values were GC-ed, the second run would
ICE/segfault because of their invalid value.

The following test suites passed for this patch:

 * The aarch64 tests.
 * The aarch64 regression tests.

The number of failures of the jit tests on aarch64 lowered from +100 to
~7.

gcc/ChangeLog:
PR target/117923
* config/aarch64/aarch64-builtins.cc: Remove GTY marker on 
aarch64_simd_types,
aarch64_simd_types_trees (new variable), rename aarch64_simd_types 
to
aarch64_simd_types_trees.
* config/aarch64/aarch64-builtins.h: Remove GTY marker on 
aarch64_simd_types,
aarch64_simd_types_trees (new variable).
* config/aarch64/aarch64-sve-builtins-shapes.cc: Rename 
aarch64_simd_types to
aarch64_simd_types_trees.
* config/aarch64/aarch64-sve-builtins.cc: Rename aarch64_simd_types 
to
aarch64_simd_types_trees.

Diff:
---
 gcc/config/aarch64/aarch64-builtins.cc| 129 --
 gcc/config/aarch64/aarch64-builtins.h |  29 +++--
 gcc/config/aarch64/aarch64-sve-builtins-shapes.cc |   4 +-
 gcc/config/aarch64/aarch64-sve-builtins.cc|   2 +-
 4 files changed, 95 insertions(+), 69 deletions(-)

diff --git a/gcc/config/aarch64/aarch64-builtins.cc 
b/gcc/config/aarch64/aarch64-builtins.cc
index f528592a17d8..02c73f11223c 100644
--- a/gcc/config/aarch64/aarch64-builtins.cc
+++ b/gcc/config/aarch64/aarch64-builtins.cc
@@ -983,16 +983,20 @@ const char *aarch64_scalar_builtin_types[] = {
   NULL
 };
 
-extern GTY(()) aarch64_simd_type_info aarch64_simd_types[];
+extern const aarch64_simd_type_info aarch64_simd_types[];
+extern GTY(()) aarch64_simd_type_info_trees aarch64_simd_types_trees[];
 
 #undef ENTRY
 #define ENTRY(E, M, Q, G)  \
-  {E, "__" #E, #G "__" #E, NULL_TREE, NULL_TREE, E_##M##mode, qualifier_##Q},
-struct aarch64_simd_type_info aarch64_simd_types [] = {
+  {E, "__" #E, #G "__" #E, E_##M##mode, qualifier_##Q},
+const struct aarch64_simd_type_info aarch64_simd_types[] = {
 #include "aarch64-simd-builtin-types.def"
 };
 #undef ENTRY
 
+struct aarch64_simd_type_info_trees
+aarch64_simd_types_trees[ARRAY_SIZE (aarch64_simd_types)];
+
 static machine_mode aarch64_simd_tuple_modes[ARM_NEON_H_TYPES_LAST][3];
 static GTY(()) tree aarch64_simd_tuple_types[ARM_NEON_H_TYPES_LAST][3];
 
@@ -1133,7 +1137,7 @@ aarch64_lookup_simd_type_in_table (machine_mode mode,
 {
   if (aarch64_simd_types[i].mode == mode
  && aarch64_simd_types[i].q == q)
-   return aarch64_simd_types[i].itype;
+   return aarch64_simd_types_trees[i].itype;
   if (aarch64_simd_tuple_types[i][0] != NULL_TREE)
for (int j = 0; j < 3; j++)
  if (aarch64_simd_tuple_modes[i][j] == mode
@@ -1180,66 +1184,76 @@ aarch64_init_simd_builtin_types (void)
   tree tdecl;
 
   /* Init all the element types built by the front-end.  */
-  aarch64_simd_types[Int8x8_t].eltype = intQI_type_node;
-  aarch64_simd_types[Int8x16_t].eltype = intQI_type_node;
-  aarch64_simd_types[Int16x4_t].eltype = intHI_type_node;
-  aarch64_simd_types[Int16x8_t].eltype = intHI_type_node;
-  aarch64_simd_types[Int32x2_t].eltype = intSI_type_node;
-  aarch64_simd_types[Int32x4_t].eltype = intSI_type_node;
-  aarch64_simd_types[Int64x1_t].eltype = intDI_type_node;
-  aarch64_simd_types[Int64x2_t].eltype = intDI_type_node;
-  aarch64_simd_types[Uint8x8_t].eltype = unsigned_intQI_type_node;
-  aarch64_simd_types[Uint8x16_t].eltype = unsigned_intQI_type_node;
-  aarch64_simd_types[Uint16x4_t].eltype = unsigned_intHI_type_node;
-  aarch64_simd_types[Uint16x8_t].eltype = unsigned_intHI_type_node;
-  aarch64_simd_types[Uint32x2_t].eltype = unsigned_intSI_type_node;
-  aarch64_simd_types[Uint32x4_t].eltype = unsigned_intSI_type_node;
-  aarch64_simd_types[Uint64x1_t].eltype = unsigned_intDI_type_node;
-  aarch64_simd_types[Uint64x2_t].eltype = unsigned_intDI_type_node;
+  aarch64_simd_types_trees[Int8x8_t].eltype = intQI_type_node;
+  aarch64_simd_types_trees[Int8x16_t].eltype = intQI_type_node;
+  aarch64_simd_types_trees[Int16x4_t].eltype = intHI_type_node;
+  aarch64_simd_types_trees[Int16x8_t].eltype = intHI_type_node;
+  aarch64_simd_types_trees[Int32x2_t].eltype = intSI_type_node;
+  aarch64_simd_types_trees[Int32x4_t].eltype = intSI_type_node;
+  aarch64_simd_types_trees[Int64x1_t].eltype = intDI_type_