Skip to content

Commit 3412d10

Browse files
committed
Add support for register variable
1 parent f88cfda commit 3412d10

File tree

6 files changed

+50
-6
lines changed

6 files changed

+50
-6
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

@@ -706,6 +707,14 @@ class lvalue : public rvalue
706707
set_decl_section_name (as_tree (), name);
707708
}
708709

710+
void
711+
set_reg_name (const char* reg_name)
712+
{
713+
set_user_assembler_name (as_tree (), reg_name);
714+
DECL_REGISTER (as_tree ()) = 1;
715+
DECL_HARD_REGISTER (as_tree ()) = 1;
716+
}
717+
709718
private:
710719
bool mark_addressable (location *loc);
711720
};

gcc/jit/jit-recording.c

+12-3
Original file line numberDiff line numberDiff line change
@@ -3900,6 +3900,11 @@ void recording::lvalue::set_link_section (const char *name)
39003900
m_link_section = new_string (name);
39013901
}
39023902

3903+
void recording::lvalue::set_register_name (const char *reg_name)
3904+
{
3905+
m_reg_name = new_string (reg_name);
3906+
}
3907+
39033908
/* The implementation of class gcc::jit::recording::param. */
39043909

39053910
/* Implementation of pure virtual hook recording::memento::replay_into
@@ -6486,11 +6491,15 @@ recording::function_pointer::write_reproducer (reproducer &r)
64866491
void
64876492
recording::local::replay_into (replayer *r)
64886493
{
6489-
set_playback_obj (
6490-
m_func->playback_function ()
6494+
playback::lvalue *obj = m_func->playback_function ()
64916495
->new_local (playback_location (r, m_loc),
64926496
m_type->playback_type (),
6493-
playback_string (m_name)));
6497+
playback_string (m_name));
6498+
if (m_reg_name != NULL)
6499+
{
6500+
obj->set_reg_name(m_reg_name->c_str());
6501+
}
6502+
set_playback_obj (obj);
64946503
}
64956504

64966505
/* Override the default implementation of

gcc/jit/jit-recording.h

+6-3
Original file line numberDiff line numberDiff line change
@@ -1152,8 +1152,9 @@ class lvalue : public rvalue
11521152
location *loc,
11531153
type *type_)
11541154
: rvalue (ctxt, loc, type_),
1155-
m_tls_model (GCC_JIT_TLS_MODEL_NONE),
1156-
m_link_section (NULL)
1155+
m_link_section (NULL),
1156+
m_reg_name (NULL),
1157+
m_tls_model (GCC_JIT_TLS_MODEL_NONE)
11571158
{}
11581159

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

11811183
protected:
1182-
enum gcc_jit_tls_model m_tls_model;
11831184
string *m_link_section;
1185+
string *m_reg_name;
1186+
enum gcc_jit_tls_model m_tls_model;
11841187
};
11851188

11861189
class param : public lvalue

gcc/jit/libgccjit.c

+13
Original file line numberDiff line numberDiff line change
@@ -2677,6 +2677,19 @@ gcc_jit_lvalue_set_link_section (gcc_jit_lvalue *lvalue,
26772677
lvalue->set_link_section (section_name);
26782678
}
26792679

2680+
/* Public entrypoint. See description in libgccjit.h.
2681+
2682+
After error-checking, the real work is done by the
2683+
gcc::jit::recording::lvalue::set_register_name method in jit-recording.c. */
2684+
2685+
void
2686+
gcc_jit_lvalue_set_register_name (gcc_jit_lvalue *lvalue,
2687+
const char *reg_name)
2688+
{
2689+
// TODO: support global variables?
2690+
lvalue->set_register_name (reg_name);
2691+
}
2692+
26802693
/* Public entrypoint. See description in libgccjit.h.
26812694
26822695
After error-checking, the real work is done by the

gcc/jit/libgccjit.h

+5
Original file line numberDiff line numberDiff line change
@@ -1297,6 +1297,11 @@ extern void
12971297
gcc_jit_lvalue_set_link_section (gcc_jit_lvalue *lvalue,
12981298
const char *section_name);
12991299

1300+
/* Make this variable a register variable and set its register name. */
1301+
void
1302+
gcc_jit_lvalue_set_register_name (gcc_jit_lvalue *lvalue,
1303+
const char *reg_name);
1304+
13001305
extern gcc_jit_lvalue *
13011306
gcc_jit_function_new_local (gcc_jit_function *func,
13021307
gcc_jit_location *loc,

gcc/jit/libgccjit.map

+5
Original file line numberDiff line numberDiff line change
@@ -249,3 +249,8 @@ LIBGCCJIT_ABI_20 {
249249
global:
250250
gcc_jit_context_new_bitcast;
251251
} LIBGCCJIT_ABI_19;
252+
253+
LIBGCCJIT_ABI_21 {
254+
global:
255+
gcc_jit_lvalue_set_register_name;
256+
} LIBGCCJIT_ABI_20;

0 commit comments

Comments
 (0)