Skip to content

Commit 18d948a

Browse files
committed
Add support for register variable
1 parent cc8b57d commit 18d948a

File tree

6 files changed

+47
-3
lines changed

6 files changed

+47
-3
lines changed

gcc/jit/jit-playback.h

+9
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ along with GCC; see the file COPYING3. If not see
2424
#include <utility> // for std::pair
2525

2626
#include "timevar.h"
27+
#include "varasm.h"
2728

2829
#include "jit-recording.h"
2930

@@ -696,6 +697,14 @@ class lvalue : public rvalue
696697
set_decl_tls_model (m_inner, tls_model);
697698
}
698699

700+
void
701+
set_reg_name (const char* reg_name)
702+
{
703+
set_user_assembler_name (m_inner, reg_name);
704+
DECL_REGISTER (m_inner) = 1;
705+
DECL_HARD_REGISTER (m_inner) = 1;
706+
}
707+
699708
private:
700709
bool mark_addressable (location *loc);
701710
};

gcc/jit/jit-recording.c

+12-3
Original file line numberDiff line numberDiff line change
@@ -3827,6 +3827,11 @@ recording::lvalue::set_tls_model (enum gcc_jit_tls_model model)
38273827
m_tls_model = model;
38283828
}
38293829

3830+
void recording::lvalue::set_register_name (const char *reg_name)
3831+
{
3832+
m_reg_name = new_string (reg_name);
3833+
}
3834+
38303835
/* The implementation of class gcc::jit::recording::param. */
38313836

38323837
/* Implementation of pure virtual hook recording::memento::replay_into
@@ -6234,11 +6239,15 @@ recording::function_pointer::write_reproducer (reproducer &r)
62346239
void
62356240
recording::local::replay_into (replayer *r)
62366241
{
6237-
set_playback_obj (
6238-
m_func->playback_function ()
6242+
playback::lvalue *obj = m_func->playback_function ()
62396243
->new_local (playback_location (r, m_loc),
62406244
m_type->playback_type (),
6241-
playback_string (m_name)));
6245+
playback_string (m_name));
6246+
if (m_reg_name != NULL)
6247+
{
6248+
obj->set_reg_name(m_reg_name->c_str());
6249+
}
6250+
set_playback_obj (obj);
62426251
}
62436252

62446253
/* Override the default implementation of

gcc/jit/jit-recording.h

+3
Original file line numberDiff line numberDiff line change
@@ -1119,6 +1119,7 @@ class lvalue : public rvalue
11191119
type *type_)
11201120
: rvalue (ctxt, loc, type_),
11211121
m_link_section (NULL),
1122+
m_reg_name (NULL),
11221123
m_tls_model (GCC_JIT_TLS_MODEL_DEFAULT)
11231124
{}
11241125

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

11471149
protected:
11481150
string *m_link_section;
1151+
string *m_reg_name;
11491152
enum gcc_jit_tls_model m_tls_model;
11501153
};
11511154

gcc/jit/libgccjit.c

+13
Original file line numberDiff line numberDiff line change
@@ -2310,6 +2310,19 @@ gcc_jit_lvalue_set_tls_model (gcc_jit_lvalue *lvalue,
23102310
lvalue->set_tls_model (model);
23112311
}
23122312

2313+
/* Public entrypoint. See description in libgccjit.h.
2314+
2315+
After error-checking, the real work is done by the
2316+
gcc::jit::recording::lvalue::set_register_name method in jit-recording.c. */
2317+
2318+
void
2319+
gcc_jit_lvalue_set_register_name (gcc_jit_lvalue *lvalue,
2320+
const char *reg_name)
2321+
{
2322+
// TODO: support global variables?
2323+
lvalue->set_register_name (reg_name);
2324+
}
2325+
23132326
/* Public entrypoint. See description in libgccjit.h.
23142327
23152328
After error-checking, the real work is done by the

gcc/jit/libgccjit.h

+5
Original file line numberDiff line numberDiff line change
@@ -1156,6 +1156,11 @@ extern void
11561156
gcc_jit_lvalue_set_tls_model (gcc_jit_lvalue *lvalue,
11571157
enum gcc_jit_tls_model model);
11581158

1159+
/* Make this variable a register variable and set its register name. */
1160+
void
1161+
gcc_jit_lvalue_set_register_name (gcc_jit_lvalue *lvalue,
1162+
const char *reg_name);
1163+
11591164
extern gcc_jit_lvalue *
11601165
gcc_jit_function_new_local (gcc_jit_function *func,
11611166
gcc_jit_location *loc,

gcc/jit/libgccjit.map

+5
Original file line numberDiff line numberDiff line change
@@ -245,3 +245,8 @@ LIBGCCJIT_ABI_19 {
245245
LIBGCCJIT_ABI_20 {
246246
gcc_jit_context_new_bitcast;
247247
} LIBGCCJIT_ABI_19;
248+
249+
LIBGCCJIT_ABI_21 {
250+
global:
251+
gcc_jit_lvalue_set_register_name;
252+
} LIBGCCJIT_ABI_20;

0 commit comments

Comments
 (0)