1 /* Internals of libgccjit: classes for recording calls made to the JIT API.
2 Copyright (C) 2013-2023 Free Software Foundation, Inc.
3 Contributed by David Malcolm <dmalcolm@redhat.com>.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3, or (at your option)
12 GCC is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
21 #ifndef JIT_RECORDING_H
22 #define JIT_RECORDING_H
24 #include "jit-common.h"
25 #include "jit-logging.h"
33 extern const char * const unary_op_reproducer_strings
[];
34 extern const char * const binary_op_reproducer_strings
[];
40 /**********************************************************************
42 **********************************************************************/
47 playback_location (replayer
*r
, location
*loc
);
50 playback_string (string
*str
);
53 playback_block (block
*b
);
55 /* A recording of a call to gcc_jit_context_enable_dump. */
58 const char *m_dumpname
;
62 /* A JIT-compilation context. */
63 class context
: public log_user
66 context (context
*parent_ctxt
);
70 get_builtins_manager ();
72 void record (memento
*m
);
73 void replay_into (replayer
*r
);
74 void disassociate_from_playback ();
77 new_string (const char *text
, bool escaped
= false);
80 new_location (const char *filename
,
83 bool created_by_user
);
86 get_type (enum gcc_jit_types type
);
89 get_int_type (int num_bytes
, int is_signed
);
92 new_array_type (location
*loc
,
97 new_field (location
*loc
,
102 new_bitfield (location
*loc
,
108 new_struct_type (location
*loc
,
112 new_union_type (location
*loc
,
116 new_function_type (type
*return_type
,
122 new_function_ptr_type (location
*loc
,
129 new_param (location
*loc
,
134 new_function (location
*loc
,
135 enum gcc_jit_function_kind kind
,
141 enum built_in_function builtin_id
);
144 get_builtin_function (const char *name
);
147 new_global (location
*loc
,
148 enum gcc_jit_global_kind kind
,
153 new_ctor (location
*loc
,
160 new_global_init_rvalue (lvalue
*variable
,
163 template <typename HOST_TYPE
>
165 new_rvalue_from_const (type
*type
,
169 new_string_literal (const char *value
);
172 new_rvalue_from_vector (location
*loc
,
177 new_unary_op (location
*loc
,
178 enum gcc_jit_unary_op op
,
183 new_binary_op (location
*loc
,
184 enum gcc_jit_binary_op op
,
186 rvalue
*a
, rvalue
*b
);
189 new_comparison (location
*loc
,
190 enum gcc_jit_comparison op
,
191 rvalue
*a
, rvalue
*b
);
194 new_call (location
*loc
,
196 int numargs
, rvalue
**args
);
199 new_call_through_ptr (location
*loc
,
201 int numargs
, rvalue
**args
);
204 new_cast (location
*loc
,
209 new_bitcast (location
*loc
,
214 new_array_access (location
*loc
,
219 new_case (rvalue
*min_value
,
224 set_str_option (enum gcc_jit_str_option opt
,
228 set_int_option (enum gcc_jit_int_option opt
,
232 set_bool_option (enum gcc_jit_bool_option opt
,
236 set_inner_bool_option (enum inner_bool_option inner_opt
,
240 add_command_line_option (const char *optname
);
243 append_command_line_options (vec
<char *> *argvec
);
246 add_driver_option (const char *optname
);
249 append_driver_options (auto_string_vec
*argvec
);
252 enable_dump (const char *dumpname
,
256 get_str_option (enum gcc_jit_str_option opt
) const
258 return m_str_options
[opt
];
262 get_int_option (enum gcc_jit_int_option opt
) const
264 return m_int_options
[opt
];
268 get_bool_option (enum gcc_jit_bool_option opt
) const
270 return m_bool_options
[opt
];
274 get_inner_bool_option (enum inner_bool_option opt
) const
276 return m_inner_bool_options
[opt
];
283 compile_to_file (enum gcc_jit_output_kind output_kind
,
284 const char *output_path
);
287 add_error (location
*loc
, const char *fmt
, ...)
291 add_error_va (location
*loc
, const char *fmt
, va_list ap
)
295 get_first_error () const;
298 get_last_error () const;
300 bool errors_occurred () const
303 if (m_parent_ctxt
->errors_occurred ())
305 return m_error_count
;
308 type
*get_opaque_FILE_type ();
310 void dump_to_file (const char *path
, bool update_locations
);
312 void dump_reproducer_to_file (const char *path
);
315 get_all_requested_dumps (vec
<recording::requested_dump
> *out
);
317 void set_timer (timer
*t
) { m_timer
= t
; }
318 timer
*get_timer () const { return m_timer
; }
320 void add_top_level_asm (location
*loc
, const char *asm_stmts
);
323 void log_all_options () const;
324 void log_str_option (enum gcc_jit_str_option opt
) const;
325 void log_int_option (enum gcc_jit_int_option opt
) const;
326 void log_bool_option (enum gcc_jit_bool_option opt
) const;
327 void log_inner_bool_option (enum inner_bool_option opt
) const;
332 context
*m_parent_ctxt
;
334 /* The ultimate ancestor of the contexts within a family tree of
335 contexts. This has itself as its own m_toplevel_ctxt. */
336 context
*m_toplevel_ctxt
;
342 char *m_first_error_str
;
343 bool m_owns_first_error_str
;
345 char *m_last_error_str
;
346 bool m_owns_last_error_str
;
348 char *m_str_options
[GCC_JIT_NUM_STR_OPTIONS
];
349 int m_int_options
[GCC_JIT_NUM_INT_OPTIONS
];
350 bool m_bool_options
[GCC_JIT_NUM_BOOL_OPTIONS
];
351 bool m_inner_bool_options
[NUM_INNER_BOOL_OPTIONS
];
352 auto_vec
<char *> m_command_line_options
;
353 auto_vec
<char *> m_driver_options
;
355 /* Dumpfiles that were requested via gcc_jit_context_enable_dump. */
356 auto_vec
<requested_dump
> m_requested_dumps
;
358 /* Recorded API usage. */
359 auto_vec
<memento
*> m_mementos
;
361 /* Specific recordings, for use by dump_to_file. */
362 auto_vec
<compound_type
*> m_compound_types
;
363 auto_vec
<global
*> m_globals
;
364 auto_vec
<function
*> m_functions
;
365 auto_vec
<top_level_asm
*> m_top_level_asms
;
367 type
*m_basic_types
[NUM_GCC_JIT_TYPES
];
370 builtins_manager
*m_builtins_manager
; // lazily created
374 /* An object with lifetime managed by the context i.e.
375 it lives until the context is released, at which
376 point it itself is cleaned up. */
381 virtual ~memento () {}
383 /* Hook for replaying this. */
384 virtual void replay_into (replayer
*r
) = 0;
386 void set_playback_obj (void *obj
) { m_playback_obj
= obj
; }
389 /* Get the context that owns this object.
391 Implements the post-error-checking part of
392 gcc_jit_object_get_context. */
393 context
*get_context () { return m_ctxt
; }
396 as_object () { return this; }
398 /* Debugging hook, for use in generating error messages etc.
399 Implements the post-error-checking part of
400 gcc_jit_object_get_debug_string. */
404 virtual void write_to_dump (dump
&d
);
405 virtual void write_reproducer (reproducer
&r
) = 0;
406 virtual location
*dyn_cast_location () { return NULL
; }
408 memento (const memento
&) = delete;
409 memento
& operator= (const memento
&) = delete;
412 memento (context
*ctxt
)
414 m_playback_obj (NULL
),
415 m_debug_string (NULL
)
420 string
*new_string (const char *text
) { return m_ctxt
->new_string (text
); }
423 virtual string
* make_debug_string () = 0;
429 void *m_playback_obj
;
432 string
*m_debug_string
;
435 /* or just use std::string? */
436 class string
: public memento
439 string (context
*ctxt
, const char *text
, bool escaped
);
442 const char *c_str () const { return m_buffer
; }
444 static string
* from_printf (context
*ctxt
, const char *fmt
, ...)
447 void replay_into (replayer
*) final override
{}
449 string (const string
&) = delete;
450 string
& operator= (const string
&) = delete;
453 string
* make_debug_string () final override
;
454 void write_reproducer (reproducer
&r
) final override
;
460 /* Flag to track if this string is the result of string::make_debug_string,
461 to avoid infinite recursion when logging all mementos: don't re-escape
466 class location
: public memento
469 location (context
*ctxt
, string
*filename
, int line
, int column
,
470 bool created_by_user
)
472 m_filename (filename
),
475 m_created_by_user (created_by_user
)
478 void replay_into (replayer
*r
) final override
;
481 playback_location (replayer
*r
)
483 /* Normally during playback, we can walk forwards through the list of
484 recording objects, playing them back. The ordering of recording
485 ensures that everything that a recording object refers to has
486 already been played back, so we can simply look up the relevant
489 Locations are an exception, due to the "write_to_dump" method of
490 recording::statement. This method can set a new location on a
491 statement after the statement is created, and thus the location
492 appears in the context's memento list *after* the statement that
495 In such circumstances, the statement is replayed *before* the location,
496 when the latter doesn't yet have a playback object.
498 Hence we need to ensure that locations have playback objects. */
503 gcc_assert (m_playback_obj
);
504 return static_cast <playback::location
*> (m_playback_obj
);
507 location
*dyn_cast_location () final override
{ return this; }
508 bool created_by_user () const { return m_created_by_user
; }
511 string
* make_debug_string () final override
;
512 void write_reproducer (reproducer
&r
) final override
;
518 bool m_created_by_user
;
521 class type
: public memento
524 type
*get_pointer ();
526 type
*get_volatile ();
527 type
*get_aligned (size_t alignment_in_bytes
);
528 type
*get_vector (size_t num_units
);
530 /* Get the type obtained when dereferencing this type.
532 This will return NULL if it's not valid to dereference this type.
533 The caller is responsible for setting an error. */
534 virtual type
*dereference () = 0;
535 /* Get the type size in bytes.
537 This is implemented only for memento_of_get_type and
538 memento_of_get_pointer as it is used for initializing globals of
540 virtual size_t get_size () { gcc_unreachable (); }
543 virtual function_type
*dyn_cast_function_type () { return NULL
; }
544 virtual function_type
*as_a_function_type() { gcc_unreachable (); return NULL
; }
545 virtual struct_
*dyn_cast_struct () { return NULL
; }
546 virtual vector_type
*dyn_cast_vector_type () { return NULL
; }
548 /* Is it typesafe to copy to this type from rtype? */
549 virtual bool accepts_writes_from (type
*rtype
)
552 return this->unqualified ()->is_same_type_as (rtype
->unqualified ());
555 virtual bool is_same_type_as (type
*other
)
557 return this == other
;
560 /* Strip off "const" etc */
561 virtual type
*unqualified ()
566 virtual bool is_int () const = 0;
567 virtual bool is_float () const = 0;
568 virtual bool is_bool () const = 0;
569 virtual type
*is_pointer () = 0;
570 virtual type
*is_volatile () { return NULL
; }
571 virtual type
*is_const () { return NULL
; }
572 virtual type
*is_array () = 0;
573 virtual struct_
*is_struct () { return NULL
; }
574 virtual bool is_union () const { return false; }
575 virtual bool is_void () const { return false; }
576 virtual vector_type
*is_vector () { return NULL
; }
577 virtual bool has_known_size () const { return true; }
578 virtual bool is_signed () const = 0;
580 bool is_numeric () const
582 return is_int () || is_float () || is_bool ();
588 return static_cast <playback::type
*> (m_playback_obj
);
591 virtual const char *access_as_type (reproducer
&r
);
596 m_pointer_to_this_type (NULL
)
600 type
*m_pointer_to_this_type
;
603 /* Result of "gcc_jit_context_get_type". */
604 class memento_of_get_type
: public type
607 memento_of_get_type (context
*ctxt
,
608 enum gcc_jit_types kind
)
612 type
*dereference () final override
;
614 size_t get_size () final override
;
616 bool accepts_writes_from (type
*rtype
) final override
618 if (m_kind
== GCC_JIT_TYPE_VOID_PTR
)
620 if (rtype
->is_pointer ())
622 /* LHS (this) is type (void *), and the RHS is a pointer:
628 && get_size () == rtype
->get_size ()
629 && is_signed () == rtype
->is_signed ())
631 /* LHS (this) is an integer of the same size and sign as rtype. */
635 return type::accepts_writes_from (rtype
);
638 bool is_int () const final override
;
639 bool is_float () const final override
;
640 bool is_bool () const final override
;
641 type
*is_pointer () final override
{ return dereference (); }
642 type
*is_array () final override
{ return NULL
; }
643 bool is_void () const final override
{ return m_kind
== GCC_JIT_TYPE_VOID
; }
644 bool is_signed () const final override
;
647 void replay_into (replayer
*r
) final override
;
650 string
* make_debug_string () final override
;
651 void write_reproducer (reproducer
&r
) final override
;
654 enum gcc_jit_types m_kind
;
657 /* Result of "gcc_jit_type_get_pointer". */
658 class memento_of_get_pointer
: public type
661 memento_of_get_pointer (type
*other_type
)
662 : type (other_type
->m_ctxt
),
663 m_other_type (other_type
) {}
665 type
*dereference () final override
{ return m_other_type
; }
667 size_t get_size () final override
;
669 bool accepts_writes_from (type
*rtype
) final override
;
671 void replay_into (replayer
*r
) final override
;
673 bool is_int () const final override
{ return false; }
674 bool is_float () const final override
{ return false; }
675 bool is_bool () const final override
{ return false; }
676 type
*is_pointer () final override
{ return m_other_type
; }
677 type
*is_array () final override
{ return NULL
; }
678 bool is_signed () const final override
{ return false; }
681 string
* make_debug_string () final override
;
682 void write_reproducer (reproducer
&r
) final override
;
688 /* A decorated version of a type, for get_const, get_volatile,
689 get_aligned, and get_vector. */
691 class decorated_type
: public type
694 decorated_type (type
*other_type
)
695 : type (other_type
->m_ctxt
),
696 m_other_type (other_type
) {}
698 type
*dereference () final override
{ return m_other_type
->dereference (); }
700 size_t get_size () final override
{ return m_other_type
->get_size (); };
702 bool is_int () const final override
{ return m_other_type
->is_int (); }
703 bool is_float () const final override
{ return m_other_type
->is_float (); }
704 bool is_bool () const final override
{ return m_other_type
->is_bool (); }
705 type
*is_pointer () final override
{ return m_other_type
->is_pointer (); }
706 type
*is_array () final override
{ return m_other_type
->is_array (); }
707 struct_
*is_struct () final override
{ return m_other_type
->is_struct (); }
708 bool is_signed () const final override
{ return m_other_type
->is_signed (); }
714 /* Result of "gcc_jit_type_get_const". */
715 class memento_of_get_const
: public decorated_type
718 memento_of_get_const (type
*other_type
)
719 : decorated_type (other_type
) {}
721 bool accepts_writes_from (type */
*rtype*/
) final override
723 /* Can't write to a "const". */
727 /* Strip off the "const", giving the underlying type. */
728 type
*unqualified () final override
{ return m_other_type
; }
730 bool is_same_type_as (type
*other
) final override
732 if (!other
->is_const ())
734 return m_other_type
->is_same_type_as (other
->is_const ());
737 type
*is_const () final override
{ return m_other_type
; }
739 void replay_into (replayer
*) final override
;
742 string
* make_debug_string () final override
;
743 void write_reproducer (reproducer
&r
) final override
;
746 /* Result of "gcc_jit_type_get_volatile". */
747 class memento_of_get_volatile
: public decorated_type
750 memento_of_get_volatile (type
*other_type
)
751 : decorated_type (other_type
) {}
753 bool is_same_type_as (type
*other
) final override
755 if (!other
->is_volatile ())
757 return m_other_type
->is_same_type_as (other
->is_volatile ());
760 /* Strip off the "volatile", giving the underlying type. */
761 type
*unqualified () final override
{ return m_other_type
; }
763 type
*is_volatile () final override
{ return m_other_type
; }
765 void replay_into (replayer
*) final override
;
768 string
* make_debug_string () final override
;
769 void write_reproducer (reproducer
&r
) final override
;
772 /* Result of "gcc_jit_type_get_aligned". */
773 class memento_of_get_aligned
: public decorated_type
776 memento_of_get_aligned (type
*other_type
, size_t alignment_in_bytes
)
777 : decorated_type (other_type
),
778 m_alignment_in_bytes (alignment_in_bytes
) {}
780 /* Strip off the alignment, giving the underlying type. */
781 type
*unqualified () final override
{ return m_other_type
; }
783 void replay_into (replayer
*) final override
;
786 string
* make_debug_string () final override
;
787 void write_reproducer (reproducer
&r
) final override
;
790 size_t m_alignment_in_bytes
;
793 /* Result of "gcc_jit_type_get_vector". */
794 class vector_type
: public decorated_type
797 vector_type (type
*other_type
, size_t num_units
)
798 : decorated_type (other_type
),
799 m_num_units (num_units
) {}
801 size_t get_num_units () const { return m_num_units
; }
803 vector_type
*dyn_cast_vector_type () final override
{ return this; }
805 type
*get_element_type () { return m_other_type
; }
807 void replay_into (replayer
*) final override
;
809 bool is_same_type_as (type
*other
) final override
811 vector_type
*other_vec_type
= other
->dyn_cast_vector_type ();
812 if (other_vec_type
== NULL
)
814 return get_num_units () == other_vec_type
->get_num_units ()
815 && get_element_type () == other_vec_type
->get_element_type ();
818 vector_type
*is_vector () final override
{ return this; }
821 string
* make_debug_string () final override
;
822 void write_reproducer (reproducer
&r
) final override
;
828 class array_type
: public type
831 array_type (context
*ctxt
,
837 m_element_type (element_type
),
838 m_num_elements (num_elements
)
841 type
*dereference () final override
;
843 bool is_int () const final override
{ return false; }
844 bool is_float () const final override
{ return false; }
845 bool is_bool () const final override
{ return false; }
846 type
*is_pointer () final override
{ return NULL
; }
847 type
*is_array () final override
{ return m_element_type
; }
848 int num_elements () { return m_num_elements
; }
849 bool is_signed () const final override
{ return false; }
851 void replay_into (replayer
*) final override
;
854 string
* make_debug_string () final override
;
855 void write_reproducer (reproducer
&r
) final override
;
859 type
*m_element_type
;
863 class function_type
: public type
866 function_type (context
*ctxt
,
872 type
*dereference () final override
;
873 function_type
*dyn_cast_function_type () final override
{ return this; }
874 function_type
*as_a_function_type () final override
{ return this; }
876 bool is_same_type_as (type
*other
) final override
;
878 bool is_int () const final override
{ return false; }
879 bool is_float () const final override
{ return false; }
880 bool is_bool () const final override
{ return false; }
881 type
*is_pointer () final override
{ return NULL
; }
882 type
*is_array () final override
{ return NULL
; }
883 bool is_signed () const final override
{ return false; }
885 void replay_into (replayer
*) final override
;
887 type
* get_return_type () const { return m_return_type
; }
888 const vec
<type
*> &get_param_types () const { return m_param_types
; }
889 int is_variadic () const { return m_is_variadic
; }
891 string
* make_debug_string_with_ptr ();
894 write_deferred_reproducer (reproducer
&r
,
898 string
* make_debug_string () final override
;
899 string
* make_debug_string_with (const char *);
900 void write_reproducer (reproducer
&r
) final override
;
904 auto_vec
<type
*> m_param_types
;
908 class field
: public memento
911 field (context
*ctxt
,
922 type
* get_type () const { return m_type
; }
924 compound_type
* get_container () const { return m_container
; }
925 void set_container (compound_type
*c
) { m_container
= c
; }
927 void replay_into (replayer
*) override
;
929 void write_to_dump (dump
&d
) override
;
932 playback_field () const
934 return static_cast <playback::field
*> (m_playback_obj
);
938 string
* make_debug_string () override
;
939 void write_reproducer (reproducer
&r
) override
;
945 compound_type
*m_container
;
949 class bitfield
: public field
952 bitfield (context
*ctxt
,
957 : field (ctxt
, loc
, type
, name
),
961 void replay_into (replayer
*) final override
;
963 void write_to_dump (dump
&d
) final override
;
966 string
* make_debug_string () final override
;
967 void write_reproducer (reproducer
&r
) final override
;
973 /* Base class for struct_ and union_ */
974 class compound_type
: public type
977 compound_type (context
*ctxt
,
981 string
*get_name () const { return m_name
; }
982 location
*get_loc () const { return m_loc
; }
983 fields
* get_fields () { return m_fields
; }
986 set_fields (location
*loc
,
990 type
*dereference () final override
;
992 bool is_int () const final override
{ return false; }
993 bool is_float () const final override
{ return false; }
994 bool is_bool () const final override
{ return false; }
995 type
*is_pointer () final override
{ return NULL
; }
996 type
*is_array () final override
{ return NULL
; }
997 bool is_signed () const final override
{ return false; }
999 bool has_known_size () const final override
{ return m_fields
!= NULL
; }
1001 playback::compound_type
*
1002 playback_compound_type ()
1004 return static_cast <playback::compound_type
*> (m_playback_obj
);
1013 class struct_
: public compound_type
1016 struct_ (context
*ctxt
,
1020 struct_
*dyn_cast_struct () final override
{ return this; }
1023 as_type () { return this; }
1025 void replay_into (replayer
*r
) final override
;
1027 const char *access_as_type (reproducer
&r
) final override
;
1029 struct_
*is_struct () final override
{ return this; }
1032 string
* make_debug_string () final override
;
1033 void write_reproducer (reproducer
&r
) final override
;
1036 // memento of struct_::set_fields
1037 class fields
: public memento
1040 fields (compound_type
*struct_or_union
,
1044 void replay_into (replayer
*r
) final override
;
1046 void write_to_dump (dump
&d
) final override
;
1048 int length () const { return m_fields
.length (); }
1049 field
*get_field (int i
) const { return m_fields
[i
]; }
1052 string
* make_debug_string () final override
;
1053 void write_reproducer (reproducer
&r
) final override
;
1056 compound_type
*m_struct_or_union
;
1057 auto_vec
<field
*> m_fields
;
1060 class union_
: public compound_type
1063 union_ (context
*ctxt
,
1067 void replay_into (replayer
*r
) final override
;
1069 bool is_union () const final override
{ return true; }
1072 string
* make_debug_string () final override
;
1073 void write_reproducer (reproducer
&r
) final override
;
1076 /* An abstract base class for operations that visit all rvalues within an
1078 Currently the only implementation is class rvalue_usage_validator within
1079 jit-recording.cc. */
1081 class rvalue_visitor
1084 virtual ~rvalue_visitor () {}
1085 virtual void visit (rvalue
*rvalue
) = 0;
1088 /* When generating debug strings for rvalues we mimic C, so we need to
1089 mimic C's precedence levels when handling compound expressions.
1090 These are in order from strongest precedence to weakest. */
1097 PRECEDENCE_MULTIPLICATIVE
,
1098 PRECEDENCE_ADDITIVE
,
1100 PRECEDENCE_RELATIONAL
,
1101 PRECEDENCE_EQUALITY
,
1102 PRECEDENCE_BITWISE_AND
,
1103 PRECEDENCE_BITWISE_XOR
,
1104 PRECEDENCE_BITWISE_IOR
,
1105 PRECEDENCE_LOGICAL_AND
,
1106 PRECEDENCE_LOGICAL_OR
1109 class rvalue
: public memento
1112 rvalue (context
*ctxt
,
1119 m_parenthesized_string (NULL
)
1124 location
* get_loc () const { return m_loc
; }
1126 /* Get the recording::type of this rvalue.
1128 Implements the post-error-checking part of
1129 gcc_jit_rvalue_get_type. */
1130 type
* get_type () const { return m_type
; }
1133 playback_rvalue () const
1135 return static_cast <playback::rvalue
*> (m_playback_obj
);
1138 access_field (location
*loc
,
1142 dereference_field (location
*loc
,
1146 dereference (location
*loc
);
1149 verify_valid_within_stmt (const char *api_funcname
, statement
*s
);
1151 virtual void visit_children (rvalue_visitor
*v
) = 0;
1153 void set_scope (function
*scope
);
1154 function
*get_scope () const { return m_scope
; }
1156 /* Dynamic casts. */
1157 virtual param
*dyn_cast_param () { return NULL
; }
1158 virtual base_call
*dyn_cast_base_call () { return NULL
; }
1160 virtual const char *access_as_rvalue (reproducer
&r
);
1162 /* Get the debug string, wrapped in parentheses. */
1164 get_debug_string_parens (enum precedence outer_prec
);
1166 virtual bool is_constant () const { return false; }
1167 virtual bool get_wide_int (wide_int
*) const { return false; }
1170 virtual enum precedence
get_precedence () const = 0;
1177 function
*m_scope
; /* NULL for globals, non-NULL for locals/params */
1178 string
*m_parenthesized_string
;
1181 class lvalue
: public rvalue
1184 lvalue (context
*ctxt
,
1187 : rvalue (ctxt
, loc
, type_
),
1188 m_link_section (NULL
),
1190 m_tls_model (GCC_JIT_TLS_MODEL_NONE
),
1195 playback_lvalue () const
1197 return static_cast <playback::lvalue
*> (m_playback_obj
);
1201 access_field (location
*loc
,
1205 get_address (location
*loc
);
1208 as_rvalue () { return this; }
1210 const char *access_as_rvalue (reproducer
&r
) override
;
1211 virtual const char *access_as_lvalue (reproducer
&r
);
1212 virtual bool is_global () const { return false; }
1213 void set_tls_model (enum gcc_jit_tls_model model
);
1214 void set_link_section (const char *name
);
1215 void set_register_name (const char *reg_name
);
1216 void set_alignment (unsigned bytes
);
1217 unsigned get_alignment () const { return m_alignment
; }
1220 string
*m_link_section
;
1222 enum gcc_jit_tls_model m_tls_model
;
1223 unsigned m_alignment
;
1226 class param
: public lvalue
1229 param (context
*ctxt
,
1233 : lvalue (ctxt
, loc
, type
),
1237 as_lvalue () { return this; }
1239 void replay_into (replayer
*r
) final override
;
1241 void visit_children (rvalue_visitor
*) final override
{}
1244 playback_param () const
1246 return static_cast <playback::param
*> (m_playback_obj
);
1249 param
*dyn_cast_param () final override
{ return this; }
1251 const char *access_as_rvalue (reproducer
&r
) final override
;
1252 const char *access_as_lvalue (reproducer
&r
) final override
;
1255 string
* make_debug_string () final override
{ return m_name
; }
1256 void write_reproducer (reproducer
&r
) final override
;
1257 enum precedence
get_precedence () const final override
1259 return PRECEDENCE_PRIMARY
;
1266 class function
: public memento
1269 function (context
*ctxt
,
1271 enum gcc_jit_function_kind kind
,
1277 enum built_in_function builtin_id
);
1279 void replay_into (replayer
*r
) final override
;
1281 playback::function
*
1282 playback_function () const
1284 return static_cast <playback::function
*> (m_playback_obj
);
1287 enum gcc_jit_function_kind
get_kind () const { return m_kind
; }
1290 new_local (location
*loc
,
1295 new_block (const char *name
);
1297 location
*get_loc () const { return m_loc
; }
1298 type
*get_return_type () const { return m_return_type
; }
1299 string
* get_name () const { return m_name
; }
1300 const vec
<param
*> &get_params () const { return m_params
; }
1302 /* Get the given param by index.
1303 Implements the post-error-checking part of
1304 gcc_jit_function_get_param. */
1305 param
*get_param (int i
) const { return m_params
[i
]; }
1307 bool is_variadic () const { return m_is_variadic
; }
1309 void write_to_dump (dump
&d
) final override
;
1313 void dump_to_dot (const char *path
);
1315 rvalue
*get_address (location
*loc
);
1318 string
* make_debug_string () final override
;
1319 void write_reproducer (reproducer
&r
) final override
;
1323 enum gcc_jit_function_kind m_kind
;
1324 type
*m_return_type
;
1326 auto_vec
<param
*> m_params
;
1328 enum built_in_function m_builtin_id
;
1329 auto_vec
<local
*> m_locals
;
1330 auto_vec
<block
*> m_blocks
;
1331 type
*m_fn_ptr_type
;
1334 class block
: public memento
1337 block (function
*func
, int index
, string
*name
)
1338 : memento (func
->m_ctxt
),
1343 m_has_been_terminated (false),
1344 m_is_reachable (false)
1348 /* Get the recording::function containing this block.
1349 Implements the post-error-checking part of
1350 gcc_jit_block_get_function. */
1351 function
*get_function () { return m_func
; }
1353 bool has_been_terminated () { return m_has_been_terminated
; }
1354 bool is_reachable () { return m_is_reachable
; }
1357 add_eval (location
*loc
,
1361 add_assignment (location
*loc
,
1366 add_assignment_op (location
*loc
,
1368 enum gcc_jit_binary_op op
,
1372 add_comment (location
*loc
,
1376 add_extended_asm (location
*loc
,
1377 const char *asm_template
);
1380 end_with_conditional (location
*loc
,
1386 end_with_jump (location
*loc
,
1390 end_with_return (location
*loc
,
1394 end_with_switch (location
*loc
,
1396 block
*default_block
,
1401 end_with_extended_asm_goto (location
*loc
,
1402 const char *asm_template
,
1403 int num_goto_blocks
,
1404 block
**goto_blocks
,
1405 block
*fallthrough_block
);
1408 playback_block () const
1410 return static_cast <playback::block
*> (m_playback_obj
);
1413 void write_to_dump (dump
&d
) final override
;
1417 location
*get_loc () const;
1419 statement
*get_first_statement () const;
1420 statement
*get_last_statement () const;
1422 vec
<block
*> get_successor_blocks () const;
1425 string
* make_debug_string () final override
;
1426 void write_reproducer (reproducer
&r
) final override
;
1428 void replay_into (replayer
*r
) final override
;
1430 void dump_to_dot (pretty_printer
*pp
);
1431 void dump_edges_to_dot (pretty_printer
*pp
);
1437 auto_vec
<statement
*> m_statements
;
1438 bool m_has_been_terminated
;
1439 bool m_is_reachable
;
1441 friend class function
;
1444 class global
: public lvalue
1447 global (context
*ctxt
,
1449 enum gcc_jit_global_kind kind
,
1452 : lvalue (ctxt
, loc
, type
),
1456 m_initializer
= NULL
;
1457 m_initializer_num_bytes
= 0;
1461 free (m_initializer
);
1464 void replay_into (replayer
*) final override
;
1466 void visit_children (rvalue_visitor
*) final override
{}
1468 void write_to_dump (dump
&d
) final override
;
1470 bool is_global () const final override
{ return true; }
1473 set_initializer (const void *initializer
,
1477 free (m_initializer
);
1478 m_initializer
= xmalloc (num_bytes
);
1479 memcpy (m_initializer
, initializer
, num_bytes
);
1480 m_initializer_num_bytes
= num_bytes
;
1483 void set_flags (int flag_fields
)
1485 m_flags
= (enum global_var_flags
)(m_flags
| flag_fields
);
1487 /* Returns true if any of the flags in the argument is set. */
1488 bool test_flags_anyof (int flag_fields
) const
1490 return m_flags
& flag_fields
;
1493 enum gcc_jit_global_kind
get_kind () const
1498 void set_rvalue_init (rvalue
*val
) { m_rvalue_init
= val
; }
1501 string
* make_debug_string () final override
{ return m_name
; }
1502 template <typename T
>
1503 void write_initializer_reproducer (const char *id
, reproducer
&r
);
1504 void write_reproducer (reproducer
&r
) final override
;
1505 enum precedence
get_precedence () const final override
1507 return PRECEDENCE_PRIMARY
;
1511 enum gcc_jit_global_kind m_kind
;
1512 enum global_var_flags m_flags
= GLOBAL_VAR_FLAGS_NONE
;
1514 void *m_initializer
;
1515 rvalue
*m_rvalue_init
= nullptr; /* Only needed for write_dump. */
1516 size_t m_initializer_num_bytes
;
1519 template <typename HOST_TYPE
>
1520 class memento_of_new_rvalue_from_const
: public rvalue
1523 memento_of_new_rvalue_from_const (context
*ctxt
,
1527 : rvalue (ctxt
, loc
, type
),
1530 void replay_into (replayer
*r
) final override
;
1532 void visit_children (rvalue_visitor
*) final override
{}
1534 bool is_constant () const final override
{ return true; }
1536 bool get_wide_int (wide_int
*out
) const final override
;
1539 string
* make_debug_string () final override
;
1540 void write_reproducer (reproducer
&r
) final override
;
1541 enum precedence
get_precedence () const final override
1543 return PRECEDENCE_PRIMARY
;
1550 class memento_of_new_string_literal
: public rvalue
1553 memento_of_new_string_literal (context
*ctxt
,
1556 : rvalue (ctxt
, loc
, ctxt
->get_type (GCC_JIT_TYPE_CONST_CHAR_PTR
)),
1559 void replay_into (replayer
*r
) final override
;
1561 void visit_children (rvalue_visitor
*) final override
{}
1564 string
* make_debug_string () final override
;
1565 void write_reproducer (reproducer
&r
) final override
;
1566 enum precedence
get_precedence () const final override
1568 return PRECEDENCE_PRIMARY
;
1575 class memento_of_new_rvalue_from_vector
: public rvalue
1578 memento_of_new_rvalue_from_vector (context
*ctxt
,
1583 void replay_into (replayer
*r
) final override
;
1585 void visit_children (rvalue_visitor
*) final override
;
1588 string
* make_debug_string () final override
;
1589 void write_reproducer (reproducer
&r
) final override
;
1590 enum precedence
get_precedence () const final override
1592 return PRECEDENCE_PRIMARY
;
1596 vector_type
*m_vector_type
;
1597 auto_vec
<rvalue
*> m_elements
;
1600 class ctor
: public rvalue
1603 ctor (context
*ctxt
,
1606 : rvalue (ctxt
, loc
, type
)
1609 void replay_into (replayer
*r
) final override
;
1611 void visit_children (rvalue_visitor
*) final override
;
1614 string
* make_debug_string () final override
;
1615 void write_reproducer (reproducer
&r
) final override
;
1616 enum precedence
get_precedence () const final override
1618 return PRECEDENCE_PRIMARY
;
1622 auto_vec
<field
*> m_fields
;
1623 auto_vec
<rvalue
*> m_values
;
1626 class unary_op
: public rvalue
1629 unary_op (context
*ctxt
,
1631 enum gcc_jit_unary_op op
,
1634 : rvalue (ctxt
, loc
, result_type
),
1639 void replay_into (replayer
*r
) final override
;
1641 void visit_children (rvalue_visitor
*v
) final override
;
1644 string
* make_debug_string () final override
;
1645 void write_reproducer (reproducer
&r
) final override
;
1646 enum precedence
get_precedence () const final override
1648 return PRECEDENCE_UNARY
;
1652 enum gcc_jit_unary_op m_op
;
1656 class binary_op
: public rvalue
1659 binary_op (context
*ctxt
,
1661 enum gcc_jit_binary_op op
,
1663 rvalue
*a
, rvalue
*b
)
1664 : rvalue (ctxt
, loc
, result_type
),
1669 void replay_into (replayer
*r
) final override
;
1671 void visit_children (rvalue_visitor
*v
) final override
;
1674 string
* make_debug_string () final override
;
1675 void write_reproducer (reproducer
&r
) final override
;
1676 enum precedence
get_precedence () const final override
;
1679 enum gcc_jit_binary_op m_op
;
1684 class comparison
: public rvalue
1687 comparison (context
*ctxt
,
1689 enum gcc_jit_comparison op
,
1690 rvalue
*a
, rvalue
*b
)
1691 : rvalue (ctxt
, loc
, ctxt
->get_type (GCC_JIT_TYPE_BOOL
)),
1696 type
*a_type
= a
->get_type ();
1697 vector_type
*vec_type
= a_type
->dyn_cast_vector_type ();
1698 if (vec_type
!= NULL
)
1700 type
*element_type
= vec_type
->get_element_type ();
1702 /* Vectors of floating-point values return a vector of integers of the
1704 if (element_type
->is_float ())
1705 inner_type
= ctxt
->get_int_type (element_type
->get_size (), false);
1707 inner_type
= element_type
;
1708 m_type
= new vector_type (inner_type
, vec_type
->get_num_units ());
1709 ctxt
->record (m_type
);
1713 void replay_into (replayer
*r
) final override
;
1715 void visit_children (rvalue_visitor
*v
) final override
;
1718 string
* make_debug_string () final override
;
1719 void write_reproducer (reproducer
&r
) final override
;
1720 enum precedence
get_precedence () const final override
;
1723 enum gcc_jit_comparison m_op
;
1728 class cast
: public rvalue
1731 cast (context
*ctxt
,
1735 : rvalue (ctxt
, loc
, type_
),
1739 void replay_into (replayer
*r
) final override
;
1741 void visit_children (rvalue_visitor
*v
) final override
;
1744 string
* make_debug_string () final override
;
1745 void write_reproducer (reproducer
&r
) final override
;
1746 enum precedence
get_precedence () const final override
1748 return PRECEDENCE_CAST
;
1755 class bitcast
: public rvalue
1758 bitcast (context
*ctxt
,
1762 : rvalue (ctxt
, loc
, type_
),
1766 void replay_into (replayer
*r
) final override
;
1768 void visit_children (rvalue_visitor
*v
) final override
;
1771 string
* make_debug_string () final override
;
1772 void write_reproducer (reproducer
&r
) final override
;
1773 enum precedence
get_precedence () const final override
1775 return PRECEDENCE_CAST
;
1782 class base_call
: public rvalue
1785 base_call (context
*ctxt
,
1791 enum precedence
get_precedence () const final override
1793 return PRECEDENCE_POSTFIX
;
1796 base_call
*dyn_cast_base_call () final override
{ return this; }
1798 void set_require_tail_call (bool require_tail_call
)
1800 m_require_tail_call
= require_tail_call
;
1804 void write_reproducer_tail_call (reproducer
&r
, const char *id
);
1807 auto_vec
<rvalue
*> m_args
;
1808 bool m_require_tail_call
;
1811 class call
: public base_call
1814 call (context
*ctxt
,
1820 void replay_into (replayer
*r
) final override
;
1822 void visit_children (rvalue_visitor
*v
) final override
;
1825 string
* make_debug_string () final override
;
1826 void write_reproducer (reproducer
&r
) final override
;
1832 class call_through_ptr
: public base_call
1835 call_through_ptr (context
*ctxt
,
1841 void replay_into (replayer
*r
) final override
;
1843 void visit_children (rvalue_visitor
*v
) final override
;
1846 string
* make_debug_string () final override
;
1847 void write_reproducer (reproducer
&r
) final override
;
1853 class array_access
: public lvalue
1856 array_access (context
*ctxt
,
1860 : lvalue (ctxt
, loc
, ptr
->get_type ()->dereference ()),
1865 void replay_into (replayer
*r
) final override
;
1867 void visit_children (rvalue_visitor
*v
) final override
;
1870 string
* make_debug_string () final override
;
1871 void write_reproducer (reproducer
&r
) final override
;
1872 enum precedence
get_precedence () const final override
1874 return PRECEDENCE_POSTFIX
;
1882 class access_field_of_lvalue
: public lvalue
1885 access_field_of_lvalue (context
*ctxt
,
1889 : lvalue (ctxt
, loc
, field
->get_type ()),
1894 void replay_into (replayer
*r
) final override
;
1896 void visit_children (rvalue_visitor
*v
) final override
;
1899 string
* make_debug_string () final override
;
1900 void write_reproducer (reproducer
&r
) final override
;
1901 enum precedence
get_precedence () const final override
1903 return PRECEDENCE_POSTFIX
;
1911 class access_field_rvalue
: public rvalue
1914 access_field_rvalue (context
*ctxt
,
1918 : rvalue (ctxt
, loc
, field
->get_type ()),
1923 void replay_into (replayer
*r
) final override
;
1925 void visit_children (rvalue_visitor
*v
) final override
;
1928 string
* make_debug_string () final override
;
1929 void write_reproducer (reproducer
&r
) final override
;
1930 enum precedence
get_precedence () const final override
1932 return PRECEDENCE_POSTFIX
;
1940 class dereference_field_rvalue
: public lvalue
1943 dereference_field_rvalue (context
*ctxt
,
1947 : lvalue (ctxt
, loc
, field
->get_type ()),
1952 void replay_into (replayer
*r
) final override
;
1954 void visit_children (rvalue_visitor
*v
) final override
;
1957 string
* make_debug_string () final override
;
1958 void write_reproducer (reproducer
&r
) final override
;
1959 enum precedence
get_precedence () const final override
1961 return PRECEDENCE_POSTFIX
;
1969 class dereference_rvalue
: public lvalue
1972 dereference_rvalue (context
*ctxt
,
1975 : lvalue (ctxt
, loc
, val
->get_type ()->dereference ()),
1978 void replay_into (replayer
*r
) final override
;
1980 void visit_children (rvalue_visitor
*v
) final override
;
1983 string
* make_debug_string () final override
;
1984 void write_reproducer (reproducer
&r
) final override
;
1985 enum precedence
get_precedence () const final override
1987 return PRECEDENCE_UNARY
;
1994 class get_address_of_lvalue
: public rvalue
1997 get_address_of_lvalue (context
*ctxt
,
2000 : rvalue (ctxt
, loc
, val
->get_type ()->get_pointer ()),
2004 void replay_into (replayer
*r
) final override
;
2006 void visit_children (rvalue_visitor
*v
) final override
;
2009 string
* make_debug_string () final override
;
2010 void write_reproducer (reproducer
&r
) final override
;
2011 enum precedence
get_precedence () const final override
2013 return PRECEDENCE_UNARY
;
2020 class function_pointer
: public rvalue
2023 function_pointer (context
*ctxt
,
2027 : rvalue (ctxt
, loc
, type
),
2030 void replay_into (replayer
*r
) final override
;
2032 void visit_children (rvalue_visitor
*v
) final override
;
2035 string
* make_debug_string () final override
;
2036 void write_reproducer (reproducer
&r
) final override
;
2037 enum precedence
get_precedence () const final override
2039 return PRECEDENCE_UNARY
;
2046 class local
: public lvalue
2049 local (function
*func
, location
*loc
, type
*type_
, string
*name
)
2050 : lvalue (func
->m_ctxt
, loc
, type_
),
2057 void replay_into (replayer
*r
) final override
;
2059 void visit_children (rvalue_visitor
*) final override
{}
2061 void write_to_dump (dump
&d
) final override
;
2064 string
* make_debug_string () final override
{ return m_name
; }
2065 void write_reproducer (reproducer
&r
) final override
;
2066 enum precedence
get_precedence () const final override
2068 return PRECEDENCE_PRIMARY
;
2076 class statement
: public memento
2079 virtual vec
<block
*> get_successor_blocks () const;
2081 void write_to_dump (dump
&d
) final override
;
2083 block
*get_block () const { return m_block
; }
2084 location
*get_loc () const { return m_loc
; }
2087 statement (block
*b
, location
*loc
)
2088 : memento (b
->m_ctxt
),
2092 playback::location
*
2093 playback_location (replayer
*r
) const
2095 return ::gcc::jit::recording::playback_location (r
, m_loc
);
2103 class eval
: public statement
2109 : statement (b
, loc
),
2110 m_rvalue (rvalue
) {}
2112 void replay_into (replayer
*r
) final override
;
2115 string
* make_debug_string () final override
;
2116 void write_reproducer (reproducer
&r
) final override
;
2122 class assignment
: public statement
2125 assignment (block
*b
,
2129 : statement (b
, loc
),
2131 m_rvalue (rvalue
) {}
2133 void replay_into (replayer
*r
) final override
;
2136 string
* make_debug_string () final override
;
2137 void write_reproducer (reproducer
&r
) final override
;
2144 class assignment_op
: public statement
2147 assignment_op (block
*b
,
2150 enum gcc_jit_binary_op op
,
2152 : statement (b
, loc
),
2155 m_rvalue (rvalue
) {}
2157 void replay_into (replayer
*r
) final override
;
2160 string
* make_debug_string () final override
;
2161 void write_reproducer (reproducer
&r
) final override
;
2165 enum gcc_jit_binary_op m_op
;
2169 class comment
: public statement
2175 : statement (b
, loc
),
2178 void replay_into (replayer
*r
) final override
;
2181 string
* make_debug_string () final override
;
2182 void write_reproducer (reproducer
&r
) final override
;
2188 class conditional
: public statement
2191 conditional (block
*b
,
2196 : statement (b
, loc
),
2197 m_boolval (boolval
),
2198 m_on_true (on_true
),
2199 m_on_false (on_false
) {}
2201 void replay_into (replayer
*r
) final override
;
2203 vec
<block
*> get_successor_blocks () const final override
;
2206 string
* make_debug_string () final override
;
2207 void write_reproducer (reproducer
&r
) final override
;
2215 class jump
: public statement
2221 : statement (b
, loc
),
2222 m_target (target
) {}
2224 void replay_into (replayer
*r
) final override
;
2226 vec
<block
*> get_successor_blocks () const final override
;
2229 string
* make_debug_string () final override
;
2230 void write_reproducer (reproducer
&r
) final override
;
2236 class return_
: public statement
2242 : statement (b
, loc
),
2243 m_rvalue (rvalue
) {}
2245 void replay_into (replayer
*r
) final override
;
2247 vec
<block
*> get_successor_blocks () const final override
;
2250 string
* make_debug_string () final override
;
2251 void write_reproducer (reproducer
&r
) final override
;
2257 class case_
: public memento
2260 case_ (context
*ctxt
,
2265 m_min_value (min_value
),
2266 m_max_value (max_value
),
2267 m_dest_block (dest_block
)
2270 rvalue
*get_min_value () const { return m_min_value
; }
2271 rvalue
*get_max_value () const { return m_max_value
; }
2272 block
*get_dest_block () const { return m_dest_block
; }
2274 void replay_into (replayer
*) final override
{ /* empty */ }
2276 void write_reproducer (reproducer
&r
) final override
;
2279 string
* make_debug_string () final override
;
2282 rvalue
*m_min_value
;
2283 rvalue
*m_max_value
;
2284 block
*m_dest_block
;
2287 class switch_
: public statement
2293 block
*default_block
,
2297 void replay_into (replayer
*r
) final override
;
2299 vec
<block
*> get_successor_blocks () const final override
;
2302 string
* make_debug_string () final override
;
2303 void write_reproducer (reproducer
&r
) final override
;
2307 block
*m_default_block
;
2308 auto_vec
<case_
*> m_cases
;
2311 class asm_operand
: public memento
2314 asm_operand (extended_asm
*ext_asm
,
2315 string
*asm_symbolic_name
,
2316 string
*constraint
);
2318 const char *get_symbolic_name () const
2320 if (m_asm_symbolic_name
)
2321 return m_asm_symbolic_name
->c_str ();
2326 const char *get_constraint () const
2328 return m_constraint
->c_str ();
2331 virtual void print (pretty_printer
*pp
) const;
2334 string
* make_debug_string () final override
;
2337 extended_asm
*m_ext_asm
;
2338 string
*m_asm_symbolic_name
;
2339 string
*m_constraint
;
2342 class output_asm_operand
: public asm_operand
2345 output_asm_operand (extended_asm
*ext_asm
,
2346 string
*asm_symbolic_name
,
2349 : asm_operand (ext_asm
, asm_symbolic_name
, constraint
),
2353 lvalue
*get_lvalue () const { return m_dest
; }
2355 void replay_into (replayer
*) final override
{}
2357 void print (pretty_printer
*pp
) const final override
;
2360 void write_reproducer (reproducer
&r
) final override
;
2366 class input_asm_operand
: public asm_operand
2369 input_asm_operand (extended_asm
*ext_asm
,
2370 string
*asm_symbolic_name
,
2373 : asm_operand (ext_asm
, asm_symbolic_name
, constraint
),
2377 rvalue
*get_rvalue () const { return m_src
; }
2379 void replay_into (replayer
*) final override
{}
2381 void print (pretty_printer
*pp
) const final override
;
2384 void write_reproducer (reproducer
&r
) final override
;
2390 /* Abstract base class for extended_asm statements. */
2392 class extended_asm
: public statement
2395 extended_asm (block
*b
,
2397 string
*asm_template
)
2398 : statement (b
, loc
),
2399 m_asm_template (asm_template
),
2400 m_is_volatile (false),
2404 void set_volatile_flag (bool flag
) { m_is_volatile
= flag
; }
2405 void set_inline_flag (bool flag
) { m_is_inline
= flag
; }
2407 void add_output_operand (const char *asm_symbolic_name
,
2408 const char *constraint
,
2410 void add_input_operand (const char *asm_symbolic_name
,
2411 const char *constraint
,
2413 void add_clobber (const char *victim
);
2415 void replay_into (replayer
*r
) override
;
2417 string
*get_asm_template () const { return m_asm_template
; }
2419 virtual bool is_goto () const = 0;
2420 virtual void maybe_print_gotos (pretty_printer
*) const = 0;
2423 void write_flags (reproducer
&r
);
2424 void write_clobbers (reproducer
&r
);
2427 string
* make_debug_string () final override
;
2428 virtual void maybe_populate_playback_blocks
2429 (auto_vec
<playback::block
*> *out
) = 0;
2432 string
*m_asm_template
;
2435 auto_vec
<output_asm_operand
*> m_output_ops
;
2436 auto_vec
<input_asm_operand
*> m_input_ops
;
2437 auto_vec
<string
*> m_clobbers
;
2440 /* An extended_asm that's not a goto, as created by
2441 gcc_jit_block_add_extended_asm. */
2443 class extended_asm_simple
: public extended_asm
2446 extended_asm_simple (block
*b
,
2448 string
*asm_template
)
2449 : extended_asm (b
, loc
, asm_template
)
2452 void write_reproducer (reproducer
&r
) override
;
2453 bool is_goto () const final override
{ return false; }
2454 void maybe_print_gotos (pretty_printer
*) const final override
{}
2457 void maybe_populate_playback_blocks
2458 (auto_vec
<playback::block
*> *) final override
2462 /* An extended_asm that's a asm goto, as created by
2463 gcc_jit_block_end_with_extended_asm_goto. */
2465 class extended_asm_goto
: public extended_asm
2468 extended_asm_goto (block
*b
,
2470 string
*asm_template
,
2471 int num_goto_blocks
,
2472 block
**goto_blocks
,
2473 block
*fallthrough_block
);
2475 void replay_into (replayer
*r
) final override
;
2476 void write_reproducer (reproducer
&r
) override
;
2478 vec
<block
*> get_successor_blocks () const final override
;
2480 bool is_goto () const final override
{ return true; }
2481 void maybe_print_gotos (pretty_printer
*) const final override
;
2484 void maybe_populate_playback_blocks
2485 (auto_vec
<playback::block
*> *out
) final override
;
2488 auto_vec
<block
*> m_goto_blocks
;
2489 block
*m_fallthrough_block
;
2492 /* A group of top-level asm statements, as created by
2493 gcc_jit_context_add_top_level_asm. */
2495 class top_level_asm
: public memento
2498 top_level_asm (context
*ctxt
, location
*loc
, string
*asm_stmts
);
2500 void write_to_dump (dump
&d
) final override
;
2503 void replay_into (replayer
*r
) final override
;
2504 string
* make_debug_string () final override
;
2505 void write_reproducer (reproducer
&r
) final override
;
2509 string
*m_asm_stmts
;
2512 class global_init_rvalue
: public memento
2515 global_init_rvalue (context
*ctxt
, lvalue
*variable
, rvalue
*init
) :
2516 memento (ctxt
), m_variable (variable
), m_init (init
) {};
2518 void write_to_dump (dump
&d
) final override
;
2521 void replay_into (replayer
*r
) final override
;
2522 string
* make_debug_string () final override
;
2523 void write_reproducer (reproducer
&r
) final override
;
2530 } // namespace gcc::jit::recording
2532 /* Create a recording::memento_of_new_rvalue_from_const instance and add
2533 it to this context's list of mementos.
2535 Implements the post-error-checking part of
2536 gcc_jit_context_new_rvalue_from_{int|long|double|ptr}. */
2538 template <typename HOST_TYPE
>
2540 recording::context::new_rvalue_from_const (recording::type
*type
,
2543 recording::rvalue
*result
=
2544 new memento_of_new_rvalue_from_const
<HOST_TYPE
> (this, NULL
, type
, value
);
2549 /* Don't call this directly. Call types_kinda_same. */
2551 types_kinda_same_internal (recording::type
*a
,
2552 recording::type
*b
);
2554 /* Strip all qualifiers and count pointer depth, returning true
2555 if the types and pointer depth are the same, otherwise false.
2557 For array and vector types the number of element also
2558 has to match, aswell as the element types themself. */
2560 types_kinda_same (recording::type
*a
, recording::type
*b
)
2562 /* Handle trivial case here, to allow for inlining. */
2563 return a
== b
|| types_kinda_same_internal (a
, b
);
2566 } // namespace gcc::jit
2570 #endif /* JIT_RECORDING_H */