Skip to content

Commit 9d618e7

Browse files
GuillaumeGomezantoyo
authored andcommitted
Add gcc_jit_rvalue_set_type
1 parent fbcb892 commit 9d618e7

File tree

7 files changed

+111
-25
lines changed

7 files changed

+111
-25
lines changed

gcc/jit/jit-recording.cc

+59-13
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,7 @@ recording::context::context (context *parent_ctxt)
568568
m_last_error_str (NULL),
569569
m_owns_last_error_str (false),
570570
m_mementos (),
571+
m_type_mementos (),
571572
m_compound_types (),
572573
m_globals (),
573574
m_functions (),
@@ -617,6 +618,10 @@ recording::context::~context ()
617618
{
618619
delete m;
619620
}
621+
FOR_EACH_VEC_ELT (m_type_mementos, i, m)
622+
{
623+
delete m;
624+
}
620625

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

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

655668
void
@@ -681,6 +694,25 @@ recording::context::replay_into (replayer *r)
681694
return;
682695

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

755+
FOR_EACH_VEC_ELT (m_type_mementos, i, m)
756+
{
757+
m->set_playback_obj (NULL);
758+
}
759+
723760
FOR_EACH_VEC_ELT (m_mementos, i, m)
724761
{
725762
m->set_playback_obj (NULL);
@@ -785,7 +822,7 @@ recording::context::get_type (enum gcc_jit_types kind)
785822
else
786823
{
787824
recording::type *result = new memento_of_get_type (this, kind);
788-
record (result);
825+
record_type (result);
789826
m_basic_types[kind] = result;
790827
}
791828
}
@@ -863,7 +900,7 @@ recording::context::new_array_type (recording::location *loc,
863900
}
864901
recording::type *result =
865902
new recording::array_type (this, loc, element_type, num_elements);
866-
record (result);
903+
record_type (result);
867904
return result;
868905
}
869906

@@ -880,7 +917,7 @@ recording::context::new_field (recording::location *loc,
880917
{
881918
recording::field *result =
882919
new recording::field (this, loc, type, new_string (name));
883-
record (result);
920+
record_type (result);
884921
return result;
885922
}
886923

@@ -913,7 +950,7 @@ recording::context::new_struct_type (recording::location *loc,
913950
const char *name)
914951
{
915952
recording::struct_ *result = new struct_ (this, loc, new_string (name));
916-
record (result);
953+
record_type (result);
917954
m_compound_types.safe_push (result);
918955
return result;
919956
}
@@ -929,7 +966,7 @@ recording::context::new_union_type (recording::location *loc,
929966
const char *name)
930967
{
931968
recording::union_ *result = new union_ (this, loc, new_string (name));
932-
record (result);
969+
record_type (result);
933970
m_compound_types.safe_push (result);
934971
return result;
935972
}
@@ -953,7 +990,7 @@ recording::context::new_function_type (recording::type *return_type,
953990
param_types,
954991
is_variadic,
955992
is_target_builtin);
956-
record (fn_type);
993+
record_type (fn_type);
957994
return fn_type;
958995
}
959996

@@ -2181,6 +2218,8 @@ recording::context::dump_reproducer_to_file (const char *path)
21812218

21822219
r.write (" /* Replay of API calls for %s. */\n",
21832220
r.get_identifier (contexts[ctxt_idx]));
2221+
FOR_EACH_VEC_ELT (contexts[ctxt_idx]->m_type_mementos, i, m)
2222+
m->write_reproducer (r);
21842223
FOR_EACH_VEC_ELT (contexts[ctxt_idx]->m_mementos, i, m)
21852224
m->write_reproducer (r);
21862225
}
@@ -2485,7 +2524,7 @@ recording::type::get_pointer ()
24852524
if (!m_pointer_to_this_type)
24862525
{
24872526
m_pointer_to_this_type = new memento_of_get_pointer (this);
2488-
m_ctxt->record (m_pointer_to_this_type);
2527+
m_ctxt->record_type (m_pointer_to_this_type);
24892528
}
24902529
return m_pointer_to_this_type;
24912530
}
@@ -2499,7 +2538,7 @@ recording::type *
24992538
recording::type::get_const ()
25002539
{
25012540
recording::type *result = new memento_of_get_const (this);
2502-
m_ctxt->record (result);
2541+
m_ctxt->record_type (result);
25032542
return result;
25042543
}
25052544

@@ -2512,7 +2551,7 @@ recording::type *
25122551
recording::type::get_restrict ()
25132552
{
25142553
recording::type *result = new memento_of_get_restrict (this);
2515-
m_ctxt->record (result);
2554+
m_ctxt->record_type (result);
25162555
return result;
25172556
}
25182557

@@ -2525,7 +2564,7 @@ recording::type *
25252564
recording::type::get_volatile ()
25262565
{
25272566
recording::type *result = new memento_of_get_volatile (this);
2528-
m_ctxt->record (result);
2567+
m_ctxt->record_type (result);
25292568
return result;
25302569
}
25312570

@@ -2539,7 +2578,7 @@ recording::type::get_aligned (size_t alignment_in_bytes)
25392578
{
25402579
recording::type *result
25412580
= new memento_of_get_aligned (this, alignment_in_bytes);
2542-
m_ctxt->record (result);
2581+
m_ctxt->record_type (result);
25432582
return result;
25442583
}
25452584

@@ -2559,7 +2598,7 @@ recording::type::get_vector (size_t num_units)
25592598
{
25602599
recording::type *result
25612600
= new vector_type (this, num_units);
2562-
m_ctxt->record (result);
2601+
m_ctxt->record_type (result);
25632602
return result;
25642603
}
25652604

@@ -3824,7 +3863,7 @@ recording::compound_type::set_fields (location *loc,
38243863
gcc_assert (m_fields == NULL);
38253864

38263865
m_fields = new fields (this, num_fields, field_array);
3827-
m_ctxt->record (m_fields);
3866+
m_ctxt->record_type (m_fields);
38283867
}
38293868

38303869
/* Implementation of pure virtual hook recording::type::dereference for
@@ -4071,6 +4110,13 @@ recording::rvalue::access_field (recording::location *loc,
40714110
return result;
40724111
}
40734112

4113+
void
4114+
recording::rvalue::set_type (type *new_type)
4115+
{
4116+
gcc_assert (new_type);
4117+
m_type = new_type;
4118+
}
4119+
40744120
/* Create a recording::dereference_field_rvalue instance and add it to
40754121
the rvalue's context's list of mementos.
40764122

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;
@@ -760,7 +762,7 @@ class memento_of_get_pointer : public type
760762
type* copy (context* ctxt) final override
761763
{
762764
type* result = new memento_of_get_pointer (m_other_type->copy (ctxt));
763-
ctxt->record (result);
765+
ctxt->record_type (result);
764766
return result;
765767
}
766768

@@ -830,7 +832,7 @@ class memento_of_get_const : public decorated_type
830832
type* copy (context* ctxt) final override
831833
{
832834
type* result = new memento_of_get_const (m_other_type->copy (ctxt));
833-
ctxt->record (result);
835+
ctxt->record_type (result);
834836
return result;
835837
}
836838

@@ -870,7 +872,7 @@ class memento_of_get_volatile : public decorated_type
870872
type* copy (context* ctxt) final override
871873
{
872874
type* result = new memento_of_get_volatile (m_other_type->copy (ctxt));
873-
ctxt->record (result);
875+
ctxt->record_type (result);
874876
return result;
875877
}
876878

@@ -903,7 +905,7 @@ class memento_of_get_restrict : public decorated_type
903905
type* copy (context* ctxt) final override
904906
{
905907
type* result = new memento_of_get_restrict (m_other_type->copy (ctxt));
906-
ctxt->record (result);
908+
ctxt->record_type (result);
907909
return result;
908910
}
909911

@@ -944,7 +946,7 @@ class memento_of_get_aligned : public decorated_type
944946
{
945947
type* result = new memento_of_get_aligned (m_other_type->copy (ctxt),
946948
m_alignment_in_bytes);
947-
ctxt->record (result);
949+
ctxt->record_type (result);
948950
return result;
949951
}
950952

@@ -993,7 +995,7 @@ class vector_type : public decorated_type
993995
type* copy (context* ctxt) final override
994996
{
995997
type* result = new vector_type (m_other_type->copy (ctxt), m_num_units);
996-
ctxt->record (result);
998+
ctxt->record_type (result);
997999
return result;
9981000
}
9991001

@@ -1054,7 +1056,7 @@ class array_type : public type
10541056
{
10551057
type* result = new array_type (ctxt, m_loc, m_element_type->copy (ctxt),
10561058
m_num_elements);
1057-
ctxt->record (result);
1059+
ctxt->record_type (result);
10581060
return result;
10591061
}
10601062

@@ -1105,7 +1107,7 @@ class function_type : public type
11051107
m_param_types.length (),
11061108
new_params.address (),
11071109
m_is_variadic, m_is_target_builtin);
1108-
ctxt->record (result);
1110+
ctxt->record_type (result);
11091111
return result;
11101112
}
11111113

@@ -1261,7 +1263,7 @@ class struct_ : public compound_type
12611263
type* copy (context* ctxt) final override
12621264
{
12631265
type* result = new struct_ (ctxt, m_loc, m_name);
1264-
ctxt->record (result);
1266+
ctxt->record_type (result);
12651267
return result;
12661268
}
12671269

@@ -1315,7 +1317,7 @@ class union_ : public compound_type
13151317
type* copy (context* ctxt) final override
13161318
{
13171319
type* result = new union_ (ctxt, m_loc, m_name);
1318-
ctxt->record (result);
1320+
ctxt->record_type (result);
13191321
return result;
13201322
}
13211323

@@ -1382,6 +1384,7 @@ class rvalue : public memento
13821384
Implements the post-error-checking part of
13831385
gcc_jit_rvalue_get_type. */
13841386
type * get_type () const { return m_type; }
1387+
void set_type (type * new_type);
13851388

13861389
playback::rvalue *
13871390
playback_rvalue () const
@@ -2076,7 +2079,7 @@ class comparison : public rvalue
20762079
else
20772080
inner_type = element_type;
20782081
m_type = new vector_type (inner_type, vec_type->get_num_units ());
2079-
ctxt->record (m_type);
2082+
ctxt->record_type (m_type);
20802083
}
20812084
}
20822085

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
@@ -1994,6 +1994,20 @@ gcc_jit_rvalue_get_type (gcc_jit_rvalue *rvalue)
19941994
return static_cast <gcc_jit_type *> (rvalue->get_type ());
19951995
}
19961996

1997+
/* Public entrypoint. See description in libgccjit.h.
1998+
1999+
After error-checking, the real work is done by the
2000+
gcc::jit::recording::rvalue::set_type method, in
2001+
jit-recording.h. */
2002+
2003+
void
2004+
gcc_jit_rvalue_set_type (gcc_jit_rvalue *rvalue, gcc_jit_type *new_type)
2005+
{
2006+
RETURN_IF_FAIL (rvalue, NULL, NULL, "NULL rvalue");
2007+
2008+
rvalue->set_type (new_type);
2009+
}
2010+
19972011
/* Verify that NUMERIC_TYPE is non-NULL, and that it is a "numeric"
19982012
type i.e. it satisfies gcc::jit::type::is_numeric (), such as the
19992013
result of gcc_jit_context_get_type (GCC_JIT_TYPE_INT). */

gcc/jit/libgccjit.h

+3
Original file line numberDiff line numberDiff line change
@@ -1093,6 +1093,9 @@ gcc_jit_rvalue_as_object (gcc_jit_rvalue *rvalue);
10931093
extern gcc_jit_type *
10941094
gcc_jit_rvalue_get_type (gcc_jit_rvalue *rvalue);
10951095

1096+
extern void
1097+
gcc_jit_rvalue_set_type (gcc_jit_rvalue *rvalue, gcc_jit_type *new_type);
1098+
10961099
/* Integer constants. */
10971100
extern gcc_jit_rvalue *
10981101
gcc_jit_context_new_rvalue_from_int (gcc_jit_context *ctxt,

gcc/jit/libgccjit.map

+5
Original file line numberDiff line numberDiff line change
@@ -363,3 +363,8 @@ LIBGCCJIT_ABI_40 {
363363
global:
364364
gcc_jit_type_is_floating_point;
365365
} LIBGCCJIT_ABI_39;
366+
367+
LIBGCCJIT_ABI_41 {
368+
global:
369+
gcc_jit_rvalue_set_type;
370+
} LIBGCCJIT_ABI_40;

0 commit comments

Comments
 (0)