aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorAndreaCorallo <andrea.corallo@arm.com>2020-03-08 13:46:33 +0000
committerAndrea Corallo <andrea.corallo@arm.com>2020-03-31 20:57:15 +0200
commit63b2923dc6f57e74d964a9cf14f4ba595ab14ed9 (patch)
tree03f4850f666021f4378a87062e2900281dd852ef /gcc
parent689418b97e5eb6a221871a2439bca3e6283ac579 (diff)
downloadgcc-63b2923dc6f57e74d964a9cf14f4ba595ab14ed9.zip
gcc-63b2923dc6f57e74d964a9cf14f4ba595ab14ed9.tar.gz
gcc-63b2923dc6f57e74d964a9cf14f4ba595ab14ed9.tar.bz2
libgccjit: add new version entry point
gcc/jit/ChangeLog 2020-03-31 Andrea Corallo <andrea.corallo@arm.com> David Malcolm <dmalcolm@redhat.com> * docs/topics/compatibility.rst (LIBGCCJIT_ABI_13): New ABI tag plus add version paragraph. * libgccjit++.h (namespace gccjit::version): Add new namespace. * libgccjit.c (gcc_jit_version_major, gcc_jit_version_minor) (gcc_jit_version_patchlevel): New functions. * libgccjit.h (LIBGCCJIT_HAVE_gcc_jit_version): New macro. (gcc_jit_version_major, gcc_jit_version_minor) (gcc_jit_version_patchlevel): New functions. * libgccjit.map (LIBGCCJIT_ABI_13) New ABI tag. gcc/testsuite/ChangeLog 2020-03-31 Andrea Corallo <andrea.corallo@arm.com> * jit.dg/test-version.c: New testcase. * jit.dg/all-non-failing-tests.h: Add test-version.c.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/jit/ChangeLog13
-rw-r--r--gcc/jit/docs/topics/compatibility.rst33
-rw-r--r--gcc/jit/libgccjit++.h22
-rw-r--r--gcc/jit/libgccjit.c46
-rw-r--r--gcc/jit/libgccjit.h16
-rw-r--r--gcc/jit/libgccjit.map9
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/jit.dg/all-non-failing-tests.h10
-rw-r--r--gcc/testsuite/jit.dg/test-version.c26
9 files changed, 179 insertions, 1 deletions
diff --git a/gcc/jit/ChangeLog b/gcc/jit/ChangeLog
index 5d39b7b..d69a6a8 100644
--- a/gcc/jit/ChangeLog
+++ b/gcc/jit/ChangeLog
@@ -1,3 +1,16 @@
+2020-03-31 Andrea Corallo <andrea.corallo@arm.com>
+ David Malcolm <dmalcolm@redhat.com>
+
+ * docs/topics/compatibility.rst (LIBGCCJIT_ABI_13): New ABI tag
+ plus add version paragraph.
+ * libgccjit++.h (namespace gccjit::version): Add new namespace.
+ * libgccjit.c (gcc_jit_version_major, gcc_jit_version_minor)
+ (gcc_jit_version_patchlevel): New functions.
+ * libgccjit.h (LIBGCCJIT_HAVE_gcc_jit_version): New macro.
+ (gcc_jit_version_major, gcc_jit_version_minor)
+ (gcc_jit_version_patchlevel): New functions.
+ * libgccjit.map (LIBGCCJIT_ABI_13) New ABI tag.
+
2020-03-23 Andrea Corallo <andrea.corallo@arm.com>
* jit-playback.h
diff --git a/gcc/jit/docs/topics/compatibility.rst b/gcc/jit/docs/topics/compatibility.rst
index a6faee0..0c0ce07 100644
--- a/gcc/jit/docs/topics/compatibility.rst
+++ b/gcc/jit/docs/topics/compatibility.rst
@@ -61,6 +61,28 @@ You can see the symbol tags provided by libgccjit.so using ``objdump``:
LIBGCCJIT_ABI_0
[...snip...]
+Programmatically checking version
+***************
+
+Client code can programmatically check libgccjit version using:
+
+.. function:: int gcc_jit_version_major (void)
+
+ Return libgccjit major version. This is analogous to __GNUC__ in C code.
+
+.. function:: int gcc_jit_version_minor (void)
+
+ Return libgccjit minor version. This is analogous to
+ __GNUC_MINOR__ in C code.
+
+.. function:: int gcc_jit_version_patchlevel (void)
+
+ Return libgccjit patchlevel version. This is analogous to
+ __GNUC_PATCHLEVEL__ in C code.
+
+.. note:: These entry points has been added with ``LIBGCCJIT_ABI_13``
+ (see below).
+
ABI symbol tags
***************
@@ -182,3 +204,14 @@ entrypoints:
--------------------
``LIBGCCJIT_ABI_12`` covers the addition of
:func:`gcc_jit_context_new_bitfield`
+
+``LIBGCCJIT_ABI_13``
+--------------------
+``LIBGCCJIT_ABI_13`` covers the addition of version functions via API
+entrypoints:
+
+ * :func:`gcc_jit_version_major`
+
+ * :func:`gcc_jit_version_minor`
+
+ * :func:`gcc_jit_version_patchlevel`
diff --git a/gcc/jit/libgccjit++.h b/gcc/jit/libgccjit++.h
index 82a62d6..69e6776 100644
--- a/gcc/jit/libgccjit++.h
+++ b/gcc/jit/libgccjit++.h
@@ -49,6 +49,8 @@ namespace gccjit
class timer;
class auto_time;
+ namespace version {};
+
/* Errors within the API become C++ exceptions of this class. */
class error
{
@@ -1913,6 +1915,26 @@ auto_time::~auto_time ()
m_timer.pop (m_item_name);
}
+namespace version
+{
+inline int
+major_v ()
+{
+ return gcc_jit_version_major ();
+}
+
+inline int
+minor_v ()
+{
+ return gcc_jit_version_minor ();
+}
+
+inline int
+patchlevel_v ()
+{
+ return gcc_jit_version_patchlevel ();
+}
+} // namespace version
} // namespace gccjit
#endif /* #ifndef LIBGCCJIT_PLUS_PLUS_H */
diff --git a/gcc/jit/libgccjit.c b/gcc/jit/libgccjit.c
index 83055fc..a29e988 100644
--- a/gcc/jit/libgccjit.c
+++ b/gcc/jit/libgccjit.c
@@ -23,6 +23,8 @@ along with GCC; see the file COPYING3. If not see
#include "coretypes.h"
#include "timevar.h"
#include "typed-splay-tree.h"
+#include "cppbuiltin.h"
+#include <pthread.h>
#include "libgccjit.h"
#include "jit-recording.h"
@@ -3175,3 +3177,47 @@ gcc_jit_context_new_rvalue_from_vector (gcc_jit_context *ctxt,
as_vec_type,
(gcc::jit::recording::rvalue **)elements);
}
+
+/* A mutex around the cached state in parse_basever.
+ Ideally this would be within parse_basever, but the mutex is only needed
+ by libgccjit. */
+
+static pthread_mutex_t version_mutex = PTHREAD_MUTEX_INITIALIZER;
+
+struct version_info
+{
+ /* Default constructor. Populate via parse_basever,
+ guarded by version_mutex. */
+ version_info ()
+ {
+ pthread_mutex_lock (&version_mutex);
+ parse_basever (&major, &minor, &patchlevel);
+ pthread_mutex_unlock (&version_mutex);
+ }
+
+ int major;
+ int minor;
+ int patchlevel;
+};
+
+
+extern int
+gcc_jit_version_major (void)
+{
+ version_info vi;
+ return vi.major;
+}
+
+extern int
+gcc_jit_version_minor (void)
+{
+ version_info vi;
+ return vi.minor;
+}
+
+extern int
+gcc_jit_version_patchlevel (void)
+{
+ version_info vi;
+ return vi.patchlevel;
+}
diff --git a/gcc/jit/libgccjit.h b/gcc/jit/libgccjit.h
index 21a0dc0..1c5a12e 100644
--- a/gcc/jit/libgccjit.h
+++ b/gcc/jit/libgccjit.h
@@ -1487,6 +1487,22 @@ gcc_jit_context_new_rvalue_from_vector (gcc_jit_context *ctxt,
size_t num_elements,
gcc_jit_rvalue **elements);
+#define LIBGCCJIT_HAVE_gcc_jit_version
+
+/* Functions to retrive libgccjit version.
+ Analogous to __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__ in C code.
+
+ These API entrypoints were added in LIBGCCJIT_ABI_13; you can test for their
+ presence using
+ #ifdef LIBGCCJIT_HAVE_gcc_jit_version
+ */
+extern int
+gcc_jit_version_major (void);
+extern int
+gcc_jit_version_minor (void);
+extern int
+gcc_jit_version_patchlevel (void);
+
#ifdef __cplusplus
}
#endif /* __cplusplus */
diff --git a/gcc/jit/libgccjit.map b/gcc/jit/libgccjit.map
index 4514bd3..6137dd4 100644
--- a/gcc/jit/libgccjit.map
+++ b/gcc/jit/libgccjit.map
@@ -179,4 +179,11 @@ LIBGCCJIT_ABI_11 {
LIBGCCJIT_ABI_12 {
global:
gcc_jit_context_new_bitfield;
-} LIBGCCJIT_ABI_11; \ No newline at end of file
+} LIBGCCJIT_ABI_11;
+
+LIBGCCJIT_ABI_13 {
+ global:
+ gcc_jit_version_major;
+ gcc_jit_version_minor;
+ gcc_jit_version_patchlevel;
+} LIBGCCJIT_ABI_12; \ No newline at end of file
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 008acc6..220789f 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2020-03-31 Andrea Corallo <andrea.corallo@arm.com>
+
+ * jit.dg/test-version.c: New testcase.
+ * jit.dg/all-non-failing-tests.h: Add test-version.c.
+
2020-03-31 Iain Buclaw <ibuclaw@gdcproject.org>
PR d/94424
diff --git a/gcc/testsuite/jit.dg/all-non-failing-tests.h b/gcc/testsuite/jit.dg/all-non-failing-tests.h
index af74419..ad469da 100644
--- a/gcc/testsuite/jit.dg/all-non-failing-tests.h
+++ b/gcc/testsuite/jit.dg/all-non-failing-tests.h
@@ -268,6 +268,13 @@
/* test-vector-types.cc: We don't use this, since it's C++. */
+/* test-version.c */
+#define create_code create_code_version
+#define verify_code verify_code_version
+#include "test-version.c"
+#undef create_code
+#undef verify_code
+
/* test-volatile.c */
#define create_code create_code_volatile
#define verify_code verify_code_volatile
@@ -392,6 +399,9 @@ const struct testcase testcases[] = {
{"using_global",
create_code_using_global,
verify_code_using_global},
+ {"version",
+ create_code_version,
+ verify_code_version},
{"volatile",
create_code_volatile,
verify_code_volatile}
diff --git a/gcc/testsuite/jit.dg/test-version.c b/gcc/testsuite/jit.dg/test-version.c
new file mode 100644
index 0000000..4338a00
--- /dev/null
+++ b/gcc/testsuite/jit.dg/test-version.c
@@ -0,0 +1,26 @@
+#include <stdlib.h>
+#include <stdio.h>
+
+#include "libgccjit.h"
+
+#include "harness.h"
+
+#ifndef LIBGCCJIT_HAVE_gcc_jit_version
+#error LIBGCCJIT_HAVE_gcc_jit_version was not defined
+#endif
+
+void
+create_code (gcc_jit_context *ctxt, void *user_data)
+{
+ /* Do nothing. */
+}
+
+void
+verify_code (gcc_jit_context *ctxt, gcc_jit_result *result)
+{
+ if (!gcc_jit_version_major ())
+ fail ("Major version is zero");
+ /* Minor and patchlevel can be zero. */
+ gcc_jit_version_minor ();
+ gcc_jit_version_patchlevel ();
+}