Skip to content

Commit

Permalink
Add support for register variable
Browse files Browse the repository at this point in the history
  • Loading branch information
antoyo committed Aug 29, 2021
1 parent cc8b57d commit 18d948a
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 3 deletions.
9 changes: 9 additions & 0 deletions gcc/jit/jit-playback.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ along with GCC; see the file COPYING3. If not see
#include <utility> // for std::pair

#include "timevar.h"
#include "varasm.h"

#include "jit-recording.h"

Expand Down Expand Up @@ -696,6 +697,14 @@ class lvalue : public rvalue
set_decl_tls_model (m_inner, tls_model);
}

void
set_reg_name (const char* reg_name)
{
set_user_assembler_name (m_inner, reg_name);
DECL_REGISTER (m_inner) = 1;
DECL_HARD_REGISTER (m_inner) = 1;
}

private:
bool mark_addressable (location *loc);
};
Expand Down
15 changes: 12 additions & 3 deletions gcc/jit/jit-recording.c
Original file line number Diff line number Diff line change
Expand Up @@ -3827,6 +3827,11 @@ recording::lvalue::set_tls_model (enum gcc_jit_tls_model model)
m_tls_model = model;
}

void recording::lvalue::set_register_name (const char *reg_name)
{
m_reg_name = new_string (reg_name);
}

/* The implementation of class gcc::jit::recording::param. */

/* Implementation of pure virtual hook recording::memento::replay_into
Expand Down Expand Up @@ -6234,11 +6239,15 @@ recording::function_pointer::write_reproducer (reproducer &r)
void
recording::local::replay_into (replayer *r)
{
set_playback_obj (
m_func->playback_function ()
playback::lvalue *obj = m_func->playback_function ()
->new_local (playback_location (r, m_loc),
m_type->playback_type (),
playback_string (m_name)));
playback_string (m_name));
if (m_reg_name != NULL)
{
obj->set_reg_name(m_reg_name->c_str());
}
set_playback_obj (obj);
}

/* Override the default implementation of
Expand Down
3 changes: 3 additions & 0 deletions gcc/jit/jit-recording.h
Original file line number Diff line number Diff line change
Expand Up @@ -1119,6 +1119,7 @@ class lvalue : public rvalue
type *type_)
: rvalue (ctxt, loc, type_),
m_link_section (NULL),
m_reg_name (NULL),
m_tls_model (GCC_JIT_TLS_MODEL_DEFAULT)
{}

Expand All @@ -1143,9 +1144,11 @@ class lvalue : public rvalue
virtual bool is_global () const { return false; }
void set_link_section (const char *name);
void set_tls_model (enum gcc_jit_tls_model model);
void set_register_name (const char *reg_name);

protected:
string *m_link_section;
string *m_reg_name;
enum gcc_jit_tls_model m_tls_model;
};

Expand Down
13 changes: 13 additions & 0 deletions gcc/jit/libgccjit.c
Original file line number Diff line number Diff line change
Expand Up @@ -2310,6 +2310,19 @@ gcc_jit_lvalue_set_tls_model (gcc_jit_lvalue *lvalue,
lvalue->set_tls_model (model);
}

/* Public entrypoint. See description in libgccjit.h.
After error-checking, the real work is done by the
gcc::jit::recording::lvalue::set_register_name method in jit-recording.c. */

void
gcc_jit_lvalue_set_register_name (gcc_jit_lvalue *lvalue,
const char *reg_name)
{
// TODO: support global variables?
lvalue->set_register_name (reg_name);
}

/* Public entrypoint. See description in libgccjit.h.
After error-checking, the real work is done by the
Expand Down
5 changes: 5 additions & 0 deletions gcc/jit/libgccjit.h
Original file line number Diff line number Diff line change
Expand Up @@ -1156,6 +1156,11 @@ extern void
gcc_jit_lvalue_set_tls_model (gcc_jit_lvalue *lvalue,
enum gcc_jit_tls_model model);

/* Make this variable a register variable and set its register name. */
void
gcc_jit_lvalue_set_register_name (gcc_jit_lvalue *lvalue,
const char *reg_name);

extern gcc_jit_lvalue *
gcc_jit_function_new_local (gcc_jit_function *func,
gcc_jit_location *loc,
Expand Down
5 changes: 5 additions & 0 deletions gcc/jit/libgccjit.map
Original file line number Diff line number Diff line change
Expand Up @@ -245,3 +245,8 @@ LIBGCCJIT_ABI_19 {
LIBGCCJIT_ABI_20 {
gcc_jit_context_new_bitcast;
} LIBGCCJIT_ABI_19;

LIBGCCJIT_ABI_21 {
global:
gcc_jit_lvalue_set_register_name;
} LIBGCCJIT_ABI_20;

0 comments on commit 18d948a

Please sign in to comment.