Fix oversight in handling of reverse SSO in SRA pass
[official-gcc.git] / gcc / jit / jit-recording.h
blob03fa1160cf0887b731232b1d73b17f9aa44136fb
1 /* Internals of libgccjit: classes for recording calls made to the JIT API.
2 Copyright (C) 2013-2021 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)
10 any later version.
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"
27 class timer;
29 namespace gcc {
31 namespace jit {
33 extern const char * const unary_op_reproducer_strings[];
34 extern const char * const binary_op_reproducer_strings[];
36 class result;
37 class dump;
38 class reproducer;
40 /**********************************************************************
41 Recording.
42 **********************************************************************/
44 namespace recording {
46 playback::location *
47 playback_location (replayer *r, location *loc);
49 const char *
50 playback_string (string *str);
52 playback::block *
53 playback_block (block *b);
55 /* A recording of a call to gcc_jit_context_enable_dump. */
56 struct requested_dump
58 const char *m_dumpname;
59 char **m_out_ptr;
62 /* A JIT-compilation context. */
63 class context : public log_user
65 public:
66 context (context *parent_ctxt);
67 ~context ();
69 builtins_manager *
70 get_builtins_manager ();
72 void record (memento *m);
73 void replay_into (replayer *r);
74 void disassociate_from_playback ();
76 string *
77 new_string (const char *text, bool escaped = false);
79 location *
80 new_location (const char *filename,
81 int line,
82 int column,
83 bool created_by_user);
85 type *
86 get_type (enum gcc_jit_types type);
88 type *
89 get_int_type (int num_bytes, int is_signed);
91 type *
92 new_array_type (location *loc,
93 type *element_type,
94 int num_elements);
96 field *
97 new_field (location *loc,
98 type *type,
99 const char *name);
101 field *
102 new_bitfield (location *loc,
103 type *type,
104 int width,
105 const char *name);
107 struct_ *
108 new_struct_type (location *loc,
109 const char *name);
111 union_ *
112 new_union_type (location *loc,
113 const char *name);
115 function_type *
116 new_function_type (type *return_type,
117 int num_params,
118 type **param_types,
119 int is_variadic);
121 type *
122 new_function_ptr_type (location *loc,
123 type *return_type,
124 int num_params,
125 type **param_types,
126 int is_variadic);
128 param *
129 new_param (location *loc,
130 type *type,
131 const char *name);
133 function *
134 new_function (location *loc,
135 enum gcc_jit_function_kind kind,
136 type *return_type,
137 const char *name,
138 int num_params,
139 param **params,
140 int is_variadic,
141 enum built_in_function builtin_id);
143 function *
144 get_builtin_function (const char *name);
146 lvalue *
147 new_global (location *loc,
148 enum gcc_jit_global_kind kind,
149 type *type,
150 const char *name);
152 template <typename HOST_TYPE>
153 rvalue *
154 new_rvalue_from_const (type *type,
155 HOST_TYPE value);
157 rvalue *
158 new_string_literal (const char *value);
160 rvalue *
161 new_rvalue_from_vector (location *loc,
162 vector_type *type,
163 rvalue **elements);
165 rvalue *
166 new_unary_op (location *loc,
167 enum gcc_jit_unary_op op,
168 type *result_type,
169 rvalue *a);
171 rvalue *
172 new_binary_op (location *loc,
173 enum gcc_jit_binary_op op,
174 type *result_type,
175 rvalue *a, rvalue *b);
177 rvalue *
178 new_comparison (location *loc,
179 enum gcc_jit_comparison op,
180 rvalue *a, rvalue *b);
182 rvalue *
183 new_call (location *loc,
184 function *func,
185 int numargs, rvalue **args);
187 rvalue *
188 new_call_through_ptr (location *loc,
189 rvalue *fn_ptr,
190 int numargs, rvalue **args);
192 rvalue *
193 new_cast (location *loc,
194 rvalue *expr,
195 type *type_);
197 lvalue *
198 new_array_access (location *loc,
199 rvalue *ptr,
200 rvalue *index);
202 case_ *
203 new_case (rvalue *min_value,
204 rvalue *max_value,
205 block *block);
207 void
208 set_str_option (enum gcc_jit_str_option opt,
209 const char *value);
211 void
212 set_int_option (enum gcc_jit_int_option opt,
213 int value);
215 void
216 set_bool_option (enum gcc_jit_bool_option opt,
217 int value);
219 void
220 set_inner_bool_option (enum inner_bool_option inner_opt,
221 int value);
223 void
224 add_command_line_option (const char *optname);
226 void
227 append_command_line_options (vec <char *> *argvec);
229 void
230 add_driver_option (const char *optname);
232 void
233 append_driver_options (auto_string_vec *argvec);
235 void
236 enable_dump (const char *dumpname,
237 char **out_ptr);
239 const char *
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];
263 result *
264 compile ();
266 void
267 compile_to_file (enum gcc_jit_output_kind output_kind,
268 const char *output_path);
270 void
271 add_error (location *loc, const char *fmt, ...)
272 GNU_PRINTF(3, 4);
274 void
275 add_error_va (location *loc, const char *fmt, va_list ap)
276 GNU_PRINTF(3, 0);
278 const char *
279 get_first_error () const;
281 const char *
282 get_last_error () const;
284 bool errors_occurred () const
286 if (m_parent_ctxt)
287 if (m_parent_ctxt->errors_occurred ())
288 return true;
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);
298 void
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; }
304 void add_top_level_asm (location *loc, const char *asm_stmts);
306 private:
307 void log_all_options () const;
308 void log_str_option (enum gcc_jit_str_option opt) const;
309 void log_int_option (enum gcc_jit_int_option opt) const;
310 void log_bool_option (enum gcc_jit_bool_option opt) const;
311 void log_inner_bool_option (enum inner_bool_option opt) const;
313 void validate ();
315 private:
316 context *m_parent_ctxt;
318 /* The ultimate ancestor of the contexts within a family tree of
319 contexts. This has itself as its own m_toplevel_ctxt. */
320 context *m_toplevel_ctxt;
322 timer *m_timer;
324 int m_error_count;
326 char *m_first_error_str;
327 bool m_owns_first_error_str;
329 char *m_last_error_str;
330 bool m_owns_last_error_str;
332 char *m_str_options[GCC_JIT_NUM_STR_OPTIONS];
333 int m_int_options[GCC_JIT_NUM_INT_OPTIONS];
334 bool m_bool_options[GCC_JIT_NUM_BOOL_OPTIONS];
335 bool m_inner_bool_options[NUM_INNER_BOOL_OPTIONS];
336 auto_vec <char *> m_command_line_options;
337 auto_vec <char *> m_driver_options;
339 /* Dumpfiles that were requested via gcc_jit_context_enable_dump. */
340 auto_vec<requested_dump> m_requested_dumps;
342 /* Recorded API usage. */
343 auto_vec<memento *> m_mementos;
345 /* Specific recordings, for use by dump_to_file. */
346 auto_vec<compound_type *> m_compound_types;
347 auto_vec<global *> m_globals;
348 auto_vec<function *> m_functions;
349 auto_vec<top_level_asm *> m_top_level_asms;
351 type *m_basic_types[NUM_GCC_JIT_TYPES];
352 type *m_FILE_type;
354 builtins_manager *m_builtins_manager; // lazily created
358 /* An object with lifetime managed by the context i.e.
359 it lives until the context is released, at which
360 point it itself is cleaned up. */
362 class memento
364 public:
365 virtual ~memento () {}
367 /* Hook for replaying this. */
368 virtual void replay_into (replayer *r) = 0;
370 void set_playback_obj (void *obj) { m_playback_obj = obj; }
373 /* Get the context that owns this object.
375 Implements the post-error-checking part of
376 gcc_jit_object_get_context. */
377 context *get_context () { return m_ctxt; }
379 memento *
380 as_object () { return this; }
382 /* Debugging hook, for use in generating error messages etc.
383 Implements the post-error-checking part of
384 gcc_jit_object_get_debug_string. */
385 const char *
386 get_debug_string ();
388 virtual void write_to_dump (dump &d);
389 virtual void write_reproducer (reproducer &r) = 0;
390 virtual location *dyn_cast_location () { return NULL; }
392 protected:
393 memento (context *ctxt)
394 : m_ctxt (ctxt),
395 m_playback_obj (NULL),
396 m_debug_string (NULL)
398 gcc_assert (ctxt);
401 string *new_string (const char *text) { return m_ctxt->new_string (text); }
403 private:
404 virtual string * make_debug_string () = 0;
406 public:
407 context *m_ctxt;
409 protected:
410 void *m_playback_obj;
412 private:
413 string *m_debug_string;
416 /* or just use std::string? */
417 class string : public memento
419 public:
420 string (context *ctxt, const char *text, bool escaped);
421 ~string ();
423 const char *c_str () { return m_buffer; }
425 static string * from_printf (context *ctxt, const char *fmt, ...)
426 GNU_PRINTF(2, 3);
428 void replay_into (replayer *) FINAL OVERRIDE {}
430 private:
431 string * make_debug_string () FINAL OVERRIDE;
432 void write_reproducer (reproducer &r) FINAL OVERRIDE;
434 private:
435 size_t m_len;
436 char *m_buffer;
438 /* Flag to track if this string is the result of string::make_debug_string,
439 to avoid infinite recursion when logging all mementos: don't re-escape
440 such strings. */
441 bool m_escaped;
444 class location : public memento
446 public:
447 location (context *ctxt, string *filename, int line, int column,
448 bool created_by_user)
449 : memento (ctxt),
450 m_filename (filename),
451 m_line (line),
452 m_column (column),
453 m_created_by_user (created_by_user)
456 void replay_into (replayer *r) FINAL OVERRIDE;
458 playback::location *
459 playback_location (replayer *r)
461 /* Normally during playback, we can walk forwards through the list of
462 recording objects, playing them back. The ordering of recording
463 ensures that everything that a recording object refers to has
464 already been played back, so we can simply look up the relevant
465 m_playback_obj.
467 Locations are an exception, due to the "write_to_dump" method of
468 recording::statement. This method can set a new location on a
469 statement after the statement is created, and thus the location
470 appears in the context's memento list *after* the statement that
471 refers to it.
473 In such circumstances, the statement is replayed *before* the location,
474 when the latter doesn't yet have a playback object.
476 Hence we need to ensure that locations have playback objects. */
477 if (!m_playback_obj)
479 replay_into (r);
481 gcc_assert (m_playback_obj);
482 return static_cast <playback::location *> (m_playback_obj);
485 location *dyn_cast_location () FINAL OVERRIDE { return this; }
486 bool created_by_user () const { return m_created_by_user; }
488 private:
489 string * make_debug_string () FINAL OVERRIDE;
490 void write_reproducer (reproducer &r) FINAL OVERRIDE;
492 private:
493 string *m_filename;
494 int m_line;
495 int m_column;
496 bool m_created_by_user;
499 class type : public memento
501 public:
502 type *get_pointer ();
503 type *get_const ();
504 type *get_volatile ();
505 type *get_aligned (size_t alignment_in_bytes);
506 type *get_vector (size_t num_units);
508 /* Get the type obtained when dereferencing this type.
510 This will return NULL if it's not valid to dereference this type.
511 The caller is responsible for setting an error. */
512 virtual type *dereference () = 0;
513 /* Get the type size in bytes.
515 This is implemented only for memento_of_get_type and
516 memento_of_get_pointer as it is used for initializing globals of
517 these types. */
518 virtual size_t get_size () { gcc_unreachable (); }
520 /* Dynamic casts. */
521 virtual function_type *dyn_cast_function_type () { return NULL; }
522 virtual function_type *as_a_function_type() { gcc_unreachable (); return NULL; }
523 virtual struct_ *dyn_cast_struct () { return NULL; }
524 virtual vector_type *dyn_cast_vector_type () { return NULL; }
526 /* Is it typesafe to copy to this type from rtype? */
527 virtual bool accepts_writes_from (type *rtype)
529 gcc_assert (rtype);
530 return this->unqualified ()->is_same_type_as (rtype->unqualified ());
533 virtual bool is_same_type_as (type *other)
535 return this == other;
538 /* Strip off "const" etc */
539 virtual type *unqualified ()
541 return this;
544 virtual bool is_int () const = 0;
545 virtual bool is_float () const = 0;
546 virtual bool is_bool () const = 0;
547 virtual type *is_pointer () = 0;
548 virtual type *is_array () = 0;
549 virtual bool is_void () const { return false; }
550 virtual bool has_known_size () const { return true; }
552 bool is_numeric () const
554 return is_int () || is_float () || is_bool ();
557 playback::type *
558 playback_type ()
560 return static_cast <playback::type *> (m_playback_obj);
563 virtual const char *access_as_type (reproducer &r);
565 protected:
566 type (context *ctxt)
567 : memento (ctxt),
568 m_pointer_to_this_type (NULL)
571 private:
572 type *m_pointer_to_this_type;
575 /* Result of "gcc_jit_context_get_type". */
576 class memento_of_get_type : public type
578 public:
579 memento_of_get_type (context *ctxt,
580 enum gcc_jit_types kind)
581 : type (ctxt),
582 m_kind (kind) {}
584 type *dereference () FINAL OVERRIDE;
586 size_t get_size () FINAL OVERRIDE;
588 bool accepts_writes_from (type *rtype) FINAL OVERRIDE
590 if (m_kind == GCC_JIT_TYPE_VOID_PTR)
591 if (rtype->is_pointer ())
593 /* LHS (this) is type (void *), and the RHS is a pointer:
594 accept it: */
595 return true;
598 return type::accepts_writes_from (rtype);
601 bool is_int () const FINAL OVERRIDE;
602 bool is_float () const FINAL OVERRIDE;
603 bool is_bool () const FINAL OVERRIDE;
604 type *is_pointer () FINAL OVERRIDE { return dereference (); }
605 type *is_array () FINAL OVERRIDE { return NULL; }
606 bool is_void () const FINAL OVERRIDE { return m_kind == GCC_JIT_TYPE_VOID; }
608 public:
609 void replay_into (replayer *r) FINAL OVERRIDE;
611 private:
612 string * make_debug_string () FINAL OVERRIDE;
613 void write_reproducer (reproducer &r) FINAL OVERRIDE;
615 private:
616 enum gcc_jit_types m_kind;
619 /* Result of "gcc_jit_type_get_pointer". */
620 class memento_of_get_pointer : public type
622 public:
623 memento_of_get_pointer (type *other_type)
624 : type (other_type->m_ctxt),
625 m_other_type (other_type) {}
627 type *dereference () FINAL OVERRIDE { return m_other_type; }
629 size_t get_size () FINAL OVERRIDE;
631 bool accepts_writes_from (type *rtype) FINAL OVERRIDE;
633 void replay_into (replayer *r) FINAL OVERRIDE;
635 bool is_int () const FINAL OVERRIDE { return false; }
636 bool is_float () const FINAL OVERRIDE { return false; }
637 bool is_bool () const FINAL OVERRIDE { return false; }
638 type *is_pointer () FINAL OVERRIDE { return m_other_type; }
639 type *is_array () FINAL OVERRIDE { return NULL; }
641 private:
642 string * make_debug_string () FINAL OVERRIDE;
643 void write_reproducer (reproducer &r) FINAL OVERRIDE;
645 private:
646 type *m_other_type;
649 /* A decorated version of a type, for get_const, get_volatile,
650 get_aligned, and get_vector. */
652 class decorated_type : public type
654 public:
655 decorated_type (type *other_type)
656 : type (other_type->m_ctxt),
657 m_other_type (other_type) {}
659 type *dereference () FINAL OVERRIDE { return m_other_type->dereference (); }
661 bool is_int () const FINAL OVERRIDE { return m_other_type->is_int (); }
662 bool is_float () const FINAL OVERRIDE { return m_other_type->is_float (); }
663 bool is_bool () const FINAL OVERRIDE { return m_other_type->is_bool (); }
664 type *is_pointer () FINAL OVERRIDE { return m_other_type->is_pointer (); }
665 type *is_array () FINAL OVERRIDE { return m_other_type->is_array (); }
667 protected:
668 type *m_other_type;
671 /* Result of "gcc_jit_type_get_const". */
672 class memento_of_get_const : public decorated_type
674 public:
675 memento_of_get_const (type *other_type)
676 : decorated_type (other_type) {}
678 bool accepts_writes_from (type */*rtype*/) FINAL OVERRIDE
680 /* Can't write to a "const". */
681 return false;
684 /* Strip off the "const", giving the underlying type. */
685 type *unqualified () FINAL OVERRIDE { return m_other_type; }
687 void replay_into (replayer *) FINAL OVERRIDE;
689 private:
690 string * make_debug_string () FINAL OVERRIDE;
691 void write_reproducer (reproducer &r) FINAL OVERRIDE;
694 /* Result of "gcc_jit_type_get_volatile". */
695 class memento_of_get_volatile : public decorated_type
697 public:
698 memento_of_get_volatile (type *other_type)
699 : decorated_type (other_type) {}
701 /* Strip off the "volatile", giving the underlying type. */
702 type *unqualified () FINAL OVERRIDE { return m_other_type; }
704 void replay_into (replayer *) FINAL OVERRIDE;
706 private:
707 string * make_debug_string () FINAL OVERRIDE;
708 void write_reproducer (reproducer &r) FINAL OVERRIDE;
711 /* Result of "gcc_jit_type_get_aligned". */
712 class memento_of_get_aligned : public decorated_type
714 public:
715 memento_of_get_aligned (type *other_type, size_t alignment_in_bytes)
716 : decorated_type (other_type),
717 m_alignment_in_bytes (alignment_in_bytes) {}
719 /* Strip off the alignment, giving the underlying type. */
720 type *unqualified () FINAL OVERRIDE { return m_other_type; }
722 void replay_into (replayer *) FINAL OVERRIDE;
724 private:
725 string * make_debug_string () FINAL OVERRIDE;
726 void write_reproducer (reproducer &r) FINAL OVERRIDE;
728 private:
729 size_t m_alignment_in_bytes;
732 /* Result of "gcc_jit_type_get_vector". */
733 class vector_type : public decorated_type
735 public:
736 vector_type (type *other_type, size_t num_units)
737 : decorated_type (other_type),
738 m_num_units (num_units) {}
740 size_t get_num_units () const { return m_num_units; }
742 vector_type *dyn_cast_vector_type () FINAL OVERRIDE { return this; }
744 type *get_element_type () { return m_other_type; }
746 void replay_into (replayer *) FINAL OVERRIDE;
748 private:
749 string * make_debug_string () FINAL OVERRIDE;
750 void write_reproducer (reproducer &r) FINAL OVERRIDE;
752 private:
753 size_t m_num_units;
756 class array_type : public type
758 public:
759 array_type (context *ctxt,
760 location *loc,
761 type *element_type,
762 int num_elements)
763 : type (ctxt),
764 m_loc (loc),
765 m_element_type (element_type),
766 m_num_elements (num_elements)
769 type *dereference () FINAL OVERRIDE;
771 bool is_int () const FINAL OVERRIDE { return false; }
772 bool is_float () const FINAL OVERRIDE { return false; }
773 bool is_bool () const FINAL OVERRIDE { return false; }
774 type *is_pointer () FINAL OVERRIDE { return NULL; }
775 type *is_array () FINAL OVERRIDE { return m_element_type; }
776 int num_elements () { return m_num_elements; }
778 void replay_into (replayer *) FINAL OVERRIDE;
780 private:
781 string * make_debug_string () FINAL OVERRIDE;
782 void write_reproducer (reproducer &r) FINAL OVERRIDE;
784 private:
785 location *m_loc;
786 type *m_element_type;
787 int m_num_elements;
790 class function_type : public type
792 public:
793 function_type (context *ctxt,
794 type *return_type,
795 int num_params,
796 type **param_types,
797 int is_variadic);
799 type *dereference () FINAL OVERRIDE;
800 function_type *dyn_cast_function_type () FINAL OVERRIDE { return this; }
801 function_type *as_a_function_type () FINAL OVERRIDE { return this; }
803 bool is_same_type_as (type *other) FINAL OVERRIDE;
805 bool is_int () const FINAL OVERRIDE { return false; }
806 bool is_float () const FINAL OVERRIDE { return false; }
807 bool is_bool () const FINAL OVERRIDE { return false; }
808 type *is_pointer () FINAL OVERRIDE { return NULL; }
809 type *is_array () FINAL OVERRIDE { return NULL; }
811 void replay_into (replayer *) FINAL OVERRIDE;
813 type * get_return_type () const { return m_return_type; }
814 const vec<type *> &get_param_types () const { return m_param_types; }
815 int is_variadic () const { return m_is_variadic; }
817 string * make_debug_string_with_ptr ();
819 void
820 write_deferred_reproducer (reproducer &r,
821 memento *ptr_type);
823 private:
824 string * make_debug_string () FINAL OVERRIDE;
825 string * make_debug_string_with (const char *);
826 void write_reproducer (reproducer &r) FINAL OVERRIDE;
828 private:
829 type *m_return_type;
830 auto_vec<type *> m_param_types;
831 int m_is_variadic;
834 class field : public memento
836 public:
837 field (context *ctxt,
838 location *loc,
839 type *type,
840 string *name)
841 : memento (ctxt),
842 m_loc (loc),
843 m_type (type),
844 m_name (name),
845 m_container (NULL)
848 type * get_type () const { return m_type; }
850 compound_type * get_container () const { return m_container; }
851 void set_container (compound_type *c) { m_container = c; }
853 void replay_into (replayer *) OVERRIDE;
855 void write_to_dump (dump &d) OVERRIDE;
857 playback::field *
858 playback_field () const
860 return static_cast <playback::field *> (m_playback_obj);
863 private:
864 string * make_debug_string () OVERRIDE;
865 void write_reproducer (reproducer &r) OVERRIDE;
867 protected:
868 location *m_loc;
869 type *m_type;
870 string *m_name;
871 compound_type *m_container;
875 class bitfield : public field
877 public:
878 bitfield (context *ctxt,
879 location *loc,
880 type *type,
881 int width,
882 string *name)
883 : field (ctxt, loc, type, name),
884 m_width (width)
887 void replay_into (replayer *) FINAL OVERRIDE;
889 void write_to_dump (dump &d) FINAL OVERRIDE;
891 private:
892 string * make_debug_string () FINAL OVERRIDE;
893 void write_reproducer (reproducer &r) FINAL OVERRIDE;
895 private:
896 int m_width;
899 /* Base class for struct_ and union_ */
900 class compound_type : public type
902 public:
903 compound_type (context *ctxt,
904 location *loc,
905 string *name);
907 string *get_name () const { return m_name; }
908 location *get_loc () const { return m_loc; }
909 fields * get_fields () { return m_fields; }
911 void
912 set_fields (location *loc,
913 int num_fields,
914 field **fields);
916 type *dereference () FINAL OVERRIDE;
918 bool is_int () const FINAL OVERRIDE { return false; }
919 bool is_float () const FINAL OVERRIDE { return false; }
920 bool is_bool () const FINAL OVERRIDE { return false; }
921 type *is_pointer () FINAL OVERRIDE { return NULL; }
922 type *is_array () FINAL OVERRIDE { return NULL; }
924 bool has_known_size () const FINAL OVERRIDE { return m_fields != NULL; }
926 playback::compound_type *
927 playback_compound_type ()
929 return static_cast <playback::compound_type *> (m_playback_obj);
932 private:
933 location *m_loc;
934 string *m_name;
935 fields *m_fields;
938 class struct_ : public compound_type
940 public:
941 struct_ (context *ctxt,
942 location *loc,
943 string *name);
945 struct_ *dyn_cast_struct () FINAL OVERRIDE { return this; }
947 type *
948 as_type () { return this; }
950 void replay_into (replayer *r) FINAL OVERRIDE;
952 const char *access_as_type (reproducer &r) FINAL OVERRIDE;
954 private:
955 string * make_debug_string () FINAL OVERRIDE;
956 void write_reproducer (reproducer &r) FINAL OVERRIDE;
959 // memento of struct_::set_fields
960 class fields : public memento
962 public:
963 fields (compound_type *struct_or_union,
964 int num_fields,
965 field **fields);
967 void replay_into (replayer *r) FINAL OVERRIDE;
969 void write_to_dump (dump &d) FINAL OVERRIDE;
971 int length () const { return m_fields.length (); }
972 field *get_field (int i) const { return m_fields[i]; }
974 private:
975 string * make_debug_string () FINAL OVERRIDE;
976 void write_reproducer (reproducer &r) FINAL OVERRIDE;
978 private:
979 compound_type *m_struct_or_union;
980 auto_vec<field *> m_fields;
983 class union_ : public compound_type
985 public:
986 union_ (context *ctxt,
987 location *loc,
988 string *name);
990 void replay_into (replayer *r) FINAL OVERRIDE;
992 private:
993 string * make_debug_string () FINAL OVERRIDE;
994 void write_reproducer (reproducer &r) FINAL OVERRIDE;
997 /* An abstract base class for operations that visit all rvalues within an
998 expression tree.
999 Currently the only implementation is class rvalue_usage_validator within
1000 jit-recording.c. */
1002 class rvalue_visitor
1004 public:
1005 virtual ~rvalue_visitor () {}
1006 virtual void visit (rvalue *rvalue) = 0;
1009 /* When generating debug strings for rvalues we mimic C, so we need to
1010 mimic C's precedence levels when handling compound expressions.
1011 These are in order from strongest precedence to weakest. */
1012 enum precedence
1014 PRECEDENCE_PRIMARY,
1015 PRECEDENCE_POSTFIX,
1016 PRECEDENCE_UNARY,
1017 PRECEDENCE_CAST,
1018 PRECEDENCE_MULTIPLICATIVE,
1019 PRECEDENCE_ADDITIVE,
1020 PRECEDENCE_SHIFT,
1021 PRECEDENCE_RELATIONAL,
1022 PRECEDENCE_EQUALITY,
1023 PRECEDENCE_BITWISE_AND,
1024 PRECEDENCE_BITWISE_XOR,
1025 PRECEDENCE_BITWISE_IOR,
1026 PRECEDENCE_LOGICAL_AND,
1027 PRECEDENCE_LOGICAL_OR
1030 class rvalue : public memento
1032 public:
1033 rvalue (context *ctxt,
1034 location *loc,
1035 type *type_)
1036 : memento (ctxt),
1037 m_loc (loc),
1038 m_type (type_),
1039 m_scope (NULL),
1040 m_parenthesized_string (NULL)
1042 gcc_assert (type_);
1045 location * get_loc () const { return m_loc; }
1047 /* Get the recording::type of this rvalue.
1049 Implements the post-error-checking part of
1050 gcc_jit_rvalue_get_type. */
1051 type * get_type () const { return m_type; }
1053 playback::rvalue *
1054 playback_rvalue () const
1056 return static_cast <playback::rvalue *> (m_playback_obj);
1058 rvalue *
1059 access_field (location *loc,
1060 field *field);
1062 lvalue *
1063 dereference_field (location *loc,
1064 field *field);
1066 lvalue *
1067 dereference (location *loc);
1069 void
1070 verify_valid_within_stmt (const char *api_funcname, statement *s);
1072 virtual void visit_children (rvalue_visitor *v) = 0;
1074 void set_scope (function *scope);
1075 function *get_scope () const { return m_scope; }
1077 /* Dynamic casts. */
1078 virtual param *dyn_cast_param () { return NULL; }
1079 virtual base_call *dyn_cast_base_call () { return NULL; }
1081 virtual const char *access_as_rvalue (reproducer &r);
1083 /* Get the debug string, wrapped in parentheses. */
1084 const char *
1085 get_debug_string_parens (enum precedence outer_prec);
1087 virtual bool is_constant () const { return false; }
1088 virtual bool get_wide_int (wide_int *) const { return false; }
1090 private:
1091 virtual enum precedence get_precedence () const = 0;
1093 protected:
1094 location *m_loc;
1095 type *m_type;
1097 private:
1098 function *m_scope; /* NULL for globals, non-NULL for locals/params */
1099 string *m_parenthesized_string;
1102 class lvalue : public rvalue
1104 public:
1105 lvalue (context *ctxt,
1106 location *loc,
1107 type *type_)
1108 : rvalue (ctxt, loc, type_)
1111 playback::lvalue *
1112 playback_lvalue () const
1114 return static_cast <playback::lvalue *> (m_playback_obj);
1117 lvalue *
1118 access_field (location *loc,
1119 field *field);
1121 rvalue *
1122 get_address (location *loc);
1124 rvalue *
1125 as_rvalue () { return this; }
1127 const char *access_as_rvalue (reproducer &r) OVERRIDE;
1128 virtual const char *access_as_lvalue (reproducer &r);
1129 virtual bool is_global () const { return false; }
1132 class param : public lvalue
1134 public:
1135 param (context *ctxt,
1136 location *loc,
1137 type *type,
1138 string *name)
1139 : lvalue (ctxt, loc, type),
1140 m_name (name) {}
1142 lvalue *
1143 as_lvalue () { return this; }
1145 void replay_into (replayer *r) FINAL OVERRIDE;
1147 void visit_children (rvalue_visitor *) FINAL OVERRIDE {}
1149 playback::param *
1150 playback_param () const
1152 return static_cast <playback::param *> (m_playback_obj);
1155 param *dyn_cast_param () FINAL OVERRIDE { return this; }
1157 const char *access_as_rvalue (reproducer &r) FINAL OVERRIDE;
1158 const char *access_as_lvalue (reproducer &r) FINAL OVERRIDE;
1160 private:
1161 string * make_debug_string () FINAL OVERRIDE { return m_name; }
1162 void write_reproducer (reproducer &r) FINAL OVERRIDE;
1163 enum precedence get_precedence () const FINAL OVERRIDE
1165 return PRECEDENCE_PRIMARY;
1168 private:
1169 string *m_name;
1172 class function : public memento
1174 public:
1175 function (context *ctxt,
1176 location *loc,
1177 enum gcc_jit_function_kind kind,
1178 type *return_type,
1179 string *name,
1180 int num_params,
1181 param **params,
1182 int is_variadic,
1183 enum built_in_function builtin_id);
1185 void replay_into (replayer *r) FINAL OVERRIDE;
1187 playback::function *
1188 playback_function () const
1190 return static_cast <playback::function *> (m_playback_obj);
1193 enum gcc_jit_function_kind get_kind () const { return m_kind; }
1195 lvalue *
1196 new_local (location *loc,
1197 type *type,
1198 const char *name);
1200 block*
1201 new_block (const char *name);
1203 location *get_loc () const { return m_loc; }
1204 type *get_return_type () const { return m_return_type; }
1205 string * get_name () const { return m_name; }
1206 const vec<param *> &get_params () const { return m_params; }
1208 /* Get the given param by index.
1209 Implements the post-error-checking part of
1210 gcc_jit_function_get_param. */
1211 param *get_param (int i) const { return m_params[i]; }
1213 bool is_variadic () const { return m_is_variadic; }
1215 void write_to_dump (dump &d) FINAL OVERRIDE;
1217 void validate ();
1219 void dump_to_dot (const char *path);
1221 rvalue *get_address (location *loc);
1223 private:
1224 string * make_debug_string () FINAL OVERRIDE;
1225 void write_reproducer (reproducer &r) FINAL OVERRIDE;
1227 private:
1228 location *m_loc;
1229 enum gcc_jit_function_kind m_kind;
1230 type *m_return_type;
1231 string *m_name;
1232 auto_vec<param *> m_params;
1233 int m_is_variadic;
1234 enum built_in_function m_builtin_id;
1235 auto_vec<local *> m_locals;
1236 auto_vec<block *> m_blocks;
1237 type *m_fn_ptr_type;
1240 class block : public memento
1242 public:
1243 block (function *func, int index, string *name)
1244 : memento (func->m_ctxt),
1245 m_func (func),
1246 m_index (index),
1247 m_name (name),
1248 m_statements (),
1249 m_has_been_terminated (false),
1250 m_is_reachable (false)
1254 /* Get the recording::function containing this block.
1255 Implements the post-error-checking part of
1256 gcc_jit_block_get_function. */
1257 function *get_function () { return m_func; }
1259 bool has_been_terminated () { return m_has_been_terminated; }
1260 bool is_reachable () { return m_is_reachable; }
1262 statement *
1263 add_eval (location *loc,
1264 rvalue *rvalue);
1266 statement *
1267 add_assignment (location *loc,
1268 lvalue *lvalue,
1269 rvalue *rvalue);
1271 statement *
1272 add_assignment_op (location *loc,
1273 lvalue *lvalue,
1274 enum gcc_jit_binary_op op,
1275 rvalue *rvalue);
1277 statement *
1278 add_comment (location *loc,
1279 const char *text);
1281 extended_asm *
1282 add_extended_asm (location *loc,
1283 const char *asm_template);
1285 statement *
1286 end_with_conditional (location *loc,
1287 rvalue *boolval,
1288 block *on_true,
1289 block *on_false);
1291 statement *
1292 end_with_jump (location *loc,
1293 block *target);
1295 statement *
1296 end_with_return (location *loc,
1297 rvalue *rvalue);
1299 statement *
1300 end_with_switch (location *loc,
1301 rvalue *expr,
1302 block *default_block,
1303 int num_cases,
1304 case_ **cases);
1306 extended_asm *
1307 end_with_extended_asm_goto (location *loc,
1308 const char *asm_template,
1309 int num_goto_blocks,
1310 block **goto_blocks,
1311 block *fallthrough_block);
1313 playback::block *
1314 playback_block () const
1316 return static_cast <playback::block *> (m_playback_obj);
1319 void write_to_dump (dump &d) FINAL OVERRIDE;
1321 bool validate ();
1323 location *get_loc () const;
1325 statement *get_first_statement () const;
1326 statement *get_last_statement () const;
1328 vec <block *> get_successor_blocks () const;
1330 private:
1331 string * make_debug_string () FINAL OVERRIDE;
1332 void write_reproducer (reproducer &r) FINAL OVERRIDE;
1334 void replay_into (replayer *r) FINAL OVERRIDE;
1336 void dump_to_dot (pretty_printer *pp);
1337 void dump_edges_to_dot (pretty_printer *pp);
1339 private:
1340 function *m_func;
1341 int m_index;
1342 string *m_name;
1343 auto_vec<statement *> m_statements;
1344 bool m_has_been_terminated;
1345 bool m_is_reachable;
1347 friend class function;
1350 class global : public lvalue
1352 public:
1353 global (context *ctxt,
1354 location *loc,
1355 enum gcc_jit_global_kind kind,
1356 type *type,
1357 string *name)
1358 : lvalue (ctxt, loc, type),
1359 m_kind (kind),
1360 m_name (name)
1362 m_initializer = NULL;
1363 m_initializer_num_bytes = 0;
1365 ~global ()
1367 free (m_initializer);
1370 void replay_into (replayer *) FINAL OVERRIDE;
1372 void visit_children (rvalue_visitor *) FINAL OVERRIDE {}
1374 void write_to_dump (dump &d) FINAL OVERRIDE;
1376 bool is_global () const FINAL OVERRIDE { return true; }
1378 void
1379 set_initializer (const void *initializer,
1380 size_t num_bytes)
1382 if (m_initializer)
1383 free (m_initializer);
1384 m_initializer = xmalloc (num_bytes);
1385 memcpy (m_initializer, initializer, num_bytes);
1386 m_initializer_num_bytes = num_bytes;
1389 private:
1390 string * make_debug_string () FINAL OVERRIDE { return m_name; }
1391 template <typename T>
1392 void write_initializer_reproducer (const char *id, reproducer &r);
1393 void write_reproducer (reproducer &r) FINAL OVERRIDE;
1394 enum precedence get_precedence () const FINAL OVERRIDE
1396 return PRECEDENCE_PRIMARY;
1399 private:
1400 enum gcc_jit_global_kind m_kind;
1401 string *m_name;
1402 void *m_initializer;
1403 size_t m_initializer_num_bytes;
1406 template <typename HOST_TYPE>
1407 class memento_of_new_rvalue_from_const : public rvalue
1409 public:
1410 memento_of_new_rvalue_from_const (context *ctxt,
1411 location *loc,
1412 type *type,
1413 HOST_TYPE value)
1414 : rvalue (ctxt, loc, type),
1415 m_value (value) {}
1417 void replay_into (replayer *r) FINAL OVERRIDE;
1419 void visit_children (rvalue_visitor *) FINAL OVERRIDE {}
1421 bool is_constant () const FINAL OVERRIDE { return true; }
1423 bool get_wide_int (wide_int *out) const FINAL OVERRIDE;
1425 private:
1426 string * make_debug_string () FINAL OVERRIDE;
1427 void write_reproducer (reproducer &r) FINAL OVERRIDE;
1428 enum precedence get_precedence () const FINAL OVERRIDE
1430 return PRECEDENCE_PRIMARY;
1433 private:
1434 HOST_TYPE m_value;
1437 class memento_of_new_string_literal : public rvalue
1439 public:
1440 memento_of_new_string_literal (context *ctxt,
1441 location *loc,
1442 string *value)
1443 : rvalue (ctxt, loc, ctxt->get_type (GCC_JIT_TYPE_CONST_CHAR_PTR)),
1444 m_value (value) {}
1446 void replay_into (replayer *r) FINAL OVERRIDE;
1448 void visit_children (rvalue_visitor *) FINAL OVERRIDE {}
1450 private:
1451 string * make_debug_string () FINAL OVERRIDE;
1452 void write_reproducer (reproducer &r) FINAL OVERRIDE;
1453 enum precedence get_precedence () const FINAL OVERRIDE
1455 return PRECEDENCE_PRIMARY;
1458 private:
1459 string *m_value;
1462 class memento_of_new_rvalue_from_vector : public rvalue
1464 public:
1465 memento_of_new_rvalue_from_vector (context *ctxt,
1466 location *loc,
1467 vector_type *type,
1468 rvalue **elements);
1470 void replay_into (replayer *r) FINAL OVERRIDE;
1472 void visit_children (rvalue_visitor *) FINAL OVERRIDE;
1474 private:
1475 string * make_debug_string () FINAL OVERRIDE;
1476 void write_reproducer (reproducer &r) FINAL OVERRIDE;
1477 enum precedence get_precedence () const FINAL OVERRIDE
1479 return PRECEDENCE_PRIMARY;
1482 private:
1483 vector_type *m_vector_type;
1484 auto_vec<rvalue *> m_elements;
1487 class unary_op : public rvalue
1489 public:
1490 unary_op (context *ctxt,
1491 location *loc,
1492 enum gcc_jit_unary_op op,
1493 type *result_type,
1494 rvalue *a)
1495 : rvalue (ctxt, loc, result_type),
1496 m_op (op),
1497 m_a (a)
1500 void replay_into (replayer *r) FINAL OVERRIDE;
1502 void visit_children (rvalue_visitor *v) FINAL OVERRIDE;
1504 private:
1505 string * make_debug_string () FINAL OVERRIDE;
1506 void write_reproducer (reproducer &r) FINAL OVERRIDE;
1507 enum precedence get_precedence () const FINAL OVERRIDE
1509 return PRECEDENCE_UNARY;
1512 private:
1513 enum gcc_jit_unary_op m_op;
1514 rvalue *m_a;
1517 class binary_op : public rvalue
1519 public:
1520 binary_op (context *ctxt,
1521 location *loc,
1522 enum gcc_jit_binary_op op,
1523 type *result_type,
1524 rvalue *a, rvalue *b)
1525 : rvalue (ctxt, loc, result_type),
1526 m_op (op),
1527 m_a (a),
1528 m_b (b) {}
1530 void replay_into (replayer *r) FINAL OVERRIDE;
1532 void visit_children (rvalue_visitor *v) FINAL OVERRIDE;
1534 private:
1535 string * make_debug_string () FINAL OVERRIDE;
1536 void write_reproducer (reproducer &r) FINAL OVERRIDE;
1537 enum precedence get_precedence () const FINAL OVERRIDE;
1539 private:
1540 enum gcc_jit_binary_op m_op;
1541 rvalue *m_a;
1542 rvalue *m_b;
1545 class comparison : public rvalue
1547 public:
1548 comparison (context *ctxt,
1549 location *loc,
1550 enum gcc_jit_comparison op,
1551 rvalue *a, rvalue *b)
1552 : rvalue (ctxt, loc, ctxt->get_type (GCC_JIT_TYPE_BOOL)),
1553 m_op (op),
1554 m_a (a),
1555 m_b (b)
1558 void replay_into (replayer *r) FINAL OVERRIDE;
1560 void visit_children (rvalue_visitor *v) FINAL OVERRIDE;
1562 private:
1563 string * make_debug_string () FINAL OVERRIDE;
1564 void write_reproducer (reproducer &r) FINAL OVERRIDE;
1565 enum precedence get_precedence () const FINAL OVERRIDE;
1567 private:
1568 enum gcc_jit_comparison m_op;
1569 rvalue *m_a;
1570 rvalue *m_b;
1573 class cast : public rvalue
1575 public:
1576 cast (context *ctxt,
1577 location *loc,
1578 rvalue *a,
1579 type *type_)
1580 : rvalue (ctxt, loc, type_),
1581 m_rvalue (a)
1584 void replay_into (replayer *r) FINAL OVERRIDE;
1586 void visit_children (rvalue_visitor *v) FINAL OVERRIDE;
1588 private:
1589 string * make_debug_string () FINAL OVERRIDE;
1590 void write_reproducer (reproducer &r) FINAL OVERRIDE;
1591 enum precedence get_precedence () const FINAL OVERRIDE
1593 return PRECEDENCE_CAST;
1596 private:
1597 rvalue *m_rvalue;
1600 class base_call : public rvalue
1602 public:
1603 base_call (context *ctxt,
1604 location *loc,
1605 type *type_,
1606 int numargs,
1607 rvalue **args);
1609 enum precedence get_precedence () const FINAL OVERRIDE
1611 return PRECEDENCE_POSTFIX;
1614 base_call *dyn_cast_base_call () FINAL OVERRIDE { return this; }
1616 void set_require_tail_call (bool require_tail_call)
1618 m_require_tail_call = require_tail_call;
1621 protected:
1622 void write_reproducer_tail_call (reproducer &r, const char *id);
1624 protected:
1625 auto_vec<rvalue *> m_args;
1626 bool m_require_tail_call;
1629 class call : public base_call
1631 public:
1632 call (context *ctxt,
1633 location *loc,
1634 function *func,
1635 int numargs,
1636 rvalue **args);
1638 void replay_into (replayer *r) FINAL OVERRIDE;
1640 void visit_children (rvalue_visitor *v) FINAL OVERRIDE;
1642 private:
1643 string * make_debug_string () FINAL OVERRIDE;
1644 void write_reproducer (reproducer &r) FINAL OVERRIDE;
1646 private:
1647 function *m_func;
1650 class call_through_ptr : public base_call
1652 public:
1653 call_through_ptr (context *ctxt,
1654 location *loc,
1655 rvalue *fn_ptr,
1656 int numargs,
1657 rvalue **args);
1659 void replay_into (replayer *r) FINAL OVERRIDE;
1661 void visit_children (rvalue_visitor *v) FINAL OVERRIDE;
1663 private:
1664 string * make_debug_string () FINAL OVERRIDE;
1665 void write_reproducer (reproducer &r) FINAL OVERRIDE;
1667 private:
1668 rvalue *m_fn_ptr;
1671 class array_access : public lvalue
1673 public:
1674 array_access (context *ctxt,
1675 location *loc,
1676 rvalue *ptr,
1677 rvalue *index)
1678 : lvalue (ctxt, loc, ptr->get_type ()->dereference ()),
1679 m_ptr (ptr),
1680 m_index (index)
1683 void replay_into (replayer *r) FINAL OVERRIDE;
1685 void visit_children (rvalue_visitor *v) FINAL OVERRIDE;
1687 private:
1688 string * make_debug_string () FINAL OVERRIDE;
1689 void write_reproducer (reproducer &r) FINAL OVERRIDE;
1690 enum precedence get_precedence () const FINAL OVERRIDE
1692 return PRECEDENCE_POSTFIX;
1695 private:
1696 rvalue *m_ptr;
1697 rvalue *m_index;
1700 class access_field_of_lvalue : public lvalue
1702 public:
1703 access_field_of_lvalue (context *ctxt,
1704 location *loc,
1705 lvalue *val,
1706 field *field)
1707 : lvalue (ctxt, loc, field->get_type ()),
1708 m_lvalue (val),
1709 m_field (field)
1712 void replay_into (replayer *r) FINAL OVERRIDE;
1714 void visit_children (rvalue_visitor *v) FINAL OVERRIDE;
1716 private:
1717 string * make_debug_string () FINAL OVERRIDE;
1718 void write_reproducer (reproducer &r) FINAL OVERRIDE;
1719 enum precedence get_precedence () const FINAL OVERRIDE
1721 return PRECEDENCE_POSTFIX;
1724 private:
1725 lvalue *m_lvalue;
1726 field *m_field;
1729 class access_field_rvalue : public rvalue
1731 public:
1732 access_field_rvalue (context *ctxt,
1733 location *loc,
1734 rvalue *val,
1735 field *field)
1736 : rvalue (ctxt, loc, field->get_type ()),
1737 m_rvalue (val),
1738 m_field (field)
1741 void replay_into (replayer *r) FINAL OVERRIDE;
1743 void visit_children (rvalue_visitor *v) FINAL OVERRIDE;
1745 private:
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_POSTFIX;
1753 private:
1754 rvalue *m_rvalue;
1755 field *m_field;
1758 class dereference_field_rvalue : public lvalue
1760 public:
1761 dereference_field_rvalue (context *ctxt,
1762 location *loc,
1763 rvalue *val,
1764 field *field)
1765 : lvalue (ctxt, loc, field->get_type ()),
1766 m_rvalue (val),
1767 m_field (field)
1770 void replay_into (replayer *r) FINAL OVERRIDE;
1772 void visit_children (rvalue_visitor *v) FINAL OVERRIDE;
1774 private:
1775 string * make_debug_string () FINAL OVERRIDE;
1776 void write_reproducer (reproducer &r) FINAL OVERRIDE;
1777 enum precedence get_precedence () const FINAL OVERRIDE
1779 return PRECEDENCE_POSTFIX;
1782 private:
1783 rvalue *m_rvalue;
1784 field *m_field;
1787 class dereference_rvalue : public lvalue
1789 public:
1790 dereference_rvalue (context *ctxt,
1791 location *loc,
1792 rvalue *val)
1793 : lvalue (ctxt, loc, val->get_type ()->dereference ()),
1794 m_rvalue (val) {}
1796 void replay_into (replayer *r) FINAL OVERRIDE;
1798 void visit_children (rvalue_visitor *v) FINAL OVERRIDE;
1800 private:
1801 string * make_debug_string () FINAL OVERRIDE;
1802 void write_reproducer (reproducer &r) FINAL OVERRIDE;
1803 enum precedence get_precedence () const FINAL OVERRIDE
1805 return PRECEDENCE_UNARY;
1808 private:
1809 rvalue *m_rvalue;
1812 class get_address_of_lvalue : public rvalue
1814 public:
1815 get_address_of_lvalue (context *ctxt,
1816 location *loc,
1817 lvalue *val)
1818 : rvalue (ctxt, loc, val->get_type ()->get_pointer ()),
1819 m_lvalue (val)
1822 void replay_into (replayer *r) FINAL OVERRIDE;
1824 void visit_children (rvalue_visitor *v) FINAL OVERRIDE;
1826 private:
1827 string * make_debug_string () FINAL OVERRIDE;
1828 void write_reproducer (reproducer &r) FINAL OVERRIDE;
1829 enum precedence get_precedence () const FINAL OVERRIDE
1831 return PRECEDENCE_UNARY;
1834 private:
1835 lvalue *m_lvalue;
1838 class function_pointer : public rvalue
1840 public:
1841 function_pointer (context *ctxt,
1842 location *loc,
1843 function *fn,
1844 type *type)
1845 : rvalue (ctxt, loc, type),
1846 m_fn (fn) {}
1848 void replay_into (replayer *r) FINAL OVERRIDE;
1850 void visit_children (rvalue_visitor *v) FINAL OVERRIDE;
1852 private:
1853 string * make_debug_string () FINAL OVERRIDE;
1854 void write_reproducer (reproducer &r) FINAL OVERRIDE;
1855 enum precedence get_precedence () const FINAL OVERRIDE
1857 return PRECEDENCE_UNARY;
1860 private:
1861 function *m_fn;
1864 class local : public lvalue
1866 public:
1867 local (function *func, location *loc, type *type_, string *name)
1868 : lvalue (func->m_ctxt, loc, type_),
1869 m_func (func),
1870 m_name (name)
1872 set_scope (func);
1875 void replay_into (replayer *r) FINAL OVERRIDE;
1877 void visit_children (rvalue_visitor *) FINAL OVERRIDE {}
1879 void write_to_dump (dump &d) FINAL OVERRIDE;
1881 private:
1882 string * make_debug_string () FINAL OVERRIDE { return m_name; }
1883 void write_reproducer (reproducer &r) FINAL OVERRIDE;
1884 enum precedence get_precedence () const FINAL OVERRIDE
1886 return PRECEDENCE_PRIMARY;
1889 private:
1890 function *m_func;
1891 string *m_name;
1894 class statement : public memento
1896 public:
1897 virtual vec <block *> get_successor_blocks () const;
1899 void write_to_dump (dump &d) FINAL OVERRIDE;
1901 block *get_block () const { return m_block; }
1902 location *get_loc () const { return m_loc; }
1904 protected:
1905 statement (block *b, location *loc)
1906 : memento (b->m_ctxt),
1907 m_block (b),
1908 m_loc (loc) {}
1910 playback::location *
1911 playback_location (replayer *r) const
1913 return ::gcc::jit::recording::playback_location (r, m_loc);
1916 private:
1917 block *m_block;
1918 location *m_loc;
1921 class eval : public statement
1923 public:
1924 eval (block *b,
1925 location *loc,
1926 rvalue *rvalue)
1927 : statement (b, loc),
1928 m_rvalue (rvalue) {}
1930 void replay_into (replayer *r) FINAL OVERRIDE;
1932 private:
1933 string * make_debug_string () FINAL OVERRIDE;
1934 void write_reproducer (reproducer &r) FINAL OVERRIDE;
1936 private:
1937 rvalue *m_rvalue;
1940 class assignment : public statement
1942 public:
1943 assignment (block *b,
1944 location *loc,
1945 lvalue *lvalue,
1946 rvalue *rvalue)
1947 : statement (b, loc),
1948 m_lvalue (lvalue),
1949 m_rvalue (rvalue) {}
1951 void replay_into (replayer *r) FINAL OVERRIDE;
1953 private:
1954 string * make_debug_string () FINAL OVERRIDE;
1955 void write_reproducer (reproducer &r) FINAL OVERRIDE;
1957 private:
1958 lvalue *m_lvalue;
1959 rvalue *m_rvalue;
1962 class assignment_op : public statement
1964 public:
1965 assignment_op (block *b,
1966 location *loc,
1967 lvalue *lvalue,
1968 enum gcc_jit_binary_op op,
1969 rvalue *rvalue)
1970 : statement (b, loc),
1971 m_lvalue (lvalue),
1972 m_op (op),
1973 m_rvalue (rvalue) {}
1975 void replay_into (replayer *r) FINAL OVERRIDE;
1977 private:
1978 string * make_debug_string () FINAL OVERRIDE;
1979 void write_reproducer (reproducer &r) FINAL OVERRIDE;
1981 private:
1982 lvalue *m_lvalue;
1983 enum gcc_jit_binary_op m_op;
1984 rvalue *m_rvalue;
1987 class comment : public statement
1989 public:
1990 comment (block *b,
1991 location *loc,
1992 string *text)
1993 : statement (b, loc),
1994 m_text (text) {}
1996 void replay_into (replayer *r) FINAL OVERRIDE;
1998 private:
1999 string * make_debug_string () FINAL OVERRIDE;
2000 void write_reproducer (reproducer &r) FINAL OVERRIDE;
2002 private:
2003 string *m_text;
2006 class conditional : public statement
2008 public:
2009 conditional (block *b,
2010 location *loc,
2011 rvalue *boolval,
2012 block *on_true,
2013 block *on_false)
2014 : statement (b, loc),
2015 m_boolval (boolval),
2016 m_on_true (on_true),
2017 m_on_false (on_false) {}
2019 void replay_into (replayer *r) FINAL OVERRIDE;
2021 vec <block *> get_successor_blocks () const FINAL OVERRIDE;
2023 private:
2024 string * make_debug_string () FINAL OVERRIDE;
2025 void write_reproducer (reproducer &r) FINAL OVERRIDE;
2027 private:
2028 rvalue *m_boolval;
2029 block *m_on_true;
2030 block *m_on_false;
2033 class jump : public statement
2035 public:
2036 jump (block *b,
2037 location *loc,
2038 block *target)
2039 : statement (b, loc),
2040 m_target (target) {}
2042 void replay_into (replayer *r) FINAL OVERRIDE;
2044 vec <block *> get_successor_blocks () const FINAL OVERRIDE;
2046 private:
2047 string * make_debug_string () FINAL OVERRIDE;
2048 void write_reproducer (reproducer &r) FINAL OVERRIDE;
2050 private:
2051 block *m_target;
2054 class return_ : public statement
2056 public:
2057 return_ (block *b,
2058 location *loc,
2059 rvalue *rvalue)
2060 : statement (b, loc),
2061 m_rvalue (rvalue) {}
2063 void replay_into (replayer *r) FINAL OVERRIDE;
2065 vec <block *> get_successor_blocks () const FINAL OVERRIDE;
2067 private:
2068 string * make_debug_string () FINAL OVERRIDE;
2069 void write_reproducer (reproducer &r) FINAL OVERRIDE;
2071 private:
2072 rvalue *m_rvalue;
2075 class case_ : public memento
2077 public:
2078 case_ (context *ctxt,
2079 rvalue *min_value,
2080 rvalue *max_value,
2081 block *dest_block)
2082 : memento (ctxt),
2083 m_min_value (min_value),
2084 m_max_value (max_value),
2085 m_dest_block (dest_block)
2088 rvalue *get_min_value () const { return m_min_value; }
2089 rvalue *get_max_value () const { return m_max_value; }
2090 block *get_dest_block () const { return m_dest_block; }
2092 void replay_into (replayer *) FINAL OVERRIDE { /* empty */ }
2094 void write_reproducer (reproducer &r) FINAL OVERRIDE;
2096 private:
2097 string * make_debug_string () FINAL OVERRIDE;
2099 private:
2100 rvalue *m_min_value;
2101 rvalue *m_max_value;
2102 block *m_dest_block;
2105 class switch_ : public statement
2107 public:
2108 switch_ (block *b,
2109 location *loc,
2110 rvalue *expr,
2111 block *default_block,
2112 int num_cases,
2113 case_ **cases);
2115 void replay_into (replayer *r) FINAL OVERRIDE;
2117 vec <block *> get_successor_blocks () const FINAL OVERRIDE;
2119 private:
2120 string * make_debug_string () FINAL OVERRIDE;
2121 void write_reproducer (reproducer &r) FINAL OVERRIDE;
2123 private:
2124 rvalue *m_expr;
2125 block *m_default_block;
2126 auto_vec <case_ *> m_cases;
2129 class asm_operand : public memento
2131 public:
2132 asm_operand (extended_asm *ext_asm,
2133 string *asm_symbolic_name,
2134 string *constraint);
2136 const char *get_symbolic_name () const
2138 if (m_asm_symbolic_name)
2139 return m_asm_symbolic_name->c_str ();
2140 else
2141 return NULL;
2144 const char *get_constraint () const
2146 return m_constraint->c_str ();
2149 virtual void print (pretty_printer *pp) const;
2151 private:
2152 string * make_debug_string () FINAL OVERRIDE;
2154 protected:
2155 extended_asm *m_ext_asm;
2156 string *m_asm_symbolic_name;
2157 string *m_constraint;
2160 class output_asm_operand : public asm_operand
2162 public:
2163 output_asm_operand (extended_asm *ext_asm,
2164 string *asm_symbolic_name,
2165 string *constraint,
2166 lvalue *dest)
2167 : asm_operand (ext_asm, asm_symbolic_name, constraint),
2168 m_dest (dest)
2171 lvalue *get_lvalue () const { return m_dest; }
2173 void replay_into (replayer *) FINAL OVERRIDE {}
2175 void print (pretty_printer *pp) const FINAL OVERRIDE;
2177 private:
2178 void write_reproducer (reproducer &r) FINAL OVERRIDE;
2180 private:
2181 lvalue *m_dest;
2184 class input_asm_operand : public asm_operand
2186 public:
2187 input_asm_operand (extended_asm *ext_asm,
2188 string *asm_symbolic_name,
2189 string *constraint,
2190 rvalue *src)
2191 : asm_operand (ext_asm, asm_symbolic_name, constraint),
2192 m_src (src)
2195 rvalue *get_rvalue () const { return m_src; }
2197 void replay_into (replayer *) FINAL OVERRIDE {}
2199 void print (pretty_printer *pp) const FINAL OVERRIDE;
2201 private:
2202 void write_reproducer (reproducer &r) FINAL OVERRIDE;
2204 private:
2205 rvalue *m_src;
2208 /* Abstract base class for extended_asm statements. */
2210 class extended_asm : public statement
2212 public:
2213 extended_asm (block *b,
2214 location *loc,
2215 string *asm_template)
2216 : statement (b, loc),
2217 m_asm_template (asm_template),
2218 m_is_volatile (false),
2219 m_is_inline (false)
2222 void set_volatile_flag (bool flag) { m_is_volatile = flag; }
2223 void set_inline_flag (bool flag) { m_is_inline = flag; }
2225 void add_output_operand (const char *asm_symbolic_name,
2226 const char *constraint,
2227 lvalue *dest);
2228 void add_input_operand (const char *asm_symbolic_name,
2229 const char *constraint,
2230 rvalue *src);
2231 void add_clobber (const char *victim);
2233 void replay_into (replayer *r) OVERRIDE;
2235 string *get_asm_template () const { return m_asm_template; }
2237 virtual bool is_goto () const = 0;
2238 virtual void maybe_print_gotos (pretty_printer *) const = 0;
2240 protected:
2241 void write_flags (reproducer &r);
2242 void write_clobbers (reproducer &r);
2244 private:
2245 string * make_debug_string () FINAL OVERRIDE;
2246 virtual void maybe_populate_playback_blocks
2247 (auto_vec <playback::block *> *out) = 0;
2249 protected:
2250 string *m_asm_template;
2251 bool m_is_volatile;
2252 bool m_is_inline;
2253 auto_vec<output_asm_operand *> m_output_ops;
2254 auto_vec<input_asm_operand *> m_input_ops;
2255 auto_vec<string *> m_clobbers;
2258 /* An extended_asm that's not a goto, as created by
2259 gcc_jit_block_add_extended_asm. */
2261 class extended_asm_simple : public extended_asm
2263 public:
2264 extended_asm_simple (block *b,
2265 location *loc,
2266 string *asm_template)
2267 : extended_asm (b, loc, asm_template)
2270 void write_reproducer (reproducer &r) OVERRIDE;
2271 bool is_goto () const FINAL OVERRIDE { return false; }
2272 void maybe_print_gotos (pretty_printer *) const FINAL OVERRIDE {}
2274 private:
2275 void maybe_populate_playback_blocks
2276 (auto_vec <playback::block *> *) FINAL OVERRIDE
2280 /* An extended_asm that's a asm goto, as created by
2281 gcc_jit_block_end_with_extended_asm_goto. */
2283 class extended_asm_goto : public extended_asm
2285 public:
2286 extended_asm_goto (block *b,
2287 location *loc,
2288 string *asm_template,
2289 int num_goto_blocks,
2290 block **goto_blocks,
2291 block *fallthrough_block);
2293 void replay_into (replayer *r) FINAL OVERRIDE;
2294 void write_reproducer (reproducer &r) OVERRIDE;
2296 vec <block *> get_successor_blocks () const FINAL OVERRIDE;
2298 bool is_goto () const FINAL OVERRIDE { return true; }
2299 void maybe_print_gotos (pretty_printer *) const FINAL OVERRIDE;
2301 private:
2302 void maybe_populate_playback_blocks
2303 (auto_vec <playback::block *> *out) FINAL OVERRIDE;
2305 private:
2306 auto_vec <block *> m_goto_blocks;
2307 block *m_fallthrough_block;
2310 /* A group of top-level asm statements, as created by
2311 gcc_jit_context_add_top_level_asm. */
2313 class top_level_asm : public memento
2315 public:
2316 top_level_asm (context *ctxt, location *loc, string *asm_stmts);
2318 void write_to_dump (dump &d) FINAL OVERRIDE;
2320 private:
2321 void replay_into (replayer *r) FINAL OVERRIDE;
2322 string * make_debug_string () FINAL OVERRIDE;
2323 void write_reproducer (reproducer &r) FINAL OVERRIDE;
2325 private:
2326 location *m_loc;
2327 string *m_asm_stmts;
2330 } // namespace gcc::jit::recording
2332 /* Create a recording::memento_of_new_rvalue_from_const instance and add
2333 it to this context's list of mementos.
2335 Implements the post-error-checking part of
2336 gcc_jit_context_new_rvalue_from_{int|long|double|ptr}. */
2338 template <typename HOST_TYPE>
2339 recording::rvalue *
2340 recording::context::new_rvalue_from_const (recording::type *type,
2341 HOST_TYPE value)
2343 recording::rvalue *result =
2344 new memento_of_new_rvalue_from_const <HOST_TYPE> (this, NULL, type, value);
2345 record (result);
2346 return result;
2349 } // namespace gcc::jit
2351 } // namespace gcc
2353 #endif /* JIT_RECORDING_H */