1 /* Internals of libgccjit: classes for recording calls made to the JIT API.
2 Copyright (C) 2013-2020 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
);
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
,
152 template <typename HOST_TYPE
>
154 new_rvalue_from_const (type
*type
,
158 new_string_literal (const char *value
);
161 new_rvalue_from_vector (location
*loc
,
166 new_unary_op (location
*loc
,
167 enum gcc_jit_unary_op op
,
172 new_binary_op (location
*loc
,
173 enum gcc_jit_binary_op op
,
175 rvalue
*a
, rvalue
*b
);
178 new_comparison (location
*loc
,
179 enum gcc_jit_comparison op
,
180 rvalue
*a
, rvalue
*b
);
183 new_call (location
*loc
,
185 int numargs
, rvalue
**args
);
188 new_call_through_ptr (location
*loc
,
190 int numargs
, rvalue
**args
);
193 new_cast (location
*loc
,
198 new_array_access (location
*loc
,
203 new_case (rvalue
*min_value
,
208 set_str_option (enum gcc_jit_str_option opt
,
212 set_int_option (enum gcc_jit_int_option opt
,
216 set_bool_option (enum gcc_jit_bool_option opt
,
220 set_inner_bool_option (enum inner_bool_option inner_opt
,
224 add_command_line_option (const char *optname
);
227 append_command_line_options (vec
<char *> *argvec
);
230 add_driver_option (const char *optname
);
233 append_driver_options (auto_string_vec
*argvec
);
236 enable_dump (const char *dumpname
,
240 get_str_option (enum gcc_jit_str_option opt
) const
242 return m_str_options
[opt
];
246 get_int_option (enum gcc_jit_int_option opt
) const
248 return m_int_options
[opt
];
252 get_bool_option (enum gcc_jit_bool_option opt
) const
254 return m_bool_options
[opt
];
258 get_inner_bool_option (enum inner_bool_option opt
) const
260 return m_inner_bool_options
[opt
];
267 compile_to_file (enum gcc_jit_output_kind output_kind
,
268 const char *output_path
);
271 add_error (location
*loc
, const char *fmt
, ...)
275 add_error_va (location
*loc
, const char *fmt
, va_list ap
)
279 get_first_error () const;
282 get_last_error () const;
284 bool errors_occurred () const
287 if (m_parent_ctxt
->errors_occurred ())
289 return m_error_count
;
292 type
*get_opaque_FILE_type ();
294 void dump_to_file (const char *path
, bool update_locations
);
296 void dump_reproducer_to_file (const char *path
);
299 get_all_requested_dumps (vec
<recording::requested_dump
> *out
);
301 void set_timer (timer
*t
) { m_timer
= t
; }
302 timer
*get_timer () const { return m_timer
; }
305 void log_all_options () const;
306 void log_str_option (enum gcc_jit_str_option opt
) const;
307 void log_int_option (enum gcc_jit_int_option opt
) const;
308 void log_bool_option (enum gcc_jit_bool_option opt
) const;
309 void log_inner_bool_option (enum inner_bool_option opt
) const;
314 context
*m_parent_ctxt
;
316 /* The ultimate ancestor of the contexts within a family tree of
317 contexts. This has itself as its own m_toplevel_ctxt. */
318 context
*m_toplevel_ctxt
;
324 char *m_first_error_str
;
325 bool m_owns_first_error_str
;
327 char *m_last_error_str
;
328 bool m_owns_last_error_str
;
330 char *m_str_options
[GCC_JIT_NUM_STR_OPTIONS
];
331 int m_int_options
[GCC_JIT_NUM_INT_OPTIONS
];
332 bool m_bool_options
[GCC_JIT_NUM_BOOL_OPTIONS
];
333 bool m_inner_bool_options
[NUM_INNER_BOOL_OPTIONS
];
334 auto_vec
<char *> m_command_line_options
;
335 auto_vec
<char *> m_driver_options
;
337 /* Dumpfiles that were requested via gcc_jit_context_enable_dump. */
338 auto_vec
<requested_dump
> m_requested_dumps
;
340 /* Recorded API usage. */
341 auto_vec
<memento
*> m_mementos
;
343 /* Specific recordings, for use by dump_to_file. */
344 auto_vec
<compound_type
*> m_compound_types
;
345 auto_vec
<global
*> m_globals
;
346 auto_vec
<function
*> m_functions
;
348 type
*m_basic_types
[NUM_GCC_JIT_TYPES
];
351 builtins_manager
*m_builtins_manager
; // lazily created
355 /* An object with lifetime managed by the context i.e.
356 it lives until the context is released, at which
357 point it itself is cleaned up. */
362 virtual ~memento () {}
364 /* Hook for replaying this. */
365 virtual void replay_into (replayer
*r
) = 0;
367 void set_playback_obj (void *obj
) { m_playback_obj
= obj
; }
370 /* Get the context that owns this object.
372 Implements the post-error-checking part of
373 gcc_jit_object_get_context. */
374 context
*get_context () { return m_ctxt
; }
377 as_object () { return this; }
379 /* Debugging hook, for use in generating error messages etc.
380 Implements the post-error-checking part of
381 gcc_jit_object_get_debug_string. */
385 virtual void write_to_dump (dump
&d
);
386 virtual void write_reproducer (reproducer
&r
) = 0;
387 virtual location
*dyn_cast_location () { return NULL
; }
390 memento (context
*ctxt
)
392 m_playback_obj (NULL
),
393 m_debug_string (NULL
)
398 string
*new_string (const char *text
) { return m_ctxt
->new_string (text
); }
401 virtual string
* make_debug_string () = 0;
407 void *m_playback_obj
;
410 string
*m_debug_string
;
413 /* or just use std::string? */
414 class string
: public memento
417 string (context
*ctxt
, const char *text
);
420 const char *c_str () { return m_buffer
; }
422 static string
* from_printf (context
*ctxt
, const char *fmt
, ...)
425 void replay_into (replayer
*) FINAL OVERRIDE
{}
428 string
* make_debug_string () FINAL OVERRIDE
;
429 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
436 class location
: public memento
439 location (context
*ctxt
, string
*filename
, int line
, int column
,
440 bool created_by_user
)
442 m_filename (filename
),
445 m_created_by_user (created_by_user
)
448 void replay_into (replayer
*r
) FINAL OVERRIDE
;
451 playback_location (replayer
*r
)
453 /* Normally during playback, we can walk forwards through the list of
454 recording objects, playing them back. The ordering of recording
455 ensures that everything that a recording object refers to has
456 already been played back, so we can simply look up the relevant
459 Locations are an exception, due to the "write_to_dump" method of
460 recording::statement. This method can set a new location on a
461 statement after the statement is created, and thus the location
462 appears in the context's memento list *after* the statement that
465 In such circumstances, the statement is replayed *before* the location,
466 when the latter doesn't yet have a playback object.
468 Hence we need to ensure that locations have playback objects. */
473 gcc_assert (m_playback_obj
);
474 return static_cast <playback::location
*> (m_playback_obj
);
477 location
*dyn_cast_location () FINAL OVERRIDE
{ return this; }
478 bool created_by_user () const { return m_created_by_user
; }
481 string
* make_debug_string () FINAL OVERRIDE
;
482 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
488 bool m_created_by_user
;
491 class type
: public memento
494 type
*get_pointer ();
496 type
*get_volatile ();
497 type
*get_aligned (size_t alignment_in_bytes
);
498 type
*get_vector (size_t num_units
);
500 /* Get the type obtained when dereferencing this type.
502 This will return NULL if it's not valid to dereference this type.
503 The caller is responsible for setting an error. */
504 virtual type
*dereference () = 0;
507 virtual function_type
*dyn_cast_function_type () { return NULL
; }
508 virtual function_type
*as_a_function_type() { gcc_unreachable (); return NULL
; }
509 virtual struct_
*dyn_cast_struct () { return NULL
; }
510 virtual vector_type
*dyn_cast_vector_type () { return NULL
; }
512 /* Is it typesafe to copy to this type from rtype? */
513 virtual bool accepts_writes_from (type
*rtype
)
516 return this->unqualified ()->is_same_type_as (rtype
->unqualified ());
519 virtual bool is_same_type_as (type
*other
)
521 return this == other
;
524 /* Strip off "const" etc */
525 virtual type
*unqualified ()
530 virtual bool is_int () const = 0;
531 virtual bool is_float () const = 0;
532 virtual bool is_bool () const = 0;
533 virtual type
*is_pointer () = 0;
534 virtual type
*is_array () = 0;
535 virtual bool is_void () const { return false; }
536 virtual bool has_known_size () const { return true; }
538 bool is_numeric () const
540 return is_int () || is_float () || is_bool ();
546 return static_cast <playback::type
*> (m_playback_obj
);
549 virtual const char *access_as_type (reproducer
&r
);
554 m_pointer_to_this_type (NULL
)
558 type
*m_pointer_to_this_type
;
561 /* Result of "gcc_jit_context_get_type". */
562 class memento_of_get_type
: public type
565 memento_of_get_type (context
*ctxt
,
566 enum gcc_jit_types kind
)
570 type
*dereference () FINAL OVERRIDE
;
572 bool accepts_writes_from (type
*rtype
) FINAL OVERRIDE
574 if (m_kind
== GCC_JIT_TYPE_VOID_PTR
)
575 if (rtype
->is_pointer ())
577 /* LHS (this) is type (void *), and the RHS is a pointer:
582 return type::accepts_writes_from (rtype
);
585 bool is_int () const FINAL OVERRIDE
;
586 bool is_float () const FINAL OVERRIDE
;
587 bool is_bool () const FINAL OVERRIDE
;
588 type
*is_pointer () FINAL OVERRIDE
{ return dereference (); }
589 type
*is_array () FINAL OVERRIDE
{ return NULL
; }
590 bool is_void () const FINAL OVERRIDE
{ return m_kind
== GCC_JIT_TYPE_VOID
; }
593 void replay_into (replayer
*r
) FINAL OVERRIDE
;
596 string
* make_debug_string () FINAL OVERRIDE
;
597 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
600 enum gcc_jit_types m_kind
;
603 /* Result of "gcc_jit_type_get_pointer". */
604 class memento_of_get_pointer
: public type
607 memento_of_get_pointer (type
*other_type
)
608 : type (other_type
->m_ctxt
),
609 m_other_type (other_type
) {}
611 type
*dereference () FINAL OVERRIDE
{ return m_other_type
; }
613 bool accepts_writes_from (type
*rtype
) FINAL OVERRIDE
;
615 void replay_into (replayer
*r
) FINAL OVERRIDE
;
617 bool is_int () const FINAL OVERRIDE
{ return false; }
618 bool is_float () const FINAL OVERRIDE
{ return false; }
619 bool is_bool () const FINAL OVERRIDE
{ return false; }
620 type
*is_pointer () FINAL OVERRIDE
{ return m_other_type
; }
621 type
*is_array () FINAL OVERRIDE
{ return NULL
; }
624 string
* make_debug_string () FINAL OVERRIDE
;
625 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
631 /* A decorated version of a type, for get_const, get_volatile,
632 get_aligned, and get_vector. */
634 class decorated_type
: public type
637 decorated_type (type
*other_type
)
638 : type (other_type
->m_ctxt
),
639 m_other_type (other_type
) {}
641 type
*dereference () FINAL OVERRIDE
{ return m_other_type
->dereference (); }
643 bool is_int () const FINAL OVERRIDE
{ return m_other_type
->is_int (); }
644 bool is_float () const FINAL OVERRIDE
{ return m_other_type
->is_float (); }
645 bool is_bool () const FINAL OVERRIDE
{ return m_other_type
->is_bool (); }
646 type
*is_pointer () FINAL OVERRIDE
{ return m_other_type
->is_pointer (); }
647 type
*is_array () FINAL OVERRIDE
{ return m_other_type
->is_array (); }
653 /* Result of "gcc_jit_type_get_const". */
654 class memento_of_get_const
: public decorated_type
657 memento_of_get_const (type
*other_type
)
658 : decorated_type (other_type
) {}
660 bool accepts_writes_from (type */
*rtype*/
) FINAL OVERRIDE
662 /* Can't write to a "const". */
666 /* Strip off the "const", giving the underlying type. */
667 type
*unqualified () FINAL OVERRIDE
{ return m_other_type
; }
669 void replay_into (replayer
*) FINAL OVERRIDE
;
672 string
* make_debug_string () FINAL OVERRIDE
;
673 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
676 /* Result of "gcc_jit_type_get_volatile". */
677 class memento_of_get_volatile
: public decorated_type
680 memento_of_get_volatile (type
*other_type
)
681 : decorated_type (other_type
) {}
683 /* Strip off the "volatile", giving the underlying type. */
684 type
*unqualified () FINAL OVERRIDE
{ return m_other_type
; }
686 void replay_into (replayer
*) FINAL OVERRIDE
;
689 string
* make_debug_string () FINAL OVERRIDE
;
690 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
693 /* Result of "gcc_jit_type_get_aligned". */
694 class memento_of_get_aligned
: public decorated_type
697 memento_of_get_aligned (type
*other_type
, size_t alignment_in_bytes
)
698 : decorated_type (other_type
),
699 m_alignment_in_bytes (alignment_in_bytes
) {}
701 /* Strip off the alignment, giving the underlying type. */
702 type
*unqualified () FINAL OVERRIDE
{ return m_other_type
; }
704 void replay_into (replayer
*) FINAL OVERRIDE
;
707 string
* make_debug_string () FINAL OVERRIDE
;
708 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
711 size_t m_alignment_in_bytes
;
714 /* Result of "gcc_jit_type_get_vector". */
715 class vector_type
: public decorated_type
718 vector_type (type
*other_type
, size_t num_units
)
719 : decorated_type (other_type
),
720 m_num_units (num_units
) {}
722 size_t get_num_units () const { return m_num_units
; }
724 vector_type
*dyn_cast_vector_type () FINAL OVERRIDE
{ return this; }
726 type
*get_element_type () { return m_other_type
; }
728 void replay_into (replayer
*) FINAL OVERRIDE
;
731 string
* make_debug_string () FINAL OVERRIDE
;
732 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
738 class array_type
: public type
741 array_type (context
*ctxt
,
747 m_element_type (element_type
),
748 m_num_elements (num_elements
)
751 type
*dereference () FINAL OVERRIDE
;
753 bool is_int () const FINAL OVERRIDE
{ return false; }
754 bool is_float () const FINAL OVERRIDE
{ return false; }
755 bool is_bool () const FINAL OVERRIDE
{ return false; }
756 type
*is_pointer () FINAL OVERRIDE
{ return NULL
; }
757 type
*is_array () FINAL OVERRIDE
{ return m_element_type
; }
759 void replay_into (replayer
*) FINAL OVERRIDE
;
762 string
* make_debug_string () FINAL OVERRIDE
;
763 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
767 type
*m_element_type
;
771 class function_type
: public type
774 function_type (context
*ctxt
,
780 type
*dereference () FINAL OVERRIDE
;
781 function_type
*dyn_cast_function_type () FINAL OVERRIDE
{ return this; }
782 function_type
*as_a_function_type () FINAL OVERRIDE
{ return this; }
784 bool is_same_type_as (type
*other
) FINAL OVERRIDE
;
786 bool is_int () const FINAL OVERRIDE
{ return false; }
787 bool is_float () const FINAL OVERRIDE
{ return false; }
788 bool is_bool () const FINAL OVERRIDE
{ return false; }
789 type
*is_pointer () FINAL OVERRIDE
{ return NULL
; }
790 type
*is_array () FINAL OVERRIDE
{ return NULL
; }
792 void replay_into (replayer
*) FINAL OVERRIDE
;
794 type
* get_return_type () const { return m_return_type
; }
795 const vec
<type
*> &get_param_types () const { return m_param_types
; }
796 int is_variadic () const { return m_is_variadic
; }
798 string
* make_debug_string_with_ptr ();
801 write_deferred_reproducer (reproducer
&r
,
805 string
* make_debug_string () FINAL OVERRIDE
;
806 string
* make_debug_string_with (const char *);
807 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
811 auto_vec
<type
*> m_param_types
;
815 class field
: public memento
818 field (context
*ctxt
,
829 type
* get_type () const { return m_type
; }
831 compound_type
* get_container () const { return m_container
; }
832 void set_container (compound_type
*c
) { m_container
= c
; }
834 void replay_into (replayer
*) OVERRIDE
;
836 void write_to_dump (dump
&d
) OVERRIDE
;
839 playback_field () const
841 return static_cast <playback::field
*> (m_playback_obj
);
845 string
* make_debug_string () OVERRIDE
;
846 void write_reproducer (reproducer
&r
) OVERRIDE
;
852 compound_type
*m_container
;
856 class bitfield
: public field
859 bitfield (context
*ctxt
,
864 : field (ctxt
, loc
, type
, name
),
868 void replay_into (replayer
*) FINAL OVERRIDE
;
870 void write_to_dump (dump
&d
) FINAL OVERRIDE
;
873 string
* make_debug_string () FINAL OVERRIDE
;
874 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
880 /* Base class for struct_ and union_ */
881 class compound_type
: public type
884 compound_type (context
*ctxt
,
888 string
*get_name () const { return m_name
; }
889 location
*get_loc () const { return m_loc
; }
890 fields
* get_fields () { return m_fields
; }
893 set_fields (location
*loc
,
897 type
*dereference () FINAL OVERRIDE
;
899 bool is_int () const FINAL OVERRIDE
{ return false; }
900 bool is_float () const FINAL OVERRIDE
{ return false; }
901 bool is_bool () const FINAL OVERRIDE
{ return false; }
902 type
*is_pointer () FINAL OVERRIDE
{ return NULL
; }
903 type
*is_array () FINAL OVERRIDE
{ return NULL
; }
905 bool has_known_size () const FINAL OVERRIDE
{ return m_fields
!= NULL
; }
907 playback::compound_type
*
908 playback_compound_type ()
910 return static_cast <playback::compound_type
*> (m_playback_obj
);
919 class struct_
: public compound_type
922 struct_ (context
*ctxt
,
926 struct_
*dyn_cast_struct () FINAL OVERRIDE
{ return this; }
929 as_type () { return this; }
931 void replay_into (replayer
*r
) FINAL OVERRIDE
;
933 const char *access_as_type (reproducer
&r
) FINAL OVERRIDE
;
936 string
* make_debug_string () FINAL OVERRIDE
;
937 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
940 // memento of struct_::set_fields
941 class fields
: public memento
944 fields (compound_type
*struct_or_union
,
948 void replay_into (replayer
*r
) FINAL OVERRIDE
;
950 void write_to_dump (dump
&d
) FINAL OVERRIDE
;
952 int length () const { return m_fields
.length (); }
953 field
*get_field (int i
) const { return m_fields
[i
]; }
956 string
* make_debug_string () FINAL OVERRIDE
;
957 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
960 compound_type
*m_struct_or_union
;
961 auto_vec
<field
*> m_fields
;
964 class union_
: public compound_type
967 union_ (context
*ctxt
,
971 void replay_into (replayer
*r
) FINAL OVERRIDE
;
974 string
* make_debug_string () FINAL OVERRIDE
;
975 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
978 /* An abstract base class for operations that visit all rvalues within an
980 Currently the only implementation is class rvalue_usage_validator within
986 virtual ~rvalue_visitor () {}
987 virtual void visit (rvalue
*rvalue
) = 0;
990 /* When generating debug strings for rvalues we mimic C, so we need to
991 mimic C's precedence levels when handling compound expressions.
992 These are in order from strongest precedence to weakest. */
999 PRECEDENCE_MULTIPLICATIVE
,
1000 PRECEDENCE_ADDITIVE
,
1002 PRECEDENCE_RELATIONAL
,
1003 PRECEDENCE_EQUALITY
,
1004 PRECEDENCE_BITWISE_AND
,
1005 PRECEDENCE_BITWISE_XOR
,
1006 PRECEDENCE_BITWISE_IOR
,
1007 PRECEDENCE_LOGICAL_AND
,
1008 PRECEDENCE_LOGICAL_OR
1011 class rvalue
: public memento
1014 rvalue (context
*ctxt
,
1021 m_parenthesized_string (NULL
)
1026 location
* get_loc () const { return m_loc
; }
1028 /* Get the recording::type of this rvalue.
1030 Implements the post-error-checking part of
1031 gcc_jit_rvalue_get_type. */
1032 type
* get_type () const { return m_type
; }
1035 playback_rvalue () const
1037 return static_cast <playback::rvalue
*> (m_playback_obj
);
1040 access_field (location
*loc
,
1044 dereference_field (location
*loc
,
1048 dereference (location
*loc
);
1051 verify_valid_within_stmt (const char *api_funcname
, statement
*s
);
1053 virtual void visit_children (rvalue_visitor
*v
) = 0;
1055 void set_scope (function
*scope
);
1056 function
*get_scope () const { return m_scope
; }
1058 /* Dynamic casts. */
1059 virtual param
*dyn_cast_param () { return NULL
; }
1060 virtual base_call
*dyn_cast_base_call () { return NULL
; }
1062 virtual const char *access_as_rvalue (reproducer
&r
);
1064 /* Get the debug string, wrapped in parentheses. */
1066 get_debug_string_parens (enum precedence outer_prec
);
1068 virtual bool is_constant () const { return false; }
1069 virtual bool get_wide_int (wide_int
*) const { return false; }
1072 virtual enum precedence
get_precedence () const = 0;
1079 function
*m_scope
; /* NULL for globals, non-NULL for locals/params */
1080 string
*m_parenthesized_string
;
1083 class lvalue
: public rvalue
1086 lvalue (context
*ctxt
,
1089 : rvalue (ctxt
, loc
, type_
)
1093 playback_lvalue () const
1095 return static_cast <playback::lvalue
*> (m_playback_obj
);
1099 access_field (location
*loc
,
1103 get_address (location
*loc
);
1106 as_rvalue () { return this; }
1108 const char *access_as_rvalue (reproducer
&r
) OVERRIDE
;
1109 virtual const char *access_as_lvalue (reproducer
&r
);
1112 class param
: public lvalue
1115 param (context
*ctxt
,
1119 : lvalue (ctxt
, loc
, type
),
1123 as_lvalue () { return this; }
1125 void replay_into (replayer
*r
) FINAL OVERRIDE
;
1127 void visit_children (rvalue_visitor
*) FINAL OVERRIDE
{}
1130 playback_param () const
1132 return static_cast <playback::param
*> (m_playback_obj
);
1135 param
*dyn_cast_param () FINAL OVERRIDE
{ return this; }
1137 const char *access_as_rvalue (reproducer
&r
) FINAL OVERRIDE
;
1138 const char *access_as_lvalue (reproducer
&r
) FINAL OVERRIDE
;
1141 string
* make_debug_string () FINAL OVERRIDE
{ return m_name
; }
1142 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
1143 enum precedence
get_precedence () const FINAL OVERRIDE
1145 return PRECEDENCE_PRIMARY
;
1152 class function
: public memento
1155 function (context
*ctxt
,
1157 enum gcc_jit_function_kind kind
,
1163 enum built_in_function builtin_id
);
1165 void replay_into (replayer
*r
) FINAL OVERRIDE
;
1167 playback::function
*
1168 playback_function () const
1170 return static_cast <playback::function
*> (m_playback_obj
);
1173 enum gcc_jit_function_kind
get_kind () const { return m_kind
; }
1176 new_local (location
*loc
,
1181 new_block (const char *name
);
1183 location
*get_loc () const { return m_loc
; }
1184 type
*get_return_type () const { return m_return_type
; }
1185 string
* get_name () const { return m_name
; }
1186 const vec
<param
*> &get_params () const { return m_params
; }
1188 /* Get the given param by index.
1189 Implements the post-error-checking part of
1190 gcc_jit_function_get_param. */
1191 param
*get_param (int i
) const { return m_params
[i
]; }
1193 bool is_variadic () const { return m_is_variadic
; }
1195 void write_to_dump (dump
&d
) FINAL OVERRIDE
;
1199 void dump_to_dot (const char *path
);
1201 rvalue
*get_address (location
*loc
);
1204 string
* make_debug_string () FINAL OVERRIDE
;
1205 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
1209 enum gcc_jit_function_kind m_kind
;
1210 type
*m_return_type
;
1212 auto_vec
<param
*> m_params
;
1214 enum built_in_function m_builtin_id
;
1215 auto_vec
<local
*> m_locals
;
1216 auto_vec
<block
*> m_blocks
;
1217 type
*m_fn_ptr_type
;
1220 class block
: public memento
1223 block (function
*func
, int index
, string
*name
)
1224 : memento (func
->m_ctxt
),
1229 m_has_been_terminated (false),
1230 m_is_reachable (false)
1234 /* Get the recording::function containing this block.
1235 Implements the post-error-checking part of
1236 gcc_jit_block_get_function. */
1237 function
*get_function () { return m_func
; }
1239 bool has_been_terminated () { return m_has_been_terminated
; }
1240 bool is_reachable () { return m_is_reachable
; }
1243 add_eval (location
*loc
,
1247 add_assignment (location
*loc
,
1252 add_assignment_op (location
*loc
,
1254 enum gcc_jit_binary_op op
,
1258 add_comment (location
*loc
,
1262 end_with_conditional (location
*loc
,
1268 end_with_jump (location
*loc
,
1272 end_with_return (location
*loc
,
1276 end_with_switch (location
*loc
,
1278 block
*default_block
,
1283 playback_block () const
1285 return static_cast <playback::block
*> (m_playback_obj
);
1288 void write_to_dump (dump
&d
) FINAL OVERRIDE
;
1292 location
*get_loc () const;
1294 statement
*get_first_statement () const;
1295 statement
*get_last_statement () const;
1297 vec
<block
*> get_successor_blocks () const;
1300 string
* make_debug_string () FINAL OVERRIDE
;
1301 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
1303 void replay_into (replayer
*r
) FINAL OVERRIDE
;
1305 void dump_to_dot (pretty_printer
*pp
);
1306 void dump_edges_to_dot (pretty_printer
*pp
);
1312 auto_vec
<statement
*> m_statements
;
1313 bool m_has_been_terminated
;
1314 bool m_is_reachable
;
1316 friend class function
;
1319 class global
: public lvalue
1322 global (context
*ctxt
,
1324 enum gcc_jit_global_kind kind
,
1327 : lvalue (ctxt
, loc
, type
),
1332 void replay_into (replayer
*) FINAL OVERRIDE
;
1334 void visit_children (rvalue_visitor
*) FINAL OVERRIDE
{}
1336 void write_to_dump (dump
&d
) FINAL OVERRIDE
;
1339 string
* make_debug_string () FINAL OVERRIDE
{ return m_name
; }
1340 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
1341 enum precedence
get_precedence () const FINAL OVERRIDE
1343 return PRECEDENCE_PRIMARY
;
1347 enum gcc_jit_global_kind m_kind
;
1351 template <typename HOST_TYPE
>
1352 class memento_of_new_rvalue_from_const
: public rvalue
1355 memento_of_new_rvalue_from_const (context
*ctxt
,
1359 : rvalue (ctxt
, loc
, type
),
1362 void replay_into (replayer
*r
) FINAL OVERRIDE
;
1364 void visit_children (rvalue_visitor
*) FINAL OVERRIDE
{}
1366 bool is_constant () const FINAL OVERRIDE
{ return true; }
1368 bool get_wide_int (wide_int
*out
) const FINAL OVERRIDE
;
1371 string
* make_debug_string () FINAL OVERRIDE
;
1372 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
1373 enum precedence
get_precedence () const FINAL OVERRIDE
1375 return PRECEDENCE_PRIMARY
;
1382 class memento_of_new_string_literal
: public rvalue
1385 memento_of_new_string_literal (context
*ctxt
,
1388 : rvalue (ctxt
, loc
, ctxt
->get_type (GCC_JIT_TYPE_CONST_CHAR_PTR
)),
1391 void replay_into (replayer
*r
) FINAL OVERRIDE
;
1393 void visit_children (rvalue_visitor
*) FINAL OVERRIDE
{}
1396 string
* make_debug_string () FINAL OVERRIDE
;
1397 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
1398 enum precedence
get_precedence () const FINAL OVERRIDE
1400 return PRECEDENCE_PRIMARY
;
1407 class memento_of_new_rvalue_from_vector
: public rvalue
1410 memento_of_new_rvalue_from_vector (context
*ctxt
,
1415 void replay_into (replayer
*r
) FINAL OVERRIDE
;
1417 void visit_children (rvalue_visitor
*) FINAL OVERRIDE
;
1420 string
* make_debug_string () FINAL OVERRIDE
;
1421 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
1422 enum precedence
get_precedence () const FINAL OVERRIDE
1424 return PRECEDENCE_PRIMARY
;
1428 vector_type
*m_vector_type
;
1429 auto_vec
<rvalue
*> m_elements
;
1432 class unary_op
: public rvalue
1435 unary_op (context
*ctxt
,
1437 enum gcc_jit_unary_op op
,
1440 : rvalue (ctxt
, loc
, result_type
),
1445 void replay_into (replayer
*r
) FINAL OVERRIDE
;
1447 void visit_children (rvalue_visitor
*v
) FINAL OVERRIDE
;
1450 string
* make_debug_string () FINAL OVERRIDE
;
1451 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
1452 enum precedence
get_precedence () const FINAL OVERRIDE
1454 return PRECEDENCE_UNARY
;
1458 enum gcc_jit_unary_op m_op
;
1462 class binary_op
: public rvalue
1465 binary_op (context
*ctxt
,
1467 enum gcc_jit_binary_op op
,
1469 rvalue
*a
, rvalue
*b
)
1470 : rvalue (ctxt
, loc
, result_type
),
1475 void replay_into (replayer
*r
) FINAL OVERRIDE
;
1477 void visit_children (rvalue_visitor
*v
) FINAL OVERRIDE
;
1480 string
* make_debug_string () FINAL OVERRIDE
;
1481 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
1482 enum precedence
get_precedence () const FINAL OVERRIDE
;
1485 enum gcc_jit_binary_op m_op
;
1490 class comparison
: public rvalue
1493 comparison (context
*ctxt
,
1495 enum gcc_jit_comparison op
,
1496 rvalue
*a
, rvalue
*b
)
1497 : rvalue (ctxt
, loc
, ctxt
->get_type (GCC_JIT_TYPE_BOOL
)),
1503 void replay_into (replayer
*r
) FINAL OVERRIDE
;
1505 void visit_children (rvalue_visitor
*v
) FINAL OVERRIDE
;
1508 string
* make_debug_string () FINAL OVERRIDE
;
1509 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
1510 enum precedence
get_precedence () const FINAL OVERRIDE
;
1513 enum gcc_jit_comparison m_op
;
1518 class cast
: public rvalue
1521 cast (context
*ctxt
,
1525 : rvalue (ctxt
, loc
, type_
),
1529 void replay_into (replayer
*r
) FINAL OVERRIDE
;
1531 void visit_children (rvalue_visitor
*v
) FINAL OVERRIDE
;
1534 string
* make_debug_string () FINAL OVERRIDE
;
1535 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
1536 enum precedence
get_precedence () const FINAL OVERRIDE
1538 return PRECEDENCE_CAST
;
1545 class base_call
: public rvalue
1548 base_call (context
*ctxt
,
1554 enum precedence
get_precedence () const FINAL OVERRIDE
1556 return PRECEDENCE_POSTFIX
;
1559 base_call
*dyn_cast_base_call () FINAL OVERRIDE
{ return this; }
1561 void set_require_tail_call (bool require_tail_call
)
1563 m_require_tail_call
= require_tail_call
;
1567 void write_reproducer_tail_call (reproducer
&r
, const char *id
);
1570 auto_vec
<rvalue
*> m_args
;
1571 bool m_require_tail_call
;
1574 class call
: public base_call
1577 call (context
*ctxt
,
1583 void replay_into (replayer
*r
) FINAL OVERRIDE
;
1585 void visit_children (rvalue_visitor
*v
) FINAL OVERRIDE
;
1588 string
* make_debug_string () FINAL OVERRIDE
;
1589 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
1595 class call_through_ptr
: public base_call
1598 call_through_ptr (context
*ctxt
,
1604 void replay_into (replayer
*r
) FINAL OVERRIDE
;
1606 void visit_children (rvalue_visitor
*v
) FINAL OVERRIDE
;
1609 string
* make_debug_string () FINAL OVERRIDE
;
1610 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
1616 class array_access
: public lvalue
1619 array_access (context
*ctxt
,
1623 : lvalue (ctxt
, loc
, ptr
->get_type ()->dereference ()),
1628 void replay_into (replayer
*r
) FINAL OVERRIDE
;
1630 void visit_children (rvalue_visitor
*v
) FINAL OVERRIDE
;
1633 string
* make_debug_string () FINAL OVERRIDE
;
1634 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
1635 enum precedence
get_precedence () const FINAL OVERRIDE
1637 return PRECEDENCE_POSTFIX
;
1645 class access_field_of_lvalue
: public lvalue
1648 access_field_of_lvalue (context
*ctxt
,
1652 : lvalue (ctxt
, loc
, field
->get_type ()),
1657 void replay_into (replayer
*r
) FINAL OVERRIDE
;
1659 void visit_children (rvalue_visitor
*v
) FINAL OVERRIDE
;
1662 string
* make_debug_string () FINAL OVERRIDE
;
1663 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
1664 enum precedence
get_precedence () const FINAL OVERRIDE
1666 return PRECEDENCE_POSTFIX
;
1674 class access_field_rvalue
: public rvalue
1677 access_field_rvalue (context
*ctxt
,
1681 : rvalue (ctxt
, loc
, field
->get_type ()),
1686 void replay_into (replayer
*r
) FINAL OVERRIDE
;
1688 void visit_children (rvalue_visitor
*v
) FINAL OVERRIDE
;
1691 string
* make_debug_string () FINAL OVERRIDE
;
1692 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
1693 enum precedence
get_precedence () const FINAL OVERRIDE
1695 return PRECEDENCE_POSTFIX
;
1703 class dereference_field_rvalue
: public lvalue
1706 dereference_field_rvalue (context
*ctxt
,
1710 : lvalue (ctxt
, loc
, field
->get_type ()),
1715 void replay_into (replayer
*r
) FINAL OVERRIDE
;
1717 void visit_children (rvalue_visitor
*v
) FINAL OVERRIDE
;
1720 string
* make_debug_string () FINAL OVERRIDE
;
1721 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
1722 enum precedence
get_precedence () const FINAL OVERRIDE
1724 return PRECEDENCE_POSTFIX
;
1732 class dereference_rvalue
: public lvalue
1735 dereference_rvalue (context
*ctxt
,
1738 : lvalue (ctxt
, loc
, val
->get_type ()->dereference ()),
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
1750 return PRECEDENCE_UNARY
;
1757 class get_address_of_lvalue
: public rvalue
1760 get_address_of_lvalue (context
*ctxt
,
1763 : rvalue (ctxt
, loc
, val
->get_type ()->get_pointer ()),
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_UNARY
;
1783 class function_pointer
: public rvalue
1786 function_pointer (context
*ctxt
,
1790 : rvalue (ctxt
, loc
, type
),
1793 void replay_into (replayer
*r
) FINAL OVERRIDE
;
1795 void visit_children (rvalue_visitor
*v
) FINAL OVERRIDE
;
1798 string
* make_debug_string () FINAL OVERRIDE
;
1799 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
1800 enum precedence
get_precedence () const FINAL OVERRIDE
1802 return PRECEDENCE_UNARY
;
1809 class local
: public lvalue
1812 local (function
*func
, location
*loc
, type
*type_
, string
*name
)
1813 : lvalue (func
->m_ctxt
, loc
, type_
),
1820 void replay_into (replayer
*r
) FINAL OVERRIDE
;
1822 void visit_children (rvalue_visitor
*) FINAL OVERRIDE
{}
1824 void write_to_dump (dump
&d
) FINAL OVERRIDE
;
1827 string
* make_debug_string () FINAL OVERRIDE
{ return m_name
; }
1828 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
1829 enum precedence
get_precedence () const FINAL OVERRIDE
1831 return PRECEDENCE_PRIMARY
;
1839 class statement
: public memento
1842 virtual vec
<block
*> get_successor_blocks () const;
1844 void write_to_dump (dump
&d
) FINAL OVERRIDE
;
1846 block
*get_block () const { return m_block
; }
1847 location
*get_loc () const { return m_loc
; }
1850 statement (block
*b
, location
*loc
)
1851 : memento (b
->m_ctxt
),
1855 playback::location
*
1856 playback_location (replayer
*r
) const
1858 return ::gcc::jit::recording::playback_location (r
, m_loc
);
1866 class eval
: public statement
1872 : statement (b
, loc
),
1873 m_rvalue (rvalue
) {}
1875 void replay_into (replayer
*r
) FINAL OVERRIDE
;
1878 string
* make_debug_string () FINAL OVERRIDE
;
1879 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
1885 class assignment
: public statement
1888 assignment (block
*b
,
1892 : statement (b
, loc
),
1894 m_rvalue (rvalue
) {}
1896 void replay_into (replayer
*r
) FINAL OVERRIDE
;
1899 string
* make_debug_string () FINAL OVERRIDE
;
1900 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
1907 class assignment_op
: public statement
1910 assignment_op (block
*b
,
1913 enum gcc_jit_binary_op op
,
1915 : statement (b
, loc
),
1918 m_rvalue (rvalue
) {}
1920 void replay_into (replayer
*r
) FINAL OVERRIDE
;
1923 string
* make_debug_string () FINAL OVERRIDE
;
1924 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
1928 enum gcc_jit_binary_op m_op
;
1932 class comment
: public statement
1938 : statement (b
, loc
),
1941 void replay_into (replayer
*r
) FINAL OVERRIDE
;
1944 string
* make_debug_string () FINAL OVERRIDE
;
1945 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
1951 class conditional
: public statement
1954 conditional (block
*b
,
1959 : statement (b
, loc
),
1960 m_boolval (boolval
),
1961 m_on_true (on_true
),
1962 m_on_false (on_false
) {}
1964 void replay_into (replayer
*r
) FINAL OVERRIDE
;
1966 vec
<block
*> get_successor_blocks () const FINAL OVERRIDE
;
1969 string
* make_debug_string () FINAL OVERRIDE
;
1970 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
1978 class jump
: public statement
1984 : statement (b
, loc
),
1985 m_target (target
) {}
1987 void replay_into (replayer
*r
) FINAL OVERRIDE
;
1989 vec
<block
*> get_successor_blocks () const FINAL OVERRIDE
;
1992 string
* make_debug_string () FINAL OVERRIDE
;
1993 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
1999 class return_
: public statement
2005 : statement (b
, loc
),
2006 m_rvalue (rvalue
) {}
2008 void replay_into (replayer
*r
) FINAL OVERRIDE
;
2010 vec
<block
*> get_successor_blocks () const FINAL OVERRIDE
;
2013 string
* make_debug_string () FINAL OVERRIDE
;
2014 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
2020 class case_
: public memento
2023 case_ (context
*ctxt
,
2028 m_min_value (min_value
),
2029 m_max_value (max_value
),
2030 m_dest_block (dest_block
)
2033 rvalue
*get_min_value () const { return m_min_value
; }
2034 rvalue
*get_max_value () const { return m_max_value
; }
2035 block
*get_dest_block () const { return m_dest_block
; }
2037 void replay_into (replayer
*) FINAL OVERRIDE
{ /* empty */ }
2039 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
2042 string
* make_debug_string () FINAL OVERRIDE
;
2045 rvalue
*m_min_value
;
2046 rvalue
*m_max_value
;
2047 block
*m_dest_block
;
2050 class switch_
: public statement
2056 block
*default_block
,
2060 void replay_into (replayer
*r
) FINAL OVERRIDE
;
2062 vec
<block
*> get_successor_blocks () const FINAL OVERRIDE
;
2065 string
* make_debug_string () FINAL OVERRIDE
;
2066 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
2070 block
*m_default_block
;
2071 auto_vec
<case_
*> m_cases
;
2074 } // namespace gcc::jit::recording
2076 /* Create a recording::memento_of_new_rvalue_from_const instance and add
2077 it to this context's list of mementos.
2079 Implements the post-error-checking part of
2080 gcc_jit_context_new_rvalue_from_{int|long|double|ptr}. */
2082 template <typename HOST_TYPE
>
2084 recording::context::new_rvalue_from_const (recording::type
*type
,
2087 recording::rvalue
*result
=
2088 new memento_of_new_rvalue_from_const
<HOST_TYPE
> (this, NULL
, type
, value
);
2093 } // namespace gcc::jit
2097 #endif /* JIT_RECORDING_H */