Skip to content

Commit 341be3b

Browse files
GuillaumeGomezantoyo
authored andcommitted
Add gcc_jit_rvalue_set_type
1 parent 6ad6c52 commit 341be3b

File tree

7 files changed

+107
-25
lines changed

7 files changed

+107
-25
lines changed

gcc/jit/jit-recording.cc

+59-13
Original file line numberDiff line numberDiff line change
@@ -567,6 +567,7 @@ recording::context::context (context *parent_ctxt)
567567
m_last_error_str (NULL),
568568
m_owns_last_error_str (false),
569569
m_mementos (),
570+
m_type_mementos (),
570571
m_compound_types (),
571572
m_globals (),
572573
m_functions (),
@@ -616,6 +617,10 @@ recording::context::~context ()
616617
{
617618
delete m;
618619
}
620+
FOR_EACH_VEC_ELT (m_type_mementos, i, m)
621+
{
622+
delete m;
623+
}
619624

620625
for (i = 0; i < GCC_JIT_NUM_STR_OPTIONS; ++i)
621626
free (m_str_options[i]);
@@ -649,6 +654,14 @@ recording::context::record (memento *m)
649654
m_mementos.safe_push (m);
650655
}
651656

657+
void
658+
recording::context::record_type (memento *m)
659+
{
660+
gcc_assert (m);
661+
662+
m_type_mementos.safe_push (m);
663+
}
664+
652665
/* Replay this context (and any parents) into the given replayer. */
653666

654667
void
@@ -680,6 +693,25 @@ recording::context::replay_into (replayer *r)
680693
return;
681694

682695
/* Replay this context's saved operations into r. */
696+
697+
FOR_EACH_VEC_ELT (m_type_mementos, i, m)
698+
{
699+
/* Disabled low-level debugging, here if we need it: print what
700+
we're replaying.
701+
Note that the calls to get_debug_string might lead to more
702+
mementos being created for the strings.
703+
This can also be used to exercise the debug_string
704+
machinery. */
705+
if (0)
706+
printf ("context %p replaying (%p): %s\n",
707+
(void *)this, (void *)m, m->get_debug_string ());
708+
709+
m->replay_into (r);
710+
711+
if (r->errors_occurred ())
712+
return;
713+
}
714+
683715
FOR_EACH_VEC_ELT (m_mementos, i, m)
684716
{
685717
/* Disabled low-level debugging, here if we need it: print what
@@ -719,6 +751,11 @@ recording::context::disassociate_from_playback ()
719751
if (m_parent_ctxt)
720752
m_parent_ctxt->disassociate_from_playback ();
721753

754+
FOR_EACH_VEC_ELT (m_type_mementos, i, m)
755+
{
756+
m->set_playback_obj (NULL);
757+
}
758+
722759
FOR_EACH_VEC_ELT (m_mementos, i, m)
723760
{
724761
m->set_playback_obj (NULL);
@@ -784,7 +821,7 @@ recording::context::get_type (enum gcc_jit_types kind)
784821
else
785822
{
786823
recording::type *result = new memento_of_get_type (this, kind);
787-
record (result);
824+
record_type (result);
788825
m_basic_types[kind] = result;
789826
}
790827
}
@@ -862,7 +899,7 @@ recording::context::new_array_type (recording::location *loc,
862899
}
863900
recording::type *result =
864901
new recording::array_type (this, loc, element_type, num_elements);
865-
record (result);
902+
record_type (result);
866903
return result;
867904
}
868905

@@ -879,7 +916,7 @@ recording::context::new_field (recording::location *loc,
879916
{
880917
recording::field *result =
881918
new recording::field (this, loc, type, new_string (name));
882-
record (result);
919+
record_type (result);
883920
return result;
884921
}
885922

@@ -912,7 +949,7 @@ recording::context::new_struct_type (recording::location *loc,
912949
const char *name)
913950
{
914951
recording::struct_ *result = new struct_ (this, loc, new_string (name));
915-
record (result);
952+
record_type (result);
916953
m_compound_types.safe_push (result);
917954
return result;
918955
}
@@ -928,7 +965,7 @@ recording::context::new_union_type (recording::location *loc,
928965
const char *name)
929966
{
930967
recording::union_ *result = new union_ (this, loc, new_string (name));
931-
record (result);
968+
record_type (result);
932969
m_compound_types.safe_push (result);
933970
return result;
934971
}
@@ -952,7 +989,7 @@ recording::context::new_function_type (recording::type *return_type,
952989
param_types,
953990
is_variadic,
954991
is_target_builtin);
955-
record (fn_type);
992+
record_type (fn_type);
956993
return fn_type;
957994
}
958995

@@ -2178,6 +2215,8 @@ recording::context::dump_reproducer_to_file (const char *path)
21782215

21792216
r.write (" /* Replay of API calls for %s. */\n",
21802217
r.get_identifier (contexts[ctxt_idx]));
2218+
FOR_EACH_VEC_ELT (contexts[ctxt_idx]->m_type_mementos, i, m)
2219+
m->write_reproducer (r);
21812220
FOR_EACH_VEC_ELT (contexts[ctxt_idx]->m_mementos, i, m)
21822221
m->write_reproducer (r);
21832222
}
@@ -2480,7 +2519,7 @@ recording::type::get_pointer ()
24802519
if (!m_pointer_to_this_type)
24812520
{
24822521
m_pointer_to_this_type = new memento_of_get_pointer (this);
2483-
m_ctxt->record (m_pointer_to_this_type);
2522+
m_ctxt->record_type (m_pointer_to_this_type);
24842523
}
24852524
return m_pointer_to_this_type;
24862525
}
@@ -2494,7 +2533,7 @@ recording::type *
24942533
recording::type::get_const ()
24952534
{
24962535
recording::type *result = new memento_of_get_const (this);
2497-
m_ctxt->record (result);
2536+
m_ctxt->record_type (result);
24982537
return result;
24992538
}
25002539

@@ -2507,7 +2546,7 @@ recording::type *
25072546
recording::type::get_restrict ()
25082547
{
25092548
recording::type *result = new memento_of_get_restrict (this);
2510-
m_ctxt->record (result);
2549+
m_ctxt->record_type (result);
25112550
return result;
25122551
}
25132552

@@ -2520,7 +2559,7 @@ recording::type *
25202559
recording::type::get_volatile ()
25212560
{
25222561
recording::type *result = new memento_of_get_volatile (this);
2523-
m_ctxt->record (result);
2562+
m_ctxt->record_type (result);
25242563
return result;
25252564
}
25262565

@@ -2534,7 +2573,7 @@ recording::type::get_aligned (size_t alignment_in_bytes)
25342573
{
25352574
recording::type *result
25362575
= new memento_of_get_aligned (this, alignment_in_bytes);
2537-
m_ctxt->record (result);
2576+
m_ctxt->record_type (result);
25382577
return result;
25392578
}
25402579

@@ -2554,7 +2593,7 @@ recording::type::get_vector (size_t num_units)
25542593
{
25552594
recording::type *result
25562595
= new vector_type (this, num_units);
2557-
m_ctxt->record (result);
2596+
m_ctxt->record_type (result);
25582597
return result;
25592598
}
25602599

@@ -3816,7 +3855,7 @@ recording::compound_type::set_fields (location *loc,
38163855
gcc_assert (m_fields == NULL);
38173856

38183857
m_fields = new fields (this, num_fields, field_array);
3819-
m_ctxt->record (m_fields);
3858+
m_ctxt->record_type (m_fields);
38203859
}
38213860

38223861
/* Implementation of pure virtual hook recording::type::dereference for
@@ -4063,6 +4102,13 @@ recording::rvalue::access_field (recording::location *loc,
40634102
return result;
40644103
}
40654104

4105+
void
4106+
recording::rvalue::set_type (type *new_type)
4107+
{
4108+
gcc_assert (new_type);
4109+
m_type = new_type;
4110+
}
4111+
40664112
/* Create a recording::dereference_field_rvalue instance and add it to
40674113
the rvalue's context's list of mementos.
40684114

gcc/jit/jit-recording.h

+14-11
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ class context : public log_user
8484
get_builtins_manager ();
8585

8686
void record (memento *m);
87+
void record_type (memento *m);
8788
void replay_into (replayer *r);
8889
void disassociate_from_playback ();
8990

@@ -412,6 +413,7 @@ class context : public log_user
412413

413414
/* Recorded API usage. */
414415
auto_vec<memento *> m_mementos;
416+
auto_vec<memento *> m_type_mementos;
415417

416418
/* Specific recordings, for use by dump_to_file. */
417419
auto_vec<compound_type *> m_compound_types;
@@ -759,7 +761,7 @@ class memento_of_get_pointer : public type
759761
type* copy(context* ctxt) final override
760762
{
761763
type* result = new memento_of_get_pointer (m_other_type->copy (ctxt));
762-
ctxt->record (result);
764+
ctxt->record_type (result);
763765
return result;
764766
}
765767

@@ -823,7 +825,7 @@ class memento_of_get_const : public decorated_type
823825
type* copy(context* ctxt) final override
824826
{
825827
type* result = new memento_of_get_const (m_other_type->copy (ctxt));
826-
ctxt->record (result);
828+
ctxt->record_type (result);
827829
return result;
828830
}
829831

@@ -868,7 +870,7 @@ class memento_of_get_volatile : public decorated_type
868870
type* copy(context* ctxt) final override
869871
{
870872
type* result = new memento_of_get_volatile (m_other_type->copy (ctxt));
871-
ctxt->record (result);
873+
ctxt->record_type (result);
872874
return result;
873875
}
874876

@@ -901,7 +903,7 @@ class memento_of_get_restrict : public decorated_type
901903
type* copy(context* ctxt) final override
902904
{
903905
type* result = new memento_of_get_restrict (m_other_type->copy (ctxt));
904-
ctxt->record (result);
906+
ctxt->record_type (result);
905907
return result;
906908
}
907909

@@ -928,7 +930,7 @@ class memento_of_get_aligned : public decorated_type
928930
type* copy(context* ctxt) final override
929931
{
930932
type* result = new memento_of_get_aligned (m_other_type->copy (ctxt), m_alignment_in_bytes);
931-
ctxt->record (result);
933+
ctxt->record_type (result);
932934
return result;
933935
}
934936

@@ -978,7 +980,7 @@ class vector_type : public decorated_type
978980
type* copy(context* ctxt) final override
979981
{
980982
type* result = new vector_type(m_other_type->copy (ctxt), m_num_units);
981-
ctxt->record (result);
983+
ctxt->record_type (result);
982984
return result;
983985
}
984986

@@ -1038,7 +1040,7 @@ class array_type : public type
10381040
type* copy(context* ctxt) final override
10391041
{
10401042
type* result = new array_type (ctxt, m_loc, m_element_type->copy (ctxt), m_num_elements);
1041-
ctxt->record (result);
1043+
ctxt->record_type (result);
10421044
return result;
10431045
}
10441046

@@ -1087,7 +1089,7 @@ class function_type : public type
10871089

10881090
type* result = new function_type (ctxt, m_return_type->copy (ctxt), m_param_types.length (), new_params.address (),
10891091
m_is_variadic, m_is_target_builtin);
1090-
ctxt->record (result);
1092+
ctxt->record_type (result);
10911093
return result;
10921094
}
10931095

@@ -1244,7 +1246,7 @@ class struct_ : public compound_type
12441246
type* copy(context* ctxt) final override
12451247
{
12461248
type* result = new struct_ (ctxt, m_loc, m_name);
1247-
ctxt->record (result);
1249+
ctxt->record_type (result);
12481250
return result;
12491251
}
12501252

@@ -1298,7 +1300,7 @@ class union_ : public compound_type
12981300
type* copy(context* ctxt) final override
12991301
{
13001302
type* result = new union_ (ctxt, m_loc, m_name);
1301-
ctxt->record (result);
1303+
ctxt->record_type (result);
13021304
return result;
13031305
}
13041306

@@ -1365,6 +1367,7 @@ class rvalue : public memento
13651367
Implements the post-error-checking part of
13661368
gcc_jit_rvalue_get_type. */
13671369
type * get_type () const { return m_type; }
1370+
void set_type (type * new_type);
13681371

13691372
playback::rvalue *
13701373
playback_rvalue () const
@@ -2062,7 +2065,7 @@ class comparison : public rvalue
20622065
else
20632066
inner_type = element_type;
20642067
m_type = new vector_type (inner_type, vec_type->get_num_units ());
2065-
ctxt->record (m_type);
2068+
ctxt->record_type (m_type);
20662069
}
20672070
}
20682071

gcc/jit/libgccjit++.h

+6
Original file line numberDiff line numberDiff line change
@@ -1768,6 +1768,12 @@ rvalue::get_type ()
17681768
return type (gcc_jit_rvalue_get_type (get_inner_rvalue ()));
17691769
}
17701770

1771+
inline void
1772+
rvalue::set_type (type *new_type)
1773+
{
1774+
gcc_jit_rvalue_set_type (get_inner_rvalue (), new_type);
1775+
}
1776+
17711777
inline rvalue
17721778
rvalue::access_field (field field,
17731779
location loc)

gcc/jit/libgccjit.cc

+14
Original file line numberDiff line numberDiff line change
@@ -2013,6 +2013,20 @@ gcc_jit_lvalue_remove (gcc_jit_lvalue *lvalue)
20132013
lvalue->remove ();
20142014
}
20152015

2016+
/* Public entrypoint. See description in libgccjit.h.
2017+
2018+
After error-checking, the real work is done by the
2019+
gcc::jit::recording::rvalue::set_type method, in
2020+
jit-recording.h. */
2021+
2022+
void
2023+
gcc_jit_rvalue_set_type (gcc_jit_rvalue *rvalue, gcc_jit_type *new_type)
2024+
{
2025+
RETURN_IF_FAIL (rvalue, NULL, NULL, "NULL rvalue");
2026+
2027+
rvalue->set_type (new_type);
2028+
}
2029+
20162030
/* Verify that NUMERIC_TYPE is non-NULL, and that it is a "numeric"
20172031
type i.e. it satisfies gcc::jit::type::is_numeric (), such as the
20182032
result of gcc_jit_context_get_type (GCC_JIT_TYPE_INT). */

gcc/jit/libgccjit.h

+3
Original file line numberDiff line numberDiff line change
@@ -1082,6 +1082,9 @@ gcc_jit_rvalue_get_type (gcc_jit_rvalue *rvalue);
10821082
extern void
10831083
gcc_jit_lvalue_remove (gcc_jit_lvalue *lvalue);
10841084

1085+
extern void
1086+
gcc_jit_rvalue_set_type (gcc_jit_rvalue *rvalue, gcc_jit_type *new_type);
1087+
10851088
/* Integer constants. */
10861089
extern gcc_jit_rvalue *
10871090
gcc_jit_context_new_rvalue_from_int (gcc_jit_context *ctxt,

gcc/jit/libgccjit.map

+1
Original file line numberDiff line numberDiff line change
@@ -366,4 +366,5 @@ LIBGCCJIT_ABI_40 {
366366
LIBGCCJIT_ABI_41 {
367367
global:
368368
gcc_jit_lvalue_remove;
369+
gcc_jit_rvalue_set_type;
369370
} LIBGCCJIT_ABI_40;

0 commit comments

Comments
 (0)