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 Dec 16, 2021
1 parent 17ebc14 commit a68a29f
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 6 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 @@ -706,6 +707,14 @@ class lvalue : public rvalue
set_decl_section_name (as_tree (), name);
}

void
set_reg_name (const char* reg_name)
{
set_user_assembler_name (as_tree (), reg_name);
DECL_REGISTER (as_tree ()) = 1;
DECL_HARD_REGISTER (as_tree ()) = 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 @@ -3900,6 +3900,11 @@ void recording::lvalue::set_link_section (const char *name)
m_link_section = new_string (name);
}

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 @@ -6486,11 +6491,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
9 changes: 6 additions & 3 deletions gcc/jit/jit-recording.h
Original file line number Diff line number Diff line change
Expand Up @@ -1152,8 +1152,9 @@ class lvalue : public rvalue
location *loc,
type *type_)
: rvalue (ctxt, loc, type_),
m_tls_model (GCC_JIT_TLS_MODEL_NONE),
m_link_section (NULL)
m_link_section (NULL),
m_reg_name (NULL),
m_tls_model (GCC_JIT_TLS_MODEL_NONE)
{}

playback::lvalue *
Expand All @@ -1177,10 +1178,12 @@ class lvalue : public rvalue
virtual bool is_global () const { return false; }
void set_tls_model (enum gcc_jit_tls_model model);
void set_link_section (const char *name);
void set_register_name (const char *reg_name);

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

class param : public lvalue
Expand Down
13 changes: 13 additions & 0 deletions gcc/jit/libgccjit.c
Original file line number Diff line number Diff line change
Expand Up @@ -2677,6 +2677,19 @@ gcc_jit_lvalue_set_link_section (gcc_jit_lvalue *lvalue,
lvalue->set_link_section (section_name);
}

/* 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 @@ -1297,6 +1297,11 @@ extern void
gcc_jit_lvalue_set_link_section (gcc_jit_lvalue *lvalue,
const char *section_name);

/* 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 @@ -249,3 +249,8 @@ LIBGCCJIT_ABI_20 {
global:
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 a68a29f

Please sign in to comment.