1 /* Internals of libgccjit: classes for recording calls made to the JIT API.
2 Copyright (C) 2013-2022 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_array_access (location
*loc
,
214 new_case (rvalue
*min_value
,
219 set_str_option (enum gcc_jit_str_option opt
,
223 set_int_option (enum gcc_jit_int_option opt
,
227 set_bool_option (enum gcc_jit_bool_option opt
,
231 set_inner_bool_option (enum inner_bool_option inner_opt
,
235 add_command_line_option (const char *optname
);
238 append_command_line_options (vec
<char *> *argvec
);
241 add_driver_option (const char *optname
);
244 append_driver_options (auto_string_vec
*argvec
);
247 enable_dump (const char *dumpname
,
251 get_str_option (enum gcc_jit_str_option opt
) const
253 return m_str_options
[opt
];
257 get_int_option (enum gcc_jit_int_option opt
) const
259 return m_int_options
[opt
];
263 get_bool_option (enum gcc_jit_bool_option opt
) const
265 return m_bool_options
[opt
];
269 get_inner_bool_option (enum inner_bool_option opt
) const
271 return m_inner_bool_options
[opt
];
278 compile_to_file (enum gcc_jit_output_kind output_kind
,
279 const char *output_path
);
282 add_error (location
*loc
, const char *fmt
, ...)
286 add_error_va (location
*loc
, const char *fmt
, va_list ap
)
290 get_first_error () const;
293 get_last_error () const;
295 bool errors_occurred () const
298 if (m_parent_ctxt
->errors_occurred ())
300 return m_error_count
;
303 type
*get_opaque_FILE_type ();
305 void dump_to_file (const char *path
, bool update_locations
);
307 void dump_reproducer_to_file (const char *path
);
310 get_all_requested_dumps (vec
<recording::requested_dump
> *out
);
312 void set_timer (timer
*t
) { m_timer
= t
; }
313 timer
*get_timer () const { return m_timer
; }
315 void add_top_level_asm (location
*loc
, const char *asm_stmts
);
318 void log_all_options () const;
319 void log_str_option (enum gcc_jit_str_option opt
) const;
320 void log_int_option (enum gcc_jit_int_option opt
) const;
321 void log_bool_option (enum gcc_jit_bool_option opt
) const;
322 void log_inner_bool_option (enum inner_bool_option opt
) const;
327 context
*m_parent_ctxt
;
329 /* The ultimate ancestor of the contexts within a family tree of
330 contexts. This has itself as its own m_toplevel_ctxt. */
331 context
*m_toplevel_ctxt
;
337 char *m_first_error_str
;
338 bool m_owns_first_error_str
;
340 char *m_last_error_str
;
341 bool m_owns_last_error_str
;
343 char *m_str_options
[GCC_JIT_NUM_STR_OPTIONS
];
344 int m_int_options
[GCC_JIT_NUM_INT_OPTIONS
];
345 bool m_bool_options
[GCC_JIT_NUM_BOOL_OPTIONS
];
346 bool m_inner_bool_options
[NUM_INNER_BOOL_OPTIONS
];
347 auto_vec
<char *> m_command_line_options
;
348 auto_vec
<char *> m_driver_options
;
350 /* Dumpfiles that were requested via gcc_jit_context_enable_dump. */
351 auto_vec
<requested_dump
> m_requested_dumps
;
353 /* Recorded API usage. */
354 auto_vec
<memento
*> m_mementos
;
356 /* Specific recordings, for use by dump_to_file. */
357 auto_vec
<compound_type
*> m_compound_types
;
358 auto_vec
<global
*> m_globals
;
359 auto_vec
<function
*> m_functions
;
360 auto_vec
<top_level_asm
*> m_top_level_asms
;
362 type
*m_basic_types
[NUM_GCC_JIT_TYPES
];
365 builtins_manager
*m_builtins_manager
; // lazily created
369 /* An object with lifetime managed by the context i.e.
370 it lives until the context is released, at which
371 point it itself is cleaned up. */
376 virtual ~memento () {}
378 /* Hook for replaying this. */
379 virtual void replay_into (replayer
*r
) = 0;
381 void set_playback_obj (void *obj
) { m_playback_obj
= obj
; }
384 /* Get the context that owns this object.
386 Implements the post-error-checking part of
387 gcc_jit_object_get_context. */
388 context
*get_context () { return m_ctxt
; }
391 as_object () { return this; }
393 /* Debugging hook, for use in generating error messages etc.
394 Implements the post-error-checking part of
395 gcc_jit_object_get_debug_string. */
399 virtual void write_to_dump (dump
&d
);
400 virtual void write_reproducer (reproducer
&r
) = 0;
401 virtual location
*dyn_cast_location () { return NULL
; }
404 memento (context
*ctxt
)
406 m_playback_obj (NULL
),
407 m_debug_string (NULL
)
412 string
*new_string (const char *text
) { return m_ctxt
->new_string (text
); }
415 virtual string
* make_debug_string () = 0;
421 void *m_playback_obj
;
424 string
*m_debug_string
;
427 /* or just use std::string? */
428 class string
: public memento
431 string (context
*ctxt
, const char *text
, bool escaped
);
434 const char *c_str () { return m_buffer
; }
436 static string
* from_printf (context
*ctxt
, const char *fmt
, ...)
439 void replay_into (replayer
*) FINAL OVERRIDE
{}
442 string
* make_debug_string () FINAL OVERRIDE
;
443 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
449 /* Flag to track if this string is the result of string::make_debug_string,
450 to avoid infinite recursion when logging all mementos: don't re-escape
455 class location
: public memento
458 location (context
*ctxt
, string
*filename
, int line
, int column
,
459 bool created_by_user
)
461 m_filename (filename
),
464 m_created_by_user (created_by_user
)
467 void replay_into (replayer
*r
) FINAL OVERRIDE
;
470 playback_location (replayer
*r
)
472 /* Normally during playback, we can walk forwards through the list of
473 recording objects, playing them back. The ordering of recording
474 ensures that everything that a recording object refers to has
475 already been played back, so we can simply look up the relevant
478 Locations are an exception, due to the "write_to_dump" method of
479 recording::statement. This method can set a new location on a
480 statement after the statement is created, and thus the location
481 appears in the context's memento list *after* the statement that
484 In such circumstances, the statement is replayed *before* the location,
485 when the latter doesn't yet have a playback object.
487 Hence we need to ensure that locations have playback objects. */
492 gcc_assert (m_playback_obj
);
493 return static_cast <playback::location
*> (m_playback_obj
);
496 location
*dyn_cast_location () FINAL OVERRIDE
{ return this; }
497 bool created_by_user () const { return m_created_by_user
; }
500 string
* make_debug_string () FINAL OVERRIDE
;
501 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
507 bool m_created_by_user
;
510 class type
: public memento
513 type
*get_pointer ();
515 type
*get_volatile ();
516 type
*get_aligned (size_t alignment_in_bytes
);
517 type
*get_vector (size_t num_units
);
519 /* Get the type obtained when dereferencing this type.
521 This will return NULL if it's not valid to dereference this type.
522 The caller is responsible for setting an error. */
523 virtual type
*dereference () = 0;
524 /* Get the type size in bytes.
526 This is implemented only for memento_of_get_type and
527 memento_of_get_pointer as it is used for initializing globals of
529 virtual size_t get_size () { gcc_unreachable (); }
532 virtual function_type
*dyn_cast_function_type () { return NULL
; }
533 virtual function_type
*as_a_function_type() { gcc_unreachable (); return NULL
; }
534 virtual struct_
*dyn_cast_struct () { return NULL
; }
535 virtual vector_type
*dyn_cast_vector_type () { return NULL
; }
537 /* Is it typesafe to copy to this type from rtype? */
538 virtual bool accepts_writes_from (type
*rtype
)
541 return this->unqualified ()->is_same_type_as (rtype
->unqualified ());
544 virtual bool is_same_type_as (type
*other
)
546 return this == other
;
549 /* Strip off "const" etc */
550 virtual type
*unqualified ()
555 virtual bool is_int () const = 0;
556 virtual bool is_float () const = 0;
557 virtual bool is_bool () const = 0;
558 virtual type
*is_pointer () = 0;
559 virtual type
*is_volatile () { return NULL
; }
560 virtual type
*is_const () { return NULL
; }
561 virtual type
*is_array () = 0;
562 virtual struct_
*is_struct () { return NULL
; }
563 virtual bool is_union () const { return false; }
564 virtual bool is_void () const { return false; }
565 virtual vector_type
*is_vector () { return NULL
; }
566 virtual bool has_known_size () const { return true; }
568 bool is_numeric () const
570 return is_int () || is_float () || is_bool ();
576 return static_cast <playback::type
*> (m_playback_obj
);
579 virtual const char *access_as_type (reproducer
&r
);
584 m_pointer_to_this_type (NULL
)
588 type
*m_pointer_to_this_type
;
591 /* Result of "gcc_jit_context_get_type". */
592 class memento_of_get_type
: public type
595 memento_of_get_type (context
*ctxt
,
596 enum gcc_jit_types kind
)
600 type
*dereference () FINAL OVERRIDE
;
602 size_t get_size () FINAL OVERRIDE
;
604 bool accepts_writes_from (type
*rtype
) FINAL OVERRIDE
606 if (m_kind
== GCC_JIT_TYPE_VOID_PTR
)
607 if (rtype
->is_pointer ())
609 /* LHS (this) is type (void *), and the RHS is a pointer:
614 return type::accepts_writes_from (rtype
);
617 bool is_int () const FINAL OVERRIDE
;
618 bool is_float () const FINAL OVERRIDE
;
619 bool is_bool () const FINAL OVERRIDE
;
620 type
*is_pointer () FINAL OVERRIDE
{ return dereference (); }
621 type
*is_array () FINAL OVERRIDE
{ return NULL
; }
622 bool is_void () const FINAL OVERRIDE
{ return m_kind
== GCC_JIT_TYPE_VOID
; }
625 void replay_into (replayer
*r
) FINAL OVERRIDE
;
628 string
* make_debug_string () FINAL OVERRIDE
;
629 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
632 enum gcc_jit_types m_kind
;
635 /* Result of "gcc_jit_type_get_pointer". */
636 class memento_of_get_pointer
: public type
639 memento_of_get_pointer (type
*other_type
)
640 : type (other_type
->m_ctxt
),
641 m_other_type (other_type
) {}
643 type
*dereference () FINAL OVERRIDE
{ return m_other_type
; }
645 size_t get_size () FINAL OVERRIDE
;
647 bool accepts_writes_from (type
*rtype
) FINAL OVERRIDE
;
649 void replay_into (replayer
*r
) FINAL OVERRIDE
;
651 bool is_int () const FINAL OVERRIDE
{ return false; }
652 bool is_float () const FINAL OVERRIDE
{ return false; }
653 bool is_bool () const FINAL OVERRIDE
{ return false; }
654 type
*is_pointer () FINAL OVERRIDE
{ return m_other_type
; }
655 type
*is_array () FINAL OVERRIDE
{ return NULL
; }
658 string
* make_debug_string () FINAL OVERRIDE
;
659 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
665 /* A decorated version of a type, for get_const, get_volatile,
666 get_aligned, and get_vector. */
668 class decorated_type
: public type
671 decorated_type (type
*other_type
)
672 : type (other_type
->m_ctxt
),
673 m_other_type (other_type
) {}
675 type
*dereference () FINAL OVERRIDE
{ return m_other_type
->dereference (); }
677 bool is_int () const FINAL OVERRIDE
{ return m_other_type
->is_int (); }
678 bool is_float () const FINAL OVERRIDE
{ return m_other_type
->is_float (); }
679 bool is_bool () const FINAL OVERRIDE
{ return m_other_type
->is_bool (); }
680 type
*is_pointer () FINAL OVERRIDE
{ return m_other_type
->is_pointer (); }
681 type
*is_array () FINAL OVERRIDE
{ return m_other_type
->is_array (); }
682 struct_
*is_struct () FINAL OVERRIDE
{ return m_other_type
->is_struct (); }
688 /* Result of "gcc_jit_type_get_const". */
689 class memento_of_get_const
: public decorated_type
692 memento_of_get_const (type
*other_type
)
693 : decorated_type (other_type
) {}
695 bool accepts_writes_from (type */
*rtype*/
) FINAL OVERRIDE
697 /* Can't write to a "const". */
701 /* Strip off the "const", giving the underlying type. */
702 type
*unqualified () FINAL OVERRIDE
{ return m_other_type
; }
704 virtual bool is_same_type_as (type
*other
)
706 if (!other
->is_const ())
708 return m_other_type
->is_same_type_as (other
->is_const ());
711 virtual type
*is_const () { return m_other_type
; }
713 void replay_into (replayer
*) FINAL OVERRIDE
;
716 string
* make_debug_string () FINAL OVERRIDE
;
717 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
720 /* Result of "gcc_jit_type_get_volatile". */
721 class memento_of_get_volatile
: public decorated_type
724 memento_of_get_volatile (type
*other_type
)
725 : decorated_type (other_type
) {}
727 virtual bool is_same_type_as (type
*other
)
729 if (!other
->is_volatile ())
731 return m_other_type
->is_same_type_as (other
->is_volatile ());
734 /* Strip off the "volatile", giving the underlying type. */
735 type
*unqualified () FINAL OVERRIDE
{ return m_other_type
; }
737 virtual type
*is_volatile () { 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_aligned". */
747 class memento_of_get_aligned
: public decorated_type
750 memento_of_get_aligned (type
*other_type
, size_t alignment_in_bytes
)
751 : decorated_type (other_type
),
752 m_alignment_in_bytes (alignment_in_bytes
) {}
754 /* Strip off the alignment, giving the underlying type. */
755 type
*unqualified () FINAL OVERRIDE
{ return m_other_type
; }
757 void replay_into (replayer
*) FINAL OVERRIDE
;
760 string
* make_debug_string () FINAL OVERRIDE
;
761 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
764 size_t m_alignment_in_bytes
;
767 /* Result of "gcc_jit_type_get_vector". */
768 class vector_type
: public decorated_type
771 vector_type (type
*other_type
, size_t num_units
)
772 : decorated_type (other_type
),
773 m_num_units (num_units
) {}
775 size_t get_num_units () const { return m_num_units
; }
777 vector_type
*dyn_cast_vector_type () FINAL OVERRIDE
{ return this; }
779 type
*get_element_type () { return m_other_type
; }
781 void replay_into (replayer
*) FINAL OVERRIDE
;
783 vector_type
*is_vector () FINAL OVERRIDE
{ return this; }
786 string
* make_debug_string () FINAL OVERRIDE
;
787 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
793 class array_type
: public type
796 array_type (context
*ctxt
,
802 m_element_type (element_type
),
803 m_num_elements (num_elements
)
806 type
*dereference () FINAL OVERRIDE
;
808 bool is_int () const FINAL OVERRIDE
{ return false; }
809 bool is_float () const FINAL OVERRIDE
{ return false; }
810 bool is_bool () const FINAL OVERRIDE
{ return false; }
811 type
*is_pointer () FINAL OVERRIDE
{ return NULL
; }
812 type
*is_array () FINAL OVERRIDE
{ return m_element_type
; }
813 int num_elements () { return m_num_elements
; }
815 void replay_into (replayer
*) FINAL OVERRIDE
;
818 string
* make_debug_string () FINAL OVERRIDE
;
819 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
823 type
*m_element_type
;
827 class function_type
: public type
830 function_type (context
*ctxt
,
836 type
*dereference () FINAL OVERRIDE
;
837 function_type
*dyn_cast_function_type () FINAL OVERRIDE
{ return this; }
838 function_type
*as_a_function_type () FINAL OVERRIDE
{ return this; }
840 bool is_same_type_as (type
*other
) FINAL OVERRIDE
;
842 bool is_int () const FINAL OVERRIDE
{ return false; }
843 bool is_float () const FINAL OVERRIDE
{ return false; }
844 bool is_bool () const FINAL OVERRIDE
{ return false; }
845 type
*is_pointer () FINAL OVERRIDE
{ return NULL
; }
846 type
*is_array () FINAL OVERRIDE
{ return NULL
; }
848 void replay_into (replayer
*) FINAL OVERRIDE
;
850 type
* get_return_type () const { return m_return_type
; }
851 const vec
<type
*> &get_param_types () const { return m_param_types
; }
852 int is_variadic () const { return m_is_variadic
; }
854 string
* make_debug_string_with_ptr ();
857 write_deferred_reproducer (reproducer
&r
,
861 string
* make_debug_string () FINAL OVERRIDE
;
862 string
* make_debug_string_with (const char *);
863 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
867 auto_vec
<type
*> m_param_types
;
871 class field
: public memento
874 field (context
*ctxt
,
885 type
* get_type () const { return m_type
; }
887 compound_type
* get_container () const { return m_container
; }
888 void set_container (compound_type
*c
) { m_container
= c
; }
890 void replay_into (replayer
*) OVERRIDE
;
892 void write_to_dump (dump
&d
) OVERRIDE
;
895 playback_field () const
897 return static_cast <playback::field
*> (m_playback_obj
);
901 string
* make_debug_string () OVERRIDE
;
902 void write_reproducer (reproducer
&r
) OVERRIDE
;
908 compound_type
*m_container
;
912 class bitfield
: public field
915 bitfield (context
*ctxt
,
920 : field (ctxt
, loc
, type
, name
),
924 void replay_into (replayer
*) FINAL OVERRIDE
;
926 void write_to_dump (dump
&d
) FINAL OVERRIDE
;
929 string
* make_debug_string () FINAL OVERRIDE
;
930 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
936 /* Base class for struct_ and union_ */
937 class compound_type
: public type
940 compound_type (context
*ctxt
,
944 string
*get_name () const { return m_name
; }
945 location
*get_loc () const { return m_loc
; }
946 fields
* get_fields () { return m_fields
; }
949 set_fields (location
*loc
,
953 type
*dereference () FINAL OVERRIDE
;
955 bool is_int () const FINAL OVERRIDE
{ return false; }
956 bool is_float () const FINAL OVERRIDE
{ return false; }
957 bool is_bool () const FINAL OVERRIDE
{ return false; }
958 type
*is_pointer () FINAL OVERRIDE
{ return NULL
; }
959 type
*is_array () FINAL OVERRIDE
{ return NULL
; }
961 bool has_known_size () const FINAL OVERRIDE
{ return m_fields
!= NULL
; }
963 playback::compound_type
*
964 playback_compound_type ()
966 return static_cast <playback::compound_type
*> (m_playback_obj
);
975 class struct_
: public compound_type
978 struct_ (context
*ctxt
,
982 struct_
*dyn_cast_struct () FINAL OVERRIDE
{ return this; }
985 as_type () { return this; }
987 void replay_into (replayer
*r
) FINAL OVERRIDE
;
989 const char *access_as_type (reproducer
&r
) FINAL OVERRIDE
;
991 struct_
*is_struct () FINAL OVERRIDE
{ return this; }
994 string
* make_debug_string () FINAL OVERRIDE
;
995 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
998 // memento of struct_::set_fields
999 class fields
: public memento
1002 fields (compound_type
*struct_or_union
,
1006 void replay_into (replayer
*r
) FINAL OVERRIDE
;
1008 void write_to_dump (dump
&d
) FINAL OVERRIDE
;
1010 int length () const { return m_fields
.length (); }
1011 field
*get_field (int i
) const { return m_fields
[i
]; }
1014 string
* make_debug_string () FINAL OVERRIDE
;
1015 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
1018 compound_type
*m_struct_or_union
;
1019 auto_vec
<field
*> m_fields
;
1022 class union_
: public compound_type
1025 union_ (context
*ctxt
,
1029 void replay_into (replayer
*r
) FINAL OVERRIDE
;
1031 virtual bool is_union () const FINAL OVERRIDE
{ return true; }
1034 string
* make_debug_string () FINAL OVERRIDE
;
1035 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
1038 /* An abstract base class for operations that visit all rvalues within an
1040 Currently the only implementation is class rvalue_usage_validator within
1041 jit-recording.cc. */
1043 class rvalue_visitor
1046 virtual ~rvalue_visitor () {}
1047 virtual void visit (rvalue
*rvalue
) = 0;
1050 /* When generating debug strings for rvalues we mimic C, so we need to
1051 mimic C's precedence levels when handling compound expressions.
1052 These are in order from strongest precedence to weakest. */
1059 PRECEDENCE_MULTIPLICATIVE
,
1060 PRECEDENCE_ADDITIVE
,
1062 PRECEDENCE_RELATIONAL
,
1063 PRECEDENCE_EQUALITY
,
1064 PRECEDENCE_BITWISE_AND
,
1065 PRECEDENCE_BITWISE_XOR
,
1066 PRECEDENCE_BITWISE_IOR
,
1067 PRECEDENCE_LOGICAL_AND
,
1068 PRECEDENCE_LOGICAL_OR
1071 class rvalue
: public memento
1074 rvalue (context
*ctxt
,
1081 m_parenthesized_string (NULL
)
1086 location
* get_loc () const { return m_loc
; }
1088 /* Get the recording::type of this rvalue.
1090 Implements the post-error-checking part of
1091 gcc_jit_rvalue_get_type. */
1092 type
* get_type () const { return m_type
; }
1095 playback_rvalue () const
1097 return static_cast <playback::rvalue
*> (m_playback_obj
);
1100 access_field (location
*loc
,
1104 dereference_field (location
*loc
,
1108 dereference (location
*loc
);
1111 verify_valid_within_stmt (const char *api_funcname
, statement
*s
);
1113 virtual void visit_children (rvalue_visitor
*v
) = 0;
1115 void set_scope (function
*scope
);
1116 function
*get_scope () const { return m_scope
; }
1118 /* Dynamic casts. */
1119 virtual param
*dyn_cast_param () { return NULL
; }
1120 virtual base_call
*dyn_cast_base_call () { return NULL
; }
1122 virtual const char *access_as_rvalue (reproducer
&r
);
1124 /* Get the debug string, wrapped in parentheses. */
1126 get_debug_string_parens (enum precedence outer_prec
);
1128 virtual bool is_constant () const { return false; }
1129 virtual bool get_wide_int (wide_int
*) const { return false; }
1132 virtual enum precedence
get_precedence () const = 0;
1139 function
*m_scope
; /* NULL for globals, non-NULL for locals/params */
1140 string
*m_parenthesized_string
;
1143 class lvalue
: public rvalue
1146 lvalue (context
*ctxt
,
1149 : rvalue (ctxt
, loc
, type_
),
1150 m_tls_model (GCC_JIT_TLS_MODEL_NONE
),
1151 m_link_section (NULL
)
1155 playback_lvalue () const
1157 return static_cast <playback::lvalue
*> (m_playback_obj
);
1161 access_field (location
*loc
,
1165 get_address (location
*loc
);
1168 as_rvalue () { return this; }
1170 const char *access_as_rvalue (reproducer
&r
) OVERRIDE
;
1171 virtual const char *access_as_lvalue (reproducer
&r
);
1172 virtual bool is_global () const { return false; }
1173 void set_tls_model (enum gcc_jit_tls_model model
);
1174 void set_link_section (const char *name
);
1177 enum gcc_jit_tls_model m_tls_model
;
1178 string
*m_link_section
;
1181 class param
: public lvalue
1184 param (context
*ctxt
,
1188 : lvalue (ctxt
, loc
, type
),
1192 as_lvalue () { return this; }
1194 void replay_into (replayer
*r
) FINAL OVERRIDE
;
1196 void visit_children (rvalue_visitor
*) FINAL OVERRIDE
{}
1199 playback_param () const
1201 return static_cast <playback::param
*> (m_playback_obj
);
1204 param
*dyn_cast_param () FINAL OVERRIDE
{ return this; }
1206 const char *access_as_rvalue (reproducer
&r
) FINAL OVERRIDE
;
1207 const char *access_as_lvalue (reproducer
&r
) FINAL OVERRIDE
;
1210 string
* make_debug_string () FINAL OVERRIDE
{ return m_name
; }
1211 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
1212 enum precedence
get_precedence () const FINAL OVERRIDE
1214 return PRECEDENCE_PRIMARY
;
1221 class function
: public memento
1224 function (context
*ctxt
,
1226 enum gcc_jit_function_kind kind
,
1232 enum built_in_function builtin_id
);
1234 void replay_into (replayer
*r
) FINAL OVERRIDE
;
1236 playback::function
*
1237 playback_function () const
1239 return static_cast <playback::function
*> (m_playback_obj
);
1242 enum gcc_jit_function_kind
get_kind () const { return m_kind
; }
1245 new_local (location
*loc
,
1250 new_block (const char *name
);
1252 location
*get_loc () const { return m_loc
; }
1253 type
*get_return_type () const { return m_return_type
; }
1254 string
* get_name () const { return m_name
; }
1255 const vec
<param
*> &get_params () const { return m_params
; }
1257 /* Get the given param by index.
1258 Implements the post-error-checking part of
1259 gcc_jit_function_get_param. */
1260 param
*get_param (int i
) const { return m_params
[i
]; }
1262 bool is_variadic () const { return m_is_variadic
; }
1264 void write_to_dump (dump
&d
) FINAL OVERRIDE
;
1268 void dump_to_dot (const char *path
);
1270 rvalue
*get_address (location
*loc
);
1273 string
* make_debug_string () FINAL OVERRIDE
;
1274 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
1278 enum gcc_jit_function_kind m_kind
;
1279 type
*m_return_type
;
1281 auto_vec
<param
*> m_params
;
1283 enum built_in_function m_builtin_id
;
1284 auto_vec
<local
*> m_locals
;
1285 auto_vec
<block
*> m_blocks
;
1286 type
*m_fn_ptr_type
;
1289 class block
: public memento
1292 block (function
*func
, int index
, string
*name
)
1293 : memento (func
->m_ctxt
),
1298 m_has_been_terminated (false),
1299 m_is_reachable (false)
1303 /* Get the recording::function containing this block.
1304 Implements the post-error-checking part of
1305 gcc_jit_block_get_function. */
1306 function
*get_function () { return m_func
; }
1308 bool has_been_terminated () { return m_has_been_terminated
; }
1309 bool is_reachable () { return m_is_reachable
; }
1312 add_eval (location
*loc
,
1316 add_assignment (location
*loc
,
1321 add_assignment_op (location
*loc
,
1323 enum gcc_jit_binary_op op
,
1327 add_comment (location
*loc
,
1331 add_extended_asm (location
*loc
,
1332 const char *asm_template
);
1335 end_with_conditional (location
*loc
,
1341 end_with_jump (location
*loc
,
1345 end_with_return (location
*loc
,
1349 end_with_switch (location
*loc
,
1351 block
*default_block
,
1356 end_with_extended_asm_goto (location
*loc
,
1357 const char *asm_template
,
1358 int num_goto_blocks
,
1359 block
**goto_blocks
,
1360 block
*fallthrough_block
);
1363 playback_block () const
1365 return static_cast <playback::block
*> (m_playback_obj
);
1368 void write_to_dump (dump
&d
) FINAL OVERRIDE
;
1372 location
*get_loc () const;
1374 statement
*get_first_statement () const;
1375 statement
*get_last_statement () const;
1377 vec
<block
*> get_successor_blocks () const;
1380 string
* make_debug_string () FINAL OVERRIDE
;
1381 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
1383 void replay_into (replayer
*r
) FINAL OVERRIDE
;
1385 void dump_to_dot (pretty_printer
*pp
);
1386 void dump_edges_to_dot (pretty_printer
*pp
);
1392 auto_vec
<statement
*> m_statements
;
1393 bool m_has_been_terminated
;
1394 bool m_is_reachable
;
1396 friend class function
;
1399 class global
: public lvalue
1402 global (context
*ctxt
,
1404 enum gcc_jit_global_kind kind
,
1407 : lvalue (ctxt
, loc
, type
),
1411 m_initializer
= NULL
;
1412 m_initializer_num_bytes
= 0;
1416 free (m_initializer
);
1419 void replay_into (replayer
*) FINAL OVERRIDE
;
1421 void visit_children (rvalue_visitor
*) FINAL OVERRIDE
{}
1423 void write_to_dump (dump
&d
) FINAL OVERRIDE
;
1425 bool is_global () const FINAL OVERRIDE
{ return true; }
1428 set_initializer (const void *initializer
,
1432 free (m_initializer
);
1433 m_initializer
= xmalloc (num_bytes
);
1434 memcpy (m_initializer
, initializer
, num_bytes
);
1435 m_initializer_num_bytes
= num_bytes
;
1438 void set_flags (int flag_fields
)
1440 m_flags
= (enum global_var_flags
)(m_flags
| flag_fields
);
1442 /* Returns true if any of the flags in the argument is set. */
1443 bool test_flags_anyof (int flag_fields
) const
1445 return m_flags
& flag_fields
;
1448 enum gcc_jit_global_kind
get_kind () const
1453 void set_rvalue_init (rvalue
*val
) { m_rvalue_init
= val
; }
1456 string
* make_debug_string () FINAL OVERRIDE
{ return m_name
; }
1457 template <typename T
>
1458 void write_initializer_reproducer (const char *id
, reproducer
&r
);
1459 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
1460 enum precedence
get_precedence () const FINAL OVERRIDE
1462 return PRECEDENCE_PRIMARY
;
1466 enum gcc_jit_global_kind m_kind
;
1467 enum global_var_flags m_flags
= GLOBAL_VAR_FLAGS_NONE
;
1469 void *m_initializer
;
1470 rvalue
*m_rvalue_init
= nullptr; /* Only needed for write_dump. */
1471 size_t m_initializer_num_bytes
;
1474 template <typename HOST_TYPE
>
1475 class memento_of_new_rvalue_from_const
: public rvalue
1478 memento_of_new_rvalue_from_const (context
*ctxt
,
1482 : rvalue (ctxt
, loc
, type
),
1485 void replay_into (replayer
*r
) FINAL OVERRIDE
;
1487 void visit_children (rvalue_visitor
*) FINAL OVERRIDE
{}
1489 bool is_constant () const FINAL OVERRIDE
{ return true; }
1491 bool get_wide_int (wide_int
*out
) const FINAL OVERRIDE
;
1494 string
* make_debug_string () FINAL OVERRIDE
;
1495 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
1496 enum precedence
get_precedence () const FINAL OVERRIDE
1498 return PRECEDENCE_PRIMARY
;
1505 class memento_of_new_string_literal
: public rvalue
1508 memento_of_new_string_literal (context
*ctxt
,
1511 : rvalue (ctxt
, loc
, ctxt
->get_type (GCC_JIT_TYPE_CONST_CHAR_PTR
)),
1514 void replay_into (replayer
*r
) FINAL OVERRIDE
;
1516 void visit_children (rvalue_visitor
*) FINAL OVERRIDE
{}
1519 string
* make_debug_string () FINAL OVERRIDE
;
1520 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
1521 enum precedence
get_precedence () const FINAL OVERRIDE
1523 return PRECEDENCE_PRIMARY
;
1530 class memento_of_new_rvalue_from_vector
: public rvalue
1533 memento_of_new_rvalue_from_vector (context
*ctxt
,
1538 void replay_into (replayer
*r
) FINAL OVERRIDE
;
1540 void visit_children (rvalue_visitor
*) FINAL OVERRIDE
;
1543 string
* make_debug_string () FINAL OVERRIDE
;
1544 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
1545 enum precedence
get_precedence () const FINAL OVERRIDE
1547 return PRECEDENCE_PRIMARY
;
1551 vector_type
*m_vector_type
;
1552 auto_vec
<rvalue
*> m_elements
;
1555 class ctor
: public rvalue
1558 ctor (context
*ctxt
,
1561 : rvalue (ctxt
, loc
, type
)
1564 void replay_into (replayer
*r
) FINAL OVERRIDE
;
1566 void visit_children (rvalue_visitor
*) FINAL OVERRIDE
;
1569 string
* make_debug_string () FINAL OVERRIDE
;
1570 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
1571 enum precedence
get_precedence () const FINAL OVERRIDE
1573 return PRECEDENCE_PRIMARY
;
1577 auto_vec
<field
*> m_fields
;
1578 auto_vec
<rvalue
*> m_values
;
1581 class unary_op
: public rvalue
1584 unary_op (context
*ctxt
,
1586 enum gcc_jit_unary_op op
,
1589 : rvalue (ctxt
, loc
, result_type
),
1594 void replay_into (replayer
*r
) FINAL OVERRIDE
;
1596 void visit_children (rvalue_visitor
*v
) FINAL OVERRIDE
;
1599 string
* make_debug_string () FINAL OVERRIDE
;
1600 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
1601 enum precedence
get_precedence () const FINAL OVERRIDE
1603 return PRECEDENCE_UNARY
;
1607 enum gcc_jit_unary_op m_op
;
1611 class binary_op
: public rvalue
1614 binary_op (context
*ctxt
,
1616 enum gcc_jit_binary_op op
,
1618 rvalue
*a
, rvalue
*b
)
1619 : rvalue (ctxt
, loc
, result_type
),
1624 void replay_into (replayer
*r
) FINAL OVERRIDE
;
1626 void visit_children (rvalue_visitor
*v
) FINAL OVERRIDE
;
1629 string
* make_debug_string () FINAL OVERRIDE
;
1630 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
1631 enum precedence
get_precedence () const FINAL OVERRIDE
;
1634 enum gcc_jit_binary_op m_op
;
1639 class comparison
: public rvalue
1642 comparison (context
*ctxt
,
1644 enum gcc_jit_comparison op
,
1645 rvalue
*a
, rvalue
*b
)
1646 : rvalue (ctxt
, loc
, ctxt
->get_type (GCC_JIT_TYPE_BOOL
)),
1652 void replay_into (replayer
*r
) FINAL OVERRIDE
;
1654 void visit_children (rvalue_visitor
*v
) FINAL OVERRIDE
;
1657 string
* make_debug_string () FINAL OVERRIDE
;
1658 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
1659 enum precedence
get_precedence () const FINAL OVERRIDE
;
1662 enum gcc_jit_comparison m_op
;
1667 class cast
: public rvalue
1670 cast (context
*ctxt
,
1674 : rvalue (ctxt
, loc
, type_
),
1678 void replay_into (replayer
*r
) FINAL OVERRIDE
;
1680 void visit_children (rvalue_visitor
*v
) FINAL OVERRIDE
;
1683 string
* make_debug_string () FINAL OVERRIDE
;
1684 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
1685 enum precedence
get_precedence () const FINAL OVERRIDE
1687 return PRECEDENCE_CAST
;
1694 class base_call
: public rvalue
1697 base_call (context
*ctxt
,
1703 enum precedence
get_precedence () const FINAL OVERRIDE
1705 return PRECEDENCE_POSTFIX
;
1708 base_call
*dyn_cast_base_call () FINAL OVERRIDE
{ return this; }
1710 void set_require_tail_call (bool require_tail_call
)
1712 m_require_tail_call
= require_tail_call
;
1716 void write_reproducer_tail_call (reproducer
&r
, const char *id
);
1719 auto_vec
<rvalue
*> m_args
;
1720 bool m_require_tail_call
;
1723 class call
: public base_call
1726 call (context
*ctxt
,
1732 void replay_into (replayer
*r
) FINAL OVERRIDE
;
1734 void visit_children (rvalue_visitor
*v
) FINAL OVERRIDE
;
1737 string
* make_debug_string () FINAL OVERRIDE
;
1738 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
1744 class call_through_ptr
: public base_call
1747 call_through_ptr (context
*ctxt
,
1753 void replay_into (replayer
*r
) FINAL OVERRIDE
;
1755 void visit_children (rvalue_visitor
*v
) FINAL OVERRIDE
;
1758 string
* make_debug_string () FINAL OVERRIDE
;
1759 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
1765 class array_access
: public lvalue
1768 array_access (context
*ctxt
,
1772 : lvalue (ctxt
, loc
, ptr
->get_type ()->dereference ()),
1777 void replay_into (replayer
*r
) FINAL OVERRIDE
;
1779 void visit_children (rvalue_visitor
*v
) FINAL OVERRIDE
;
1782 string
* make_debug_string () FINAL OVERRIDE
;
1783 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
1784 enum precedence
get_precedence () const FINAL OVERRIDE
1786 return PRECEDENCE_POSTFIX
;
1794 class access_field_of_lvalue
: public lvalue
1797 access_field_of_lvalue (context
*ctxt
,
1801 : lvalue (ctxt
, loc
, field
->get_type ()),
1806 void replay_into (replayer
*r
) FINAL OVERRIDE
;
1808 void visit_children (rvalue_visitor
*v
) FINAL OVERRIDE
;
1811 string
* make_debug_string () FINAL OVERRIDE
;
1812 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
1813 enum precedence
get_precedence () const FINAL OVERRIDE
1815 return PRECEDENCE_POSTFIX
;
1823 class access_field_rvalue
: public rvalue
1826 access_field_rvalue (context
*ctxt
,
1830 : rvalue (ctxt
, loc
, field
->get_type ()),
1835 void replay_into (replayer
*r
) FINAL OVERRIDE
;
1837 void visit_children (rvalue_visitor
*v
) FINAL OVERRIDE
;
1840 string
* make_debug_string () FINAL OVERRIDE
;
1841 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
1842 enum precedence
get_precedence () const FINAL OVERRIDE
1844 return PRECEDENCE_POSTFIX
;
1852 class dereference_field_rvalue
: public lvalue
1855 dereference_field_rvalue (context
*ctxt
,
1859 : lvalue (ctxt
, loc
, field
->get_type ()),
1864 void replay_into (replayer
*r
) FINAL OVERRIDE
;
1866 void visit_children (rvalue_visitor
*v
) FINAL OVERRIDE
;
1869 string
* make_debug_string () FINAL OVERRIDE
;
1870 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
1871 enum precedence
get_precedence () const FINAL OVERRIDE
1873 return PRECEDENCE_POSTFIX
;
1881 class dereference_rvalue
: public lvalue
1884 dereference_rvalue (context
*ctxt
,
1887 : lvalue (ctxt
, loc
, val
->get_type ()->dereference ()),
1890 void replay_into (replayer
*r
) FINAL OVERRIDE
;
1892 void visit_children (rvalue_visitor
*v
) FINAL OVERRIDE
;
1895 string
* make_debug_string () FINAL OVERRIDE
;
1896 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
1897 enum precedence
get_precedence () const FINAL OVERRIDE
1899 return PRECEDENCE_UNARY
;
1906 class get_address_of_lvalue
: public rvalue
1909 get_address_of_lvalue (context
*ctxt
,
1912 : rvalue (ctxt
, loc
, val
->get_type ()->get_pointer ()),
1916 void replay_into (replayer
*r
) FINAL OVERRIDE
;
1918 void visit_children (rvalue_visitor
*v
) FINAL OVERRIDE
;
1921 string
* make_debug_string () FINAL OVERRIDE
;
1922 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
1923 enum precedence
get_precedence () const FINAL OVERRIDE
1925 return PRECEDENCE_UNARY
;
1932 class function_pointer
: public rvalue
1935 function_pointer (context
*ctxt
,
1939 : rvalue (ctxt
, loc
, type
),
1942 void replay_into (replayer
*r
) FINAL OVERRIDE
;
1944 void visit_children (rvalue_visitor
*v
) FINAL OVERRIDE
;
1947 string
* make_debug_string () FINAL OVERRIDE
;
1948 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
1949 enum precedence
get_precedence () const FINAL OVERRIDE
1951 return PRECEDENCE_UNARY
;
1958 class local
: public lvalue
1961 local (function
*func
, location
*loc
, type
*type_
, string
*name
)
1962 : lvalue (func
->m_ctxt
, loc
, type_
),
1969 void replay_into (replayer
*r
) FINAL OVERRIDE
;
1971 void visit_children (rvalue_visitor
*) FINAL OVERRIDE
{}
1973 void write_to_dump (dump
&d
) FINAL OVERRIDE
;
1976 string
* make_debug_string () FINAL OVERRIDE
{ return m_name
; }
1977 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
1978 enum precedence
get_precedence () const FINAL OVERRIDE
1980 return PRECEDENCE_PRIMARY
;
1988 class statement
: public memento
1991 virtual vec
<block
*> get_successor_blocks () const;
1993 void write_to_dump (dump
&d
) FINAL OVERRIDE
;
1995 block
*get_block () const { return m_block
; }
1996 location
*get_loc () const { return m_loc
; }
1999 statement (block
*b
, location
*loc
)
2000 : memento (b
->m_ctxt
),
2004 playback::location
*
2005 playback_location (replayer
*r
) const
2007 return ::gcc::jit::recording::playback_location (r
, m_loc
);
2015 class eval
: public statement
2021 : statement (b
, loc
),
2022 m_rvalue (rvalue
) {}
2024 void replay_into (replayer
*r
) FINAL OVERRIDE
;
2027 string
* make_debug_string () FINAL OVERRIDE
;
2028 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
2034 class assignment
: public statement
2037 assignment (block
*b
,
2041 : statement (b
, loc
),
2043 m_rvalue (rvalue
) {}
2045 void replay_into (replayer
*r
) FINAL OVERRIDE
;
2048 string
* make_debug_string () FINAL OVERRIDE
;
2049 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
2056 class assignment_op
: public statement
2059 assignment_op (block
*b
,
2062 enum gcc_jit_binary_op op
,
2064 : statement (b
, loc
),
2067 m_rvalue (rvalue
) {}
2069 void replay_into (replayer
*r
) FINAL OVERRIDE
;
2072 string
* make_debug_string () FINAL OVERRIDE
;
2073 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
2077 enum gcc_jit_binary_op m_op
;
2081 class comment
: public statement
2087 : statement (b
, loc
),
2090 void replay_into (replayer
*r
) FINAL OVERRIDE
;
2093 string
* make_debug_string () FINAL OVERRIDE
;
2094 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
2100 class conditional
: public statement
2103 conditional (block
*b
,
2108 : statement (b
, loc
),
2109 m_boolval (boolval
),
2110 m_on_true (on_true
),
2111 m_on_false (on_false
) {}
2113 void replay_into (replayer
*r
) FINAL OVERRIDE
;
2115 vec
<block
*> get_successor_blocks () const FINAL OVERRIDE
;
2118 string
* make_debug_string () FINAL OVERRIDE
;
2119 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
2127 class jump
: public statement
2133 : statement (b
, loc
),
2134 m_target (target
) {}
2136 void replay_into (replayer
*r
) FINAL OVERRIDE
;
2138 vec
<block
*> get_successor_blocks () const FINAL OVERRIDE
;
2141 string
* make_debug_string () FINAL OVERRIDE
;
2142 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
2148 class return_
: public statement
2154 : statement (b
, loc
),
2155 m_rvalue (rvalue
) {}
2157 void replay_into (replayer
*r
) FINAL OVERRIDE
;
2159 vec
<block
*> get_successor_blocks () const FINAL OVERRIDE
;
2162 string
* make_debug_string () FINAL OVERRIDE
;
2163 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
2169 class case_
: public memento
2172 case_ (context
*ctxt
,
2177 m_min_value (min_value
),
2178 m_max_value (max_value
),
2179 m_dest_block (dest_block
)
2182 rvalue
*get_min_value () const { return m_min_value
; }
2183 rvalue
*get_max_value () const { return m_max_value
; }
2184 block
*get_dest_block () const { return m_dest_block
; }
2186 void replay_into (replayer
*) FINAL OVERRIDE
{ /* empty */ }
2188 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
2191 string
* make_debug_string () FINAL OVERRIDE
;
2194 rvalue
*m_min_value
;
2195 rvalue
*m_max_value
;
2196 block
*m_dest_block
;
2199 class switch_
: public statement
2205 block
*default_block
,
2209 void replay_into (replayer
*r
) FINAL OVERRIDE
;
2211 vec
<block
*> get_successor_blocks () const FINAL OVERRIDE
;
2214 string
* make_debug_string () FINAL OVERRIDE
;
2215 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
2219 block
*m_default_block
;
2220 auto_vec
<case_
*> m_cases
;
2223 class asm_operand
: public memento
2226 asm_operand (extended_asm
*ext_asm
,
2227 string
*asm_symbolic_name
,
2228 string
*constraint
);
2230 const char *get_symbolic_name () const
2232 if (m_asm_symbolic_name
)
2233 return m_asm_symbolic_name
->c_str ();
2238 const char *get_constraint () const
2240 return m_constraint
->c_str ();
2243 virtual void print (pretty_printer
*pp
) const;
2246 string
* make_debug_string () FINAL OVERRIDE
;
2249 extended_asm
*m_ext_asm
;
2250 string
*m_asm_symbolic_name
;
2251 string
*m_constraint
;
2254 class output_asm_operand
: public asm_operand
2257 output_asm_operand (extended_asm
*ext_asm
,
2258 string
*asm_symbolic_name
,
2261 : asm_operand (ext_asm
, asm_symbolic_name
, constraint
),
2265 lvalue
*get_lvalue () const { return m_dest
; }
2267 void replay_into (replayer
*) FINAL OVERRIDE
{}
2269 void print (pretty_printer
*pp
) const FINAL OVERRIDE
;
2272 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
2278 class input_asm_operand
: public asm_operand
2281 input_asm_operand (extended_asm
*ext_asm
,
2282 string
*asm_symbolic_name
,
2285 : asm_operand (ext_asm
, asm_symbolic_name
, constraint
),
2289 rvalue
*get_rvalue () const { return m_src
; }
2291 void replay_into (replayer
*) FINAL OVERRIDE
{}
2293 void print (pretty_printer
*pp
) const FINAL OVERRIDE
;
2296 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
2302 /* Abstract base class for extended_asm statements. */
2304 class extended_asm
: public statement
2307 extended_asm (block
*b
,
2309 string
*asm_template
)
2310 : statement (b
, loc
),
2311 m_asm_template (asm_template
),
2312 m_is_volatile (false),
2316 void set_volatile_flag (bool flag
) { m_is_volatile
= flag
; }
2317 void set_inline_flag (bool flag
) { m_is_inline
= flag
; }
2319 void add_output_operand (const char *asm_symbolic_name
,
2320 const char *constraint
,
2322 void add_input_operand (const char *asm_symbolic_name
,
2323 const char *constraint
,
2325 void add_clobber (const char *victim
);
2327 void replay_into (replayer
*r
) OVERRIDE
;
2329 string
*get_asm_template () const { return m_asm_template
; }
2331 virtual bool is_goto () const = 0;
2332 virtual void maybe_print_gotos (pretty_printer
*) const = 0;
2335 void write_flags (reproducer
&r
);
2336 void write_clobbers (reproducer
&r
);
2339 string
* make_debug_string () FINAL OVERRIDE
;
2340 virtual void maybe_populate_playback_blocks
2341 (auto_vec
<playback::block
*> *out
) = 0;
2344 string
*m_asm_template
;
2347 auto_vec
<output_asm_operand
*> m_output_ops
;
2348 auto_vec
<input_asm_operand
*> m_input_ops
;
2349 auto_vec
<string
*> m_clobbers
;
2352 /* An extended_asm that's not a goto, as created by
2353 gcc_jit_block_add_extended_asm. */
2355 class extended_asm_simple
: public extended_asm
2358 extended_asm_simple (block
*b
,
2360 string
*asm_template
)
2361 : extended_asm (b
, loc
, asm_template
)
2364 void write_reproducer (reproducer
&r
) OVERRIDE
;
2365 bool is_goto () const FINAL OVERRIDE
{ return false; }
2366 void maybe_print_gotos (pretty_printer
*) const FINAL OVERRIDE
{}
2369 void maybe_populate_playback_blocks
2370 (auto_vec
<playback::block
*> *) FINAL OVERRIDE
2374 /* An extended_asm that's a asm goto, as created by
2375 gcc_jit_block_end_with_extended_asm_goto. */
2377 class extended_asm_goto
: public extended_asm
2380 extended_asm_goto (block
*b
,
2382 string
*asm_template
,
2383 int num_goto_blocks
,
2384 block
**goto_blocks
,
2385 block
*fallthrough_block
);
2387 void replay_into (replayer
*r
) FINAL OVERRIDE
;
2388 void write_reproducer (reproducer
&r
) OVERRIDE
;
2390 vec
<block
*> get_successor_blocks () const FINAL OVERRIDE
;
2392 bool is_goto () const FINAL OVERRIDE
{ return true; }
2393 void maybe_print_gotos (pretty_printer
*) const FINAL OVERRIDE
;
2396 void maybe_populate_playback_blocks
2397 (auto_vec
<playback::block
*> *out
) FINAL OVERRIDE
;
2400 auto_vec
<block
*> m_goto_blocks
;
2401 block
*m_fallthrough_block
;
2404 /* A group of top-level asm statements, as created by
2405 gcc_jit_context_add_top_level_asm. */
2407 class top_level_asm
: public memento
2410 top_level_asm (context
*ctxt
, location
*loc
, string
*asm_stmts
);
2412 void write_to_dump (dump
&d
) FINAL OVERRIDE
;
2415 void replay_into (replayer
*r
) FINAL OVERRIDE
;
2416 string
* make_debug_string () FINAL OVERRIDE
;
2417 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
2421 string
*m_asm_stmts
;
2424 class global_init_rvalue
: public memento
2427 global_init_rvalue (context
*ctxt
, lvalue
*variable
, rvalue
*init
) :
2428 memento (ctxt
), m_variable (variable
), m_init (init
) {};
2430 void write_to_dump (dump
&d
) FINAL OVERRIDE
;
2433 void replay_into (replayer
*r
) FINAL OVERRIDE
;
2434 string
* make_debug_string () FINAL OVERRIDE
;
2435 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
2442 } // namespace gcc::jit::recording
2444 /* Create a recording::memento_of_new_rvalue_from_const instance and add
2445 it to this context's list of mementos.
2447 Implements the post-error-checking part of
2448 gcc_jit_context_new_rvalue_from_{int|long|double|ptr}. */
2450 template <typename HOST_TYPE
>
2452 recording::context::new_rvalue_from_const (recording::type
*type
,
2455 recording::rvalue
*result
=
2456 new memento_of_new_rvalue_from_const
<HOST_TYPE
> (this, NULL
, type
, value
);
2461 /* Don't call this directly. Call types_kinda_same. */
2463 types_kinda_same_internal (recording::type
*a
,
2464 recording::type
*b
);
2466 /* Strip all qualifiers and count pointer depth, returning true
2467 if the types and pointer depth are the same, otherwise false.
2469 For array and vector types the number of element also
2470 has to match, aswell as the element types themself. */
2472 types_kinda_same (recording::type
*a
, recording::type
*b
)
2474 /* Handle trivial case here, to allow for inlining. */
2475 return a
== b
|| types_kinda_same_internal (a
, b
);
2478 } // namespace gcc::jit
2482 #endif /* JIT_RECORDING_H */