1 /* Internals of libgccjit: classes for recording calls made to the JIT API.
2 Copyright (C) 2013-2017 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_unary_op (location
*loc
,
153 enum gcc_jit_unary_op op
,
158 new_binary_op (location
*loc
,
159 enum gcc_jit_binary_op op
,
161 rvalue
*a
, rvalue
*b
);
164 new_comparison (location
*loc
,
165 enum gcc_jit_comparison op
,
166 rvalue
*a
, rvalue
*b
);
169 new_call (location
*loc
,
171 int numargs
, rvalue
**args
);
174 new_call_through_ptr (location
*loc
,
176 int numargs
, rvalue
**args
);
179 new_cast (location
*loc
,
184 new_array_access (location
*loc
,
189 new_case (rvalue
*min_value
,
194 set_str_option (enum gcc_jit_str_option opt
,
198 set_int_option (enum gcc_jit_int_option opt
,
202 set_bool_option (enum gcc_jit_bool_option opt
,
206 set_inner_bool_option (enum inner_bool_option inner_opt
,
210 add_command_line_option (const char *optname
);
213 append_command_line_options (vec
<char *> *argvec
);
216 enable_dump (const char *dumpname
,
220 get_str_option (enum gcc_jit_str_option opt
) const
222 return m_str_options
[opt
];
226 get_int_option (enum gcc_jit_int_option opt
) const
228 return m_int_options
[opt
];
232 get_bool_option (enum gcc_jit_bool_option opt
) const
234 return m_bool_options
[opt
];
238 get_inner_bool_option (enum inner_bool_option opt
) const
240 return m_inner_bool_options
[opt
];
247 compile_to_file (enum gcc_jit_output_kind output_kind
,
248 const char *output_path
);
251 add_error (location
*loc
, const char *fmt
, ...)
255 add_error_va (location
*loc
, const char *fmt
, va_list ap
)
259 get_first_error () const;
262 get_last_error () const;
264 bool errors_occurred () const
267 if (m_parent_ctxt
->errors_occurred ())
269 return m_error_count
;
272 type
*get_opaque_FILE_type ();
274 void dump_to_file (const char *path
, bool update_locations
);
276 void dump_reproducer_to_file (const char *path
);
279 get_all_requested_dumps (vec
<recording::requested_dump
> *out
);
281 void set_timer (timer
*t
) { m_timer
= t
; }
282 timer
*get_timer () const { return m_timer
; }
285 void log_all_options () const;
286 void log_str_option (enum gcc_jit_str_option opt
) const;
287 void log_int_option (enum gcc_jit_int_option opt
) const;
288 void log_bool_option (enum gcc_jit_bool_option opt
) const;
289 void log_inner_bool_option (enum inner_bool_option opt
) const;
294 context
*m_parent_ctxt
;
296 /* The ultimate ancestor of the contexts within a family tree of
297 contexts. This has itself as its own m_toplevel_ctxt. */
298 context
*m_toplevel_ctxt
;
304 char *m_first_error_str
;
305 bool m_owns_first_error_str
;
307 char *m_last_error_str
;
308 bool m_owns_last_error_str
;
310 char *m_str_options
[GCC_JIT_NUM_STR_OPTIONS
];
311 int m_int_options
[GCC_JIT_NUM_INT_OPTIONS
];
312 bool m_bool_options
[GCC_JIT_NUM_BOOL_OPTIONS
];
313 bool m_inner_bool_options
[NUM_INNER_BOOL_OPTIONS
];
314 auto_vec
<char *> m_command_line_options
;
316 /* Dumpfiles that were requested via gcc_jit_context_enable_dump. */
317 auto_vec
<requested_dump
> m_requested_dumps
;
319 /* Recorded API usage. */
320 auto_vec
<memento
*> m_mementos
;
322 /* Specific recordings, for use by dump_to_file. */
323 auto_vec
<compound_type
*> m_compound_types
;
324 auto_vec
<global
*> m_globals
;
325 auto_vec
<function
*> m_functions
;
327 type
*m_basic_types
[NUM_GCC_JIT_TYPES
];
330 builtins_manager
*m_builtins_manager
; // lazily created
334 /* An object with lifetime managed by the context i.e.
335 it lives until the context is released, at which
336 point it itself is cleaned up. */
341 virtual ~memento () {}
343 /* Hook for replaying this. */
344 virtual void replay_into (replayer
*r
) = 0;
346 void set_playback_obj (void *obj
) { m_playback_obj
= obj
; }
349 /* Get the context that owns this object.
351 Implements the post-error-checking part of
352 gcc_jit_object_get_context. */
353 context
*get_context () { return m_ctxt
; }
356 as_object () { return this; }
358 /* Debugging hook, for use in generating error messages etc.
359 Implements the post-error-checking part of
360 gcc_jit_object_get_debug_string. */
364 virtual void write_to_dump (dump
&d
);
365 virtual void write_reproducer (reproducer
&r
) = 0;
366 virtual location
*dyn_cast_location () { return NULL
; }
369 memento (context
*ctxt
)
371 m_playback_obj (NULL
),
372 m_debug_string (NULL
)
377 string
*new_string (const char *text
) { return m_ctxt
->new_string (text
); }
380 virtual string
* make_debug_string () = 0;
386 void *m_playback_obj
;
389 string
*m_debug_string
;
392 /* or just use std::string? */
393 class string
: public memento
396 string (context
*ctxt
, const char *text
);
399 const char *c_str () { return m_buffer
; }
401 static string
* from_printf (context
*ctxt
, const char *fmt
, ...)
404 void replay_into (replayer
*) FINAL OVERRIDE
{}
407 string
* make_debug_string () FINAL OVERRIDE
;
408 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
415 class location
: public memento
418 location (context
*ctxt
, string
*filename
, int line
, int column
,
419 bool created_by_user
)
421 m_filename (filename
),
424 m_created_by_user (created_by_user
)
427 void replay_into (replayer
*r
) FINAL OVERRIDE
;
430 playback_location (replayer
*r
)
432 /* Normally during playback, we can walk forwards through the list of
433 recording objects, playing them back. The ordering of recording
434 ensures that everything that a recording object refers to has
435 already been played back, so we can simply look up the relevant
438 Locations are an exception, due to the "write_to_dump" method of
439 recording::statement. This method can set a new location on a
440 statement after the statement is created, and thus the location
441 appears in the context's memento list *after* the statement that
444 In such circumstances, the statement is replayed *before* the location,
445 when the latter doesn't yet have a playback object.
447 Hence we need to ensure that locations have playback objects. */
452 gcc_assert (m_playback_obj
);
453 return static_cast <playback::location
*> (m_playback_obj
);
456 location
*dyn_cast_location () FINAL OVERRIDE
{ return this; }
457 bool created_by_user () const { return m_created_by_user
; }
460 string
* make_debug_string () FINAL OVERRIDE
;
461 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
467 bool m_created_by_user
;
470 class type
: public memento
473 type
*get_pointer ();
475 type
*get_volatile ();
476 type
*get_aligned (size_t alignment_in_bytes
);
478 /* Get the type obtained when dereferencing this type.
480 This will return NULL if it's not valid to dereference this type.
481 The caller is responsible for setting an error. */
482 virtual type
*dereference () = 0;
485 virtual function_type
*dyn_cast_function_type () { return NULL
; }
486 virtual function_type
*as_a_function_type() { gcc_unreachable (); return NULL
; }
487 virtual struct_
*dyn_cast_struct () { return NULL
; }
489 /* Is it typesafe to copy to this type from rtype? */
490 virtual bool accepts_writes_from (type
*rtype
)
493 return this->unqualified () == rtype
->unqualified ();
496 /* Strip off "const" etc */
497 virtual type
*unqualified ()
502 virtual bool is_int () const = 0;
503 virtual bool is_float () const = 0;
504 virtual bool is_bool () const = 0;
505 virtual type
*is_pointer () = 0;
506 virtual type
*is_array () = 0;
507 virtual bool is_void () const { return false; }
508 virtual bool has_known_size () const { return true; }
510 bool is_numeric () const
512 return is_int () || is_float () || is_bool ();
518 return static_cast <playback::type
*> (m_playback_obj
);
521 virtual const char *access_as_type (reproducer
&r
);
526 m_pointer_to_this_type (NULL
)
530 type
*m_pointer_to_this_type
;
533 /* Result of "gcc_jit_context_get_type". */
534 class memento_of_get_type
: public type
537 memento_of_get_type (context
*ctxt
,
538 enum gcc_jit_types kind
)
542 type
*dereference () FINAL OVERRIDE
;
544 bool accepts_writes_from (type
*rtype
) FINAL OVERRIDE
546 if (m_kind
== GCC_JIT_TYPE_VOID_PTR
)
547 if (rtype
->is_pointer ())
549 /* LHS (this) is type (void *), and the RHS is a pointer:
554 return type::accepts_writes_from (rtype
);
557 bool is_int () const FINAL OVERRIDE
;
558 bool is_float () const FINAL OVERRIDE
;
559 bool is_bool () const FINAL OVERRIDE
;
560 type
*is_pointer () FINAL OVERRIDE
{ return dereference (); }
561 type
*is_array () FINAL OVERRIDE
{ return NULL
; }
562 bool is_void () const FINAL OVERRIDE
{ return m_kind
== GCC_JIT_TYPE_VOID
; }
565 void replay_into (replayer
*r
) FINAL OVERRIDE
;
568 string
* make_debug_string () FINAL OVERRIDE
;
569 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
572 enum gcc_jit_types m_kind
;
575 /* Result of "gcc_jit_type_get_pointer". */
576 class memento_of_get_pointer
: public type
579 memento_of_get_pointer (type
*other_type
)
580 : type (other_type
->m_ctxt
),
581 m_other_type (other_type
) {}
583 type
*dereference () FINAL OVERRIDE
{ return m_other_type
; }
585 bool accepts_writes_from (type
*rtype
) FINAL OVERRIDE
;
587 void replay_into (replayer
*r
) FINAL OVERRIDE
;
589 bool is_int () const FINAL OVERRIDE
{ return false; }
590 bool is_float () const FINAL OVERRIDE
{ return false; }
591 bool is_bool () const FINAL OVERRIDE
{ return false; }
592 type
*is_pointer () FINAL OVERRIDE
{ return m_other_type
; }
593 type
*is_array () FINAL OVERRIDE
{ return NULL
; }
596 string
* make_debug_string () FINAL OVERRIDE
;
597 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
603 /* A decorated version of a type, for get_const, get_volatile and
606 class decorated_type
: public type
609 decorated_type (type
*other_type
)
610 : type (other_type
->m_ctxt
),
611 m_other_type (other_type
) {}
613 type
*dereference () FINAL OVERRIDE
{ return m_other_type
->dereference (); }
615 bool is_int () const FINAL OVERRIDE
{ return m_other_type
->is_int (); }
616 bool is_float () const FINAL OVERRIDE
{ return m_other_type
->is_float (); }
617 bool is_bool () const FINAL OVERRIDE
{ return m_other_type
->is_bool (); }
618 type
*is_pointer () FINAL OVERRIDE
{ return m_other_type
->is_pointer (); }
619 type
*is_array () FINAL OVERRIDE
{ return m_other_type
->is_array (); }
625 /* Result of "gcc_jit_type_get_const". */
626 class memento_of_get_const
: public decorated_type
629 memento_of_get_const (type
*other_type
)
630 : decorated_type (other_type
) {}
632 bool accepts_writes_from (type */
*rtype*/
) FINAL OVERRIDE
634 /* Can't write to a "const". */
638 /* Strip off the "const", giving the underlying type. */
639 type
*unqualified () FINAL OVERRIDE
{ return m_other_type
; }
641 void replay_into (replayer
*) FINAL OVERRIDE
;
644 string
* make_debug_string () FINAL OVERRIDE
;
645 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
648 /* Result of "gcc_jit_type_get_volatile". */
649 class memento_of_get_volatile
: public decorated_type
652 memento_of_get_volatile (type
*other_type
)
653 : decorated_type (other_type
) {}
655 /* Strip off the "volatile", giving the underlying type. */
656 type
*unqualified () FINAL OVERRIDE
{ return m_other_type
; }
658 void replay_into (replayer
*) FINAL OVERRIDE
;
661 string
* make_debug_string () FINAL OVERRIDE
;
662 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
665 /* Result of "gcc_jit_type_get_aligned". */
666 class memento_of_get_aligned
: public decorated_type
669 memento_of_get_aligned (type
*other_type
, size_t alignment_in_bytes
)
670 : decorated_type (other_type
),
671 m_alignment_in_bytes (alignment_in_bytes
) {}
673 /* Strip off the alignment, giving the underlying type. */
674 type
*unqualified () FINAL OVERRIDE
{ return m_other_type
; }
676 void replay_into (replayer
*) FINAL OVERRIDE
;
679 string
* make_debug_string () FINAL OVERRIDE
;
680 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
683 size_t m_alignment_in_bytes
;
686 class array_type
: public type
689 array_type (context
*ctxt
,
695 m_element_type (element_type
),
696 m_num_elements (num_elements
)
699 type
*dereference () FINAL OVERRIDE
;
701 bool is_int () const FINAL OVERRIDE
{ return false; }
702 bool is_float () const FINAL OVERRIDE
{ return false; }
703 bool is_bool () const FINAL OVERRIDE
{ return false; }
704 type
*is_pointer () FINAL OVERRIDE
{ return NULL
; }
705 type
*is_array () FINAL OVERRIDE
{ return m_element_type
; }
707 void replay_into (replayer
*) FINAL OVERRIDE
;
710 string
* make_debug_string () FINAL OVERRIDE
;
711 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
715 type
*m_element_type
;
719 class function_type
: public type
722 function_type (context
*ctxt
,
728 type
*dereference () FINAL OVERRIDE
;
729 function_type
*dyn_cast_function_type () FINAL OVERRIDE
{ return this; }
730 function_type
*as_a_function_type () FINAL OVERRIDE
{ return this; }
732 bool is_int () const FINAL OVERRIDE
{ return false; }
733 bool is_float () const FINAL OVERRIDE
{ return false; }
734 bool is_bool () const FINAL OVERRIDE
{ return false; }
735 type
*is_pointer () FINAL OVERRIDE
{ return NULL
; }
736 type
*is_array () FINAL OVERRIDE
{ return NULL
; }
738 void replay_into (replayer
*) FINAL OVERRIDE
;
740 type
* get_return_type () const { return m_return_type
; }
741 const vec
<type
*> &get_param_types () const { return m_param_types
; }
742 int is_variadic () const { return m_is_variadic
; }
744 string
* make_debug_string_with_ptr ();
747 write_deferred_reproducer (reproducer
&r
,
751 string
* make_debug_string () FINAL OVERRIDE
;
752 string
* make_debug_string_with (const char *);
753 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
757 auto_vec
<type
*> m_param_types
;
761 class field
: public memento
764 field (context
*ctxt
,
775 type
* get_type () const { return m_type
; }
777 compound_type
* get_container () const { return m_container
; }
778 void set_container (compound_type
*c
) { m_container
= c
; }
780 void replay_into (replayer
*) FINAL OVERRIDE
;
782 void write_to_dump (dump
&d
) FINAL OVERRIDE
;
785 playback_field () const
787 return static_cast <playback::field
*> (m_playback_obj
);
791 string
* make_debug_string () FINAL OVERRIDE
;
792 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
798 compound_type
*m_container
;
801 /* Base class for struct_ and union_ */
802 class compound_type
: public type
805 compound_type (context
*ctxt
,
809 string
*get_name () const { return m_name
; }
810 location
*get_loc () const { return m_loc
; }
811 fields
* get_fields () { return m_fields
; }
814 set_fields (location
*loc
,
818 type
*dereference () FINAL OVERRIDE
;
820 bool is_int () const FINAL OVERRIDE
{ return false; }
821 bool is_float () const FINAL OVERRIDE
{ return false; }
822 bool is_bool () const FINAL OVERRIDE
{ return false; }
823 type
*is_pointer () FINAL OVERRIDE
{ return NULL
; }
824 type
*is_array () FINAL OVERRIDE
{ return NULL
; }
826 bool has_known_size () const FINAL OVERRIDE
{ return m_fields
!= NULL
; }
828 playback::compound_type
*
829 playback_compound_type ()
831 return static_cast <playback::compound_type
*> (m_playback_obj
);
840 class struct_
: public compound_type
843 struct_ (context
*ctxt
,
847 struct_
*dyn_cast_struct () FINAL OVERRIDE
{ return this; }
850 as_type () { return this; }
852 void replay_into (replayer
*r
) FINAL OVERRIDE
;
854 const char *access_as_type (reproducer
&r
) FINAL OVERRIDE
;
857 string
* make_debug_string () FINAL OVERRIDE
;
858 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
861 // memento of struct_::set_fields
862 class fields
: public memento
865 fields (compound_type
*struct_or_union
,
869 void replay_into (replayer
*r
) FINAL OVERRIDE
;
871 void write_to_dump (dump
&d
) FINAL OVERRIDE
;
873 int length () const { return m_fields
.length (); }
874 field
*get_field (int i
) const { return m_fields
[i
]; }
877 string
* make_debug_string () FINAL OVERRIDE
;
878 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
881 compound_type
*m_struct_or_union
;
882 auto_vec
<field
*> m_fields
;
885 class union_
: public compound_type
888 union_ (context
*ctxt
,
892 void replay_into (replayer
*r
) FINAL OVERRIDE
;
895 string
* make_debug_string () FINAL OVERRIDE
;
896 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
903 /* An abstract base class for operations that visit all rvalues within an
905 Currently the only implementation is class rvalue_usage_validator within
911 virtual ~rvalue_visitor () {}
912 virtual void visit (rvalue
*rvalue
) = 0;
915 /* When generating debug strings for rvalues we mimic C, so we need to
916 mimic C's precedence levels when handling compound expressions.
917 These are in order from strongest precedence to weakest. */
924 PRECEDENCE_MULTIPLICATIVE
,
927 PRECEDENCE_RELATIONAL
,
929 PRECEDENCE_BITWISE_AND
,
930 PRECEDENCE_BITWISE_XOR
,
931 PRECEDENCE_BITWISE_IOR
,
932 PRECEDENCE_LOGICAL_AND
,
933 PRECEDENCE_LOGICAL_OR
936 class rvalue
: public memento
939 rvalue (context
*ctxt
,
946 m_parenthesized_string (NULL
)
951 location
* get_loc () const { return m_loc
; }
953 /* Get the recording::type of this rvalue.
955 Implements the post-error-checking part of
956 gcc_jit_rvalue_get_type. */
957 type
* get_type () const { return m_type
; }
960 playback_rvalue () const
962 return static_cast <playback::rvalue
*> (m_playback_obj
);
965 access_field (location
*loc
,
969 dereference_field (location
*loc
,
973 dereference (location
*loc
);
976 verify_valid_within_stmt (const char *api_funcname
, statement
*s
);
978 virtual void visit_children (rvalue_visitor
*v
) = 0;
980 void set_scope (function
*scope
);
981 function
*get_scope () const { return m_scope
; }
984 virtual param
*dyn_cast_param () { return NULL
; }
985 virtual base_call
*dyn_cast_base_call () { return NULL
; }
987 virtual const char *access_as_rvalue (reproducer
&r
);
989 /* Get the debug string, wrapped in parentheses. */
991 get_debug_string_parens (enum precedence outer_prec
);
993 virtual bool is_constant () const { return false; }
994 virtual bool get_wide_int (wide_int
*) const { return false; }
997 virtual enum precedence
get_precedence () const = 0;
1004 function
*m_scope
; /* NULL for globals, non-NULL for locals/params */
1005 string
*m_parenthesized_string
;
1008 class lvalue
: public rvalue
1011 lvalue (context
*ctxt
,
1014 : rvalue (ctxt
, loc
, type_
)
1018 playback_lvalue () const
1020 return static_cast <playback::lvalue
*> (m_playback_obj
);
1024 access_field (location
*loc
,
1028 get_address (location
*loc
);
1031 as_rvalue () { return this; }
1033 const char *access_as_rvalue (reproducer
&r
) OVERRIDE
;
1034 virtual const char *access_as_lvalue (reproducer
&r
);
1037 class param
: public lvalue
1040 param (context
*ctxt
,
1044 : lvalue (ctxt
, loc
, type
),
1048 as_lvalue () { return this; }
1050 void replay_into (replayer
*r
) FINAL OVERRIDE
;
1052 void visit_children (rvalue_visitor
*) FINAL OVERRIDE
{}
1055 playback_param () const
1057 return static_cast <playback::param
*> (m_playback_obj
);
1060 param
*dyn_cast_param () FINAL OVERRIDE
{ return this; }
1062 const char *access_as_rvalue (reproducer
&r
) FINAL OVERRIDE
;
1063 const char *access_as_lvalue (reproducer
&r
) FINAL OVERRIDE
;
1066 string
* make_debug_string () FINAL OVERRIDE
{ return m_name
; }
1067 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
1068 enum precedence
get_precedence () const FINAL OVERRIDE
1070 return PRECEDENCE_PRIMARY
;
1077 class function
: public memento
1080 function (context
*ctxt
,
1082 enum gcc_jit_function_kind kind
,
1088 enum built_in_function builtin_id
);
1090 void replay_into (replayer
*r
) FINAL OVERRIDE
;
1092 playback::function
*
1093 playback_function () const
1095 return static_cast <playback::function
*> (m_playback_obj
);
1098 enum gcc_jit_function_kind
get_kind () const { return m_kind
; }
1101 new_local (location
*loc
,
1106 new_block (const char *name
);
1108 location
*get_loc () const { return m_loc
; }
1109 type
*get_return_type () const { return m_return_type
; }
1110 string
* get_name () const { return m_name
; }
1111 const vec
<param
*> &get_params () const { return m_params
; }
1113 /* Get the given param by index.
1114 Implements the post-error-checking part of
1115 gcc_jit_function_get_param. */
1116 param
*get_param (int i
) const { return m_params
[i
]; }
1118 bool is_variadic () const { return m_is_variadic
; }
1120 void write_to_dump (dump
&d
) FINAL OVERRIDE
;
1124 void dump_to_dot (const char *path
);
1127 string
* make_debug_string () FINAL OVERRIDE
;
1128 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
1132 enum gcc_jit_function_kind m_kind
;
1133 type
*m_return_type
;
1135 auto_vec
<param
*> m_params
;
1137 enum built_in_function m_builtin_id
;
1138 auto_vec
<local
*> m_locals
;
1139 auto_vec
<block
*> m_blocks
;
1142 class block
: public memento
1145 block (function
*func
, int index
, string
*name
)
1146 : memento (func
->m_ctxt
),
1151 m_has_been_terminated (false),
1152 m_is_reachable (false)
1156 /* Get the recording::function containing this block.
1157 Implements the post-error-checking part of
1158 gcc_jit_block_get_function. */
1159 function
*get_function () { return m_func
; }
1161 bool has_been_terminated () { return m_has_been_terminated
; }
1162 bool is_reachable () { return m_is_reachable
; }
1165 add_eval (location
*loc
,
1169 add_assignment (location
*loc
,
1174 add_assignment_op (location
*loc
,
1176 enum gcc_jit_binary_op op
,
1180 add_comment (location
*loc
,
1184 end_with_conditional (location
*loc
,
1190 end_with_jump (location
*loc
,
1194 end_with_return (location
*loc
,
1198 end_with_switch (location
*loc
,
1200 block
*default_block
,
1205 playback_block () const
1207 return static_cast <playback::block
*> (m_playback_obj
);
1210 void write_to_dump (dump
&d
) FINAL OVERRIDE
;
1214 location
*get_loc () const;
1216 statement
*get_first_statement () const;
1217 statement
*get_last_statement () const;
1219 vec
<block
*> get_successor_blocks () const;
1222 string
* make_debug_string () FINAL OVERRIDE
;
1223 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
1225 void replay_into (replayer
*r
) FINAL OVERRIDE
;
1227 void dump_to_dot (pretty_printer
*pp
);
1228 void dump_edges_to_dot (pretty_printer
*pp
);
1234 auto_vec
<statement
*> m_statements
;
1235 bool m_has_been_terminated
;
1236 bool m_is_reachable
;
1238 friend class function
;
1241 class global
: public lvalue
1244 global (context
*ctxt
,
1246 enum gcc_jit_global_kind kind
,
1249 : lvalue (ctxt
, loc
, type
),
1254 void replay_into (replayer
*) FINAL OVERRIDE
;
1256 void visit_children (rvalue_visitor
*) FINAL OVERRIDE
{}
1258 void write_to_dump (dump
&d
) FINAL OVERRIDE
;
1261 string
* make_debug_string () FINAL OVERRIDE
{ return m_name
; }
1262 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
1263 enum precedence
get_precedence () const FINAL OVERRIDE
1265 return PRECEDENCE_PRIMARY
;
1269 enum gcc_jit_global_kind m_kind
;
1273 template <typename HOST_TYPE
>
1274 class memento_of_new_rvalue_from_const
: public rvalue
1277 memento_of_new_rvalue_from_const (context
*ctxt
,
1281 : rvalue (ctxt
, loc
, type
),
1284 void replay_into (replayer
*r
) FINAL OVERRIDE
;
1286 void visit_children (rvalue_visitor
*) FINAL OVERRIDE
{}
1288 bool is_constant () const FINAL OVERRIDE
{ return true; }
1290 bool get_wide_int (wide_int
*out
) const FINAL OVERRIDE
;
1293 string
* make_debug_string () FINAL OVERRIDE
;
1294 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
1295 enum precedence
get_precedence () const FINAL OVERRIDE
1297 return PRECEDENCE_PRIMARY
;
1304 class memento_of_new_string_literal
: public rvalue
1307 memento_of_new_string_literal (context
*ctxt
,
1310 : rvalue (ctxt
, loc
, ctxt
->get_type (GCC_JIT_TYPE_CONST_CHAR_PTR
)),
1313 void replay_into (replayer
*r
) FINAL OVERRIDE
;
1315 void visit_children (rvalue_visitor
*) FINAL OVERRIDE
{}
1318 string
* make_debug_string () FINAL OVERRIDE
;
1319 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
1320 enum precedence
get_precedence () const FINAL OVERRIDE
1322 return PRECEDENCE_PRIMARY
;
1329 class unary_op
: public rvalue
1332 unary_op (context
*ctxt
,
1334 enum gcc_jit_unary_op op
,
1337 : rvalue (ctxt
, loc
, result_type
),
1342 void replay_into (replayer
*r
) FINAL OVERRIDE
;
1344 void visit_children (rvalue_visitor
*v
) FINAL OVERRIDE
;
1347 string
* make_debug_string () FINAL OVERRIDE
;
1348 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
1349 enum precedence
get_precedence () const FINAL OVERRIDE
1351 return PRECEDENCE_UNARY
;
1355 enum gcc_jit_unary_op m_op
;
1359 class binary_op
: public rvalue
1362 binary_op (context
*ctxt
,
1364 enum gcc_jit_binary_op op
,
1366 rvalue
*a
, rvalue
*b
)
1367 : rvalue (ctxt
, loc
, result_type
),
1372 void replay_into (replayer
*r
) FINAL OVERRIDE
;
1374 void visit_children (rvalue_visitor
*v
) FINAL OVERRIDE
;
1377 string
* make_debug_string () FINAL OVERRIDE
;
1378 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
1379 enum precedence
get_precedence () const FINAL OVERRIDE
;
1382 enum gcc_jit_binary_op m_op
;
1387 class comparison
: public rvalue
1390 comparison (context
*ctxt
,
1392 enum gcc_jit_comparison op
,
1393 rvalue
*a
, rvalue
*b
)
1394 : rvalue (ctxt
, loc
, ctxt
->get_type (GCC_JIT_TYPE_BOOL
)),
1400 void replay_into (replayer
*r
) FINAL OVERRIDE
;
1402 void visit_children (rvalue_visitor
*v
) FINAL OVERRIDE
;
1405 string
* make_debug_string () FINAL OVERRIDE
;
1406 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
1407 enum precedence
get_precedence () const FINAL OVERRIDE
;
1410 enum gcc_jit_comparison m_op
;
1415 class cast
: public rvalue
1418 cast (context
*ctxt
,
1422 : rvalue (ctxt
, loc
, type_
),
1426 void replay_into (replayer
*r
) FINAL OVERRIDE
;
1428 void visit_children (rvalue_visitor
*v
) FINAL OVERRIDE
;
1431 string
* make_debug_string () FINAL OVERRIDE
;
1432 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
1433 enum precedence
get_precedence () const FINAL OVERRIDE
1435 return PRECEDENCE_CAST
;
1442 class base_call
: public rvalue
1445 base_call (context
*ctxt
,
1451 enum precedence
get_precedence () const FINAL OVERRIDE
1453 return PRECEDENCE_POSTFIX
;
1456 base_call
*dyn_cast_base_call () FINAL OVERRIDE
{ return this; }
1458 void set_require_tail_call (bool require_tail_call
)
1460 m_require_tail_call
= require_tail_call
;
1464 void write_reproducer_tail_call (reproducer
&r
, const char *id
);
1467 auto_vec
<rvalue
*> m_args
;
1468 bool m_require_tail_call
;
1471 class call
: public base_call
1474 call (context
*ctxt
,
1480 void replay_into (replayer
*r
) FINAL OVERRIDE
;
1482 void visit_children (rvalue_visitor
*v
) FINAL OVERRIDE
;
1485 string
* make_debug_string () FINAL OVERRIDE
;
1486 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
1492 class call_through_ptr
: public base_call
1495 call_through_ptr (context
*ctxt
,
1501 void replay_into (replayer
*r
) FINAL OVERRIDE
;
1503 void visit_children (rvalue_visitor
*v
) FINAL OVERRIDE
;
1506 string
* make_debug_string () FINAL OVERRIDE
;
1507 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
1513 class array_access
: public lvalue
1516 array_access (context
*ctxt
,
1520 : lvalue (ctxt
, loc
, ptr
->get_type ()->dereference ()),
1525 void replay_into (replayer
*r
) FINAL OVERRIDE
;
1527 void visit_children (rvalue_visitor
*v
) FINAL OVERRIDE
;
1530 string
* make_debug_string () FINAL OVERRIDE
;
1531 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
1532 enum precedence
get_precedence () const FINAL OVERRIDE
1534 return PRECEDENCE_POSTFIX
;
1542 class access_field_of_lvalue
: public lvalue
1545 access_field_of_lvalue (context
*ctxt
,
1549 : lvalue (ctxt
, loc
, field
->get_type ()),
1554 void replay_into (replayer
*r
) FINAL OVERRIDE
;
1556 void visit_children (rvalue_visitor
*v
) FINAL OVERRIDE
;
1559 string
* make_debug_string () FINAL OVERRIDE
;
1560 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
1561 enum precedence
get_precedence () const FINAL OVERRIDE
1563 return PRECEDENCE_POSTFIX
;
1571 class access_field_rvalue
: public rvalue
1574 access_field_rvalue (context
*ctxt
,
1578 : rvalue (ctxt
, loc
, field
->get_type ()),
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
;
1590 enum precedence
get_precedence () const FINAL OVERRIDE
1592 return PRECEDENCE_POSTFIX
;
1600 class dereference_field_rvalue
: public lvalue
1603 dereference_field_rvalue (context
*ctxt
,
1607 : lvalue (ctxt
, loc
, field
->get_type ()),
1612 void replay_into (replayer
*r
) FINAL OVERRIDE
;
1614 void visit_children (rvalue_visitor
*v
) FINAL OVERRIDE
;
1617 string
* make_debug_string () FINAL OVERRIDE
;
1618 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
1619 enum precedence
get_precedence () const FINAL OVERRIDE
1621 return PRECEDENCE_POSTFIX
;
1629 class dereference_rvalue
: public lvalue
1632 dereference_rvalue (context
*ctxt
,
1635 : lvalue (ctxt
, loc
, val
->get_type ()->dereference ()),
1638 void replay_into (replayer
*r
) FINAL OVERRIDE
;
1640 void visit_children (rvalue_visitor
*v
) FINAL OVERRIDE
;
1643 string
* make_debug_string () FINAL OVERRIDE
;
1644 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
1645 enum precedence
get_precedence () const FINAL OVERRIDE
1647 return PRECEDENCE_UNARY
;
1654 class get_address_of_lvalue
: public rvalue
1657 get_address_of_lvalue (context
*ctxt
,
1660 : rvalue (ctxt
, loc
, val
->get_type ()->get_pointer ()),
1664 void replay_into (replayer
*r
) FINAL OVERRIDE
;
1666 void visit_children (rvalue_visitor
*v
) FINAL OVERRIDE
;
1669 string
* make_debug_string () FINAL OVERRIDE
;
1670 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
1671 enum precedence
get_precedence () const FINAL OVERRIDE
1673 return PRECEDENCE_UNARY
;
1680 class local
: public lvalue
1683 local (function
*func
, location
*loc
, type
*type_
, string
*name
)
1684 : lvalue (func
->m_ctxt
, loc
, type_
),
1691 void replay_into (replayer
*r
) FINAL OVERRIDE
;
1693 void visit_children (rvalue_visitor
*) FINAL OVERRIDE
{}
1695 void write_to_dump (dump
&d
) FINAL OVERRIDE
;
1698 string
* make_debug_string () FINAL OVERRIDE
{ return m_name
; }
1699 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
1700 enum precedence
get_precedence () const FINAL OVERRIDE
1702 return PRECEDENCE_PRIMARY
;
1710 class statement
: public memento
1713 virtual vec
<block
*> get_successor_blocks () const;
1715 void write_to_dump (dump
&d
) FINAL OVERRIDE
;
1717 block
*get_block () const { return m_block
; }
1718 location
*get_loc () const { return m_loc
; }
1721 statement (block
*b
, location
*loc
)
1722 : memento (b
->m_ctxt
),
1726 playback::location
*
1727 playback_location (replayer
*r
) const
1729 return ::gcc::jit::recording::playback_location (r
, m_loc
);
1737 class eval
: public statement
1743 : statement (b
, loc
),
1744 m_rvalue (rvalue
) {}
1746 void replay_into (replayer
*r
) FINAL OVERRIDE
;
1749 string
* make_debug_string () FINAL OVERRIDE
;
1750 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
1756 class assignment
: public statement
1759 assignment (block
*b
,
1763 : statement (b
, loc
),
1765 m_rvalue (rvalue
) {}
1767 void replay_into (replayer
*r
) FINAL OVERRIDE
;
1770 string
* make_debug_string () FINAL OVERRIDE
;
1771 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
1778 class assignment_op
: public statement
1781 assignment_op (block
*b
,
1784 enum gcc_jit_binary_op op
,
1786 : statement (b
, loc
),
1789 m_rvalue (rvalue
) {}
1791 void replay_into (replayer
*r
) FINAL OVERRIDE
;
1794 string
* make_debug_string () FINAL OVERRIDE
;
1795 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
1799 enum gcc_jit_binary_op m_op
;
1803 class comment
: public statement
1809 : statement (b
, loc
),
1812 void replay_into (replayer
*r
) FINAL OVERRIDE
;
1815 string
* make_debug_string () FINAL OVERRIDE
;
1816 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
1822 class conditional
: public statement
1825 conditional (block
*b
,
1830 : statement (b
, loc
),
1831 m_boolval (boolval
),
1832 m_on_true (on_true
),
1833 m_on_false (on_false
) {}
1835 void replay_into (replayer
*r
) FINAL OVERRIDE
;
1837 vec
<block
*> get_successor_blocks () const FINAL OVERRIDE
;
1840 string
* make_debug_string () FINAL OVERRIDE
;
1841 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
1849 class jump
: public statement
1855 : statement (b
, loc
),
1856 m_target (target
) {}
1858 void replay_into (replayer
*r
) FINAL OVERRIDE
;
1860 vec
<block
*> get_successor_blocks () const FINAL OVERRIDE
;
1863 string
* make_debug_string () FINAL OVERRIDE
;
1864 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
1870 class return_
: public statement
1876 : statement (b
, loc
),
1877 m_rvalue (rvalue
) {}
1879 void replay_into (replayer
*r
) FINAL OVERRIDE
;
1881 vec
<block
*> get_successor_blocks () const FINAL OVERRIDE
;
1884 string
* make_debug_string () FINAL OVERRIDE
;
1885 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
1891 class case_
: public memento
1894 case_ (context
*ctxt
,
1899 m_min_value (min_value
),
1900 m_max_value (max_value
),
1901 m_dest_block (dest_block
)
1904 rvalue
*get_min_value () const { return m_min_value
; }
1905 rvalue
*get_max_value () const { return m_max_value
; }
1906 block
*get_dest_block () const { return m_dest_block
; }
1908 void replay_into (replayer
*) FINAL OVERRIDE
{ /* empty */ }
1910 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
1913 string
* make_debug_string () FINAL OVERRIDE
;
1916 rvalue
*m_min_value
;
1917 rvalue
*m_max_value
;
1918 block
*m_dest_block
;
1921 class switch_
: public statement
1927 block
*default_block
,
1931 void replay_into (replayer
*r
) FINAL OVERRIDE
;
1933 vec
<block
*> get_successor_blocks () const FINAL OVERRIDE
;
1936 string
* make_debug_string () FINAL OVERRIDE
;
1937 void write_reproducer (reproducer
&r
) FINAL OVERRIDE
;
1941 block
*m_default_block
;
1942 auto_vec
<case_
*> m_cases
;
1945 } // namespace gcc::jit::recording
1947 /* Create a recording::memento_of_new_rvalue_from_const instance and add
1948 it to this context's list of mementos.
1950 Implements the post-error-checking part of
1951 gcc_jit_context_new_rvalue_from_{int|long|double|ptr}. */
1953 template <typename HOST_TYPE
>
1955 recording::context::new_rvalue_from_const (recording::type
*type
,
1958 recording::rvalue
*result
=
1959 new memento_of_new_rvalue_from_const
<HOST_TYPE
> (this, NULL
, type
, value
);
1964 } // namespace gcc::jit
1968 #endif /* JIT_RECORDING_H */