Line data Source code
1 : /* Internals of libgccjit: classes for recording calls made to the JIT API.
2 : Copyright (C) 2013-2026 Free Software Foundation, Inc.
3 : Contributed by David Malcolm <dmalcolm@redhat.com>.
4 :
5 : This file is part of GCC.
6 :
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.
11 :
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.
16 :
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/>. */
20 :
21 : #ifndef JIT_RECORDING_H
22 : #define JIT_RECORDING_H
23 :
24 : #include "jit-common.h"
25 : #include "jit-logging.h"
26 : #include "jit-target.h"
27 : #include "diagnostic-core.h"
28 : #include "libgccjit.h"
29 :
30 : #include <string>
31 : #include <vector>
32 :
33 : #include <unordered_map>
34 :
35 : class timer;
36 :
37 : extern std::unordered_map<std::string, gcc::jit::recording::function_type*>
38 : target_function_types;
39 :
40 : namespace gcc {
41 :
42 : namespace jit {
43 : extern const char * const unary_op_reproducer_strings[];
44 : extern const char * const binary_op_reproducer_strings[];
45 :
46 : class result;
47 : class dump;
48 : class reproducer;
49 :
50 : /**********************************************************************
51 : Recording.
52 : **********************************************************************/
53 :
54 : namespace recording {
55 :
56 : enum type_info_type {
57 : TYPE_INFO_ALIGN_OF,
58 : TYPE_INFO_SIZE_OF,
59 : };
60 :
61 : playback::location *
62 : playback_location (replayer *r, location *loc);
63 :
64 : const char *
65 : playback_string (string *str);
66 :
67 : playback::block *
68 : playback_block (block *b);
69 :
70 : /* A recording of a call to gcc_jit_context_enable_dump. */
71 : struct requested_dump
72 : {
73 : const char *m_dumpname;
74 : char **m_out_ptr;
75 : };
76 :
77 : /* A JIT-compilation context. */
78 : class context : public log_user
79 : {
80 : public:
81 : context (context *parent_ctxt);
82 : ~context ();
83 :
84 : builtins_manager *
85 : get_builtins_manager ();
86 :
87 : void record (memento *m);
88 : void replay_into (replayer *r);
89 : void disassociate_from_playback ();
90 :
91 : string *
92 : new_string (const char *text, bool escaped = false);
93 :
94 : location *
95 : new_location (const char *filename,
96 : int line,
97 : int column,
98 : bool created_by_user);
99 :
100 : type *
101 : get_type (enum gcc_jit_types type);
102 :
103 : type *
104 : get_int_type (int num_bytes, int is_signed);
105 :
106 : type *
107 : new_array_type (location *loc,
108 : type *element_type,
109 : uint64_t num_elements);
110 :
111 : field *
112 : new_field (location *loc,
113 : type *type,
114 : const char *name);
115 :
116 : field *
117 : new_bitfield (location *loc,
118 : type *type,
119 : int width,
120 : const char *name);
121 :
122 : struct_ *
123 : new_struct_type (location *loc,
124 : const char *name);
125 :
126 : union_ *
127 : new_union_type (location *loc,
128 : const char *name);
129 :
130 : function_type *
131 : new_function_type (type *return_type,
132 : int num_params,
133 : type **param_types,
134 : int is_variadic,
135 : bool is_target_builtin);
136 :
137 : type *
138 : new_function_ptr_type (location *loc,
139 : type *return_type,
140 : int num_params,
141 : type **param_types,
142 : int is_variadic);
143 :
144 : param *
145 : new_param (location *loc,
146 : type *type,
147 : const char *name);
148 :
149 : function *
150 : new_function (location *loc,
151 : enum gcc_jit_function_kind kind,
152 : type *return_type,
153 : const char *name,
154 : int num_params,
155 : param **params,
156 : int is_variadic,
157 : enum built_in_function builtin_id);
158 :
159 : function *
160 : get_builtin_function (const char *name);
161 :
162 : function *
163 : get_target_builtin_function (const char *name);
164 :
165 : lvalue *
166 : new_global (location *loc,
167 : enum gcc_jit_global_kind kind,
168 : type *type,
169 : const char *name);
170 :
171 : rvalue *
172 : new_ctor (location *loc,
173 : type *type,
174 : size_t num_values,
175 : field **fields,
176 : rvalue **values);
177 :
178 : void
179 : new_global_init_rvalue (lvalue *variable,
180 : rvalue *init);
181 :
182 : template <typename HOST_TYPE>
183 : rvalue *
184 : new_rvalue_from_const (type *type,
185 : HOST_TYPE value);
186 :
187 : rvalue *
188 : new_sizeof (type *type);
189 :
190 : rvalue *
191 : new_alignof (type *type);
192 :
193 : rvalue *
194 : new_string_literal (const char *value);
195 :
196 : rvalue *
197 : new_rvalue_from_vector (location *loc,
198 : vector_type *type,
199 : rvalue **elements);
200 :
201 : rvalue *
202 : new_rvalue_vector_perm (location *loc,
203 : rvalue *elements1,
204 : rvalue *elements2,
205 : rvalue *mask);
206 :
207 : rvalue *
208 : new_unary_op (location *loc,
209 : enum gcc_jit_unary_op op,
210 : type *result_type,
211 : rvalue *a);
212 :
213 : rvalue *
214 : new_binary_op (location *loc,
215 : enum gcc_jit_binary_op op,
216 : type *result_type,
217 : rvalue *a, rvalue *b);
218 :
219 : rvalue *
220 : new_comparison (location *loc,
221 : enum gcc_jit_comparison op,
222 : rvalue *a, rvalue *b);
223 :
224 : rvalue *
225 : new_call (location *loc,
226 : function *func,
227 : int numargs, rvalue **args);
228 :
229 : rvalue *
230 : new_call_through_ptr (location *loc,
231 : rvalue *fn_ptr,
232 : int numargs, rvalue **args);
233 :
234 : rvalue *
235 : new_cast (location *loc,
236 : rvalue *expr,
237 : type *type_);
238 :
239 : rvalue *
240 : new_bitcast (location *loc,
241 : rvalue *expr,
242 : type *type_);
243 :
244 : lvalue *
245 : new_array_access (location *loc,
246 : rvalue *ptr,
247 : rvalue *index);
248 :
249 : rvalue *
250 : new_convert_vector (location *loc,
251 : rvalue *vector,
252 : type *type);
253 :
254 : lvalue *
255 : new_vector_access (location *loc,
256 : rvalue *vector,
257 : rvalue *index);
258 :
259 : case_ *
260 : new_case (rvalue *min_value,
261 : rvalue *max_value,
262 : block *block);
263 :
264 : void
265 : set_str_option (enum gcc_jit_str_option opt,
266 : const char *value);
267 :
268 : const char*
269 : get_str_option (enum gcc_jit_str_option opt);
270 :
271 : void
272 : set_output_ident (const char *output_ident);
273 :
274 : bool
275 : get_abort_on_unsupported_target_builtin ();
276 :
277 : void
278 : set_abort_on_unsupported_target_builtin ();
279 :
280 : void
281 : set_int_option (enum gcc_jit_int_option opt,
282 : int value);
283 :
284 : void
285 : set_bool_option (enum gcc_jit_bool_option opt,
286 : int value);
287 :
288 : void
289 : set_inner_bool_option (enum inner_bool_option inner_opt,
290 : int value);
291 :
292 : void
293 : add_command_line_option (const char *optname);
294 :
295 : void
296 : append_command_line_options (vec <char *> *argvec);
297 :
298 : void
299 : add_driver_option (const char *optname);
300 :
301 : void
302 : append_driver_options (auto_string_vec *argvec);
303 :
304 : void
305 : enable_dump (const char *dumpname,
306 : char **out_ptr);
307 :
308 : const char *
309 : get_str_option (enum gcc_jit_str_option opt) const
310 : {
311 : return m_str_options[opt];
312 : }
313 :
314 : int
315 1381 : get_int_option (enum gcc_jit_int_option opt) const
316 : {
317 1381 : return m_int_options[opt];
318 : }
319 :
320 : int
321 31711 : get_bool_option (enum gcc_jit_bool_option opt) const
322 : {
323 30663 : return m_bool_options[opt];
324 : }
325 :
326 : int
327 11035 : get_inner_bool_option (enum inner_bool_option opt) const
328 : {
329 11035 : return m_inner_bool_options[opt];
330 : }
331 :
332 : result *
333 : compile ();
334 :
335 : void
336 : compile_to_file (enum gcc_jit_output_kind output_kind,
337 : const char *output_path);
338 :
339 : void
340 : populate_target_info ();
341 :
342 62 : target_info *move_target_info ()
343 : {
344 62 : target_info *info = m_target_info;
345 62 : m_target_info = nullptr;
346 62 : return info;
347 : }
348 :
349 : void
350 : add_diagnostic (location *loc, enum diagnostics::kind diagnostic_kind,
351 : const char *fmt, ...)
352 : GNU_PRINTF (4, 5);
353 :
354 : void
355 : add_error (location *loc, const char *fmt, ...)
356 : GNU_PRINTF(3, 4);
357 :
358 : void
359 : add_error_va (location *loc, enum diagnostics::kind diagnostic_kind,
360 : const char *fmt,
361 : va_list ap)
362 : GNU_PRINTF (4, 0);
363 :
364 : const char *
365 : get_first_error () const;
366 :
367 : const char *
368 : get_last_error () const;
369 :
370 214915 : bool errors_occurred () const
371 : {
372 214915 : if (m_parent_ctxt)
373 6770 : if (m_parent_ctxt->errors_occurred ())
374 : return true;
375 214915 : return m_error_count;
376 : }
377 :
378 : type *get_opaque_FILE_type ();
379 :
380 : void dump_to_file (const char *path, bool update_locations);
381 :
382 : void dump_reproducer_to_file (const char *path);
383 :
384 : void
385 : get_all_requested_dumps (vec <recording::requested_dump> *out);
386 :
387 400 : void set_timer (timer *t) { m_timer = t; }
388 6435 : timer *get_timer () const { return m_timer; }
389 :
390 : void add_top_level_asm (location *loc, const char *asm_stmts);
391 :
392 : private:
393 : void log_all_options () const;
394 : void log_str_option (enum gcc_jit_str_option opt) const;
395 : void log_int_option (enum gcc_jit_int_option opt) const;
396 : void log_bool_option (enum gcc_jit_bool_option opt) const;
397 : void log_inner_bool_option (enum inner_bool_option opt) const;
398 :
399 : void validate ();
400 :
401 : private:
402 : context *m_parent_ctxt;
403 :
404 : /* The ultimate ancestor of the contexts within a family tree of
405 : contexts. This has itself as its own m_toplevel_ctxt. */
406 : context *m_toplevel_ctxt;
407 :
408 : timer *m_timer;
409 :
410 : int m_error_count;
411 :
412 : char *m_first_error_str;
413 : bool m_owns_first_error_str;
414 :
415 : char *m_last_error_str;
416 : bool m_owns_last_error_str;
417 :
418 : char *m_str_options[GCC_JIT_NUM_STR_OPTIONS];
419 : int m_int_options[GCC_JIT_NUM_INT_OPTIONS];
420 : bool m_bool_options[GCC_JIT_NUM_BOOL_OPTIONS];
421 : bool m_inner_bool_options[NUM_INNER_BOOL_OPTIONS];
422 : auto_vec <char *> m_command_line_options;
423 : auto_vec <char *> m_driver_options;
424 :
425 : /* Dumpfiles that were requested via gcc_jit_context_enable_dump. */
426 : auto_vec<requested_dump> m_requested_dumps;
427 :
428 : /* Recorded API usage. */
429 : auto_vec<memento *> m_mementos;
430 :
431 : /* Specific recordings, for use by dump_to_file. */
432 : auto_vec<compound_type *> m_compound_types;
433 : auto_vec<global *> m_globals;
434 : auto_vec<function *> m_functions;
435 : auto_vec<top_level_asm *> m_top_level_asms;
436 :
437 : type *m_basic_types[NUM_GCC_JIT_TYPES];
438 : type *m_FILE_type;
439 :
440 : bool m_populated_target_info = false;
441 : bool m_abort_on_unsupported_target_builtin = false;
442 :
443 : builtins_manager *m_builtins_manager; // lazily created
444 :
445 : target_info *m_target_info;
446 : };
447 :
448 :
449 : /* An object with lifetime managed by the context i.e.
450 : it lives until the context is released, at which
451 : point it itself is cleaned up. */
452 :
453 : class memento
454 : {
455 : public:
456 142248 : virtual ~memento () {}
457 :
458 : /* Hook for replaying this. */
459 : virtual void replay_into (replayer *r) = 0;
460 :
461 227377 : void set_playback_obj (void *obj) { m_playback_obj = obj; }
462 :
463 :
464 : /* Get the context that owns this object.
465 :
466 : Implements the post-error-checking part of
467 : gcc_jit_object_get_context. */
468 91056 : context *get_context () { return m_ctxt; }
469 :
470 : memento *
471 : as_object () { return this; }
472 :
473 : /* Debugging hook, for use in generating error messages etc.
474 : Implements the post-error-checking part of
475 : gcc_jit_object_get_debug_string. */
476 : const char *
477 : get_debug_string ();
478 :
479 : virtual void write_to_dump (dump &d);
480 : virtual void write_reproducer (reproducer &r) = 0;
481 83084 : virtual location *dyn_cast_location () { return NULL; }
482 :
483 : memento (const memento&) = delete;
484 : memento& operator= (const memento&) = delete;
485 :
486 : protected:
487 4260112 : memento (context *ctxt)
488 4260112 : : m_ctxt (ctxt),
489 4260112 : m_playback_obj (NULL),
490 4260112 : m_debug_string (NULL)
491 : {
492 4260112 : gcc_assert (ctxt);
493 4260112 : }
494 :
495 11818 : string *new_string (const char *text) { return m_ctxt->new_string (text); }
496 :
497 : private:
498 : virtual string * make_debug_string () = 0;
499 :
500 : public:
501 : context *m_ctxt;
502 :
503 : protected:
504 : void *m_playback_obj;
505 :
506 : private:
507 : string *m_debug_string;
508 : };
509 :
510 : /* or just use std::string? */
511 : class string : public memento
512 : {
513 : public:
514 : string (context *ctxt, const char *text, bool escaped);
515 : ~string ();
516 :
517 61523 : const char *c_str () const { return m_buffer; }
518 :
519 : static string * from_printf (context *ctxt, const char *fmt, ...)
520 : GNU_PRINTF(2, 3);
521 :
522 92317 : void replay_into (replayer *) final override {}
523 :
524 : string (const string&) = delete;
525 : string& operator= (const string&) = delete;
526 :
527 : private:
528 : string * make_debug_string () final override;
529 : void write_reproducer (reproducer &r) final override;
530 :
531 : private:
532 : size_t m_len;
533 : char *m_buffer;
534 :
535 : /* Flag to track if this string is the result of string::make_debug_string,
536 : to avoid infinite recursion when logging all mementos: don't re-escape
537 : such strings. */
538 : bool m_escaped;
539 : };
540 :
541 : class output_ident : public memento
542 : {
543 : public:
544 : output_ident (context *ctxt, const char *text);
545 : ~output_ident ();
546 :
547 : void replay_into (replayer *) final override;
548 :
549 : output_ident (const output_ident&) = delete;
550 : output_ident& operator= (const output_ident&) = delete;
551 :
552 : private:
553 : string * make_debug_string () final override;
554 : void write_reproducer (reproducer &r) final override;
555 :
556 : private:
557 : char *m_ident;
558 : };
559 :
560 : class location : public memento
561 : {
562 : public:
563 9908 : location (context *ctxt, string *filename, int line, int column,
564 : bool created_by_user)
565 : : memento (ctxt),
566 9908 : m_filename (filename),
567 9908 : m_line (line),
568 9908 : m_column (column),
569 9908 : m_created_by_user (created_by_user)
570 : {}
571 :
572 : void replay_into (replayer *r) final override;
573 :
574 : playback::location *
575 1473 : playback_location (replayer *r)
576 : {
577 : /* Normally during playback, we can walk forwards through the list of
578 : recording objects, playing them back. The ordering of recording
579 : ensures that everything that a recording object refers to has
580 : already been played back, so we can simply look up the relevant
581 : m_playback_obj.
582 :
583 : Locations are an exception, due to the "write_to_dump" method of
584 : recording::statement. This method can set a new location on a
585 : statement after the statement is created, and thus the location
586 : appears in the context's memento list *after* the statement that
587 : refers to it.
588 :
589 : In such circumstances, the statement is replayed *before* the location,
590 : when the latter doesn't yet have a playback object.
591 :
592 : Hence we need to ensure that locations have playback objects. */
593 1473 : if (!m_playback_obj)
594 : {
595 228 : replay_into (r);
596 : }
597 1473 : gcc_assert (m_playback_obj);
598 1473 : return static_cast <playback::location *> (m_playback_obj);
599 : }
600 :
601 6494 : location *dyn_cast_location () final override { return this; }
602 6494 : bool created_by_user () const { return m_created_by_user; }
603 :
604 : private:
605 : string * make_debug_string () final override;
606 : void write_reproducer (reproducer &r) final override;
607 :
608 : private:
609 : string *m_filename;
610 : int m_line;
611 : int m_column;
612 : bool m_created_by_user;
613 : };
614 :
615 : class type : public memento
616 : {
617 : public:
618 : type *get_pointer ();
619 : type *get_const ();
620 : type *get_volatile ();
621 : type *get_restrict ();
622 : type *get_aligned (size_t alignment_in_bytes);
623 : type *get_vector (size_t num_units);
624 :
625 : /* Get the type obtained when dereferencing this type.
626 :
627 : This will return NULL if it's not valid to dereference this type.
628 : The caller is responsible for setting an error. */
629 : virtual type *dereference () = 0;
630 : /* Get the type size in bytes.
631 :
632 : This is implemented only for memento_of_get_type and
633 : memento_of_get_pointer as it is used for initializing globals of
634 : these types. */
635 0 : virtual size_t get_size () { gcc_unreachable (); }
636 :
637 : virtual type* copy (context* ctxt) = 0;
638 :
639 : /* Dynamic casts. */
640 2303 : virtual function_type *dyn_cast_function_type () { return NULL; }
641 0 : virtual function_type *as_a_function_type() { gcc_unreachable (); return NULL; }
642 470 : virtual struct_ *dyn_cast_struct () { return NULL; }
643 2565 : virtual vector_type *dyn_cast_vector_type () { return NULL; }
644 0 : virtual array_type *dyn_cast_array_type () { return NULL; }
645 0 : virtual memento_of_get_aligned *dyn_cast_aligned_type () { return NULL; }
646 :
647 : /* Is it typesafe to copy to this type from rtype? */
648 16346 : virtual bool accepts_writes_from (type *rtype)
649 : {
650 16346 : gcc_assert (rtype);
651 16346 : return this->unqualified ()->is_same_type_as (rtype->unqualified ());
652 : }
653 :
654 16363 : virtual bool is_same_type_as (type *other)
655 : {
656 32726 : if (((is_int () && other->is_int ()) || (is_float () && other->is_float ()))
657 13415 : && get_size () == other->get_size ()
658 29432 : && is_signed () == other->is_signed ())
659 : {
660 : /* LHS (this) is an integer of the same size and sign as rtype. */
661 : return true;
662 : }
663 3352 : return this == other;
664 : }
665 :
666 : /* Strip off "const" etc */
667 45354 : virtual type *unqualified ()
668 : {
669 45354 : return this;
670 : }
671 :
672 : virtual bool is_int () const = 0;
673 : virtual bool is_float () const = 0;
674 : virtual bool is_bool () const = 0;
675 10 : virtual bool is_numeric_vector () const { return false; }
676 : virtual type *is_pointer () = 0;
677 10 : virtual type *is_volatile () { return NULL; }
678 0 : virtual type *is_restrict () { return NULL; }
679 2 : virtual type *is_const () { return NULL; }
680 6 : virtual type *is_aligned () { return NULL; }
681 : virtual type *is_array () = 0;
682 370 : virtual struct_ *is_struct () { return NULL; }
683 650 : virtual bool is_union () const { return false; }
684 5687 : virtual bool is_void () const { return false; }
685 180 : virtual vector_type *is_vector () { return NULL; }
686 10571 : virtual bool has_known_size () const { return true; }
687 : virtual bool is_signed () const = 0;
688 :
689 14012 : bool is_numeric () const
690 : {
691 14012 : return is_int () || is_float () || is_bool ();
692 : }
693 :
694 : playback::type *
695 72634 : playback_type ()
696 : {
697 67082 : return static_cast <playback::type *> (m_playback_obj);
698 : }
699 :
700 : virtual const char *access_as_type (reproducer &r);
701 :
702 : protected:
703 4015878 : type (context *ctxt)
704 : : memento (ctxt),
705 4551931 : m_pointer_to_this_type (NULL)
706 : {}
707 :
708 : private:
709 : type *m_pointer_to_this_type;
710 : };
711 :
712 : /* Result of "gcc_jit_context_get_type". */
713 : class memento_of_get_type : public type
714 : {
715 : public:
716 2028032 : memento_of_get_type (context *ctxt,
717 : enum gcc_jit_types kind)
718 : : type (ctxt),
719 2028032 : m_kind (kind) {}
720 :
721 : type *dereference () final override;
722 :
723 : size_t get_size () final override;
724 :
725 20 : type* copy (context* ctxt) final override
726 : {
727 20 : return ctxt->get_type (m_kind);
728 : }
729 :
730 14438 : bool accepts_writes_from (type *rtype) final override
731 : {
732 14438 : if (m_kind == GCC_JIT_TYPE_VOID_PTR)
733 : {
734 230 : if (rtype->is_pointer ())
735 : {
736 : /* LHS (this) is type (void *), and the RHS is a pointer:
737 : accept it: */
738 : return true;
739 : }
740 : }
741 :
742 14264 : return type::accepts_writes_from (rtype);
743 : }
744 :
745 : bool is_int () const final override;
746 : bool is_float () const final override;
747 : bool is_bool () const final override;
748 1067 : type *is_pointer () final override { return dereference (); }
749 570 : type *is_array () final override { return NULL; }
750 16279 : bool is_void () const final override { return m_kind == GCC_JIT_TYPE_VOID; }
751 : bool is_signed () const final override;
752 :
753 : public:
754 : void replay_into (replayer *r) final override;
755 :
756 : private:
757 : string * make_debug_string () final override;
758 : void write_reproducer (reproducer &r) final override;
759 :
760 : private:
761 : enum gcc_jit_types m_kind;
762 : };
763 :
764 : /* Result of "gcc_jit_type_get_pointer". */
765 : class memento_of_get_pointer : public type
766 : {
767 : public:
768 44866 : memento_of_get_pointer (type *other_type)
769 : : type (other_type->m_ctxt),
770 44866 : m_other_type (other_type) {}
771 :
772 1094 : type *dereference () final override { return m_other_type; }
773 :
774 0 : type* copy (context* ctxt) final override
775 : {
776 0 : type* result = new memento_of_get_pointer (m_other_type->copy (ctxt));
777 0 : ctxt->record (result);
778 0 : return result;
779 : }
780 :
781 : size_t get_size () final override;
782 :
783 : bool accepts_writes_from (type *rtype) final override;
784 :
785 : void replay_into (replayer *r) final override;
786 :
787 444 : bool is_int () const final override { return false; }
788 412 : bool is_float () const final override { return false; }
789 390 : bool is_bool () const final override { return false; }
790 3291 : type *is_pointer () final override { return m_other_type; }
791 0 : type *is_array () final override { return NULL; }
792 0 : bool is_signed () const final override { return false; }
793 :
794 : private:
795 : string * make_debug_string () final override;
796 : void write_reproducer (reproducer &r) final override;
797 :
798 : private:
799 : type *m_other_type;
800 : };
801 :
802 : /* A decorated version of a type, for get_const, get_volatile,
803 : get_aligned, get_restrict, and get_vector. */
804 :
805 : class decorated_type : public type
806 : {
807 : public:
808 1434591 : decorated_type (type *other_type)
809 : : type (other_type->m_ctxt),
810 2869182 : m_other_type (other_type) {}
811 :
812 40 : type *dereference () final override { return m_other_type->dereference (); }
813 :
814 35 : size_t get_size () final override { return m_other_type->get_size (); };
815 :
816 318 : bool is_int () const override { return m_other_type->is_int (); }
817 346 : bool is_float () const final override { return m_other_type->is_float (); }
818 222 : bool is_bool () const final override { return m_other_type->is_bool (); }
819 0 : bool is_numeric_vector () const override {
820 0 : return m_other_type->is_numeric_vector ();
821 : }
822 384 : type *is_pointer () final override { return m_other_type->is_pointer (); }
823 305 : type *is_array () final override { return m_other_type->is_array (); }
824 0 : struct_ *is_struct () final override { return m_other_type->is_struct (); }
825 27 : bool is_signed () const final override { return m_other_type->is_signed (); }
826 :
827 : protected:
828 : type *m_other_type;
829 : };
830 :
831 : /* Result of "gcc_jit_type_get_const". */
832 : class memento_of_get_const : public decorated_type
833 : {
834 : public:
835 8208 : memento_of_get_const (type *other_type)
836 8208 : : decorated_type (other_type) {}
837 :
838 111 : bool accepts_writes_from (type */*rtype*/) final override
839 : {
840 : /* Can't write to a "const". */
841 111 : return false;
842 : }
843 :
844 0 : type* copy (context* ctxt) final override
845 : {
846 0 : type* result = new memento_of_get_const (m_other_type->copy (ctxt));
847 0 : ctxt->record (result);
848 0 : return result;
849 : }
850 :
851 : /* Strip off the "const", giving the underlying type. */
852 961 : type *unqualified () final override { return m_other_type; }
853 :
854 19 : bool is_same_type_as (type *other) final override
855 : {
856 19 : if (!other->is_const ())
857 : return false;
858 17 : return m_other_type->is_same_type_as (other->is_const ());
859 : }
860 :
861 34 : type *is_const () final override { return m_other_type; }
862 :
863 : void replay_into (replayer *) final override;
864 :
865 : private:
866 : string * make_debug_string () final override;
867 : void write_reproducer (reproducer &r) final override;
868 : };
869 :
870 : /* Result of "gcc_jit_type_get_volatile". */
871 : class memento_of_get_volatile : public decorated_type
872 : {
873 : public:
874 291 : memento_of_get_volatile (type *other_type)
875 291 : : decorated_type (other_type) {}
876 :
877 25 : bool is_same_type_as (type *other) final override
878 : {
879 25 : if (!other->is_volatile ())
880 : return false;
881 15 : return m_other_type->is_same_type_as (other->is_volatile ());
882 : }
883 :
884 0 : type* copy (context* ctxt) final override
885 : {
886 0 : type* result = new memento_of_get_volatile (m_other_type->copy (ctxt));
887 0 : ctxt->record (result);
888 0 : return result;
889 : }
890 :
891 : /* Strip off the "volatile", giving the underlying type. */
892 241 : type *unqualified () final override { return m_other_type; }
893 :
894 30 : type *is_volatile () final override { return m_other_type; }
895 :
896 : void replay_into (replayer *) final override;
897 :
898 : private:
899 : string * make_debug_string () final override;
900 : void write_reproducer (reproducer &r) final override;
901 : };
902 :
903 : /* Result of "gcc_jit_type_get_restrict". */
904 : class memento_of_get_restrict : public decorated_type
905 : {
906 : public:
907 10 : memento_of_get_restrict (type *other_type)
908 10 : : decorated_type (other_type) {}
909 :
910 0 : bool is_same_type_as (type *other) final override
911 : {
912 0 : if (!other->is_restrict ())
913 : return false;
914 0 : return m_other_type->is_same_type_as (other->is_restrict ());
915 : }
916 :
917 0 : type* copy (context* ctxt) final override
918 : {
919 0 : type* result = new memento_of_get_restrict (m_other_type->copy (ctxt));
920 0 : ctxt->record (result);
921 0 : return result;
922 : }
923 :
924 : /* Strip off the "restrict", giving the underlying type. */
925 0 : type *unqualified () final override { return m_other_type; }
926 :
927 0 : type *is_restrict () final override { return m_other_type; }
928 :
929 : void replay_into (replayer *) final override;
930 :
931 : private:
932 : string * make_debug_string () final override;
933 : void write_reproducer (reproducer &r) final override;
934 : };
935 :
936 : /* Result of "gcc_jit_type_get_aligned". */
937 : class memento_of_get_aligned : public decorated_type
938 : {
939 : public:
940 414 : memento_of_get_aligned (type *other_type, size_t alignment_in_bytes)
941 : : decorated_type (other_type),
942 414 : m_alignment_in_bytes (alignment_in_bytes) {}
943 :
944 6 : bool is_same_type_as (type *other) final override
945 : {
946 6 : if (!other->is_aligned ())
947 : {
948 6 : return m_other_type->is_same_type_as (other);
949 : }
950 0 : return m_alignment_in_bytes
951 0 : == other->dyn_cast_aligned_type ()->m_alignment_in_bytes
952 0 : && m_other_type->is_same_type_as (other->is_aligned ());
953 : }
954 :
955 0 : type *is_aligned () final override { return m_other_type; }
956 :
957 0 : type* copy (context* ctxt) final override
958 : {
959 0 : type* result = new memento_of_get_aligned (m_other_type->copy (ctxt),
960 0 : m_alignment_in_bytes);
961 0 : ctxt->record (result);
962 0 : return result;
963 : }
964 :
965 : /* Strip off the alignment, giving the underlying type. */
966 945 : type *unqualified () final override { return m_other_type; }
967 :
968 : void replay_into (replayer *) final override;
969 0 : memento_of_get_aligned *dyn_cast_aligned_type () final override
970 : {
971 0 : return this;
972 : }
973 :
974 0 : array_type *dyn_cast_array_type () final override
975 : {
976 0 : return m_other_type->dyn_cast_array_type ();
977 : }
978 :
979 30 : vector_type *dyn_cast_vector_type () final override {
980 30 : return m_other_type->dyn_cast_vector_type ();
981 : }
982 :
983 : private:
984 : string * make_debug_string () final override;
985 : void write_reproducer (reproducer &r) final override;
986 :
987 : private:
988 : size_t m_alignment_in_bytes;
989 : };
990 :
991 : /* Result of "gcc_jit_type_get_vector". */
992 : class vector_type : public decorated_type
993 : {
994 : public:
995 1425668 : vector_type (type *other_type, size_t num_units)
996 : : decorated_type (other_type),
997 1425533 : m_num_units (num_units) {}
998 :
999 237 : bool is_int () const final override {
1000 237 : return false;
1001 : }
1002 :
1003 80 : bool is_numeric_vector () const final override {
1004 80 : return true;
1005 : }
1006 :
1007 0 : type* copy (context* ctxt) final override
1008 : {
1009 0 : type* result = new vector_type (m_other_type->copy (ctxt), m_num_units);
1010 0 : ctxt->record (result);
1011 0 : return result;
1012 : }
1013 :
1014 855 : size_t get_num_units () const { return m_num_units; }
1015 :
1016 1041 : vector_type *dyn_cast_vector_type () final override { return this; }
1017 :
1018 180 : type *get_element_type () { return m_other_type; }
1019 :
1020 : void replay_into (replayer *) final override;
1021 :
1022 763 : bool is_same_type_as (type *other) final override
1023 : {
1024 763 : vector_type *other_vec_type = other->dyn_cast_vector_type ();
1025 763 : if (other_vec_type == NULL)
1026 : return false;
1027 681 : return get_num_units () == other_vec_type->get_num_units ()
1028 681 : && get_element_type ()->is_same_type_as (
1029 : other_vec_type->get_element_type ());
1030 : }
1031 :
1032 15 : vector_type *is_vector () final override { return this; }
1033 :
1034 : private:
1035 : string * make_debug_string () final override;
1036 : void write_reproducer (reproducer &r) final override;
1037 :
1038 : private:
1039 : size_t m_num_units;
1040 : };
1041 :
1042 : class array_type : public type
1043 : {
1044 : public:
1045 410 : array_type (context *ctxt,
1046 : location *loc,
1047 : type *element_type,
1048 : uint64_t num_elements)
1049 : : type (ctxt),
1050 410 : m_loc (loc),
1051 410 : m_element_type (element_type),
1052 410 : m_num_elements (num_elements)
1053 : {}
1054 :
1055 : type *dereference () final override;
1056 :
1057 80 : bool is_same_type_as (type *other) final override
1058 : {
1059 80 : array_type *other_array_type = other->dyn_cast_array_type ();
1060 80 : if (!other_array_type)
1061 : return false;
1062 80 : return m_num_elements == other_array_type->m_num_elements
1063 80 : && m_element_type->is_same_type_as (other_array_type->m_element_type);
1064 : }
1065 :
1066 80 : array_type *dyn_cast_array_type () final override { return this; }
1067 :
1068 0 : type* copy (context* ctxt) final override
1069 : {
1070 0 : type* result = new array_type (ctxt, m_loc, m_element_type->copy (ctxt),
1071 0 : m_num_elements);
1072 0 : ctxt->record (result);
1073 0 : return result;
1074 : }
1075 :
1076 5 : bool is_int () const final override { return false; }
1077 5 : bool is_float () const final override { return false; }
1078 5 : bool is_bool () const final override { return false; }
1079 35 : type *is_pointer () final override { return NULL; }
1080 15 : type *is_array () final override { return m_element_type; }
1081 285 : uint64_t num_elements () { return m_num_elements; }
1082 0 : bool is_signed () const final override { return false; }
1083 :
1084 : void replay_into (replayer *) final override;
1085 :
1086 : private:
1087 : string * make_debug_string () final override;
1088 : void write_reproducer (reproducer &r) final override;
1089 :
1090 : private:
1091 : location *m_loc;
1092 : type *m_element_type;
1093 : uint64_t m_num_elements;
1094 : };
1095 :
1096 : class function_type : public type
1097 : {
1098 : public:
1099 : function_type (context *ctxt,
1100 : type *return_type,
1101 : int num_params,
1102 : type **param_types,
1103 : int is_variadic,
1104 : bool is_target_builtin);
1105 :
1106 : type *dereference () final override;
1107 215 : function_type *dyn_cast_function_type () final override { return this; }
1108 13765 : function_type *as_a_function_type () final override { return this; }
1109 :
1110 : bool is_same_type_as (type *other) final override;
1111 :
1112 10 : type* copy (context* ctxt) final override
1113 : {
1114 10 : auto_vec<type *> new_params{};
1115 20 : for (size_t i = 0; i < m_param_types.length (); i++)
1116 10 : new_params.safe_push (m_param_types[i]->copy (ctxt));
1117 :
1118 20 : type* result = new function_type (ctxt, m_return_type->copy (ctxt),
1119 20 : m_param_types.length (),
1120 : new_params.address (),
1121 30 : m_is_variadic, m_is_target_builtin);
1122 10 : ctxt->record (result);
1123 10 : return result;
1124 10 : }
1125 :
1126 0 : bool is_int () const final override { return false; }
1127 0 : bool is_float () const final override { return false; }
1128 0 : bool is_bool () const final override { return false; }
1129 0 : type *is_pointer () final override { return NULL; }
1130 0 : type *is_array () final override { return NULL; }
1131 0 : bool is_signed () const final override { return false; }
1132 :
1133 : void replay_into (replayer *) final override;
1134 :
1135 13790 : type * get_return_type () const { return m_return_type; }
1136 10 : const vec<type *> &get_param_types () const { return m_param_types; }
1137 13790 : int is_variadic () const { return m_is_variadic; }
1138 :
1139 : string * make_debug_string_with_ptr ();
1140 :
1141 : void
1142 : write_deferred_reproducer (reproducer &r,
1143 : memento *ptr_type);
1144 :
1145 : private:
1146 : string * make_debug_string () final override;
1147 : string * make_debug_string_with (const char *);
1148 : void write_reproducer (reproducer &r) final override;
1149 :
1150 : private:
1151 : type *m_return_type;
1152 : auto_vec<type *> m_param_types;
1153 : int m_is_variadic;
1154 : bool m_is_target_builtin;
1155 : };
1156 :
1157 : class field : public memento
1158 : {
1159 : public:
1160 4630 : field (context *ctxt,
1161 : location *loc,
1162 : type *type,
1163 : string *name)
1164 : : memento (ctxt),
1165 4630 : m_loc (loc),
1166 4630 : m_type (type),
1167 4630 : m_name (name),
1168 4520 : m_container (NULL)
1169 : {}
1170 :
1171 2434 : type * get_type () const { return m_type; }
1172 :
1173 10082 : compound_type * get_container () const { return m_container; }
1174 3659 : void set_container (compound_type *c) { m_container = c; }
1175 :
1176 : void replay_into (replayer *) override;
1177 :
1178 : void write_to_dump (dump &d) override;
1179 :
1180 : playback::field *
1181 5594 : playback_field () const
1182 : {
1183 5594 : return static_cast <playback::field *> (m_playback_obj);
1184 : }
1185 :
1186 : private:
1187 : string * make_debug_string () override;
1188 : void write_reproducer (reproducer &r) override;
1189 :
1190 : protected:
1191 : location *m_loc;
1192 : type *m_type;
1193 : string *m_name;
1194 : compound_type *m_container;
1195 : };
1196 :
1197 :
1198 : class bitfield : public field
1199 : {
1200 : public:
1201 110 : bitfield (context *ctxt,
1202 : location *loc,
1203 : type *type,
1204 : int width,
1205 : string *name)
1206 : : field (ctxt, loc, type, name),
1207 110 : m_width (width)
1208 : {}
1209 :
1210 : void replay_into (replayer *) final override;
1211 :
1212 : void write_to_dump (dump &d) final override;
1213 :
1214 : private:
1215 : string * make_debug_string () final override;
1216 : void write_reproducer (reproducer &r) final override;
1217 :
1218 : private:
1219 : int m_width;
1220 : };
1221 :
1222 : /* Base class for struct_ and union_ */
1223 : class compound_type : public type
1224 : {
1225 : public:
1226 : compound_type (context *ctxt,
1227 : location *loc,
1228 : string *name);
1229 :
1230 1803 : string *get_name () const { return m_name; }
1231 1679 : location *get_loc () const { return m_loc; }
1232 717 : fields * get_fields () { return m_fields; }
1233 :
1234 : void
1235 : set_fields (location *loc,
1236 : int num_fields,
1237 : field **fields);
1238 :
1239 : type *dereference () final override;
1240 :
1241 887 : bool is_int () const final override { return false; }
1242 867 : bool is_float () const final override { return false; }
1243 133 : bool is_bool () const final override { return false; }
1244 159 : type *is_pointer () final override { return NULL; }
1245 1350 : type *is_array () final override { return NULL; }
1246 0 : bool is_signed () const final override { return false; }
1247 :
1248 840 : bool has_known_size () const final override { return m_fields != NULL; }
1249 :
1250 : playback::compound_type *
1251 737 : playback_compound_type ()
1252 : {
1253 737 : return static_cast <playback::compound_type *> (m_playback_obj);
1254 : }
1255 :
1256 : protected:
1257 : location *m_loc;
1258 : string *m_name;
1259 :
1260 : private:
1261 : fields *m_fields;
1262 : };
1263 :
1264 : class struct_ : public compound_type
1265 : {
1266 : public:
1267 : struct_ (context *ctxt,
1268 : location *loc,
1269 : string *name);
1270 :
1271 803 : struct_ *dyn_cast_struct () final override { return this; }
1272 :
1273 0 : type* copy (context* ctxt) final override
1274 : {
1275 0 : type* result = new struct_ (ctxt, m_loc, m_name);
1276 0 : ctxt->record (result);
1277 0 : return result;
1278 : }
1279 :
1280 : type *
1281 1027 : as_type () { return this; }
1282 :
1283 : void replay_into (replayer *r) final override;
1284 :
1285 : const char *access_as_type (reproducer &r) final override;
1286 :
1287 925 : struct_ *is_struct () final override { return this; }
1288 :
1289 : private:
1290 : string * make_debug_string () final override;
1291 : void write_reproducer (reproducer &r) final override;
1292 : };
1293 :
1294 : // memento of struct_::set_fields
1295 : class fields : public memento
1296 : {
1297 : public:
1298 : fields (compound_type *struct_or_union,
1299 : int num_fields,
1300 : field **fields);
1301 :
1302 : void replay_into (replayer *r) final override;
1303 :
1304 : void write_to_dump (dump &d) final override;
1305 :
1306 1580 : int length () const { return m_fields.length (); }
1307 1145 : field *get_field (int i) const { return m_fields[i]; }
1308 :
1309 : private:
1310 : string * make_debug_string () final override;
1311 : void write_reproducer (reproducer &r) final override;
1312 :
1313 : private:
1314 : compound_type *m_struct_or_union;
1315 : auto_vec<field *> m_fields;
1316 : };
1317 :
1318 : class union_ : public compound_type
1319 : {
1320 : public:
1321 : union_ (context *ctxt,
1322 : location *loc,
1323 : string *name);
1324 :
1325 : void replay_into (replayer *r) final override;
1326 :
1327 0 : type* copy (context* ctxt) final override
1328 : {
1329 0 : type* result = new union_ (ctxt, m_loc, m_name);
1330 0 : ctxt->record (result);
1331 0 : return result;
1332 : }
1333 :
1334 240 : bool is_union () const final override { return true; }
1335 :
1336 : private:
1337 : string * make_debug_string () final override;
1338 : void write_reproducer (reproducer &r) final override;
1339 : };
1340 :
1341 : /* An abstract base class for operations that visit all rvalues within an
1342 : expression tree.
1343 : Currently the only implementation is class rvalue_usage_validator within
1344 : jit-recording.cc. */
1345 :
1346 17564 : class rvalue_visitor
1347 : {
1348 : public:
1349 17563 : virtual ~rvalue_visitor () {}
1350 : virtual void visit (rvalue *rvalue) = 0;
1351 : };
1352 :
1353 : /* When generating debug strings for rvalues we mimic C, so we need to
1354 : mimic C's precedence levels when handling compound expressions.
1355 : These are in order from strongest precedence to weakest. */
1356 : enum precedence
1357 : {
1358 : PRECEDENCE_PRIMARY,
1359 : PRECEDENCE_POSTFIX,
1360 : PRECEDENCE_UNARY,
1361 : PRECEDENCE_CAST,
1362 : PRECEDENCE_MULTIPLICATIVE,
1363 : PRECEDENCE_ADDITIVE,
1364 : PRECEDENCE_SHIFT,
1365 : PRECEDENCE_RELATIONAL,
1366 : PRECEDENCE_EQUALITY,
1367 : PRECEDENCE_BITWISE_AND,
1368 : PRECEDENCE_BITWISE_XOR,
1369 : PRECEDENCE_BITWISE_IOR,
1370 : PRECEDENCE_LOGICAL_AND,
1371 : PRECEDENCE_LOGICAL_OR
1372 : };
1373 :
1374 2479 : class rvalue : public memento
1375 : {
1376 : public:
1377 48137 : rvalue (context *ctxt,
1378 : location *loc,
1379 : type *type_)
1380 : : memento (ctxt),
1381 48138 : m_loc (loc),
1382 48138 : m_type (type_),
1383 48138 : m_scope (NULL),
1384 48137 : m_parenthesized_string (NULL)
1385 : {
1386 48138 : gcc_assert (type_);
1387 48138 : }
1388 :
1389 30 : location * get_loc () const { return m_loc; }
1390 :
1391 : /* Get the recording::type of this rvalue.
1392 :
1393 : Implements the post-error-checking part of
1394 : gcc_jit_rvalue_get_type. */
1395 37193 : type * get_type () const { return m_type; }
1396 :
1397 : playback::rvalue *
1398 26550 : playback_rvalue () const
1399 : {
1400 25245 : return static_cast <playback::rvalue *> (m_playback_obj);
1401 : }
1402 : rvalue *
1403 : access_field (location *loc,
1404 : field *field);
1405 :
1406 : lvalue *
1407 : dereference_field (location *loc,
1408 : field *field);
1409 :
1410 : lvalue *
1411 : dereference (location *loc);
1412 :
1413 : void
1414 : verify_valid_within_stmt (const char *api_funcname, statement *s);
1415 :
1416 : bool verify_valid_within_global_init (const char *api_funcname,
1417 : lvalue *global);
1418 :
1419 : virtual void visit_children (rvalue_visitor *v) = 0;
1420 :
1421 : void set_scope (function *scope);
1422 61586 : function *get_scope () const { return m_scope; }
1423 :
1424 : /* Dynamic casts. */
1425 19507 : virtual param *dyn_cast_param () { return NULL; }
1426 0 : virtual base_call *dyn_cast_base_call () { return NULL; }
1427 :
1428 : virtual const char *access_as_rvalue (reproducer &r);
1429 :
1430 : /* Get the debug string, wrapped in parentheses. */
1431 : const char *
1432 : get_debug_string_parens (enum precedence outer_prec);
1433 :
1434 5 : virtual bool is_constant () const { return false; }
1435 0 : virtual bool get_wide_int (wide_int *) const { return false; }
1436 :
1437 : private:
1438 : virtual enum precedence get_precedence () const = 0;
1439 :
1440 : protected:
1441 : location *m_loc;
1442 : type *m_type;
1443 :
1444 : private:
1445 : function *m_scope; /* NULL for globals, non-NULL for locals/params */
1446 : string *m_parenthesized_string;
1447 : };
1448 :
1449 4958 : class lvalue : public rvalue
1450 : {
1451 : public:
1452 30416 : lvalue (context *ctxt,
1453 : location *loc,
1454 : type *type_)
1455 : : rvalue (ctxt, loc, type_),
1456 30416 : m_link_section (NULL),
1457 30416 : m_reg_name (NULL),
1458 30416 : m_tls_model (GCC_JIT_TLS_MODEL_NONE),
1459 30416 : m_alignment (0),
1460 30416 : m_string_attributes ()
1461 30416 : {}
1462 :
1463 : playback::lvalue *
1464 8415 : playback_lvalue () const
1465 : {
1466 3105 : return static_cast <playback::lvalue *> (m_playback_obj);
1467 : }
1468 :
1469 : lvalue *
1470 : access_field (location *loc,
1471 : field *field);
1472 :
1473 : rvalue *
1474 : get_address (location *loc);
1475 :
1476 : rvalue *
1477 14658 : as_rvalue () { return this; }
1478 :
1479 : const char *access_as_rvalue (reproducer &r) override;
1480 :
1481 : void add_string_attribute (gcc_jit_variable_attribute attribute, const char* value);
1482 :
1483 4708 : bool get_readonly () const
1484 : {
1485 4708 : return m_readonly;
1486 : }
1487 :
1488 10 : void set_readonly ()
1489 : {
1490 10 : m_readonly = true;
1491 : }
1492 :
1493 : virtual const char *access_as_lvalue (reproducer &r);
1494 0 : virtual bool is_global () const { return false; }
1495 0 : virtual bool is_local () const { return false; }
1496 : void set_tls_model (enum gcc_jit_tls_model model);
1497 : void set_link_section (const char *name);
1498 : void set_register_name (const char *reg_name);
1499 : void set_alignment (unsigned bytes);
1500 10 : unsigned get_alignment () const { return m_alignment; }
1501 :
1502 : protected:
1503 : string *m_link_section;
1504 : string *m_reg_name;
1505 : enum gcc_jit_tls_model m_tls_model;
1506 : unsigned m_alignment;
1507 : std::vector<std::pair<gcc_jit_variable_attribute,
1508 : std::string>> m_string_attributes;
1509 : bool m_readonly = false;
1510 : };
1511 :
1512 : class param : public lvalue
1513 : {
1514 : public:
1515 20959 : param (context *ctxt,
1516 : location *loc,
1517 : type *type,
1518 : string *name)
1519 : : lvalue (ctxt, loc, type),
1520 20959 : m_name (name) {}
1521 :
1522 : lvalue *
1523 1758 : as_lvalue () { return this; }
1524 :
1525 : void replay_into (replayer *r) final override;
1526 :
1527 6295 : void visit_children (rvalue_visitor *) final override {}
1528 :
1529 : playback::param *
1530 18208 : playback_param () const
1531 : {
1532 18208 : return static_cast <playback::param *> (m_playback_obj);
1533 : }
1534 :
1535 5 : param *dyn_cast_param () final override { return this; }
1536 :
1537 : const char *access_as_rvalue (reproducer &r) final override;
1538 : const char *access_as_lvalue (reproducer &r) final override;
1539 :
1540 : private:
1541 7548 : string * make_debug_string () final override { return m_name; }
1542 : void write_reproducer (reproducer &r) final override;
1543 5363 : enum precedence get_precedence () const final override
1544 : {
1545 5363 : return PRECEDENCE_PRIMARY;
1546 : }
1547 :
1548 : private:
1549 : string *m_name;
1550 : };
1551 :
1552 : class function : public memento
1553 : {
1554 : public:
1555 : function (context *ctxt,
1556 : location *loc,
1557 : enum gcc_jit_function_kind kind,
1558 : type *return_type,
1559 : string *name,
1560 : int num_params,
1561 : param **params,
1562 : int is_variadic,
1563 : enum built_in_function builtin_id,
1564 : bool is_target_builtin);
1565 :
1566 : void replay_into (replayer *r) final override;
1567 :
1568 : playback::function *
1569 10755 : playback_function () const
1570 : {
1571 10755 : return static_cast <playback::function *> (m_playback_obj);
1572 : }
1573 :
1574 10991 : enum gcc_jit_function_kind get_kind () const { return m_kind; }
1575 :
1576 : lvalue *
1577 : new_local (location *loc,
1578 : type *type,
1579 : const char *name);
1580 :
1581 : lvalue *
1582 : new_temp (location *loc,
1583 : type *type);
1584 :
1585 : block*
1586 : new_block (const char *name);
1587 :
1588 : location *get_loc () const { return m_loc; }
1589 5484 : type *get_return_type () const { return m_return_type; }
1590 25 : string * get_name () const { return m_name; }
1591 : const vec<param *> &get_params () const { return m_params; }
1592 :
1593 : /* Get the given param by index.
1594 : Implements the post-error-checking part of
1595 : gcc_jit_function_get_param. */
1596 845 : param *get_param (int i) const { return m_params[i]; }
1597 :
1598 830 : bool is_variadic () const { return m_is_variadic; }
1599 :
1600 : void write_to_dump (dump &d) final override;
1601 :
1602 : void validate ();
1603 :
1604 : void dump_to_dot (const char *path);
1605 :
1606 : rvalue *get_address (location *loc);
1607 :
1608 : void add_attribute (gcc_jit_fn_attribute attribute);
1609 : void add_string_attribute (gcc_jit_fn_attribute attribute, const char* value);
1610 : void add_integer_array_attribute (gcc_jit_fn_attribute attribute, const int* value, size_t length);
1611 :
1612 : private:
1613 : string * make_debug_string () final override;
1614 : void write_reproducer (reproducer &r) final override;
1615 :
1616 : private:
1617 : location *m_loc;
1618 : enum gcc_jit_function_kind m_kind;
1619 : type *m_return_type;
1620 : string *m_name;
1621 : auto_vec<param *> m_params;
1622 : int m_is_variadic;
1623 : enum built_in_function m_builtin_id;
1624 : auto_vec<local *> m_locals;
1625 : auto_vec<block *> m_blocks;
1626 : type *m_fn_ptr_type;
1627 : std::vector<gcc_jit_fn_attribute> m_attributes;
1628 : std::vector<std::pair<gcc_jit_fn_attribute, std::string>> m_string_attributes;
1629 : std::vector<std::pair<gcc_jit_fn_attribute, std::vector<int>>> m_int_array_attributes;
1630 : bool m_is_target_builtin;
1631 : };
1632 :
1633 : class block : public memento
1634 : {
1635 : public:
1636 6609 : block (function *func, int index, string *name)
1637 : : memento (func->m_ctxt),
1638 6609 : m_func (func),
1639 6609 : m_index (index),
1640 6609 : m_name (name),
1641 6609 : m_statements (),
1642 6609 : m_has_been_terminated (false),
1643 6609 : m_is_reachable (false)
1644 : {
1645 : }
1646 :
1647 : /* Get the recording::function containing this block.
1648 : Implements the post-error-checking part of
1649 : gcc_jit_block_get_function. */
1650 38566 : function *get_function () { return m_func; }
1651 :
1652 23023 : bool has_been_terminated () { return m_has_been_terminated; }
1653 : bool is_reachable () { return m_is_reachable; }
1654 :
1655 : statement *
1656 : add_eval (location *loc,
1657 : rvalue *rvalue);
1658 :
1659 : statement *
1660 : add_assignment (location *loc,
1661 : lvalue *lvalue,
1662 : rvalue *rvalue);
1663 :
1664 : statement *
1665 : add_assignment_op (location *loc,
1666 : lvalue *lvalue,
1667 : enum gcc_jit_binary_op op,
1668 : rvalue *rvalue);
1669 :
1670 : statement *
1671 : add_comment (location *loc,
1672 : const char *text);
1673 :
1674 : extended_asm *
1675 : add_extended_asm (location *loc,
1676 : const char *asm_template);
1677 :
1678 : statement *
1679 : end_with_conditional (location *loc,
1680 : rvalue *boolval,
1681 : block *on_true,
1682 : block *on_false);
1683 :
1684 : statement *
1685 : end_with_jump (location *loc,
1686 : block *target);
1687 :
1688 : rvalue * get_address (location *loc);
1689 :
1690 : statement * end_with_indirect_jump (location *loc,
1691 : rvalue *target_address,
1692 : int num_destinations,
1693 : block **destinations);
1694 :
1695 : statement *
1696 : end_with_return (location *loc,
1697 : rvalue *rvalue);
1698 :
1699 : statement *
1700 : end_with_switch (location *loc,
1701 : rvalue *expr,
1702 : block *default_block,
1703 : int num_cases,
1704 : case_ **cases);
1705 :
1706 : extended_asm *
1707 : end_with_extended_asm_goto (location *loc,
1708 : const char *asm_template,
1709 : int num_goto_blocks,
1710 : block **goto_blocks,
1711 : block *fallthrough_block);
1712 :
1713 : playback::block *
1714 17506 : playback_block () const
1715 : {
1716 17406 : return static_cast <playback::block *> (m_playback_obj);
1717 : }
1718 :
1719 : void write_to_dump (dump &d) final override;
1720 :
1721 : bool validate ();
1722 :
1723 : location *get_loc () const;
1724 :
1725 : statement *get_first_statement () const;
1726 : statement *get_last_statement () const;
1727 :
1728 : vec <block *> get_successor_blocks () const;
1729 :
1730 : private:
1731 : string * make_debug_string () final override;
1732 : void write_reproducer (reproducer &r) final override;
1733 :
1734 : void replay_into (replayer *r) final override;
1735 :
1736 : void dump_to_dot (pretty_printer *pp);
1737 : void dump_edges_to_dot (pretty_printer *pp);
1738 :
1739 : private:
1740 : function *m_func;
1741 : int m_index;
1742 : string *m_name;
1743 : auto_vec<statement *> m_statements;
1744 : bool m_has_been_terminated;
1745 : bool m_is_reachable;
1746 :
1747 : friend class function;
1748 : };
1749 :
1750 : class global : public lvalue
1751 : {
1752 : public:
1753 2479 : global (context *ctxt,
1754 : location *loc,
1755 : enum gcc_jit_global_kind kind,
1756 : type *type,
1757 : string *name)
1758 : : lvalue (ctxt, loc, type),
1759 2479 : m_kind (kind),
1760 2479 : m_name (name)
1761 : {
1762 2479 : m_initializer = NULL;
1763 2479 : m_initializer_num_bytes = 0;
1764 : }
1765 4958 : ~global ()
1766 : {
1767 2479 : free (m_initializer);
1768 4958 : }
1769 :
1770 : void replay_into (replayer *) final override;
1771 :
1772 1171 : void visit_children (rvalue_visitor *) final override {}
1773 :
1774 : void write_to_dump (dump &d) final override;
1775 :
1776 920 : bool is_global () const final override { return true; }
1777 :
1778 : void
1779 15 : set_initializer (const void *initializer,
1780 : size_t num_bytes)
1781 : {
1782 15 : if (m_initializer)
1783 0 : free (m_initializer);
1784 15 : m_initializer = xmalloc (num_bytes);
1785 15 : memcpy (m_initializer, initializer, num_bytes);
1786 15 : m_initializer_num_bytes = num_bytes;
1787 15 : }
1788 :
1789 875 : void set_flags (int flag_fields)
1790 : {
1791 875 : m_flags = (enum global_var_flags)(m_flags | flag_fields);
1792 : }
1793 : /* Returns true if any of the flags in the argument is set. */
1794 890 : bool test_flags_anyof (int flag_fields) const
1795 : {
1796 890 : return m_flags & flag_fields;
1797 : }
1798 :
1799 875 : enum gcc_jit_global_kind get_kind () const
1800 : {
1801 875 : return m_kind;
1802 : }
1803 :
1804 860 : void set_rvalue_init (rvalue *val) { m_rvalue_init = val; }
1805 :
1806 : private:
1807 2163 : string * make_debug_string () final override { return m_name; }
1808 : template <typename T>
1809 : void write_initializer_reproducer (const char *id, reproducer &r);
1810 : void write_reproducer (reproducer &r) final override;
1811 150 : enum precedence get_precedence () const final override
1812 : {
1813 150 : return PRECEDENCE_PRIMARY;
1814 : }
1815 :
1816 : private:
1817 : enum gcc_jit_global_kind m_kind;
1818 : enum global_var_flags m_flags = GLOBAL_VAR_FLAGS_NONE;
1819 : string *m_name;
1820 : void *m_initializer;
1821 : rvalue *m_rvalue_init = nullptr; /* Only needed for write_dump. */
1822 : size_t m_initializer_num_bytes;
1823 : };
1824 :
1825 : template <typename HOST_TYPE>
1826 : class memento_of_new_rvalue_from_const : public rvalue
1827 : {
1828 : public:
1829 7943 : memento_of_new_rvalue_from_const (context *ctxt,
1830 : location *loc,
1831 : type *type,
1832 : HOST_TYPE value)
1833 : : rvalue (ctxt, loc, type),
1834 15886 : m_value (value) {}
1835 :
1836 : void replay_into (replayer *r) final override;
1837 :
1838 7302 : void visit_children (rvalue_visitor *) final override {}
1839 :
1840 210 : bool is_constant () const final override { return true; }
1841 :
1842 : bool get_wide_int (wide_int *out) const final override;
1843 :
1844 : private:
1845 : string * make_debug_string () final override;
1846 : void write_reproducer (reproducer &r) final override;
1847 1798 : enum precedence get_precedence () const final override
1848 : {
1849 1798 : return PRECEDENCE_PRIMARY;
1850 : }
1851 :
1852 : private:
1853 : HOST_TYPE m_value;
1854 : };
1855 :
1856 : class memento_of_typeinfo : public rvalue
1857 : {
1858 : public:
1859 30 : memento_of_typeinfo (context *ctxt,
1860 : location *loc,
1861 : type *type,
1862 : type_info_type type_info)
1863 : : rvalue (ctxt, loc, ctxt->get_type (GCC_JIT_TYPE_INT)),
1864 30 : m_type (type),
1865 30 : m_info_type (type_info) {}
1866 :
1867 : void replay_into (replayer *r) final override;
1868 :
1869 30 : void visit_children (rvalue_visitor *) final override {}
1870 :
1871 : private:
1872 : string * make_debug_string () final override;
1873 : void write_reproducer (reproducer &r) final override;
1874 0 : enum precedence get_precedence () const final override
1875 : {
1876 0 : return PRECEDENCE_PRIMARY;
1877 : }
1878 :
1879 : private:
1880 : type *m_type;
1881 : type_info_type m_info_type;
1882 : };
1883 :
1884 : class memento_of_new_string_literal : public rvalue
1885 : {
1886 : public:
1887 1963 : memento_of_new_string_literal (context *ctxt,
1888 : location *loc,
1889 : string *value)
1890 : : rvalue (ctxt, loc, ctxt->get_type (GCC_JIT_TYPE_CONST_CHAR_PTR)),
1891 1963 : m_value (value) {}
1892 :
1893 : void replay_into (replayer *r) final override;
1894 :
1895 654 : void visit_children (rvalue_visitor *) final override {}
1896 :
1897 : private:
1898 : string * make_debug_string () final override;
1899 : void write_reproducer (reproducer &r) final override;
1900 120 : enum precedence get_precedence () const final override
1901 : {
1902 120 : return PRECEDENCE_PRIMARY;
1903 : }
1904 :
1905 : private:
1906 : string *m_value;
1907 : };
1908 :
1909 : class memento_of_new_rvalue_from_vector : public rvalue
1910 : {
1911 : public:
1912 : memento_of_new_rvalue_from_vector (context *ctxt,
1913 : location *loc,
1914 : vector_type *type,
1915 : rvalue **elements);
1916 :
1917 : void replay_into (replayer *r) final override;
1918 :
1919 : void visit_children (rvalue_visitor *) final override;
1920 :
1921 : private:
1922 : string * make_debug_string () final override;
1923 : void write_reproducer (reproducer &r) final override;
1924 10 : enum precedence get_precedence () const final override
1925 : {
1926 10 : return PRECEDENCE_PRIMARY;
1927 : }
1928 :
1929 : private:
1930 : vector_type *m_vector_type;
1931 : auto_vec<rvalue *> m_elements;
1932 : };
1933 :
1934 : class memento_of_new_rvalue_vector_perm : public rvalue
1935 : {
1936 : public:
1937 : memento_of_new_rvalue_vector_perm (context *ctxt,
1938 : location *loc,
1939 : rvalue *elements1,
1940 : rvalue *elements2,
1941 : rvalue *mask);
1942 :
1943 : void replay_into (replayer *r) final override;
1944 :
1945 : void visit_children (rvalue_visitor *) final override;
1946 :
1947 : private:
1948 : string * make_debug_string () final override;
1949 : void write_reproducer (reproducer &r) final override;
1950 0 : enum precedence get_precedence () const final override
1951 : {
1952 0 : return PRECEDENCE_PRIMARY;
1953 : }
1954 :
1955 : private:
1956 : rvalue *m_elements1;
1957 : rvalue *m_elements2;
1958 : rvalue *m_mask;
1959 : };
1960 :
1961 : class ctor : public rvalue
1962 : {
1963 : public:
1964 680 : ctor (context *ctxt,
1965 : location *loc,
1966 : type *type)
1967 680 : : rvalue (ctxt, loc, type)
1968 : { }
1969 :
1970 : void replay_into (replayer *r) final override;
1971 :
1972 : void visit_children (rvalue_visitor *) final override;
1973 :
1974 : private:
1975 : string * make_debug_string () final override;
1976 : void write_reproducer (reproducer &r) final override;
1977 30 : enum precedence get_precedence () const final override
1978 : {
1979 30 : return PRECEDENCE_PRIMARY;
1980 : }
1981 :
1982 : public:
1983 : auto_vec<field *> m_fields;
1984 : auto_vec<rvalue *> m_values;
1985 : };
1986 :
1987 : class unary_op : public rvalue
1988 : {
1989 : public:
1990 128 : unary_op (context *ctxt,
1991 : location *loc,
1992 : enum gcc_jit_unary_op op,
1993 : type *result_type,
1994 : rvalue *a)
1995 : : rvalue (ctxt, loc, result_type),
1996 128 : m_op (op),
1997 128 : m_a (a)
1998 : {}
1999 :
2000 : void replay_into (replayer *r) final override;
2001 :
2002 : void visit_children (rvalue_visitor *v) final override;
2003 :
2004 : private:
2005 : string * make_debug_string () final override;
2006 : void write_reproducer (reproducer &r) final override;
2007 89 : enum precedence get_precedence () const final override
2008 : {
2009 89 : return PRECEDENCE_UNARY;
2010 : }
2011 :
2012 : private:
2013 : enum gcc_jit_unary_op m_op;
2014 : rvalue *m_a;
2015 : };
2016 :
2017 : class binary_op : public rvalue
2018 : {
2019 : public:
2020 3333 : binary_op (context *ctxt,
2021 : location *loc,
2022 : enum gcc_jit_binary_op op,
2023 : type *result_type,
2024 : rvalue *a, rvalue *b)
2025 : : rvalue (ctxt, loc, result_type),
2026 3333 : m_op (op),
2027 3333 : m_a (a),
2028 3333 : m_b (b) {}
2029 :
2030 : void replay_into (replayer *r) final override;
2031 :
2032 : void visit_children (rvalue_visitor *v) final override;
2033 :
2034 : private:
2035 : string * make_debug_string () final override;
2036 : void write_reproducer (reproducer &r) final override;
2037 : enum precedence get_precedence () const final override;
2038 :
2039 : private:
2040 : enum gcc_jit_binary_op m_op;
2041 : rvalue *m_a;
2042 : rvalue *m_b;
2043 : };
2044 :
2045 : class comparison : public rvalue
2046 : {
2047 : public:
2048 1524 : comparison (context *ctxt,
2049 : location *loc,
2050 : enum gcc_jit_comparison op,
2051 : rvalue *a, rvalue *b)
2052 : : rvalue (ctxt, loc, ctxt->get_type (GCC_JIT_TYPE_BOOL)),
2053 1524 : m_op (op),
2054 1524 : m_a (a),
2055 1524 : m_b (b)
2056 : {
2057 1524 : type *a_type = a->get_type ();
2058 1524 : vector_type *vec_type = a_type->dyn_cast_vector_type ();
2059 1524 : if (vec_type != NULL)
2060 : {
2061 135 : type *element_type = vec_type->get_element_type ();
2062 135 : type *inner_type;
2063 : /* Vectors of floating-point values return a vector of integers of the
2064 : same size. */
2065 135 : if (element_type->is_float ())
2066 45 : inner_type = ctxt->get_int_type (element_type->get_size (), false);
2067 : else
2068 : inner_type = element_type;
2069 135 : m_type = new vector_type (inner_type, vec_type->get_num_units ());
2070 135 : ctxt->record (m_type);
2071 : }
2072 1524 : }
2073 :
2074 : void replay_into (replayer *r) final override;
2075 :
2076 : void visit_children (rvalue_visitor *v) final override;
2077 :
2078 : private:
2079 : string * make_debug_string () final override;
2080 : void write_reproducer (reproducer &r) final override;
2081 : enum precedence get_precedence () const final override;
2082 :
2083 : private:
2084 : enum gcc_jit_comparison m_op;
2085 : rvalue *m_a;
2086 : rvalue *m_b;
2087 : };
2088 :
2089 : class cast : public rvalue
2090 : {
2091 : public:
2092 394 : cast (context *ctxt,
2093 : location *loc,
2094 : rvalue *a,
2095 : type *type_)
2096 : : rvalue (ctxt, loc, type_),
2097 394 : m_rvalue (a)
2098 : {}
2099 :
2100 : void replay_into (replayer *r) final override;
2101 :
2102 : void visit_children (rvalue_visitor *v) final override;
2103 :
2104 : private:
2105 : string * make_debug_string () final override;
2106 : void write_reproducer (reproducer &r) final override;
2107 290 : enum precedence get_precedence () const final override
2108 : {
2109 290 : return PRECEDENCE_CAST;
2110 : }
2111 :
2112 : private:
2113 : rvalue *m_rvalue;
2114 : };
2115 :
2116 : class bitcast : public rvalue
2117 : {
2118 : public:
2119 25 : bitcast (context *ctxt,
2120 : location *loc,
2121 : rvalue *a,
2122 : type *type_)
2123 : : rvalue (ctxt, loc, type_),
2124 25 : m_rvalue (a)
2125 : {}
2126 :
2127 : void replay_into (replayer *r) final override;
2128 :
2129 : void visit_children (rvalue_visitor *v) final override;
2130 :
2131 : private:
2132 : string * make_debug_string () final override;
2133 : void write_reproducer (reproducer &r) final override;
2134 0 : enum precedence get_precedence () const final override
2135 : {
2136 0 : return PRECEDENCE_CAST;
2137 : }
2138 :
2139 : private:
2140 : rvalue *m_rvalue;
2141 : };
2142 :
2143 : class base_call : public rvalue
2144 : {
2145 : public:
2146 : base_call (context *ctxt,
2147 : location *loc,
2148 : type *type_,
2149 : int numargs,
2150 : rvalue **args);
2151 :
2152 90 : enum precedence get_precedence () const final override
2153 : {
2154 90 : return PRECEDENCE_POSTFIX;
2155 : }
2156 :
2157 20 : base_call *dyn_cast_base_call () final override { return this; }
2158 :
2159 20 : void set_require_tail_call (bool require_tail_call)
2160 : {
2161 20 : m_require_tail_call = require_tail_call;
2162 : }
2163 :
2164 : protected:
2165 : void write_reproducer_tail_call (reproducer &r, const char *id);
2166 :
2167 : protected:
2168 : auto_vec<rvalue *> m_args;
2169 : bool m_require_tail_call;
2170 : };
2171 :
2172 : class call : public base_call
2173 : {
2174 : public:
2175 : call (context *ctxt,
2176 : location *loc,
2177 : function *func,
2178 : int numargs,
2179 : rvalue **args);
2180 :
2181 : void replay_into (replayer *r) final override;
2182 :
2183 : void visit_children (rvalue_visitor *v) final override;
2184 :
2185 : private:
2186 : string * make_debug_string () final override;
2187 : void write_reproducer (reproducer &r) final override;
2188 :
2189 : private:
2190 : function *m_func;
2191 : };
2192 :
2193 : class call_through_ptr : public base_call
2194 : {
2195 : public:
2196 : call_through_ptr (context *ctxt,
2197 : location *loc,
2198 : rvalue *fn_ptr,
2199 : int numargs,
2200 : rvalue **args);
2201 :
2202 : void replay_into (replayer *r) final override;
2203 :
2204 : void visit_children (rvalue_visitor *v) final override;
2205 :
2206 : private:
2207 : string * make_debug_string () final override;
2208 : void write_reproducer (reproducer &r) final override;
2209 :
2210 : private:
2211 : rvalue *m_fn_ptr;
2212 : };
2213 :
2214 : class array_access : public lvalue
2215 : {
2216 : public:
2217 534 : array_access (context *ctxt,
2218 : location *loc,
2219 : rvalue *ptr,
2220 : rvalue *index)
2221 534 : : lvalue (ctxt, loc, ptr->get_type ()->dereference ()),
2222 534 : m_ptr (ptr),
2223 534 : m_index (index)
2224 534 : {}
2225 :
2226 : void replay_into (replayer *r) final override;
2227 :
2228 : void visit_children (rvalue_visitor *v) final override;
2229 :
2230 : private:
2231 : string * make_debug_string () final override;
2232 : void write_reproducer (reproducer &r) final override;
2233 155 : enum precedence get_precedence () const final override
2234 : {
2235 155 : return PRECEDENCE_POSTFIX;
2236 : }
2237 :
2238 : private:
2239 : rvalue *m_ptr;
2240 : rvalue *m_index;
2241 : };
2242 :
2243 : class convert_vector : public rvalue
2244 : {
2245 : public:
2246 15 : convert_vector (context *ctxt,
2247 : location *loc,
2248 : rvalue *vector,
2249 : type *type)
2250 : : rvalue (ctxt, loc, type),
2251 15 : m_vector (vector),
2252 15 : m_type (type)
2253 : {}
2254 :
2255 : void replay_into (replayer *r) final override;
2256 :
2257 : void visit_children (rvalue_visitor *v) final override;
2258 :
2259 : private:
2260 : string * make_debug_string () final override;
2261 : void write_reproducer (reproducer &r) final override;
2262 0 : enum precedence get_precedence () const final override
2263 : {
2264 0 : return PRECEDENCE_POSTFIX;
2265 : }
2266 :
2267 : private:
2268 : rvalue *m_vector;
2269 : type *m_type;
2270 : };
2271 :
2272 : class vector_access : public lvalue
2273 : {
2274 : public:
2275 15 : vector_access (context *ctxt,
2276 : location *loc,
2277 : rvalue *vector,
2278 : rvalue *index)
2279 15 : : lvalue (ctxt, loc, vector->get_type ()->dyn_cast_vector_type ()
2280 : ->get_element_type ()),
2281 15 : m_vector (vector),
2282 15 : m_index (index)
2283 15 : {}
2284 :
2285 : void replay_into (replayer *r) final override;
2286 :
2287 : void visit_children (rvalue_visitor *v) final override;
2288 :
2289 : private:
2290 : string * make_debug_string () final override;
2291 : void write_reproducer (reproducer &r) final override;
2292 0 : enum precedence get_precedence () const final override
2293 : {
2294 0 : return PRECEDENCE_POSTFIX;
2295 : }
2296 :
2297 : private:
2298 : rvalue *m_vector;
2299 : rvalue *m_index;
2300 : };
2301 :
2302 : class access_field_of_lvalue : public lvalue
2303 : {
2304 : public:
2305 219 : access_field_of_lvalue (context *ctxt,
2306 : location *loc,
2307 : lvalue *val,
2308 : field *field)
2309 : : lvalue (ctxt, loc, field->get_type ()),
2310 219 : m_lvalue (val),
2311 219 : m_field (field)
2312 : {}
2313 :
2314 : void replay_into (replayer *r) final override;
2315 :
2316 : void visit_children (rvalue_visitor *v) final override;
2317 :
2318 : private:
2319 : string * make_debug_string () final override;
2320 : void write_reproducer (reproducer &r) final override;
2321 55 : enum precedence get_precedence () const final override
2322 : {
2323 55 : return PRECEDENCE_POSTFIX;
2324 : }
2325 :
2326 : private:
2327 : lvalue *m_lvalue;
2328 : field *m_field;
2329 : };
2330 :
2331 : class access_field_rvalue : public rvalue
2332 : {
2333 : public:
2334 139 : access_field_rvalue (context *ctxt,
2335 : location *loc,
2336 : rvalue *val,
2337 : field *field)
2338 : : rvalue (ctxt, loc, field->get_type ()),
2339 139 : m_rvalue (val),
2340 139 : m_field (field)
2341 : {}
2342 :
2343 : void replay_into (replayer *r) final override;
2344 :
2345 : void visit_children (rvalue_visitor *v) final override;
2346 :
2347 : private:
2348 : string * make_debug_string () final override;
2349 : void write_reproducer (reproducer &r) final override;
2350 100 : enum precedence get_precedence () const final override
2351 : {
2352 100 : return PRECEDENCE_POSTFIX;
2353 : }
2354 :
2355 : private:
2356 : rvalue *m_rvalue;
2357 : field *m_field;
2358 : };
2359 :
2360 : class dereference_field_rvalue : public lvalue
2361 : {
2362 : public:
2363 1531 : dereference_field_rvalue (context *ctxt,
2364 : location *loc,
2365 : rvalue *val,
2366 : field *field)
2367 : : lvalue (ctxt, loc, field->get_type ()),
2368 1531 : m_rvalue (val),
2369 1531 : m_field (field)
2370 : {}
2371 :
2372 : void replay_into (replayer *r) final override;
2373 :
2374 : void visit_children (rvalue_visitor *v) final override;
2375 :
2376 : private:
2377 : string * make_debug_string () final override;
2378 : void write_reproducer (reproducer &r) final override;
2379 521 : enum precedence get_precedence () const final override
2380 : {
2381 521 : return PRECEDENCE_POSTFIX;
2382 : }
2383 :
2384 : private:
2385 : rvalue *m_rvalue;
2386 : field *m_field;
2387 : };
2388 :
2389 : class dereference_rvalue : public lvalue
2390 : {
2391 : public:
2392 684 : dereference_rvalue (context *ctxt,
2393 : location *loc,
2394 : rvalue *val)
2395 684 : : lvalue (ctxt, loc, val->get_type ()->dereference ()),
2396 684 : m_rvalue (val) {}
2397 :
2398 : void replay_into (replayer *r) final override;
2399 :
2400 : void visit_children (rvalue_visitor *v) final override;
2401 :
2402 : private:
2403 : string * make_debug_string () final override;
2404 : void write_reproducer (reproducer &r) final override;
2405 200 : enum precedence get_precedence () const final override
2406 : {
2407 200 : return PRECEDENCE_UNARY;
2408 : }
2409 :
2410 : private:
2411 : rvalue *m_rvalue;
2412 : };
2413 :
2414 : class get_address_of_lvalue : public rvalue
2415 : {
2416 : public:
2417 508 : get_address_of_lvalue (context *ctxt,
2418 : location *loc,
2419 : lvalue *val)
2420 : : rvalue (ctxt, loc, val->get_type ()->get_pointer ()),
2421 508 : m_lvalue (val)
2422 508 : {}
2423 :
2424 : void replay_into (replayer *r) final override;
2425 :
2426 : void visit_children (rvalue_visitor *v) final override;
2427 :
2428 : private:
2429 : string * make_debug_string () final override;
2430 : void write_reproducer (reproducer &r) final override;
2431 429 : enum precedence get_precedence () const final override
2432 : {
2433 429 : return PRECEDENCE_UNARY;
2434 : }
2435 :
2436 : private:
2437 : lvalue *m_lvalue;
2438 : };
2439 :
2440 : class get_block_address : public rvalue
2441 : {
2442 : public:
2443 55 : get_block_address (context *ctxt,
2444 : location *loc,
2445 : block *b)
2446 : : rvalue (ctxt, loc, ctxt->get_type (GCC_JIT_TYPE_VOID_PTR)),
2447 55 : m_block (b)
2448 : {
2449 55 : set_scope (b->get_function ());
2450 55 : }
2451 :
2452 : void replay_into (replayer *r) final override;
2453 :
2454 65 : void visit_children (rvalue_visitor *) final override {}
2455 :
2456 : private:
2457 : string * make_debug_string () final override;
2458 : void write_reproducer (reproducer &r) final override;
2459 5 : enum precedence get_precedence () const final override
2460 : {
2461 5 : return PRECEDENCE_UNARY;
2462 : }
2463 :
2464 : private:
2465 : block *m_block;
2466 : };
2467 :
2468 : class function_pointer : public rvalue
2469 : {
2470 : public:
2471 15 : function_pointer (context *ctxt,
2472 : location *loc,
2473 : function *fn,
2474 : type *type)
2475 : : rvalue (ctxt, loc, type),
2476 15 : m_fn (fn) {}
2477 :
2478 : void replay_into (replayer *r) final override;
2479 :
2480 : void visit_children (rvalue_visitor *v) final override;
2481 :
2482 : private:
2483 : string * make_debug_string () final override;
2484 : void write_reproducer (reproducer &r) final override;
2485 0 : enum precedence get_precedence () const final override
2486 : {
2487 0 : return PRECEDENCE_UNARY;
2488 : }
2489 :
2490 : private:
2491 : function *m_fn;
2492 : };
2493 :
2494 : class local : public lvalue
2495 : {
2496 : public:
2497 3995 : local (function *func, location *loc, type *type_, string *name)
2498 : : lvalue (func->m_ctxt, loc, type_),
2499 3995 : m_func (func),
2500 3995 : m_name (name)
2501 : {
2502 3995 : set_scope (func);
2503 3995 : }
2504 :
2505 : void replay_into (replayer *r) final override;
2506 :
2507 8405 : void visit_children (rvalue_visitor *) final override {}
2508 :
2509 0 : bool is_local () const final override { return true; }
2510 :
2511 : void write_to_dump (dump &d) final override;
2512 :
2513 : private:
2514 2819 : string * make_debug_string () final override {
2515 2819 : if (m_name)
2516 : return m_name;
2517 : else
2518 5 : return m_ctxt->new_string ("temp");
2519 : }
2520 : void write_reproducer (reproducer &r) final override;
2521 1822 : enum precedence get_precedence () const final override
2522 : {
2523 1822 : return PRECEDENCE_PRIMARY;
2524 : }
2525 :
2526 : private:
2527 : function *m_func;
2528 : string *m_name;
2529 : };
2530 :
2531 : class statement : public memento
2532 : {
2533 : public:
2534 : virtual vec <block *> get_successor_blocks () const;
2535 :
2536 : void write_to_dump (dump &d) final override;
2537 :
2538 53729 : block *get_block () const { return m_block; }
2539 8514 : location *get_loc () const { return m_loc; }
2540 :
2541 : protected:
2542 13900 : statement (block *b, location *loc)
2543 : : memento (b->m_ctxt),
2544 13899 : m_block (b),
2545 40 : m_loc (loc) {}
2546 :
2547 : playback::location *
2548 14395 : playback_location (replayer *r) const
2549 : {
2550 14395 : return ::gcc::jit::recording::playback_location (r, m_loc);
2551 : }
2552 :
2553 : private:
2554 : block *m_block;
2555 : location *m_loc;
2556 : };
2557 :
2558 : class eval : public statement
2559 : {
2560 : public:
2561 2027 : eval (block *b,
2562 : location *loc,
2563 : rvalue *rvalue)
2564 : : statement (b, loc),
2565 2027 : m_rvalue (rvalue) {}
2566 :
2567 : void replay_into (replayer *r) final override;
2568 :
2569 : private:
2570 : string * make_debug_string () final override;
2571 : void write_reproducer (reproducer &r) final override;
2572 :
2573 : private:
2574 : rvalue *m_rvalue;
2575 : };
2576 :
2577 : class assignment : public statement
2578 : {
2579 : public:
2580 4703 : assignment (block *b,
2581 : location *loc,
2582 : lvalue *lvalue,
2583 : rvalue *rvalue)
2584 : : statement (b, loc),
2585 4703 : m_lvalue (lvalue),
2586 4703 : m_rvalue (rvalue) {}
2587 :
2588 : void replay_into (replayer *r) final override;
2589 :
2590 : private:
2591 : string * make_debug_string () final override;
2592 : void write_reproducer (reproducer &r) final override;
2593 :
2594 : private:
2595 : lvalue *m_lvalue;
2596 : rvalue *m_rvalue;
2597 : };
2598 :
2599 : class assignment_op : public statement
2600 : {
2601 : public:
2602 484 : assignment_op (block *b,
2603 : location *loc,
2604 : lvalue *lvalue,
2605 : enum gcc_jit_binary_op op,
2606 : rvalue *rvalue)
2607 : : statement (b, loc),
2608 484 : m_lvalue (lvalue),
2609 484 : m_op (op),
2610 484 : m_rvalue (rvalue) {}
2611 :
2612 : void replay_into (replayer *r) final override;
2613 :
2614 : private:
2615 : string * make_debug_string () final override;
2616 : void write_reproducer (reproducer &r) final override;
2617 :
2618 : private:
2619 : lvalue *m_lvalue;
2620 : enum gcc_jit_binary_op m_op;
2621 : rvalue *m_rvalue;
2622 : };
2623 :
2624 : class comment : public statement
2625 : {
2626 : public:
2627 450 : comment (block *b,
2628 : location *loc,
2629 : string *text)
2630 : : statement (b, loc),
2631 450 : m_text (text) {}
2632 :
2633 : void replay_into (replayer *r) final override;
2634 :
2635 : private:
2636 : string * make_debug_string () final override;
2637 : void write_reproducer (reproducer &r) final override;
2638 :
2639 : private:
2640 : string *m_text;
2641 : };
2642 :
2643 : class conditional : public statement
2644 : {
2645 : public:
2646 894 : conditional (block *b,
2647 : location *loc,
2648 : rvalue *boolval,
2649 : block *on_true,
2650 : block *on_false)
2651 : : statement (b, loc),
2652 894 : m_boolval (boolval),
2653 894 : m_on_true (on_true),
2654 894 : m_on_false (on_false) {}
2655 :
2656 : void replay_into (replayer *r) final override;
2657 :
2658 : vec <block *> get_successor_blocks () const final override;
2659 :
2660 : private:
2661 : string * make_debug_string () final override;
2662 : void write_reproducer (reproducer &r) final override;
2663 :
2664 : private:
2665 : rvalue *m_boolval;
2666 : block *m_on_true;
2667 : block *m_on_false;
2668 : };
2669 :
2670 : class jump : public statement
2671 : {
2672 : public:
2673 1202 : jump (block *b,
2674 : location *loc,
2675 : block *target)
2676 : : statement (b, loc),
2677 1202 : m_target (target) {}
2678 :
2679 : void replay_into (replayer *r) final override;
2680 :
2681 : vec <block *> get_successor_blocks () const final override;
2682 :
2683 : private:
2684 : string * make_debug_string () final override;
2685 : void write_reproducer (reproducer &r) final override;
2686 :
2687 : private:
2688 : block *m_target;
2689 : };
2690 :
2691 : class indirect_jump : public statement
2692 : {
2693 : public:
2694 : indirect_jump (block *b,
2695 : location *loc,
2696 : rvalue *target_address,
2697 : int num_destinations,
2698 : block **destinations);
2699 :
2700 : void replay_into (replayer *r) final override;
2701 :
2702 : vec <block *> get_successor_blocks () const final override;
2703 :
2704 : private:
2705 : string * make_debug_string () final override;
2706 : void write_reproducer (reproducer &r) final override;
2707 :
2708 : private:
2709 : rvalue *m_target_address;
2710 : auto_vec <block *> m_destinations;
2711 : };
2712 :
2713 : class return_ : public statement
2714 : {
2715 : public:
2716 4030 : return_ (block *b,
2717 : location *loc,
2718 : rvalue *rvalue)
2719 : : statement (b, loc),
2720 4030 : m_rvalue (rvalue) {}
2721 :
2722 : void replay_into (replayer *r) final override;
2723 :
2724 : vec <block *> get_successor_blocks () const final override;
2725 :
2726 : private:
2727 : string * make_debug_string () final override;
2728 : void write_reproducer (reproducer &r) final override;
2729 :
2730 : private:
2731 : rvalue *m_rvalue;
2732 : };
2733 :
2734 : class case_ : public memento
2735 : {
2736 : public:
2737 95 : case_ (context *ctxt,
2738 : rvalue *min_value,
2739 : rvalue *max_value,
2740 : block *dest_block)
2741 : : memento (ctxt),
2742 95 : m_min_value (min_value),
2743 95 : m_max_value (max_value),
2744 95 : m_dest_block (dest_block)
2745 : {}
2746 :
2747 530 : rvalue *get_min_value () const { return m_min_value; }
2748 345 : rvalue *get_max_value () const { return m_max_value; }
2749 275 : block *get_dest_block () const { return m_dest_block; }
2750 :
2751 100 : void replay_into (replayer *) final override { /* empty */ }
2752 :
2753 : void write_reproducer (reproducer &r) final override;
2754 :
2755 : private:
2756 : string * make_debug_string () final override;
2757 :
2758 : private:
2759 : rvalue *m_min_value;
2760 : rvalue *m_max_value;
2761 : block *m_dest_block;
2762 : };
2763 :
2764 : class switch_ : public statement
2765 : {
2766 : public:
2767 : switch_ (block *b,
2768 : location *loc,
2769 : rvalue *expr,
2770 : block *default_block,
2771 : int num_cases,
2772 : case_ **cases);
2773 :
2774 : void replay_into (replayer *r) final override;
2775 :
2776 : vec <block *> get_successor_blocks () const final override;
2777 :
2778 : private:
2779 : string * make_debug_string () final override;
2780 : void write_reproducer (reproducer &r) final override;
2781 :
2782 : private:
2783 : rvalue *m_expr;
2784 : block *m_default_block;
2785 : auto_vec <case_ *> m_cases;
2786 : };
2787 :
2788 : class asm_operand : public memento
2789 : {
2790 : public:
2791 : asm_operand (extended_asm *ext_asm,
2792 : string *asm_symbolic_name,
2793 : string *constraint);
2794 :
2795 100 : const char *get_symbolic_name () const
2796 : {
2797 100 : if (m_asm_symbolic_name)
2798 20 : return m_asm_symbolic_name->c_str ();
2799 : else
2800 : return NULL;
2801 : }
2802 :
2803 100 : const char *get_constraint () const
2804 : {
2805 100 : return m_constraint->c_str ();
2806 : }
2807 :
2808 : virtual void print (pretty_printer *pp) const;
2809 :
2810 : private:
2811 : string * make_debug_string () final override;
2812 :
2813 : protected:
2814 : extended_asm *m_ext_asm;
2815 : string *m_asm_symbolic_name;
2816 : string *m_constraint;
2817 : };
2818 :
2819 : class output_asm_operand : public asm_operand
2820 : {
2821 : public:
2822 40 : output_asm_operand (extended_asm *ext_asm,
2823 : string *asm_symbolic_name,
2824 : string *constraint,
2825 : lvalue *dest)
2826 : : asm_operand (ext_asm, asm_symbolic_name, constraint),
2827 40 : m_dest (dest)
2828 : {}
2829 :
2830 40 : lvalue *get_lvalue () const { return m_dest; }
2831 :
2832 40 : void replay_into (replayer *) final override {}
2833 :
2834 : void print (pretty_printer *pp) const final override;
2835 :
2836 : private:
2837 : void write_reproducer (reproducer &r) final override;
2838 :
2839 : private:
2840 : lvalue *m_dest;
2841 : };
2842 :
2843 : class input_asm_operand : public asm_operand
2844 : {
2845 : public:
2846 60 : input_asm_operand (extended_asm *ext_asm,
2847 : string *asm_symbolic_name,
2848 : string *constraint,
2849 : rvalue *src)
2850 : : asm_operand (ext_asm, asm_symbolic_name, constraint),
2851 60 : m_src (src)
2852 : {}
2853 :
2854 60 : rvalue *get_rvalue () const { return m_src; }
2855 :
2856 60 : void replay_into (replayer *) final override {}
2857 :
2858 : void print (pretty_printer *pp) const final override;
2859 :
2860 : private:
2861 : void write_reproducer (reproducer &r) final override;
2862 :
2863 : private:
2864 : rvalue *m_src;
2865 : };
2866 :
2867 : /* Abstract base class for extended_asm statements. */
2868 :
2869 : class extended_asm : public statement
2870 : {
2871 : public:
2872 70 : extended_asm (block *b,
2873 : location *loc,
2874 : string *asm_template)
2875 : : statement (b, loc),
2876 70 : m_asm_template (asm_template),
2877 70 : m_is_volatile (false),
2878 70 : m_is_inline (false)
2879 : {}
2880 :
2881 20 : void set_volatile_flag (bool flag) { m_is_volatile = flag; }
2882 0 : void set_inline_flag (bool flag) { m_is_inline = flag; }
2883 :
2884 : void add_output_operand (const char *asm_symbolic_name,
2885 : const char *constraint,
2886 : lvalue *dest);
2887 : void add_input_operand (const char *asm_symbolic_name,
2888 : const char *constraint,
2889 : rvalue *src);
2890 : void add_clobber (const char *victim);
2891 :
2892 : void replay_into (replayer *r) override;
2893 :
2894 : string *get_asm_template () const { return m_asm_template; }
2895 :
2896 : virtual bool is_goto () const = 0;
2897 : virtual void maybe_print_gotos (pretty_printer *) const = 0;
2898 :
2899 : protected:
2900 : void write_flags (reproducer &r);
2901 : void write_clobbers (reproducer &r);
2902 :
2903 : private:
2904 : string * make_debug_string () final override;
2905 : virtual void maybe_populate_playback_blocks
2906 : (auto_vec <playback::block *> *out) = 0;
2907 :
2908 : protected:
2909 : string *m_asm_template;
2910 : bool m_is_volatile;
2911 : bool m_is_inline;
2912 : auto_vec<output_asm_operand *> m_output_ops;
2913 : auto_vec<input_asm_operand *> m_input_ops;
2914 : auto_vec<string *> m_clobbers;
2915 : };
2916 :
2917 : /* An extended_asm that's not a goto, as created by
2918 : gcc_jit_block_add_extended_asm. */
2919 :
2920 : class extended_asm_simple : public extended_asm
2921 : {
2922 : public:
2923 50 : extended_asm_simple (block *b,
2924 : location *loc,
2925 : string *asm_template)
2926 50 : : extended_asm (b, loc, asm_template)
2927 : {}
2928 :
2929 : void write_reproducer (reproducer &r) override;
2930 90 : bool is_goto () const final override { return false; }
2931 50 : void maybe_print_gotos (pretty_printer *) const final override {}
2932 :
2933 : private:
2934 50 : void maybe_populate_playback_blocks
2935 : (auto_vec <playback::block *> *) final override
2936 50 : {}
2937 : };
2938 :
2939 : /* An extended_asm that's a asm goto, as created by
2940 : gcc_jit_block_end_with_extended_asm_goto. */
2941 :
2942 : class extended_asm_goto : public extended_asm
2943 : {
2944 : public:
2945 : extended_asm_goto (block *b,
2946 : location *loc,
2947 : string *asm_template,
2948 : int num_goto_blocks,
2949 : block **goto_blocks,
2950 : block *fallthrough_block);
2951 :
2952 : void replay_into (replayer *r) final override;
2953 : void write_reproducer (reproducer &r) override;
2954 :
2955 : vec <block *> get_successor_blocks () const final override;
2956 :
2957 20 : bool is_goto () const final override { return true; }
2958 : void maybe_print_gotos (pretty_printer *) const final override;
2959 :
2960 : private:
2961 : void maybe_populate_playback_blocks
2962 : (auto_vec <playback::block *> *out) final override;
2963 :
2964 : private:
2965 : auto_vec <block *> m_goto_blocks;
2966 : block *m_fallthrough_block;
2967 : };
2968 :
2969 : /* A group of top-level asm statements, as created by
2970 : gcc_jit_context_add_top_level_asm. */
2971 :
2972 : class top_level_asm : public memento
2973 : {
2974 : public:
2975 : top_level_asm (context *ctxt, location *loc, string *asm_stmts);
2976 :
2977 : void write_to_dump (dump &d) final override;
2978 :
2979 : private:
2980 : void replay_into (replayer *r) final override;
2981 : string * make_debug_string () final override;
2982 : void write_reproducer (reproducer &r) final override;
2983 :
2984 : private:
2985 : location *m_loc;
2986 : string *m_asm_stmts;
2987 : };
2988 :
2989 : class global_init_rvalue : public memento
2990 : {
2991 : public:
2992 860 : global_init_rvalue (context *ctxt, lvalue *variable, rvalue *init) :
2993 860 : memento (ctxt), m_variable (variable), m_init (init) {};
2994 :
2995 : void write_to_dump (dump &d) final override;
2996 :
2997 : private:
2998 : void replay_into (replayer *r) final override;
2999 : string * make_debug_string () final override;
3000 : void write_reproducer (reproducer &r) final override;
3001 :
3002 : private:
3003 : lvalue *m_variable;
3004 : rvalue *m_init;
3005 : };
3006 :
3007 : } // namespace gcc::jit::recording
3008 :
3009 : /* Create a recording::memento_of_new_rvalue_from_const instance and add
3010 : it to this context's list of mementos.
3011 :
3012 : Implements the post-error-checking part of
3013 : gcc_jit_context_new_rvalue_from_{int|long|double|ptr}. */
3014 :
3015 : template <typename HOST_TYPE>
3016 : recording::rvalue *
3017 7943 : recording::context::new_rvalue_from_const (recording::type *type,
3018 : HOST_TYPE value)
3019 : {
3020 7943 : recording::rvalue *result =
3021 7943 : new memento_of_new_rvalue_from_const <HOST_TYPE> (this, NULL, type, value);
3022 7943 : record (result);
3023 7943 : return result;
3024 : }
3025 :
3026 : /* Don't call this directly. Call types_kinda_same. */
3027 : bool
3028 : types_kinda_same_internal (recording::type *a,
3029 : recording::type *b);
3030 :
3031 : /* Strip all qualifiers and count pointer depth, returning true
3032 : if the types and pointer depth are the same, otherwise false.
3033 :
3034 : For array and vector types the number of element also
3035 : has to match, as well as the element types themself. */
3036 : inline bool
3037 2375 : types_kinda_same (recording::type *a, recording::type *b)
3038 : {
3039 : /* Handle trivial case here, to allow for inlining. */
3040 2375 : return a == b || types_kinda_same_internal (a, b);
3041 : }
3042 :
3043 : } // namespace gcc::jit
3044 :
3045 : } // namespace gcc
3046 :
3047 : #endif /* JIT_RECORDING_H */
|