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_restrict ();
528 type
*get_aligned (size_t alignment_in_bytes
);
529 type
*get_vector (size_t num_units
);
531 /* Get the type obtained when dereferencing this type.
533 This will return NULL if it's not valid to dereference this type.
534 The caller is responsible for setting an error. */
535 virtual type
*dereference () = 0;
536 /* Get the type size in bytes.
538 This is implemented only for memento_of_get_type and
539 memento_of_get_pointer as it is used for initializing globals of
541 virtual size_t get_size () { gcc_unreachable (); }
544 virtual function_type
*dyn_cast_function_type () { return NULL
; }
545 virtual function_type
*as_a_function_type() { gcc_unreachable (); return NULL
; }
546 virtual struct_
*dyn_cast_struct () { return NULL
; }
547 virtual vector_type
*dyn_cast_vector_type () { return NULL
; }
549 /* Is it typesafe to copy to this type from rtype? */
550 virtual bool accepts_writes_from (type
*rtype
)
553 return this->unqualified ()->is_same_type_as (rtype
->unqualified ());
556 virtual bool is_same_type_as (type
*other
)
558 return this == other
;
561 /* Strip off "const" etc */
562 virtual type
*unqualified ()
567 virtual bool is_int () const = 0;
568 virtual bool is_float () const = 0;
569 virtual bool is_bool () const = 0;
570 virtual type
*is_pointer () = 0;
571 virtual type
*is_volatile () { return NULL
; }
572 virtual type
*is_restrict () { return NULL
; }
573 virtual type
*is_const () { return NULL
; }
574 virtual type
*is_array () = 0;
575 virtual struct_
*is_struct () { return NULL
; }
576 virtual bool is_union () const { return false; }
577 virtual bool is_void () const { return false; }
578 virtual vector_type
*is_vector () { return NULL
; }
579 virtual bool has_known_size () const { return true; }
580 virtual bool is_signed () const = 0;
582 bool is_numeric () const
584 return is_int () || is_float () || is_bool ();
590 return static_cast <playback::type
*> (m_playback_obj
);
593 virtual const char *access_as_type (reproducer
&r
);
598 m_pointer_to_this_type (NULL
)
602 type
*m_pointer_to_this_type
;
605 /* Result of "gcc_jit_context_get_type". */
606 class memento_of_get_type
: public type
609 memento_of_get_type (context
*ctxt
,
610 enum gcc_jit_types kind
)
614 type
*dereference () final override
;
616 size_t get_size () final override
;
618 bool accepts_writes_from (type
*rtype
) final override
620 if (m_kind
== GCC_JIT_TYPE_VOID_PTR
)
622 if (rtype
->is_pointer ())
624 /* LHS (this) is type (void *), and the RHS is a pointer:
630 && get_size () == rtype
->get_size ()
631 && is_signed () == rtype
->is_signed ())
633 /* LHS (this) is an integer of the same size and sign as rtype. */
637 return type::accepts_writes_from (rtype
);
640 bool is_int () const final override
;
641 bool is_float () const final override
;
642 bool is_bool () const final override
;
643 type
*is_pointer () final override
{ return dereference (); }
644 type
*is_array () final override
{ return NULL
; }
645 bool is_void () const final override
{ return m_kind
== GCC_JIT_TYPE_VOID
; }
646 bool is_signed () const final override
;
649 void replay_into (replayer
*r
) final override
;
652 string
* make_debug_string () final override
;
653 void write_reproducer (reproducer
&r
) final override
;
656 enum gcc_jit_types m_kind
;
659 /* Result of "gcc_jit_type_get_pointer". */
660 class memento_of_get_pointer
: public type
663 memento_of_get_pointer (type
*other_type
)
664 : type (other_type
->m_ctxt
),
665 m_other_type (other_type
) {}
667 type
*dereference () final override
{ return m_other_type
; }
669 size_t get_size () final override
;
671 bool accepts_writes_from (type
*rtype
) final override
;
673 void replay_into (replayer
*r
) final override
;
675 bool is_int () const final override
{ return false; }
676 bool is_float () const final override
{ return false; }
677 bool is_bool () const final override
{ return false; }
678 type
*is_pointer () final override
{ return m_other_type
; }
679 type
*is_array () final override
{ return NULL
; }
680 bool is_signed () const final override
{ return false; }
683 string
* make_debug_string () final override
;
684 void write_reproducer (reproducer
&r
) final override
;
690 /* A decorated version of a type, for get_const, get_volatile,
691 get_aligned, get_restrict, and get_vector. */
693 class decorated_type
: public type
696 decorated_type (type
*other_type
)
697 : type (other_type
->m_ctxt
),
698 m_other_type (other_type
) {}
700 type
*dereference () final override
{ return m_other_type
->dereference (); }
702 size_t get_size () final override
{ return m_other_type
->get_size (); };
704 bool is_int () const final override
{ return m_other_type
->is_int (); }
705 bool is_float () const final override
{ return m_other_type
->is_float (); }
706 bool is_bool () const final override
{ return m_other_type
->is_bool (); }
707 type
*is_pointer () final override
{ return m_other_type
->is_pointer (); }
708 type
*is_array () final override
{ return m_other_type
->is_array (); }
709 struct_
*is_struct () final override
{ return m_other_type
->is_struct (); }
710 bool is_signed () const final override
{ return m_other_type
->is_signed (); }
716 /* Result of "gcc_jit_type_get_const". */
717 class memento_of_get_const
: public decorated_type
720 memento_of_get_const (type
*other_type
)
721 : decorated_type (other_type
) {}
723 bool accepts_writes_from (type */
*rtype*/
) final override
725 /* Can't write to a "const". */
729 /* Strip off the "const", giving the underlying type. */
730 type
*unqualified () final override
{ return m_other_type
; }
732 bool is_same_type_as (type
*other
) final override
734 if (!other
->is_const ())
736 return m_other_type
->is_same_type_as (other
->is_const ());
739 type
*is_const () final override
{ return m_other_type
; }
741 void replay_into (replayer
*) final override
;
744 string
* make_debug_string () final override
;
745 void write_reproducer (reproducer
&r
) final override
;
748 /* Result of "gcc_jit_type_get_volatile". */
749 class memento_of_get_volatile
: public decorated_type
752 memento_of_get_volatile (type
*other_type
)
753 : decorated_type (other_type
) {}
755 bool is_same_type_as (type
*other
) final override
757 if (!other
->is_volatile ())
759 return m_other_type
->is_same_type_as (other
->is_volatile ());
762 /* Strip off the "volatile", giving the underlying type. */
763 type
*unqualified () final override
{ return m_other_type
; }
765 type
*is_volatile () final override
{ return m_other_type
; }
767 void replay_into (replayer
*) final override
;
770 string
* make_debug_string () final override
;
771 void write_reproducer (reproducer
&r
) final override
;
774 /* Result of "gcc_jit_type_get_restrict". */
775 class memento_of_get_restrict
: public decorated_type
778 memento_of_get_restrict (type
*other_type
)
779 : decorated_type (other_type
) {}
781 bool is_same_type_as (type
*other
) final override
783 if (!other
->is_restrict ())
785 return m_other_type
->is_same_type_as (other
->is_restrict ());
788 /* Strip off the "restrict", giving the underlying type. */
789 type
*unqualified () final override
{ return m_other_type
; }
791 type
*is_restrict () final override
{ return m_other_type
; }
793 void replay_into (replayer
*) final override
;
796 string
* make_debug_string () final override
;
797 void write_reproducer (reproducer
&r
) final override
;
800 /* Result of "gcc_jit_type_get_aligned". */
801 class memento_of_get_aligned
: public decorated_type
804 memento_of_get_aligned (type
*other_type
, size_t alignment_in_bytes
)
805 : decorated_type (other_type
),
806 m_alignment_in_bytes (alignment_in_bytes
) {}
808 /* Strip off the alignment, giving the underlying type. */
809 type
*unqualified () final override
{ return m_other_type
; }
811 void replay_into (replayer
*) final override
;
814 string
* make_debug_string () final override
;
815 void write_reproducer (reproducer
&r
) final override
;
818 size_t m_alignment_in_bytes
;
821 /* Result of "gcc_jit_type_get_vector". */
822 class vector_type
: public decorated_type
825 vector_type (type
*other_type
, size_t num_units
)
826 : decorated_type (other_type
),
827 m_num_units (num_units
) {}
829 size_t get_num_units () const { return m_num_units
; }
831 vector_type
*dyn_cast_vector_type () final override
{ return this; }
833 type
*get_element_type () { return m_other_type
; }
835 void replay_into (replayer
*) final override
;
837 bool is_same_type_as (type
*other
) final override
839 vector_type
*other_vec_type
= other
->dyn_cast_vector_type ();
840 if (other_vec_type
== NULL
)
842 return get_num_units () == other_vec_type
->get_num_units ()
843 && get_element_type () == other_vec_type
->get_element_type ();
846 vector_type
*is_vector () final override
{ return this; }
849 string
* make_debug_string () final override
;
850 void write_reproducer (reproducer
&r
) final override
;
856 class array_type
: public type
859 array_type (context
*ctxt
,
865 m_element_type (element_type
),
866 m_num_elements (num_elements
)
869 type
*dereference () final override
;
871 bool is_int () const final override
{ return false; }
872 bool is_float () const final override
{ return false; }
873 bool is_bool () const final override
{ return false; }
874 type
*is_pointer () final override
{ return NULL
; }
875 type
*is_array () final override
{ return m_element_type
; }
876 int num_elements () { return m_num_elements
; }
877 bool is_signed () const final override
{ return false; }
879 void replay_into (replayer
*) final override
;
882 string
* make_debug_string () final override
;
883 void write_reproducer (reproducer
&r
) final override
;
887 type
*m_element_type
;
891 class function_type
: public type
894 function_type (context
*ctxt
,
900 type
*dereference () final override
;
901 function_type
*dyn_cast_function_type () final override
{ return this; }
902 function_type
*as_a_function_type () final override
{ return this; }
904 bool is_same_type_as (type
*other
) final override
;
906 bool is_int () const final override
{ return false; }
907 bool is_float () const final override
{ return false; }
908 bool is_bool () const final override
{ return false; }
909 type
*is_pointer () final override
{ return NULL
; }
910 type
*is_array () final override
{ return NULL
; }
911 bool is_signed () const final override
{ return false; }
913 void replay_into (replayer
*) final override
;
915 type
* get_return_type () const { return m_return_type
; }
916 const vec
<type
*> &get_param_types () const { return m_param_types
; }
917 int is_variadic () const { return m_is_variadic
; }
919 string
* make_debug_string_with_ptr ();
922 write_deferred_reproducer (reproducer
&r
,
926 string
* make_debug_string () final override
;
927 string
* make_debug_string_with (const char *);
928 void write_reproducer (reproducer
&r
) final override
;
932 auto_vec
<type
*> m_param_types
;
936 class field
: public memento
939 field (context
*ctxt
,
950 type
* get_type () const { return m_type
; }
952 compound_type
* get_container () const { return m_container
; }
953 void set_container (compound_type
*c
) { m_container
= c
; }
955 void replay_into (replayer
*) override
;
957 void write_to_dump (dump
&d
) override
;
960 playback_field () const
962 return static_cast <playback::field
*> (m_playback_obj
);
966 string
* make_debug_string () override
;
967 void write_reproducer (reproducer
&r
) override
;
973 compound_type
*m_container
;
977 class bitfield
: public field
980 bitfield (context
*ctxt
,
985 : field (ctxt
, loc
, type
, name
),
989 void replay_into (replayer
*) final override
;
991 void write_to_dump (dump
&d
) final override
;
994 string
* make_debug_string () final override
;
995 void write_reproducer (reproducer
&r
) final override
;
1001 /* Base class for struct_ and union_ */
1002 class compound_type
: public type
1005 compound_type (context
*ctxt
,
1009 string
*get_name () const { return m_name
; }
1010 location
*get_loc () const { return m_loc
; }
1011 fields
* get_fields () { return m_fields
; }
1014 set_fields (location
*loc
,
1018 type
*dereference () final override
;
1020 bool is_int () const final override
{ return false; }
1021 bool is_float () const final override
{ return false; }
1022 bool is_bool () const final override
{ return false; }
1023 type
*is_pointer () final override
{ return NULL
; }
1024 type
*is_array () final override
{ return NULL
; }
1025 bool is_signed () const final override
{ return false; }
1027 bool has_known_size () const final override
{ return m_fields
!= NULL
; }
1029 playback::compound_type
*
1030 playback_compound_type ()
1032 return static_cast <playback::compound_type
*> (m_playback_obj
);
1041 class struct_
: public compound_type
1044 struct_ (context
*ctxt
,
1048 struct_
*dyn_cast_struct () final override
{ return this; }
1051 as_type () { return this; }
1053 void replay_into (replayer
*r
) final override
;
1055 const char *access_as_type (reproducer
&r
) final override
;
1057 struct_
*is_struct () final override
{ return this; }
1060 string
* make_debug_string () final override
;
1061 void write_reproducer (reproducer
&r
) final override
;
1064 // memento of struct_::set_fields
1065 class fields
: public memento
1068 fields (compound_type
*struct_or_union
,
1072 void replay_into (replayer
*r
) final override
;
1074 void write_to_dump (dump
&d
) final override
;
1076 int length () const { return m_fields
.length (); }
1077 field
*get_field (int i
) const { return m_fields
[i
]; }
1080 string
* make_debug_string () final override
;
1081 void write_reproducer (reproducer
&r
) final override
;
1084 compound_type
*m_struct_or_union
;
1085 auto_vec
<field
*> m_fields
;
1088 class union_
: public compound_type
1091 union_ (context
*ctxt
,
1095 void replay_into (replayer
*r
) final override
;
1097 bool is_union () const final override
{ return true; }
1100 string
* make_debug_string () final override
;
1101 void write_reproducer (reproducer
&r
) final override
;
1104 /* An abstract base class for operations that visit all rvalues within an
1106 Currently the only implementation is class rvalue_usage_validator within
1107 jit-recording.cc. */
1109 class rvalue_visitor
1112 virtual ~rvalue_visitor () {}
1113 virtual void visit (rvalue
*rvalue
) = 0;
1116 /* When generating debug strings for rvalues we mimic C, so we need to
1117 mimic C's precedence levels when handling compound expressions.
1118 These are in order from strongest precedence to weakest. */
1125 PRECEDENCE_MULTIPLICATIVE
,
1126 PRECEDENCE_ADDITIVE
,
1128 PRECEDENCE_RELATIONAL
,
1129 PRECEDENCE_EQUALITY
,
1130 PRECEDENCE_BITWISE_AND
,
1131 PRECEDENCE_BITWISE_XOR
,
1132 PRECEDENCE_BITWISE_IOR
,
1133 PRECEDENCE_LOGICAL_AND
,
1134 PRECEDENCE_LOGICAL_OR
1137 class rvalue
: public memento
1140 rvalue (context
*ctxt
,
1147 m_parenthesized_string (NULL
)
1152 location
* get_loc () const { return m_loc
; }
1154 /* Get the recording::type of this rvalue.
1156 Implements the post-error-checking part of
1157 gcc_jit_rvalue_get_type. */
1158 type
* get_type () const { return m_type
; }
1161 playback_rvalue () const
1163 return static_cast <playback::rvalue
*> (m_playback_obj
);
1166 access_field (location
*loc
,
1170 dereference_field (location
*loc
,
1174 dereference (location
*loc
);
1177 verify_valid_within_stmt (const char *api_funcname
, statement
*s
);
1179 virtual void visit_children (rvalue_visitor
*v
) = 0;
1181 void set_scope (function
*scope
);
1182 function
*get_scope () const { return m_scope
; }
1184 /* Dynamic casts. */
1185 virtual param
*dyn_cast_param () { return NULL
; }
1186 virtual base_call
*dyn_cast_base_call () { return NULL
; }
1188 virtual const char *access_as_rvalue (reproducer
&r
);
1190 /* Get the debug string, wrapped in parentheses. */
1192 get_debug_string_parens (enum precedence outer_prec
);
1194 virtual bool is_constant () const { return false; }
1195 virtual bool get_wide_int (wide_int
*) const { return false; }
1198 virtual enum precedence
get_precedence () const = 0;
1205 function
*m_scope
; /* NULL for globals, non-NULL for locals/params */
1206 string
*m_parenthesized_string
;
1209 class lvalue
: public rvalue
1212 lvalue (context
*ctxt
,
1215 : rvalue (ctxt
, loc
, type_
),
1216 m_link_section (NULL
),
1218 m_tls_model (GCC_JIT_TLS_MODEL_NONE
),
1223 playback_lvalue () const
1225 return static_cast <playback::lvalue
*> (m_playback_obj
);
1229 access_field (location
*loc
,
1233 get_address (location
*loc
);
1236 as_rvalue () { return this; }
1238 const char *access_as_rvalue (reproducer
&r
) override
;
1239 virtual const char *access_as_lvalue (reproducer
&r
);
1240 virtual bool is_global () const { return false; }
1241 void set_tls_model (enum gcc_jit_tls_model model
);
1242 void set_link_section (const char *name
);
1243 void set_register_name (const char *reg_name
);
1244 void set_alignment (unsigned bytes
);
1245 unsigned get_alignment () const { return m_alignment
; }
1248 string
*m_link_section
;
1250 enum gcc_jit_tls_model m_tls_model
;
1251 unsigned m_alignment
;
1254 class param
: public lvalue
1257 param (context
*ctxt
,
1261 : lvalue (ctxt
, loc
, type
),
1265 as_lvalue () { return this; }
1267 void replay_into (replayer
*r
) final override
;
1269 void visit_children (rvalue_visitor
*) final override
{}
1272 playback_param () const
1274 return static_cast <playback::param
*> (m_playback_obj
);
1277 param
*dyn_cast_param () final override
{ return this; }
1279 const char *access_as_rvalue (reproducer
&r
) final override
;
1280 const char *access_as_lvalue (reproducer
&r
) final override
;
1283 string
* make_debug_string () final override
{ return m_name
; }
1284 void write_reproducer (reproducer
&r
) final override
;
1285 enum precedence
get_precedence () const final override
1287 return PRECEDENCE_PRIMARY
;
1294 class function
: public memento
1297 function (context
*ctxt
,
1299 enum gcc_jit_function_kind kind
,
1305 enum built_in_function builtin_id
);
1307 void replay_into (replayer
*r
) final override
;
1309 playback::function
*
1310 playback_function () const
1312 return static_cast <playback::function
*> (m_playback_obj
);
1315 enum gcc_jit_function_kind
get_kind () const { return m_kind
; }
1318 new_local (location
*loc
,
1323 new_block (const char *name
);
1325 location
*get_loc () const { return m_loc
; }
1326 type
*get_return_type () const { return m_return_type
; }
1327 string
* get_name () const { return m_name
; }
1328 const vec
<param
*> &get_params () const { return m_params
; }
1330 /* Get the given param by index.
1331 Implements the post-error-checking part of
1332 gcc_jit_function_get_param. */
1333 param
*get_param (int i
) const { return m_params
[i
]; }
1335 bool is_variadic () const { return m_is_variadic
; }
1337 void write_to_dump (dump
&d
) final override
;
1341 void dump_to_dot (const char *path
);
1343 rvalue
*get_address (location
*loc
);
1346 string
* make_debug_string () final override
;
1347 void write_reproducer (reproducer
&r
) final override
;
1351 enum gcc_jit_function_kind m_kind
;
1352 type
*m_return_type
;
1354 auto_vec
<param
*> m_params
;
1356 enum built_in_function m_builtin_id
;
1357 auto_vec
<local
*> m_locals
;
1358 auto_vec
<block
*> m_blocks
;
1359 type
*m_fn_ptr_type
;
1362 class block
: public memento
1365 block (function
*func
, int index
, string
*name
)
1366 : memento (func
->m_ctxt
),
1371 m_has_been_terminated (false),
1372 m_is_reachable (false)
1376 /* Get the recording::function containing this block.
1377 Implements the post-error-checking part of
1378 gcc_jit_block_get_function. */
1379 function
*get_function () { return m_func
; }
1381 bool has_been_terminated () { return m_has_been_terminated
; }
1382 bool is_reachable () { return m_is_reachable
; }
1385 add_eval (location
*loc
,
1389 add_assignment (location
*loc
,
1394 add_assignment_op (location
*loc
,
1396 enum gcc_jit_binary_op op
,
1400 add_comment (location
*loc
,
1404 add_extended_asm (location
*loc
,
1405 const char *asm_template
);
1408 end_with_conditional (location
*loc
,
1414 end_with_jump (location
*loc
,
1418 end_with_return (location
*loc
,
1422 end_with_switch (location
*loc
,
1424 block
*default_block
,
1429 end_with_extended_asm_goto (location
*loc
,
1430 const char *asm_template
,
1431 int num_goto_blocks
,
1432 block
**goto_blocks
,
1433 block
*fallthrough_block
);
1436 playback_block () const
1438 return static_cast <playback::block
*> (m_playback_obj
);
1441 void write_to_dump (dump
&d
) final override
;
1445 location
*get_loc () const;
1447 statement
*get_first_statement () const;
1448 statement
*get_last_statement () const;
1450 vec
<block
*> get_successor_blocks () const;
1453 string
* make_debug_string () final override
;
1454 void write_reproducer (reproducer
&r
) final override
;
1456 void replay_into (replayer
*r
) final override
;
1458 void dump_to_dot (pretty_printer
*pp
);
1459 void dump_edges_to_dot (pretty_printer
*pp
);
1465 auto_vec
<statement
*> m_statements
;
1466 bool m_has_been_terminated
;
1467 bool m_is_reachable
;
1469 friend class function
;
1472 class global
: public lvalue
1475 global (context
*ctxt
,
1477 enum gcc_jit_global_kind kind
,
1480 : lvalue (ctxt
, loc
, type
),
1484 m_initializer
= NULL
;
1485 m_initializer_num_bytes
= 0;
1489 free (m_initializer
);
1492 void replay_into (replayer
*) final override
;
1494 void visit_children (rvalue_visitor
*) final override
{}
1496 void write_to_dump (dump
&d
) final override
;
1498 bool is_global () const final override
{ return true; }
1501 set_initializer (const void *initializer
,
1505 free (m_initializer
);
1506 m_initializer
= xmalloc (num_bytes
);
1507 memcpy (m_initializer
, initializer
, num_bytes
);
1508 m_initializer_num_bytes
= num_bytes
;
1511 void set_flags (int flag_fields
)
1513 m_flags
= (enum global_var_flags
)(m_flags
| flag_fields
);
1515 /* Returns true if any of the flags in the argument is set. */
1516 bool test_flags_anyof (int flag_fields
) const
1518 return m_flags
& flag_fields
;
1521 enum gcc_jit_global_kind
get_kind () const
1526 void set_rvalue_init (rvalue
*val
) { m_rvalue_init
= val
; }
1529 string
* make_debug_string () final override
{ return m_name
; }
1530 template <typename T
>
1531 void write_initializer_reproducer (const char *id
, reproducer
&r
);
1532 void write_reproducer (reproducer
&r
) final override
;
1533 enum precedence
get_precedence () const final override
1535 return PRECEDENCE_PRIMARY
;
1539 enum gcc_jit_global_kind m_kind
;
1540 enum global_var_flags m_flags
= GLOBAL_VAR_FLAGS_NONE
;
1542 void *m_initializer
;
1543 rvalue
*m_rvalue_init
= nullptr; /* Only needed for write_dump. */
1544 size_t m_initializer_num_bytes
;
1547 template <typename HOST_TYPE
>
1548 class memento_of_new_rvalue_from_const
: public rvalue
1551 memento_of_new_rvalue_from_const (context
*ctxt
,
1555 : rvalue (ctxt
, loc
, type
),
1558 void replay_into (replayer
*r
) final override
;
1560 void visit_children (rvalue_visitor
*) final override
{}
1562 bool is_constant () const final override
{ return true; }
1564 bool get_wide_int (wide_int
*out
) const final override
;
1567 string
* make_debug_string () final override
;
1568 void write_reproducer (reproducer
&r
) final override
;
1569 enum precedence
get_precedence () const final override
1571 return PRECEDENCE_PRIMARY
;
1578 class memento_of_new_string_literal
: public rvalue
1581 memento_of_new_string_literal (context
*ctxt
,
1584 : rvalue (ctxt
, loc
, ctxt
->get_type (GCC_JIT_TYPE_CONST_CHAR_PTR
)),
1587 void replay_into (replayer
*r
) final override
;
1589 void visit_children (rvalue_visitor
*) final override
{}
1592 string
* make_debug_string () final override
;
1593 void write_reproducer (reproducer
&r
) final override
;
1594 enum precedence
get_precedence () const final override
1596 return PRECEDENCE_PRIMARY
;
1603 class memento_of_new_rvalue_from_vector
: public rvalue
1606 memento_of_new_rvalue_from_vector (context
*ctxt
,
1611 void replay_into (replayer
*r
) final override
;
1613 void visit_children (rvalue_visitor
*) final override
;
1616 string
* make_debug_string () final override
;
1617 void write_reproducer (reproducer
&r
) final override
;
1618 enum precedence
get_precedence () const final override
1620 return PRECEDENCE_PRIMARY
;
1624 vector_type
*m_vector_type
;
1625 auto_vec
<rvalue
*> m_elements
;
1628 class ctor
: public rvalue
1631 ctor (context
*ctxt
,
1634 : rvalue (ctxt
, loc
, type
)
1637 void replay_into (replayer
*r
) final override
;
1639 void visit_children (rvalue_visitor
*) final override
;
1642 string
* make_debug_string () final override
;
1643 void write_reproducer (reproducer
&r
) final override
;
1644 enum precedence
get_precedence () const final override
1646 return PRECEDENCE_PRIMARY
;
1650 auto_vec
<field
*> m_fields
;
1651 auto_vec
<rvalue
*> m_values
;
1654 class unary_op
: public rvalue
1657 unary_op (context
*ctxt
,
1659 enum gcc_jit_unary_op op
,
1662 : rvalue (ctxt
, loc
, result_type
),
1667 void replay_into (replayer
*r
) final override
;
1669 void visit_children (rvalue_visitor
*v
) final override
;
1672 string
* make_debug_string () final override
;
1673 void write_reproducer (reproducer
&r
) final override
;
1674 enum precedence
get_precedence () const final override
1676 return PRECEDENCE_UNARY
;
1680 enum gcc_jit_unary_op m_op
;
1684 class binary_op
: public rvalue
1687 binary_op (context
*ctxt
,
1689 enum gcc_jit_binary_op op
,
1691 rvalue
*a
, rvalue
*b
)
1692 : rvalue (ctxt
, loc
, result_type
),
1697 void replay_into (replayer
*r
) final override
;
1699 void visit_children (rvalue_visitor
*v
) final override
;
1702 string
* make_debug_string () final override
;
1703 void write_reproducer (reproducer
&r
) final override
;
1704 enum precedence
get_precedence () const final override
;
1707 enum gcc_jit_binary_op m_op
;
1712 class comparison
: public rvalue
1715 comparison (context
*ctxt
,
1717 enum gcc_jit_comparison op
,
1718 rvalue
*a
, rvalue
*b
)
1719 : rvalue (ctxt
, loc
, ctxt
->get_type (GCC_JIT_TYPE_BOOL
)),
1724 type
*a_type
= a
->get_type ();
1725 vector_type
*vec_type
= a_type
->dyn_cast_vector_type ();
1726 if (vec_type
!= NULL
)
1728 type
*element_type
= vec_type
->get_element_type ();
1730 /* Vectors of floating-point values return a vector of integers of the
1732 if (element_type
->is_float ())
1733 inner_type
= ctxt
->get_int_type (element_type
->get_size (), false);
1735 inner_type
= element_type
;
1736 m_type
= new vector_type (inner_type
, vec_type
->get_num_units ());
1737 ctxt
->record (m_type
);
1741 void replay_into (replayer
*r
) final override
;
1743 void visit_children (rvalue_visitor
*v
) final override
;
1746 string
* make_debug_string () final override
;
1747 void write_reproducer (reproducer
&r
) final override
;
1748 enum precedence
get_precedence () const final override
;
1751 enum gcc_jit_comparison m_op
;
1756 class cast
: public rvalue
1759 cast (context
*ctxt
,
1763 : rvalue (ctxt
, loc
, type_
),
1767 void replay_into (replayer
*r
) final override
;
1769 void visit_children (rvalue_visitor
*v
) final override
;
1772 string
* make_debug_string () final override
;
1773 void write_reproducer (reproducer
&r
) final override
;
1774 enum precedence
get_precedence () const final override
1776 return PRECEDENCE_CAST
;
1783 class bitcast
: public rvalue
1786 bitcast (context
*ctxt
,
1790 : rvalue (ctxt
, loc
, type_
),
1794 void replay_into (replayer
*r
) final override
;
1796 void visit_children (rvalue_visitor
*v
) final override
;
1799 string
* make_debug_string () final override
;
1800 void write_reproducer (reproducer
&r
) final override
;
1801 enum precedence
get_precedence () const final override
1803 return PRECEDENCE_CAST
;
1810 class base_call
: public rvalue
1813 base_call (context
*ctxt
,
1819 enum precedence
get_precedence () const final override
1821 return PRECEDENCE_POSTFIX
;
1824 base_call
*dyn_cast_base_call () final override
{ return this; }
1826 void set_require_tail_call (bool require_tail_call
)
1828 m_require_tail_call
= require_tail_call
;
1832 void write_reproducer_tail_call (reproducer
&r
, const char *id
);
1835 auto_vec
<rvalue
*> m_args
;
1836 bool m_require_tail_call
;
1839 class call
: public base_call
1842 call (context
*ctxt
,
1848 void replay_into (replayer
*r
) final override
;
1850 void visit_children (rvalue_visitor
*v
) final override
;
1853 string
* make_debug_string () final override
;
1854 void write_reproducer (reproducer
&r
) final override
;
1860 class call_through_ptr
: public base_call
1863 call_through_ptr (context
*ctxt
,
1869 void replay_into (replayer
*r
) final override
;
1871 void visit_children (rvalue_visitor
*v
) final override
;
1874 string
* make_debug_string () final override
;
1875 void write_reproducer (reproducer
&r
) final override
;
1881 class array_access
: public lvalue
1884 array_access (context
*ctxt
,
1888 : lvalue (ctxt
, loc
, ptr
->get_type ()->dereference ()),
1893 void replay_into (replayer
*r
) final override
;
1895 void visit_children (rvalue_visitor
*v
) final override
;
1898 string
* make_debug_string () final override
;
1899 void write_reproducer (reproducer
&r
) final override
;
1900 enum precedence
get_precedence () const final override
1902 return PRECEDENCE_POSTFIX
;
1910 class access_field_of_lvalue
: public lvalue
1913 access_field_of_lvalue (context
*ctxt
,
1917 : lvalue (ctxt
, loc
, field
->get_type ()),
1922 void replay_into (replayer
*r
) final override
;
1924 void visit_children (rvalue_visitor
*v
) final override
;
1927 string
* make_debug_string () final override
;
1928 void write_reproducer (reproducer
&r
) final override
;
1929 enum precedence
get_precedence () const final override
1931 return PRECEDENCE_POSTFIX
;
1939 class access_field_rvalue
: public rvalue
1942 access_field_rvalue (context
*ctxt
,
1946 : rvalue (ctxt
, loc
, field
->get_type ()),
1951 void replay_into (replayer
*r
) final override
;
1953 void visit_children (rvalue_visitor
*v
) final override
;
1956 string
* make_debug_string () final override
;
1957 void write_reproducer (reproducer
&r
) final override
;
1958 enum precedence
get_precedence () const final override
1960 return PRECEDENCE_POSTFIX
;
1968 class dereference_field_rvalue
: public lvalue
1971 dereference_field_rvalue (context
*ctxt
,
1975 : lvalue (ctxt
, loc
, field
->get_type ()),
1980 void replay_into (replayer
*r
) final override
;
1982 void visit_children (rvalue_visitor
*v
) final override
;
1985 string
* make_debug_string () final override
;
1986 void write_reproducer (reproducer
&r
) final override
;
1987 enum precedence
get_precedence () const final override
1989 return PRECEDENCE_POSTFIX
;
1997 class dereference_rvalue
: public lvalue
2000 dereference_rvalue (context
*ctxt
,
2003 : lvalue (ctxt
, loc
, val
->get_type ()->dereference ()),
2006 void replay_into (replayer
*r
) final override
;
2008 void visit_children (rvalue_visitor
*v
) final override
;
2011 string
* make_debug_string () final override
;
2012 void write_reproducer (reproducer
&r
) final override
;
2013 enum precedence
get_precedence () const final override
2015 return PRECEDENCE_UNARY
;
2022 class get_address_of_lvalue
: public rvalue
2025 get_address_of_lvalue (context
*ctxt
,
2028 : rvalue (ctxt
, loc
, val
->get_type ()->get_pointer ()),
2032 void replay_into (replayer
*r
) final override
;
2034 void visit_children (rvalue_visitor
*v
) final override
;
2037 string
* make_debug_string () final override
;
2038 void write_reproducer (reproducer
&r
) final override
;
2039 enum precedence
get_precedence () const final override
2041 return PRECEDENCE_UNARY
;
2048 class function_pointer
: public rvalue
2051 function_pointer (context
*ctxt
,
2055 : rvalue (ctxt
, loc
, type
),
2058 void replay_into (replayer
*r
) final override
;
2060 void visit_children (rvalue_visitor
*v
) final override
;
2063 string
* make_debug_string () final override
;
2064 void write_reproducer (reproducer
&r
) final override
;
2065 enum precedence
get_precedence () const final override
2067 return PRECEDENCE_UNARY
;
2074 class local
: public lvalue
2077 local (function
*func
, location
*loc
, type
*type_
, string
*name
)
2078 : lvalue (func
->m_ctxt
, loc
, type_
),
2085 void replay_into (replayer
*r
) final override
;
2087 void visit_children (rvalue_visitor
*) final override
{}
2089 void write_to_dump (dump
&d
) final override
;
2092 string
* make_debug_string () final override
{ return m_name
; }
2093 void write_reproducer (reproducer
&r
) final override
;
2094 enum precedence
get_precedence () const final override
2096 return PRECEDENCE_PRIMARY
;
2104 class statement
: public memento
2107 virtual vec
<block
*> get_successor_blocks () const;
2109 void write_to_dump (dump
&d
) final override
;
2111 block
*get_block () const { return m_block
; }
2112 location
*get_loc () const { return m_loc
; }
2115 statement (block
*b
, location
*loc
)
2116 : memento (b
->m_ctxt
),
2120 playback::location
*
2121 playback_location (replayer
*r
) const
2123 return ::gcc::jit::recording::playback_location (r
, m_loc
);
2131 class eval
: public statement
2137 : statement (b
, loc
),
2138 m_rvalue (rvalue
) {}
2140 void replay_into (replayer
*r
) final override
;
2143 string
* make_debug_string () final override
;
2144 void write_reproducer (reproducer
&r
) final override
;
2150 class assignment
: public statement
2153 assignment (block
*b
,
2157 : statement (b
, loc
),
2159 m_rvalue (rvalue
) {}
2161 void replay_into (replayer
*r
) final override
;
2164 string
* make_debug_string () final override
;
2165 void write_reproducer (reproducer
&r
) final override
;
2172 class assignment_op
: public statement
2175 assignment_op (block
*b
,
2178 enum gcc_jit_binary_op op
,
2180 : statement (b
, loc
),
2183 m_rvalue (rvalue
) {}
2185 void replay_into (replayer
*r
) final override
;
2188 string
* make_debug_string () final override
;
2189 void write_reproducer (reproducer
&r
) final override
;
2193 enum gcc_jit_binary_op m_op
;
2197 class comment
: public statement
2203 : statement (b
, loc
),
2206 void replay_into (replayer
*r
) final override
;
2209 string
* make_debug_string () final override
;
2210 void write_reproducer (reproducer
&r
) final override
;
2216 class conditional
: public statement
2219 conditional (block
*b
,
2224 : statement (b
, loc
),
2225 m_boolval (boolval
),
2226 m_on_true (on_true
),
2227 m_on_false (on_false
) {}
2229 void replay_into (replayer
*r
) final override
;
2231 vec
<block
*> get_successor_blocks () const final override
;
2234 string
* make_debug_string () final override
;
2235 void write_reproducer (reproducer
&r
) final override
;
2243 class jump
: public statement
2249 : statement (b
, loc
),
2250 m_target (target
) {}
2252 void replay_into (replayer
*r
) final override
;
2254 vec
<block
*> get_successor_blocks () const final override
;
2257 string
* make_debug_string () final override
;
2258 void write_reproducer (reproducer
&r
) final override
;
2264 class return_
: public statement
2270 : statement (b
, loc
),
2271 m_rvalue (rvalue
) {}
2273 void replay_into (replayer
*r
) final override
;
2275 vec
<block
*> get_successor_blocks () const final override
;
2278 string
* make_debug_string () final override
;
2279 void write_reproducer (reproducer
&r
) final override
;
2285 class case_
: public memento
2288 case_ (context
*ctxt
,
2293 m_min_value (min_value
),
2294 m_max_value (max_value
),
2295 m_dest_block (dest_block
)
2298 rvalue
*get_min_value () const { return m_min_value
; }
2299 rvalue
*get_max_value () const { return m_max_value
; }
2300 block
*get_dest_block () const { return m_dest_block
; }
2302 void replay_into (replayer
*) final override
{ /* empty */ }
2304 void write_reproducer (reproducer
&r
) final override
;
2307 string
* make_debug_string () final override
;
2310 rvalue
*m_min_value
;
2311 rvalue
*m_max_value
;
2312 block
*m_dest_block
;
2315 class switch_
: public statement
2321 block
*default_block
,
2325 void replay_into (replayer
*r
) final override
;
2327 vec
<block
*> get_successor_blocks () const final override
;
2330 string
* make_debug_string () final override
;
2331 void write_reproducer (reproducer
&r
) final override
;
2335 block
*m_default_block
;
2336 auto_vec
<case_
*> m_cases
;
2339 class asm_operand
: public memento
2342 asm_operand (extended_asm
*ext_asm
,
2343 string
*asm_symbolic_name
,
2344 string
*constraint
);
2346 const char *get_symbolic_name () const
2348 if (m_asm_symbolic_name
)
2349 return m_asm_symbolic_name
->c_str ();
2354 const char *get_constraint () const
2356 return m_constraint
->c_str ();
2359 virtual void print (pretty_printer
*pp
) const;
2362 string
* make_debug_string () final override
;
2365 extended_asm
*m_ext_asm
;
2366 string
*m_asm_symbolic_name
;
2367 string
*m_constraint
;
2370 class output_asm_operand
: public asm_operand
2373 output_asm_operand (extended_asm
*ext_asm
,
2374 string
*asm_symbolic_name
,
2377 : asm_operand (ext_asm
, asm_symbolic_name
, constraint
),
2381 lvalue
*get_lvalue () const { return m_dest
; }
2383 void replay_into (replayer
*) final override
{}
2385 void print (pretty_printer
*pp
) const final override
;
2388 void write_reproducer (reproducer
&r
) final override
;
2394 class input_asm_operand
: public asm_operand
2397 input_asm_operand (extended_asm
*ext_asm
,
2398 string
*asm_symbolic_name
,
2401 : asm_operand (ext_asm
, asm_symbolic_name
, constraint
),
2405 rvalue
*get_rvalue () const { return m_src
; }
2407 void replay_into (replayer
*) final override
{}
2409 void print (pretty_printer
*pp
) const final override
;
2412 void write_reproducer (reproducer
&r
) final override
;
2418 /* Abstract base class for extended_asm statements. */
2420 class extended_asm
: public statement
2423 extended_asm (block
*b
,
2425 string
*asm_template
)
2426 : statement (b
, loc
),
2427 m_asm_template (asm_template
),
2428 m_is_volatile (false),
2432 void set_volatile_flag (bool flag
) { m_is_volatile
= flag
; }
2433 void set_inline_flag (bool flag
) { m_is_inline
= flag
; }
2435 void add_output_operand (const char *asm_symbolic_name
,
2436 const char *constraint
,
2438 void add_input_operand (const char *asm_symbolic_name
,
2439 const char *constraint
,
2441 void add_clobber (const char *victim
);
2443 void replay_into (replayer
*r
) override
;
2445 string
*get_asm_template () const { return m_asm_template
; }
2447 virtual bool is_goto () const = 0;
2448 virtual void maybe_print_gotos (pretty_printer
*) const = 0;
2451 void write_flags (reproducer
&r
);
2452 void write_clobbers (reproducer
&r
);
2455 string
* make_debug_string () final override
;
2456 virtual void maybe_populate_playback_blocks
2457 (auto_vec
<playback::block
*> *out
) = 0;
2460 string
*m_asm_template
;
2463 auto_vec
<output_asm_operand
*> m_output_ops
;
2464 auto_vec
<input_asm_operand
*> m_input_ops
;
2465 auto_vec
<string
*> m_clobbers
;
2468 /* An extended_asm that's not a goto, as created by
2469 gcc_jit_block_add_extended_asm. */
2471 class extended_asm_simple
: public extended_asm
2474 extended_asm_simple (block
*b
,
2476 string
*asm_template
)
2477 : extended_asm (b
, loc
, asm_template
)
2480 void write_reproducer (reproducer
&r
) override
;
2481 bool is_goto () const final override
{ return false; }
2482 void maybe_print_gotos (pretty_printer
*) const final override
{}
2485 void maybe_populate_playback_blocks
2486 (auto_vec
<playback::block
*> *) final override
2490 /* An extended_asm that's a asm goto, as created by
2491 gcc_jit_block_end_with_extended_asm_goto. */
2493 class extended_asm_goto
: public extended_asm
2496 extended_asm_goto (block
*b
,
2498 string
*asm_template
,
2499 int num_goto_blocks
,
2500 block
**goto_blocks
,
2501 block
*fallthrough_block
);
2503 void replay_into (replayer
*r
) final override
;
2504 void write_reproducer (reproducer
&r
) override
;
2506 vec
<block
*> get_successor_blocks () const final override
;
2508 bool is_goto () const final override
{ return true; }
2509 void maybe_print_gotos (pretty_printer
*) const final override
;
2512 void maybe_populate_playback_blocks
2513 (auto_vec
<playback::block
*> *out
) final override
;
2516 auto_vec
<block
*> m_goto_blocks
;
2517 block
*m_fallthrough_block
;
2520 /* A group of top-level asm statements, as created by
2521 gcc_jit_context_add_top_level_asm. */
2523 class top_level_asm
: public memento
2526 top_level_asm (context
*ctxt
, location
*loc
, string
*asm_stmts
);
2528 void write_to_dump (dump
&d
) final override
;
2531 void replay_into (replayer
*r
) final override
;
2532 string
* make_debug_string () final override
;
2533 void write_reproducer (reproducer
&r
) final override
;
2537 string
*m_asm_stmts
;
2540 class global_init_rvalue
: public memento
2543 global_init_rvalue (context
*ctxt
, lvalue
*variable
, rvalue
*init
) :
2544 memento (ctxt
), m_variable (variable
), m_init (init
) {};
2546 void write_to_dump (dump
&d
) final override
;
2549 void replay_into (replayer
*r
) final override
;
2550 string
* make_debug_string () final override
;
2551 void write_reproducer (reproducer
&r
) final override
;
2558 } // namespace gcc::jit::recording
2560 /* Create a recording::memento_of_new_rvalue_from_const instance and add
2561 it to this context's list of mementos.
2563 Implements the post-error-checking part of
2564 gcc_jit_context_new_rvalue_from_{int|long|double|ptr}. */
2566 template <typename HOST_TYPE
>
2568 recording::context::new_rvalue_from_const (recording::type
*type
,
2571 recording::rvalue
*result
=
2572 new memento_of_new_rvalue_from_const
<HOST_TYPE
> (this, NULL
, type
, value
);
2577 /* Don't call this directly. Call types_kinda_same. */
2579 types_kinda_same_internal (recording::type
*a
,
2580 recording::type
*b
);
2582 /* Strip all qualifiers and count pointer depth, returning true
2583 if the types and pointer depth are the same, otherwise false.
2585 For array and vector types the number of element also
2586 has to match, aswell as the element types themself. */
2588 types_kinda_same (recording::type
*a
, recording::type
*b
)
2590 /* Handle trivial case here, to allow for inlining. */
2591 return a
== b
|| types_kinda_same_internal (a
, b
);
2594 } // namespace gcc::jit
2598 #endif /* JIT_RECORDING_H */