From: Antoni Boucher <[email protected]>

gcc/jit/ChangeLog:

        * Make-lang.in: Define new variables.
        * docs/topics/compatibility.rst (LIBGCCJIT_ABI_36): New ABI tag.
        * docs/topics/compilation.rst: Document gcc_jit_is_lto_supported.
        * libgccjit.cc (gcc_jit_is_lto_supported): New function.
        * libgccjit.h (gcc_jit_is_lto_supported): New function.
        * libgccjit.map (LIBGCCJIT_ABI_36): New ABI tag.
---
 gcc/jit/Make-lang.in                  |  4 ++++
 gcc/jit/docs/topics/compatibility.rst |  8 ++++++++
 gcc/jit/docs/topics/compilation.rst   | 13 +++++++++++++
 gcc/jit/libgccjit.cc                  | 16 ++++++++++++++++
 gcc/jit/libgccjit.h                   |  5 +++++
 gcc/jit/libgccjit.map                 |  5 +++++
 6 files changed, 51 insertions(+)

diff --git a/gcc/jit/Make-lang.in b/gcc/jit/Make-lang.in
index 0429137d694..05a3f6ad23a 100644
--- a/gcc/jit/Make-lang.in
+++ b/gcc/jit/Make-lang.in
@@ -130,6 +130,10 @@ jit.serial = $(LIBGCCJIT_FILENAME)
 # Tell GNU make to ignore these if they exist.
 .PHONY: jit
 
+CFLAGS-jit/libgccjit.o += -DDEFAULT_TARGET_VERSION=\"$(version)\" \
+	-DDEFAULT_TARGET_MACHINE=\"$(target_noncanonical)\" \
+	-DSTANDARD_LIBEXEC_PREFIX=\"$(libexecdir)/gcc/\"
+
 JIT_OBJS = attribs.o \
 	jit/dummy-frontend.o \
 	jit/libgccjit.o \
diff --git a/gcc/jit/docs/topics/compatibility.rst b/gcc/jit/docs/topics/compatibility.rst
index 19be33eb4b5..b2f73b64949 100644
--- a/gcc/jit/docs/topics/compatibility.rst
+++ b/gcc/jit/docs/topics/compatibility.rst
@@ -466,3 +466,11 @@ information:
   * :func:`gcc_jit_target_info_cpu_supports`
   * :func:`gcc_jit_target_info_arch`
   * :func:`gcc_jit_target_info_supports_target_dependent_type`
+
+.. _LIBGCCJIT_ABI_36:
+
+``LIBGCCJIT_ABI_36``
+--------------------
+``LIBGCCJIT_ABI_36`` covers the addition of
+
+ * :func:`gcc_jit_is_lto_supported`
diff --git a/gcc/jit/docs/topics/compilation.rst b/gcc/jit/docs/topics/compilation.rst
index 80c80af510d..df6670cd6ea 100644
--- a/gcc/jit/docs/topics/compilation.rst
+++ b/gcc/jit/docs/topics/compilation.rst
@@ -255,3 +255,16 @@ You can query the target information by using the following API:
    .. code-block:: c
 
       #ifdef LIBGCCJIT_HAVE_TARGET_INFO_API
+
+.. function:: bool
+              gcc_jit_is_lto_supported ()
+
+   Get whether LTO is enabled in this GCC config and whether the LTO frontend
+   executable is found.
+
+   This API entrypoint was added in :ref:`LIBGCCJIT_ABI_36`; you can test
+   for its presence using
+
+   .. code-block:: c
+
+      #ifdef LIBGCCJIT_HAVE_gcc_jit_is_lto_supported
diff --git a/gcc/jit/libgccjit.cc b/gcc/jit/libgccjit.cc
index 33369447074..846e92ba8ea 100644
--- a/gcc/jit/libgccjit.cc
+++ b/gcc/jit/libgccjit.cc
@@ -4706,3 +4706,19 @@ gcc_jit_context_add_top_level_asm (gcc_jit_context *ctxt,
   RETURN_IF_FAIL (asm_stmts, ctxt, NULL, "NULL asm_stmts");
   ctxt->add_top_level_asm (loc, asm_stmts);
 }
+
+bool
+gcc_jit_is_lto_supported ()
+{
+#ifdef ENABLE_LTO
+  char lto1_path[PATH_MAX];
+  snprintf (lto1_path, sizeof (lto1_path), "%s%s/%s/lto1",
+    STANDARD_LIBEXEC_PREFIX, DEFAULT_TARGET_MACHINE, DEFAULT_TARGET_VERSION);
+  if (access (lto1_path, X_OK) == 0)
+  {
+    return true;
+  }
+#endif
+
+  return false;
+}
diff --git a/gcc/jit/libgccjit.h b/gcc/jit/libgccjit.h
index a5855100793..feaeb8c39b1 100644
--- a/gcc/jit/libgccjit.h
+++ b/gcc/jit/libgccjit.h
@@ -2216,6 +2216,11 @@ gcc_jit_context_set_output_ident (gcc_jit_context *ctxt,
 
 #define LIBGCCJIT_HAVE_gcc_jit_context_set_output_ident
 
+extern bool
+gcc_jit_is_lto_supported ();
+
+#define LIBGCCJIT_HAVE_gcc_jit_is_lto_supported
+
 #ifdef __cplusplus
 }
 #endif /* __cplusplus */
diff --git a/gcc/jit/libgccjit.map b/gcc/jit/libgccjit.map
index 4662ca4b3c0..8332e1b0e47 100644
--- a/gcc/jit/libgccjit.map
+++ b/gcc/jit/libgccjit.map
@@ -334,3 +334,8 @@ LIBGCCJIT_ABI_35 {
     gcc_jit_target_info_arch;
     gcc_jit_target_info_supports_target_dependent_type;
 } LIBGCCJIT_ABI_34;
+
+LIBGCCJIT_ABI_36 {
+  global:
+    gcc_jit_is_lto_supported;
+} LIBGCCJIT_ABI_35;

Reply via email to