1 /* Internals of libgccjit: classes for recording calls made to the JIT API.
2 Copyright (C) 2013-2018 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"
37 /**********************************************************************
39 **********************************************************************/
44 playback_location (replayer
*r
, location
*loc
);
47 playback_string (string
*str
);
50 playback_block (block
*b
);
52 /* A recording of a call to gcc_jit_context_enable_dump. */
55 const char *m_dumpname
;
59 /* A JIT-compilation context. */
60 class context
: public log_user
63 context (context
*parent_ctxt
);
67 get_builtins_manager ();
69 void record (memento
*m
);
70 void replay_into (replayer
*r
);
71 void disassociate_from_playback ();
74 new_string (const char *text
);
77 new_location (const char *filename
,
80 bool created_by_user
);
83 get_type (enum gcc_jit_types type
);
86 get_int_type (int num_bytes
, int is_signed
);
89 new_array_type (location
*loc
,
94 new_field (location
*loc
,
99 new_struct_type (location
*loc
,
103 new_union_type (location
*loc
,
107 new_function_type (type
*return_type
,
113 new_function_ptr_type (location
*loc
,
120 new_param (location
*loc
,
125 new_function (location
*loc
,
126 enum gcc_jit_function_kind kind
,
132 enum built_in_function builtin_id
);
135 get_builtin_function (const char *name
);
138 new_global (location
*loc
,
139 enum gcc_jit_global_kind kind
,
143 template <typename HOST_TYPE
>
145 new_rvalue_from_const (type
*type
,
149 new_string_literal (const char *value
);
152 new_rvalue_from_vector (location
*loc
,
157 new_unary_op (location
*loc
,
158 enum gcc_jit_unary_op op
,
163 new_binary_op (location
*loc
,
164 enum gcc_jit_binary_op op
,
166 rvalue
*a
, rvalue
*b
);
169 new_comparison (location
*loc
,
170 enum gcc_jit_comparison op
,
171 rvalue
*a
, rvalue
*b
);
174 new_call (location
*loc
,
176 int numargs
, rvalue
**args
);
179 new_call_through_ptr (location
*loc
,
181 int numargs
, rvalue
**args
);
184 new_cast (location
*loc
,
189 new_array_access (location
*loc
,
194 new_case (rvalue
*min_value
,
199 set_str_option (enum gcc_jit_str_option opt
,
203 set_int_option (enum gcc_jit_int_option opt
,
207 set_bool_option (enum gcc_jit_bool_option opt
,
211 set_inner_bool_option (enum inner_bool_option inner_opt
,
215 add_command_line_option (const char *optname
);
218 append_command_line_options (vec
<char *> *argvec
);
221 enable_dump (const char *dumpname
,
225 get_str_option (enum gcc_jit_str_option opt
) const
227 return m_str_options
[opt
];
231 get_int_option (enum gcc_jit_int_option opt
) const
233 return m_int_options
[opt
];
237 get_bool_option (enum gcc_jit_bool_option opt
) const
239 return m_bool_options
[opt
];
243 get_inner_bool_option (enum inner_bool_option opt
) const
245 return m_inner_bool_options
[opt
];
252 compile_to_file (enum gcc_jit_output_kind output_kind
,
253 const char *output_path
);
256 add_error (location
*loc
, const char *fmt
, ...)
260 add_error_va (location
*loc
, const char *fmt
, va_list ap
)
264 get_first_error () const;
267 get_last_error () const;
269 bool errors_occurred () const
272 if (m_parent_ctxt
->errors_occurred ())
274 return m_error_count
;
277 type
*get_opaque_FILE_type ();
279 void dump_to_file (const char *path
, bool update_locations
);
281 void dump_reproducer_to_file (const char *path
);
284 get_all_requested_dumps (vec
<recording::requested_dump
> *out
);
286 void set_timer (timer
*t
) { m_timer
= t
; }
287 timer
*get_timer () const { return m_timer
; }
290 void log_all_options () const;
291 void log_str_option (enum gcc_jit_str_option opt
) const;
292 void log_int_option (enum gcc_jit_int_option opt
) const;
293 void log_bool_option (enum gcc_jit_bool_option opt
) const;
294 void log_inner_bool_option (enum inner_bool_option opt
) const;
299 context
*m_parent_ctxt
;
301 /* The ultimate ancestor of the contexts within a family tree of
302 contexts. This has itself as its own m_toplevel_ctxt. */
303 context
*m_toplevel_ctxt
;
309 char *m_first_error_str
;
310 bool m_owns_first_error_str
;
312 char *m_last_error_str
;
313 bool m_owns_last_error_str
;
315 char *m_str_options
[GCC_JIT_NUM_STR_OPTIONS
];
316 int m_int_options
[GCC_JIT_NUM_INT_OPTIONS
];
317 bool m_bool_options
[GCC_JIT_NUM_BOOL_OPTIONS
];
318 bool m_inner_bool_options
[NUM_INNER_BOOL_OPTIONS
];
319 auto_vec
<char *> m_command_line_options
;
321 /* Dumpfiles that were requested via gcc_jit_context_enable_dump. */
322 auto_vec
<requested_dump
> m_requested_dumps
;
324 /* Recorded API usage. */
325 auto_vec
<memento
*> m_mementos
;
327 /* Specific recordings, for use by dump_to_file. */
328 auto_vec
<compound_type
*> m_compound_types
;
329 auto_vec
<global
*> m_globals
;
330 auto_vec
<function
*> m_functions
;
332 type
*m_basic_types
[NUM_GCC_JIT_TYPES
];
335 builtins_manager
*m_builtins_manager
; // lazily created
339 /* An object with lifetime managed by the context i.e.
340 it lives until the context is released, at which
341 point it itself is cleaned up. */
346 virtual ~memento () {}
348 /* Hook for replaying this. */
349 virtual void replay_into (replayer
*r
) = 0;
351 void set_playback_obj (void *obj
) { m_playback_obj
= obj
; }
354 /* Get the context that owns this object.
356 Implements the post-error-checking part of
357 gcc_jit_object_get_context. */
358 context
*get_context () { return m_ctxt
; }
361 as_object () { return this; }
363 /* Debugging hook, for use in generating error messages etc.
364 Implements the post-error-checking part of
365 gcc_jit_object_get_debug_string. */
369 virtual void write_to_dump (dump
&d
);
370 virtual void write_reproducer (reproducer
&r
) = 0;
371 virtual location
*dyn_cast_location () { return NULL
; }
374 memento (context
*ctxt
)
376 m_playback_obj (NULL
),
377 m_debug_string (NULL
)
382 string
*new_string (const char *text
) { return m_ctxt
->new_string (text
); }
385 virtual string
* make_debug_string () = 0;
391 void *m_playback_obj
;
394 string
*m_debug_string
;
397 /* or just use std::string? */
398 class string
: public memento
401 string (context
*ctxt
, const char *text
);
404 const char *c_str () { return m_buffer
; }
406 static string
* from_printf (context
*ctxt
, const char *fmt
, ...)
409 void replay_into (replayer
*) FINAL OVERRIDE
{}
412 string
* make_debug_string () FINAL OVERRIDE
;
413 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
420 class location
: public memento
423 location (context
*ctxt
, string
*filename
, int line
, int column
,
424 bool created_by_user
)
426 m_filename (filename
),
429 m_created_by_user (created_by_user
)
432 void replay_into (replayer
*r
) FINAL OVERRIDE
;
435 playback_location (replayer
*r
)
437 /* Normally during playback, we can walk forwards through the list of
438 recording objects, playing them back. The ordering of recording
439 ensures that everything that a recording object refers to has
440 already been played back, so we can simply look up the relevant
443 Locations are an exception, due to the "write_to_dump" method of
444 recording::statement. This method can set a new location on a
445 statement after the statement is created, and thus the location
446 appears in the context's memento list *after* the statement that
449 In such circumstances, the statement is replayed *before* the location,
450 when the latter doesn't yet have a playback object.
452 Hence we need to ensure that locations have playback objects. */
457 gcc_assert (m_playback_obj
);
458 return static_cast <playback::location
*> (m_playback_obj
);
461 location
*dyn_cast_location () FINAL OVERRIDE
{ return this; }
462 bool created_by_user () const { return m_created_by_user
; }
465 string
* make_debug_string () FINAL OVERRIDE
;
466 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
472 bool m_created_by_user
;
475 class type
: public memento
478 type
*get_pointer ();
480 type
*get_volatile ();
481 type
*get_aligned (size_t alignment_in_bytes
);
482 type
*get_vector (size_t num_units
);
484 /* Get the type obtained when dereferencing this type.
486 This will return NULL if it's not valid to dereference this type.
487 The caller is responsible for setting an error. */
488 virtual type
*dereference () = 0;
491 virtual function_type
*dyn_cast_function_type () { return NULL
; }
492 virtual function_type
*as_a_function_type() { gcc_unreachable (); return NULL
; }
493 virtual struct_
*dyn_cast_struct () { return NULL
; }
494 virtual vector_type
*dyn_cast_vector_type () { return NULL
; }
496 /* Is it typesafe to copy to this type from rtype? */
497 virtual bool accepts_writes_from (type
*rtype
)
500 return this->unqualified ()->is_same_type_as (rtype
->unqualified ());
503 virtual bool is_same_type_as (type
*other
)
505 return this == other
;
508 /* Strip off "const" etc */
509 virtual type
*unqualified ()
514 virtual bool is_int () const = 0;
515 virtual bool is_float () const = 0;
516 virtual bool is_bool () const = 0;
517 virtual type
*is_pointer () = 0;
518 virtual type
*is_array () = 0;
519 virtual bool is_void () const { return false; }
520 virtual bool has_known_size () const { return true; }
522 bool is_numeric () const
524 return is_int () || is_float () || is_bool ();
530 return static_cast <playback::type
*> (m_playback_obj
);
533 virtual const char *access_as_type (reproducer
&r
);
538 m_pointer_to_this_type (NULL
)
542 type
*m_pointer_to_this_type
;
545 /* Result of "gcc_jit_context_get_type". */
546 class memento_of_get_type
: public type
549 memento_of_get_type (context
*ctxt
,
550 enum gcc_jit_types kind
)
554 type
*dereference () FINAL OVERRIDE
;
556 bool accepts_writes_from (type
*rtype
) FINAL OVERRIDE
558 if (m_kind
== GCC_JIT_TYPE_VOID_PTR
)
559 if (rtype
->is_pointer ())
561 /* LHS (this) is type (void *), and the RHS is a pointer:
566 return type::accepts_writes_from (rtype
);
569 bool is_int () const FINAL OVERRIDE
;
570 bool is_float () const FINAL OVERRIDE
;
571 bool is_bool () const FINAL OVERRIDE
;
572 type
*is_pointer () FINAL OVERRIDE
{ return dereference (); }
573 type
*is_array () FINAL OVERRIDE
{ return NULL
; }
574 bool is_void () const FINAL OVERRIDE
{ return m_kind
== GCC_JIT_TYPE_VOID
; }
577 void replay_into (replayer
*r
) FINAL OVERRIDE
;
580 string
* make_debug_string () FINAL OVERRIDE
;
581 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
584 enum gcc_jit_types m_kind
;
587 /* Result of "gcc_jit_type_get_pointer". */
588 class memento_of_get_pointer
: public type
591 memento_of_get_pointer (type
*other_type
)
592 : type (other_type
->m_ctxt
),
593 m_other_type (other_type
) {}
595 type
*dereference () FINAL OVERRIDE
{ return m_other_type
; }
597 bool accepts_writes_from (type
*rtype
) FINAL OVERRIDE
;
599 void replay_into (replayer
*r
) FINAL OVERRIDE
;
601 bool is_int () const FINAL OVERRIDE
{ return false; }
602 bool is_float () const FINAL OVERRIDE
{ return false; }
603 bool is_bool () const FINAL OVERRIDE
{ return false; }
604 type
*is_pointer () FINAL OVERRIDE
{ return m_other_type
; }
605 type
*is_array () FINAL OVERRIDE
{ return NULL
; }
608 string
* make_debug_string () FINAL OVERRIDE
;
609 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
615 /* A decorated version of a type, for get_const, get_volatile,
616 get_aligned, and get_vector. */
618 class decorated_type
: public type
621 decorated_type (type
*other_type
)
622 : type (other_type
->m_ctxt
),
623 m_other_type (other_type
) {}
625 type
*dereference () FINAL OVERRIDE
{ return m_other_type
->dereference (); }
627 bool is_int () const FINAL OVERRIDE
{ return m_other_type
->is_int (); }
628 bool is_float () const FINAL OVERRIDE
{ return m_other_type
->is_float (); }
629 bool is_bool () const FINAL OVERRIDE
{ return m_other_type
->is_bool (); }
630 type
*is_pointer () FINAL OVERRIDE
{ return m_other_type
->is_pointer (); }
631 type
*is_array () FINAL OVERRIDE
{ return m_other_type
->is_array (); }
637 /* Result of "gcc_jit_type_get_const". */
638 class memento_of_get_const
: public decorated_type
641 memento_of_get_const (type
*other_type
)
642 : decorated_type (other_type
) {}
644 bool accepts_writes_from (type */
*rtype*/
) FINAL OVERRIDE
646 /* Can't write to a "const". */
650 /* Strip off the "const", giving the underlying type. */
651 type
*unqualified () FINAL OVERRIDE
{ return m_other_type
; }
653 void replay_into (replayer
*) FINAL OVERRIDE
;
656 string
* make_debug_string () FINAL OVERRIDE
;
657 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
660 /* Result of "gcc_jit_type_get_volatile". */
661 class memento_of_get_volatile
: public decorated_type
664 memento_of_get_volatile (type
*other_type
)
665 : decorated_type (other_type
) {}
667 /* Strip off the "volatile", giving the underlying type. */
668 type
*unqualified () FINAL OVERRIDE
{ return m_other_type
; }
670 void replay_into (replayer
*) FINAL OVERRIDE
;
673 string
* make_debug_string () FINAL OVERRIDE
;
674 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
677 /* Result of "gcc_jit_type_get_aligned". */
678 class memento_of_get_aligned
: public decorated_type
681 memento_of_get_aligned (type
*other_type
, size_t alignment_in_bytes
)
682 : decorated_type (other_type
),
683 m_alignment_in_bytes (alignment_in_bytes
) {}
685 /* Strip off the alignment, giving the underlying type. */
686 type
*unqualified () FINAL OVERRIDE
{ return m_other_type
; }
688 void replay_into (replayer
*) FINAL OVERRIDE
;
691 string
* make_debug_string () FINAL OVERRIDE
;
692 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
695 size_t m_alignment_in_bytes
;
698 /* Result of "gcc_jit_type_get_vector". */
699 class vector_type
: public decorated_type
702 vector_type (type
*other_type
, size_t num_units
)
703 : decorated_type (other_type
),
704 m_num_units (num_units
) {}
706 size_t get_num_units () const { return m_num_units
; }
708 vector_type
*dyn_cast_vector_type () FINAL OVERRIDE
{ return this; }
710 type
*get_element_type () { return m_other_type
; }
712 void replay_into (replayer
*) FINAL OVERRIDE
;
715 string
* make_debug_string () FINAL OVERRIDE
;
716 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
722 class array_type
: public type
725 array_type (context
*ctxt
,
731 m_element_type (element_type
),
732 m_num_elements (num_elements
)
735 type
*dereference () FINAL OVERRIDE
;
737 bool is_int () const FINAL OVERRIDE
{ return false; }
738 bool is_float () const FINAL OVERRIDE
{ return false; }
739 bool is_bool () const FINAL OVERRIDE
{ return false; }
740 type
*is_pointer () FINAL OVERRIDE
{ return NULL
; }
741 type
*is_array () FINAL OVERRIDE
{ return m_element_type
; }
743 void replay_into (replayer
*) FINAL OVERRIDE
;
746 string
* make_debug_string () FINAL OVERRIDE
;
747 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
751 type
*m_element_type
;
755 class function_type
: public type
758 function_type (context
*ctxt
,
764 type
*dereference () FINAL OVERRIDE
;
765 function_type
*dyn_cast_function_type () FINAL OVERRIDE
{ return this; }
766 function_type
*as_a_function_type () FINAL OVERRIDE
{ return this; }
768 bool is_same_type_as (type
*other
) FINAL OVERRIDE
;
770 bool is_int () const FINAL OVERRIDE
{ return false; }
771 bool is_float () const FINAL OVERRIDE
{ return false; }
772 bool is_bool () const FINAL OVERRIDE
{ return false; }
773 type
*is_pointer () FINAL OVERRIDE
{ return NULL
; }
774 type
*is_array () FINAL OVERRIDE
{ return NULL
; }
776 void replay_into (replayer
*) FINAL OVERRIDE
;
778 type
* get_return_type () const { return m_return_type
; }
779 const vec
<type
*> &get_param_types () const { return m_param_types
; }
780 int is_variadic () const { return m_is_variadic
; }
782 string
* make_debug_string_with_ptr ();
785 write_deferred_reproducer (reproducer
&r
,
789 string
* make_debug_string () FINAL OVERRIDE
;
790 string
* make_debug_string_with (const char *);
791 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
795 auto_vec
<type
*> m_param_types
;
799 class field
: public memento
802 field (context
*ctxt
,
813 type
* get_type () const { return m_type
; }
815 compound_type
* get_container () const { return m_container
; }
816 void set_container (compound_type
*c
) { m_container
= c
; }
818 void replay_into (replayer
*) FINAL OVERRIDE
;
820 void write_to_dump (dump
&d
) FINAL OVERRIDE
;
823 playback_field () const
825 return static_cast <playback::field
*> (m_playback_obj
);
829 string
* make_debug_string () FINAL OVERRIDE
;
830 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
836 compound_type
*m_container
;
839 /* Base class for struct_ and union_ */
840 class compound_type
: public type
843 compound_type (context
*ctxt
,
847 string
*get_name () const { return m_name
; }
848 location
*get_loc () const { return m_loc
; }
849 fields
* get_fields () { return m_fields
; }
852 set_fields (location
*loc
,
856 type
*dereference () FINAL OVERRIDE
;
858 bool is_int () const FINAL OVERRIDE
{ return false; }
859 bool is_float () const FINAL OVERRIDE
{ return false; }
860 bool is_bool () const FINAL OVERRIDE
{ return false; }
861 type
*is_pointer () FINAL OVERRIDE
{ return NULL
; }
862 type
*is_array () FINAL OVERRIDE
{ return NULL
; }
864 bool has_known_size () const FINAL OVERRIDE
{ return m_fields
!= NULL
; }
866 playback::compound_type
*
867 playback_compound_type ()
869 return static_cast <playback::compound_type
*> (m_playback_obj
);
878 class struct_
: public compound_type
881 struct_ (context
*ctxt
,
885 struct_
*dyn_cast_struct () FINAL OVERRIDE
{ return this; }
888 as_type () { return this; }
890 void replay_into (replayer
*r
) FINAL OVERRIDE
;
892 const char *access_as_type (reproducer
&r
) FINAL OVERRIDE
;
895 string
* make_debug_string () FINAL OVERRIDE
;
896 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
899 // memento of struct_::set_fields
900 class fields
: public memento
903 fields (compound_type
*struct_or_union
,
907 void replay_into (replayer
*r
) FINAL OVERRIDE
;
909 void write_to_dump (dump
&d
) FINAL OVERRIDE
;
911 int length () const { return m_fields
.length (); }
912 field
*get_field (int i
) const { return m_fields
[i
]; }
915 string
* make_debug_string () FINAL OVERRIDE
;
916 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
919 compound_type
*m_struct_or_union
;
920 auto_vec
<field
*> m_fields
;
923 class union_
: public compound_type
926 union_ (context
*ctxt
,
930 void replay_into (replayer
*r
) FINAL OVERRIDE
;
933 string
* make_debug_string () FINAL OVERRIDE
;
934 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
937 /* An abstract base class for operations that visit all rvalues within an
939 Currently the only implementation is class rvalue_usage_validator within
945 virtual ~rvalue_visitor () {}
946 virtual void visit (rvalue
*rvalue
) = 0;
949 /* When generating debug strings for rvalues we mimic C, so we need to
950 mimic C's precedence levels when handling compound expressions.
951 These are in order from strongest precedence to weakest. */
958 PRECEDENCE_MULTIPLICATIVE
,
961 PRECEDENCE_RELATIONAL
,
963 PRECEDENCE_BITWISE_AND
,
964 PRECEDENCE_BITWISE_XOR
,
965 PRECEDENCE_BITWISE_IOR
,
966 PRECEDENCE_LOGICAL_AND
,
967 PRECEDENCE_LOGICAL_OR
970 class rvalue
: public memento
973 rvalue (context
*ctxt
,
980 m_parenthesized_string (NULL
)
985 location
* get_loc () const { return m_loc
; }
987 /* Get the recording::type of this rvalue.
989 Implements the post-error-checking part of
990 gcc_jit_rvalue_get_type. */
991 type
* get_type () const { return m_type
; }
994 playback_rvalue () const
996 return static_cast <playback::rvalue
*> (m_playback_obj
);
999 access_field (location
*loc
,
1003 dereference_field (location
*loc
,
1007 dereference (location
*loc
);
1010 verify_valid_within_stmt (const char *api_funcname
, statement
*s
);
1012 virtual void visit_children (rvalue_visitor
*v
) = 0;
1014 void set_scope (function
*scope
);
1015 function
*get_scope () const { return m_scope
; }
1017 /* Dynamic casts. */
1018 virtual param
*dyn_cast_param () { return NULL
; }
1019 virtual base_call
*dyn_cast_base_call () { return NULL
; }
1021 virtual const char *access_as_rvalue (reproducer
&r
);
1023 /* Get the debug string, wrapped in parentheses. */
1025 get_debug_string_parens (enum precedence outer_prec
);
1027 virtual bool is_constant () const { return false; }
1028 virtual bool get_wide_int (wide_int
*) const { return false; }
1031 virtual enum precedence
get_precedence () const = 0;
1038 function
*m_scope
; /* NULL for globals, non-NULL for locals/params */
1039 string
*m_parenthesized_string
;
1042 class lvalue
: public rvalue
1045 lvalue (context
*ctxt
,
1048 : rvalue (ctxt
, loc
, type_
)
1052 playback_lvalue () const
1054 return static_cast <playback::lvalue
*> (m_playback_obj
);
1058 access_field (location
*loc
,
1062 get_address (location
*loc
);
1065 as_rvalue () { return this; }
1067 const char *access_as_rvalue (reproducer
&r
) OVERRIDE
;
1068 virtual const char *access_as_lvalue (reproducer
&r
);
1071 class param
: public lvalue
1074 param (context
*ctxt
,
1078 : lvalue (ctxt
, loc
, type
),
1082 as_lvalue () { return this; }
1084 void replay_into (replayer
*r
) FINAL OVERRIDE
;
1086 void visit_children (rvalue_visitor
*) FINAL OVERRIDE
{}
1089 playback_param () const
1091 return static_cast <playback::param
*> (m_playback_obj
);
1094 param
*dyn_cast_param () FINAL OVERRIDE
{ return this; }
1096 const char *access_as_rvalue (reproducer
&r
) FINAL OVERRIDE
;
1097 const char *access_as_lvalue (reproducer
&r
) FINAL OVERRIDE
;
1100 string
* make_debug_string () FINAL OVERRIDE
{ return m_name
; }
1101 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
1102 enum precedence
get_precedence () const FINAL OVERRIDE
1104 return PRECEDENCE_PRIMARY
;
1111 class function
: public memento
1114 function (context
*ctxt
,
1116 enum gcc_jit_function_kind kind
,
1122 enum built_in_function builtin_id
);
1124 void replay_into (replayer
*r
) FINAL OVERRIDE
;
1126 playback::function
*
1127 playback_function () const
1129 return static_cast <playback::function
*> (m_playback_obj
);
1132 enum gcc_jit_function_kind
get_kind () const { return m_kind
; }
1135 new_local (location
*loc
,
1140 new_block (const char *name
);
1142 location
*get_loc () const { return m_loc
; }
1143 type
*get_return_type () const { return m_return_type
; }
1144 string
* get_name () const { return m_name
; }
1145 const vec
<param
*> &get_params () const { return m_params
; }
1147 /* Get the given param by index.
1148 Implements the post-error-checking part of
1149 gcc_jit_function_get_param. */
1150 param
*get_param (int i
) const { return m_params
[i
]; }
1152 bool is_variadic () const { return m_is_variadic
; }
1154 void write_to_dump (dump
&d
) FINAL OVERRIDE
;
1158 void dump_to_dot (const char *path
);
1160 rvalue
*get_address (location
*loc
);
1163 string
* make_debug_string () FINAL OVERRIDE
;
1164 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
1168 enum gcc_jit_function_kind m_kind
;
1169 type
*m_return_type
;
1171 auto_vec
<param
*> m_params
;
1173 enum built_in_function m_builtin_id
;
1174 auto_vec
<local
*> m_locals
;
1175 auto_vec
<block
*> m_blocks
;
1176 type
*m_fn_ptr_type
;
1179 class block
: public memento
1182 block (function
*func
, int index
, string
*name
)
1183 : memento (func
->m_ctxt
),
1188 m_has_been_terminated (false),
1189 m_is_reachable (false)
1193 /* Get the recording::function containing this block.
1194 Implements the post-error-checking part of
1195 gcc_jit_block_get_function. */
1196 function
*get_function () { return m_func
; }
1198 bool has_been_terminated () { return m_has_been_terminated
; }
1199 bool is_reachable () { return m_is_reachable
; }
1202 add_eval (location
*loc
,
1206 add_assignment (location
*loc
,
1211 add_assignment_op (location
*loc
,
1213 enum gcc_jit_binary_op op
,
1217 add_comment (location
*loc
,
1221 end_with_conditional (location
*loc
,
1227 end_with_jump (location
*loc
,
1231 end_with_return (location
*loc
,
1235 end_with_switch (location
*loc
,
1237 block
*default_block
,
1242 playback_block () const
1244 return static_cast <playback::block
*> (m_playback_obj
);
1247 void write_to_dump (dump
&d
) FINAL OVERRIDE
;
1251 location
*get_loc () const;
1253 statement
*get_first_statement () const;
1254 statement
*get_last_statement () const;
1256 vec
<block
*> get_successor_blocks () const;
1259 string
* make_debug_string () FINAL OVERRIDE
;
1260 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
1262 void replay_into (replayer
*r
) FINAL OVERRIDE
;
1264 void dump_to_dot (pretty_printer
*pp
);
1265 void dump_edges_to_dot (pretty_printer
*pp
);
1271 auto_vec
<statement
*> m_statements
;
1272 bool m_has_been_terminated
;
1273 bool m_is_reachable
;
1275 friend class function
;
1278 class global
: public lvalue
1281 global (context
*ctxt
,
1283 enum gcc_jit_global_kind kind
,
1286 : lvalue (ctxt
, loc
, type
),
1291 void replay_into (replayer
*) FINAL OVERRIDE
;
1293 void visit_children (rvalue_visitor
*) FINAL OVERRIDE
{}
1295 void write_to_dump (dump
&d
) FINAL OVERRIDE
;
1298 string
* make_debug_string () FINAL OVERRIDE
{ return m_name
; }
1299 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
1300 enum precedence
get_precedence () const FINAL OVERRIDE
1302 return PRECEDENCE_PRIMARY
;
1306 enum gcc_jit_global_kind m_kind
;
1310 template <typename HOST_TYPE
>
1311 class memento_of_new_rvalue_from_const
: public rvalue
1314 memento_of_new_rvalue_from_const (context
*ctxt
,
1318 : rvalue (ctxt
, loc
, type
),
1321 void replay_into (replayer
*r
) FINAL OVERRIDE
;
1323 void visit_children (rvalue_visitor
*) FINAL OVERRIDE
{}
1325 bool is_constant () const FINAL OVERRIDE
{ return true; }
1327 bool get_wide_int (wide_int
*out
) const FINAL OVERRIDE
;
1330 string
* make_debug_string () FINAL OVERRIDE
;
1331 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
1332 enum precedence
get_precedence () const FINAL OVERRIDE
1334 return PRECEDENCE_PRIMARY
;
1341 class memento_of_new_string_literal
: public rvalue
1344 memento_of_new_string_literal (context
*ctxt
,
1347 : rvalue (ctxt
, loc
, ctxt
->get_type (GCC_JIT_TYPE_CONST_CHAR_PTR
)),
1350 void replay_into (replayer
*r
) FINAL OVERRIDE
;
1352 void visit_children (rvalue_visitor
*) FINAL OVERRIDE
{}
1355 string
* make_debug_string () FINAL OVERRIDE
;
1356 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
1357 enum precedence
get_precedence () const FINAL OVERRIDE
1359 return PRECEDENCE_PRIMARY
;
1366 class memento_of_new_rvalue_from_vector
: public rvalue
1369 memento_of_new_rvalue_from_vector (context
*ctxt
,
1374 void replay_into (replayer
*r
) FINAL OVERRIDE
;
1376 void visit_children (rvalue_visitor
*) FINAL OVERRIDE
;
1379 string
* make_debug_string () FINAL OVERRIDE
;
1380 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
1381 enum precedence
get_precedence () const FINAL OVERRIDE
1383 return PRECEDENCE_PRIMARY
;
1387 vector_type
*m_vector_type
;
1388 auto_vec
<rvalue
*> m_elements
;
1391 class unary_op
: public rvalue
1394 unary_op (context
*ctxt
,
1396 enum gcc_jit_unary_op op
,
1399 : rvalue (ctxt
, loc
, result_type
),
1404 void replay_into (replayer
*r
) FINAL OVERRIDE
;
1406 void visit_children (rvalue_visitor
*v
) FINAL OVERRIDE
;
1409 string
* make_debug_string () FINAL OVERRIDE
;
1410 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
1411 enum precedence
get_precedence () const FINAL OVERRIDE
1413 return PRECEDENCE_UNARY
;
1417 enum gcc_jit_unary_op m_op
;
1421 class binary_op
: public rvalue
1424 binary_op (context
*ctxt
,
1426 enum gcc_jit_binary_op op
,
1428 rvalue
*a
, rvalue
*b
)
1429 : rvalue (ctxt
, loc
, result_type
),
1434 void replay_into (replayer
*r
) FINAL OVERRIDE
;
1436 void visit_children (rvalue_visitor
*v
) FINAL OVERRIDE
;
1439 string
* make_debug_string () FINAL OVERRIDE
;
1440 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
1441 enum precedence
get_precedence () const FINAL OVERRIDE
;
1444 enum gcc_jit_binary_op m_op
;
1449 class comparison
: public rvalue
1452 comparison (context
*ctxt
,
1454 enum gcc_jit_comparison op
,
1455 rvalue
*a
, rvalue
*b
)
1456 : rvalue (ctxt
, loc
, ctxt
->get_type (GCC_JIT_TYPE_BOOL
)),
1462 void replay_into (replayer
*r
) FINAL OVERRIDE
;
1464 void visit_children (rvalue_visitor
*v
) FINAL OVERRIDE
;
1467 string
* make_debug_string () FINAL OVERRIDE
;
1468 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
1469 enum precedence
get_precedence () const FINAL OVERRIDE
;
1472 enum gcc_jit_comparison m_op
;
1477 class cast
: public rvalue
1480 cast (context
*ctxt
,
1484 : rvalue (ctxt
, loc
, type_
),
1488 void replay_into (replayer
*r
) FINAL OVERRIDE
;
1490 void visit_children (rvalue_visitor
*v
) FINAL OVERRIDE
;
1493 string
* make_debug_string () FINAL OVERRIDE
;
1494 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
1495 enum precedence
get_precedence () const FINAL OVERRIDE
1497 return PRECEDENCE_CAST
;
1504 class base_call
: public rvalue
1507 base_call (context
*ctxt
,
1513 enum precedence
get_precedence () const FINAL OVERRIDE
1515 return PRECEDENCE_POSTFIX
;
1518 base_call
*dyn_cast_base_call () FINAL OVERRIDE
{ return this; }
1520 void set_require_tail_call (bool require_tail_call
)
1522 m_require_tail_call
= require_tail_call
;
1526 void write_reproducer_tail_call (reproducer
&r
, const char *id
);
1529 auto_vec
<rvalue
*> m_args
;
1530 bool m_require_tail_call
;
1533 class call
: public base_call
1536 call (context
*ctxt
,
1542 void replay_into (replayer
*r
) FINAL OVERRIDE
;
1544 void visit_children (rvalue_visitor
*v
) FINAL OVERRIDE
;
1547 string
* make_debug_string () FINAL OVERRIDE
;
1548 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
1554 class call_through_ptr
: public base_call
1557 call_through_ptr (context
*ctxt
,
1563 void replay_into (replayer
*r
) FINAL OVERRIDE
;
1565 void visit_children (rvalue_visitor
*v
) FINAL OVERRIDE
;
1568 string
* make_debug_string () FINAL OVERRIDE
;
1569 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
1575 class array_access
: public lvalue
1578 array_access (context
*ctxt
,
1582 : lvalue (ctxt
, loc
, ptr
->get_type ()->dereference ()),
1587 void replay_into (replayer
*r
) FINAL OVERRIDE
;
1589 void visit_children (rvalue_visitor
*v
) 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_POSTFIX
;
1604 class access_field_of_lvalue
: public lvalue
1607 access_field_of_lvalue (context
*ctxt
,
1611 : lvalue (ctxt
, loc
, field
->get_type ()),
1616 void replay_into (replayer
*r
) FINAL OVERRIDE
;
1618 void visit_children (rvalue_visitor
*v
) FINAL OVERRIDE
;
1621 string
* make_debug_string () FINAL OVERRIDE
;
1622 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
1623 enum precedence
get_precedence () const FINAL OVERRIDE
1625 return PRECEDENCE_POSTFIX
;
1633 class access_field_rvalue
: public rvalue
1636 access_field_rvalue (context
*ctxt
,
1640 : rvalue (ctxt
, loc
, field
->get_type ()),
1645 void replay_into (replayer
*r
) FINAL OVERRIDE
;
1647 void visit_children (rvalue_visitor
*v
) FINAL OVERRIDE
;
1650 string
* make_debug_string () FINAL OVERRIDE
;
1651 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
1652 enum precedence
get_precedence () const FINAL OVERRIDE
1654 return PRECEDENCE_POSTFIX
;
1662 class dereference_field_rvalue
: public lvalue
1665 dereference_field_rvalue (context
*ctxt
,
1669 : lvalue (ctxt
, loc
, field
->get_type ()),
1674 void replay_into (replayer
*r
) FINAL OVERRIDE
;
1676 void visit_children (rvalue_visitor
*v
) FINAL OVERRIDE
;
1679 string
* make_debug_string () FINAL OVERRIDE
;
1680 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
1681 enum precedence
get_precedence () const FINAL OVERRIDE
1683 return PRECEDENCE_POSTFIX
;
1691 class dereference_rvalue
: public lvalue
1694 dereference_rvalue (context
*ctxt
,
1697 : lvalue (ctxt
, loc
, val
->get_type ()->dereference ()),
1700 void replay_into (replayer
*r
) FINAL OVERRIDE
;
1702 void visit_children (rvalue_visitor
*v
) FINAL OVERRIDE
;
1705 string
* make_debug_string () FINAL OVERRIDE
;
1706 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
1707 enum precedence
get_precedence () const FINAL OVERRIDE
1709 return PRECEDENCE_UNARY
;
1716 class get_address_of_lvalue
: public rvalue
1719 get_address_of_lvalue (context
*ctxt
,
1722 : rvalue (ctxt
, loc
, val
->get_type ()->get_pointer ()),
1726 void replay_into (replayer
*r
) FINAL OVERRIDE
;
1728 void visit_children (rvalue_visitor
*v
) FINAL OVERRIDE
;
1731 string
* make_debug_string () FINAL OVERRIDE
;
1732 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
1733 enum precedence
get_precedence () const FINAL OVERRIDE
1735 return PRECEDENCE_UNARY
;
1742 class function_pointer
: public rvalue
1745 function_pointer (context
*ctxt
,
1749 : rvalue (ctxt
, loc
, type
),
1752 void replay_into (replayer
*r
) FINAL OVERRIDE
;
1754 void visit_children (rvalue_visitor
*v
) FINAL OVERRIDE
;
1757 string
* make_debug_string () FINAL OVERRIDE
;
1758 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
1759 enum precedence
get_precedence () const FINAL OVERRIDE
1761 return PRECEDENCE_UNARY
;
1768 class local
: public lvalue
1771 local (function
*func
, location
*loc
, type
*type_
, string
*name
)
1772 : lvalue (func
->m_ctxt
, loc
, type_
),
1779 void replay_into (replayer
*r
) FINAL OVERRIDE
;
1781 void visit_children (rvalue_visitor
*) FINAL OVERRIDE
{}
1783 void write_to_dump (dump
&d
) FINAL OVERRIDE
;
1786 string
* make_debug_string () FINAL OVERRIDE
{ return m_name
; }
1787 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
1788 enum precedence
get_precedence () const FINAL OVERRIDE
1790 return PRECEDENCE_PRIMARY
;
1798 class statement
: public memento
1801 virtual vec
<block
*> get_successor_blocks () const;
1803 void write_to_dump (dump
&d
) FINAL OVERRIDE
;
1805 block
*get_block () const { return m_block
; }
1806 location
*get_loc () const { return m_loc
; }
1809 statement (block
*b
, location
*loc
)
1810 : memento (b
->m_ctxt
),
1814 playback::location
*
1815 playback_location (replayer
*r
) const
1817 return ::gcc::jit::recording::playback_location (r
, m_loc
);
1825 class eval
: public statement
1831 : statement (b
, loc
),
1832 m_rvalue (rvalue
) {}
1834 void replay_into (replayer
*r
) FINAL OVERRIDE
;
1837 string
* make_debug_string () FINAL OVERRIDE
;
1838 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
1844 class assignment
: public statement
1847 assignment (block
*b
,
1851 : statement (b
, loc
),
1853 m_rvalue (rvalue
) {}
1855 void replay_into (replayer
*r
) FINAL OVERRIDE
;
1858 string
* make_debug_string () FINAL OVERRIDE
;
1859 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
1866 class assignment_op
: public statement
1869 assignment_op (block
*b
,
1872 enum gcc_jit_binary_op op
,
1874 : statement (b
, loc
),
1877 m_rvalue (rvalue
) {}
1879 void replay_into (replayer
*r
) FINAL OVERRIDE
;
1882 string
* make_debug_string () FINAL OVERRIDE
;
1883 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
1887 enum gcc_jit_binary_op m_op
;
1891 class comment
: public statement
1897 : statement (b
, loc
),
1900 void replay_into (replayer
*r
) FINAL OVERRIDE
;
1903 string
* make_debug_string () FINAL OVERRIDE
;
1904 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
1910 class conditional
: public statement
1913 conditional (block
*b
,
1918 : statement (b
, loc
),
1919 m_boolval (boolval
),
1920 m_on_true (on_true
),
1921 m_on_false (on_false
) {}
1923 void replay_into (replayer
*r
) FINAL OVERRIDE
;
1925 vec
<block
*> get_successor_blocks () const FINAL OVERRIDE
;
1928 string
* make_debug_string () FINAL OVERRIDE
;
1929 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
1937 class jump
: public statement
1943 : statement (b
, loc
),
1944 m_target (target
) {}
1946 void replay_into (replayer
*r
) FINAL OVERRIDE
;
1948 vec
<block
*> get_successor_blocks () const FINAL OVERRIDE
;
1951 string
* make_debug_string () FINAL OVERRIDE
;
1952 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
1958 class return_
: public statement
1964 : statement (b
, loc
),
1965 m_rvalue (rvalue
) {}
1967 void replay_into (replayer
*r
) FINAL OVERRIDE
;
1969 vec
<block
*> get_successor_blocks () const FINAL OVERRIDE
;
1972 string
* make_debug_string () FINAL OVERRIDE
;
1973 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
1979 class case_
: public memento
1982 case_ (context
*ctxt
,
1987 m_min_value (min_value
),
1988 m_max_value (max_value
),
1989 m_dest_block (dest_block
)
1992 rvalue
*get_min_value () const { return m_min_value
; }
1993 rvalue
*get_max_value () const { return m_max_value
; }
1994 block
*get_dest_block () const { return m_dest_block
; }
1996 void replay_into (replayer
*) FINAL OVERRIDE
{ /* empty */ }
1998 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
2001 string
* make_debug_string () FINAL OVERRIDE
;
2004 rvalue
*m_min_value
;
2005 rvalue
*m_max_value
;
2006 block
*m_dest_block
;
2009 class switch_
: public statement
2015 block
*default_block
,
2019 void replay_into (replayer
*r
) FINAL OVERRIDE
;
2021 vec
<block
*> get_successor_blocks () const FINAL OVERRIDE
;
2024 string
* make_debug_string () FINAL OVERRIDE
;
2025 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
2029 block
*m_default_block
;
2030 auto_vec
<case_
*> m_cases
;
2033 } // namespace gcc::jit::recording
2035 /* Create a recording::memento_of_new_rvalue_from_const instance and add
2036 it to this context's list of mementos.
2038 Implements the post-error-checking part of
2039 gcc_jit_context_new_rvalue_from_{int|long|double|ptr}. */
2041 template <typename HOST_TYPE
>
2043 recording::context::new_rvalue_from_const (recording::type
*type
,
2046 recording::rvalue
*result
=
2047 new memento_of_new_rvalue_from_const
<HOST_TYPE
> (this, NULL
, type
, value
);
2052 } // namespace gcc::jit
2056 #endif /* JIT_RECORDING_H */