diff --git a/gcc/jit/docs/topics/compatibility.rst b/gcc/jit/docs/topics/compatibility.rst index 1c4b81bfff1ad..0f2159072ea8b 100644 --- a/gcc/jit/docs/topics/compatibility.rst +++ b/gcc/jit/docs/topics/compatibility.rst @@ -453,3 +453,10 @@ temporary variable: ``LIBGCCJIT_ABI_34`` covers the addition of * :func:`gcc_jit_context_set_output_ident` + +``LIBGCCJIT_ABI_44`` +-------------------- +``LIBGCCJIT_ABI_44`` covers the addition of a function to get the name +of an lvalue. + + * :func:`gcc_jit_lvalue_get_name` diff --git a/gcc/jit/docs/topics/expressions.rst b/gcc/jit/docs/topics/expressions.rst index 5dcb5d10bce8f..2525e8836e468 100644 --- a/gcc/jit/docs/topics/expressions.rst +++ b/gcc/jit/docs/topics/expressions.rst @@ -923,6 +923,18 @@ where the rvalue is computed by reading from the storage area. #ifdef LIBGCCJIT_HAVE_ALIGNMENT +.. function:: const char *\ + gcc_jit_lvalue_get_name (gcc_jit_lvalue *lvalue) + + Returns the name of an lvalue. + + This entrypoint was added in :ref:`LIBGCCJIT_ABI_44`; you can test for + its present using + + .. code-block:: c + + #ifdef LIBGCCJIT_HAVE_gcc_jit_lvalue_get_name + Global variables **************** diff --git a/gcc/jit/jit-recording.h b/gcc/jit/jit-recording.h index 4e069a8f6fb66..8ee1987330264 100644 --- a/gcc/jit/jit-recording.h +++ b/gcc/jit/jit-recording.h @@ -1499,6 +1499,7 @@ class lvalue : public rvalue void set_register_name (const char *reg_name); void set_alignment (unsigned bytes); unsigned get_alignment () const { return m_alignment; } + virtual string * get_name () const { return NULL; } protected: string *m_link_section; @@ -1539,6 +1540,8 @@ class param : public lvalue const char *access_as_rvalue (reproducer &r) final override; const char *access_as_lvalue (reproducer &r) final override; + string * get_name () const final override { return m_name; } + private: string * make_debug_string () final override { return m_name; } void write_reproducer (reproducer &r) final override; @@ -1807,6 +1810,8 @@ class global : public lvalue void set_rvalue_init (rvalue *val) { m_rvalue_init = val; } + string * get_name () const final override { return m_name; } + private: string * make_debug_string () final override { return m_name; } template diff --git a/gcc/jit/libgccjit.cc b/gcc/jit/libgccjit.cc index 84a88b276f681..9117e748bbb54 100644 --- a/gcc/jit/libgccjit.cc +++ b/gcc/jit/libgccjit.cc @@ -4842,6 +4842,22 @@ gcc_jit_context_add_top_level_asm (gcc_jit_context *ctxt, ctxt->add_top_level_asm (loc, asm_stmts); } +/* Public entrypoint. See description in libgccjit.h. + + After error-checking, this calls the trivial + gcc::jit::recording::lvalue::get_name method, in jit-recording.h. */ + +extern const char * +gcc_jit_lvalue_get_name (gcc_jit_lvalue *lvalue) +{ + RETURN_NULL_IF_FAIL (lvalue, NULL, NULL, "NULL lvalue"); + auto name = lvalue->get_name (); + + if (!name) + return NULL; + return name->c_str (); +} + /* Public entrypoint. See description in libgccjit.h. After error-checking, this calls the trivial diff --git a/gcc/jit/libgccjit.h b/gcc/jit/libgccjit.h index 4a4ebe3a6df15..9218ca856a335 100644 --- a/gcc/jit/libgccjit.h +++ b/gcc/jit/libgccjit.h @@ -2236,6 +2236,12 @@ gcc_jit_lvalue_add_string_attribute (gcc_jit_lvalue *variable, enum gcc_jit_variable_attribute attribute, const char* value); +/* Returns the name of the `lvalue`, if any. Returns NULL otherwise. */ +extern const char * +gcc_jit_lvalue_get_name (gcc_jit_lvalue *lvalue); + +#define LIBGCCJIT_HAVE_gcc_jit_lvalue_get_name + extern void gcc_jit_context_set_output_ident (gcc_jit_context *ctxt, const char* output_ident); diff --git a/gcc/jit/libgccjit.map b/gcc/jit/libgccjit.map index ad9dc1ccad109..6e5ad4d805a2b 100644 --- a/gcc/jit/libgccjit.map +++ b/gcc/jit/libgccjit.map @@ -377,4 +377,9 @@ LIBGCCJIT_ABI_42 { LIBGCCJIT_ABI_43{ global: gcc_jit_type_set_tree_addressable; -} LIBGCCJIT_ABI_42; \ No newline at end of file +} LIBGCCJIT_ABI_42; + +LIBGCCJIT_ABI_44{ + global: + gcc_jit_lvalue_get_name; +} LIBGCCJIT_ABI_43; diff --git a/gcc/testsuite/jit.dg/test-tls.c b/gcc/testsuite/jit.dg/test-tls.c index 3b20182ac1071..a6a967eac56ff 100644 --- a/gcc/testsuite/jit.dg/test-tls.c +++ b/gcc/testsuite/jit.dg/test-tls.c @@ -28,6 +28,8 @@ create_code (gcc_jit_context *ctxt, void *user_data) ctxt, NULL, GCC_JIT_GLOBAL_EXPORTED, int_type, "foo"); gcc_jit_lvalue_set_tls_model (foo, GCC_JIT_TLS_MODEL_GLOBAL_DYNAMIC); + CHECK_STRING_VALUE (gcc_jit_lvalue_get_name (foo), "foo"); + /* Build the test_fn. */ gcc_jit_function *test_fn = gcc_jit_context_new_function (ctxt, NULL,