ipa-cp.c (ipcp_cloning_candidate_p): Use opt_for_fn.
[gcc.git] / gcc / jit / jit-recording.h
1 /* Internals of libgccjit: classes for recording calls made to the JIT API.
2 Copyright (C) 2013-2014 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
26 namespace gcc {
27
28 namespace jit {
29
30 class result;
31 class dump;
32
33 /**********************************************************************
34 Recording.
35 **********************************************************************/
36
37 namespace recording {
38
39 playback::location *
40 playback_location (replayer *r, location *loc);
41
42 const char *
43 playback_string (string *str);
44
45 playback::block *
46 playback_block (block *b);
47
48 /* A JIT-compilation context. */
49 class context
50 {
51 public:
52 context (context *parent_ctxt);
53 ~context ();
54
55 void record (memento *m);
56 void replay_into (replayer *r);
57 void disassociate_from_playback ();
58
59 string *
60 new_string (const char *text);
61
62 location *
63 new_location (const char *filename,
64 int line,
65 int column);
66
67 type *
68 get_type (enum gcc_jit_types type);
69
70 type *
71 get_int_type (int num_bytes, int is_signed);
72
73 type *
74 new_array_type (location *loc,
75 type *element_type,
76 int num_elements);
77
78 field *
79 new_field (location *loc,
80 type *type,
81 const char *name);
82
83 struct_ *
84 new_struct_type (location *loc,
85 const char *name);
86
87 union_ *
88 new_union_type (location *loc,
89 const char *name);
90
91 type *
92 new_function_ptr_type (location *loc,
93 type *return_type,
94 int num_params,
95 type **param_types,
96 int is_variadic);
97
98 param *
99 new_param (location *loc,
100 type *type,
101 const char *name);
102
103 function *
104 new_function (location *loc,
105 enum gcc_jit_function_kind kind,
106 type *return_type,
107 const char *name,
108 int num_params,
109 param **params,
110 int is_variadic,
111 enum built_in_function builtin_id);
112
113 function *
114 get_builtin_function (const char *name);
115
116 lvalue *
117 new_global (location *loc,
118 type *type,
119 const char *name);
120
121 rvalue *
122 new_rvalue_from_int (type *numeric_type,
123 int value);
124
125 rvalue *
126 new_rvalue_from_double (type *numeric_type,
127 double value);
128
129 rvalue *
130 new_rvalue_from_ptr (type *pointer_type,
131 void *value);
132
133 rvalue *
134 new_string_literal (const char *value);
135
136 rvalue *
137 new_unary_op (location *loc,
138 enum gcc_jit_unary_op op,
139 type *result_type,
140 rvalue *a);
141
142 rvalue *
143 new_binary_op (location *loc,
144 enum gcc_jit_binary_op op,
145 type *result_type,
146 rvalue *a, rvalue *b);
147
148 rvalue *
149 new_comparison (location *loc,
150 enum gcc_jit_comparison op,
151 rvalue *a, rvalue *b);
152
153 rvalue *
154 new_call (location *loc,
155 function *func,
156 int numargs, rvalue **args);
157
158 rvalue *
159 new_call_through_ptr (location *loc,
160 rvalue *fn_ptr,
161 int numargs, rvalue **args);
162
163 rvalue *
164 new_cast (location *loc,
165 rvalue *expr,
166 type *type_);
167
168 lvalue *
169 new_array_access (location *loc,
170 rvalue *ptr,
171 rvalue *index);
172
173 void
174 set_str_option (enum gcc_jit_str_option opt,
175 const char *value);
176
177 void
178 set_int_option (enum gcc_jit_int_option opt,
179 int value);
180
181 void
182 set_bool_option (enum gcc_jit_bool_option opt,
183 int value);
184
185 const char *
186 get_str_option (enum gcc_jit_str_option opt) const
187 {
188 return m_str_options[opt];
189 }
190
191 int
192 get_int_option (enum gcc_jit_int_option opt) const
193 {
194 return m_int_options[opt];
195 }
196
197 int
198 get_bool_option (enum gcc_jit_bool_option opt) const
199 {
200 return m_bool_options[opt];
201 }
202
203 result *
204 compile ();
205
206 void
207 add_error (location *loc, const char *fmt, ...)
208 GNU_PRINTF(3, 4);
209
210 void
211 add_error_va (location *loc, const char *fmt, va_list ap)
212 GNU_PRINTF(3, 0);
213
214 const char *
215 get_first_error () const;
216
217 bool errors_occurred () const
218 {
219 if (m_parent_ctxt)
220 if (m_parent_ctxt->errors_occurred ())
221 return true;
222 return m_error_count;
223 }
224
225 type *get_opaque_FILE_type ();
226
227 void dump_to_file (const char *path, bool update_locations);
228
229 private:
230 void validate ();
231
232 private:
233 context *m_parent_ctxt;
234
235 int m_error_count;
236
237 char *m_first_error_str;
238 bool m_owns_first_error_str;
239
240 const char *m_str_options[GCC_JIT_NUM_STR_OPTIONS];
241 int m_int_options[GCC_JIT_NUM_INT_OPTIONS];
242 bool m_bool_options[GCC_JIT_NUM_BOOL_OPTIONS];
243
244 /* Recorded API usage. */
245 vec<memento *> m_mementos;
246
247 /* Specific recordings, for use by dump_to_file. */
248 vec<compound_type *> m_compound_types;
249 vec<function *> m_functions;
250
251 type *m_basic_types[NUM_GCC_JIT_TYPES];
252 type *m_FILE_type;
253
254 builtins_manager *m_builtins_manager; // lazily created
255 };
256
257
258 /* An object with lifetime managed by the context i.e.
259 it lives until the context is released, at which
260 point it itself is cleaned up. */
261
262 class memento
263 {
264 public:
265 virtual ~memento () {}
266
267 /* Hook for replaying this. */
268 virtual void replay_into (replayer *r) = 0;
269
270 void set_playback_obj (void *obj) { m_playback_obj = obj; }
271
272
273 /* Get the context that owns this object.
274
275 Implements the post-error-checking part of
276 gcc_jit_object_get_context. */
277 context *get_context () { return m_ctxt; }
278
279 memento *
280 as_object () { return this; }
281
282 /* Debugging hook, for use in generating error messages etc.
283 Implements the post-error-checking part of
284 gcc_jit_object_get_debug_string. */
285 const char *
286 get_debug_string ();
287
288 virtual void write_to_dump (dump &d);
289
290 protected:
291 memento (context *ctxt)
292 : m_ctxt (ctxt),
293 m_playback_obj (NULL),
294 m_debug_string (NULL)
295 {
296 gcc_assert (ctxt);
297 }
298
299 string *new_string (const char *text) { return m_ctxt->new_string (text); }
300
301 private:
302 virtual string * make_debug_string () = 0;
303
304 public:
305 context *m_ctxt;
306
307 protected:
308 void *m_playback_obj;
309
310 private:
311 string *m_debug_string;
312 };
313
314 /* or just use std::string? */
315 class string : public memento
316 {
317 public:
318 string (context *ctxt, const char *text);
319 ~string ();
320
321 const char *c_str () { return m_buffer; }
322
323 static string * from_printf (context *ctxt, const char *fmt, ...)
324 GNU_PRINTF(2, 3);
325
326 void replay_into (replayer *) {}
327
328 private:
329 string * make_debug_string ();
330
331 private:
332 size_t m_len;
333 char *m_buffer;
334 };
335
336 class location : public memento
337 {
338 public:
339 location (context *ctxt, string *filename, int line, int column)
340 : memento (ctxt),
341 m_filename (filename),
342 m_line (line),
343 m_column (column)
344 {}
345
346 void replay_into (replayer *r);
347
348 playback::location *
349 playback_location (replayer *r)
350 {
351 /* Normally during playback, we can walk forwards through the list of
352 recording objects, playing them back. The ordering of recording
353 ensures that everything that a recording object refers to has
354 already been played back, so we can simply look up the relevant
355 m_playback_obj.
356
357 Locations are an exception, due to the "write_to_dump" method of
358 recording::statement. This method can set a new location on a
359 statement after the statement is created, and thus the location
360 appears in the context's memento list *after* the statement that
361 refers to it.
362
363 In such circumstances, the statement is replayed *before* the location,
364 when the latter doesn't yet have a playback object.
365
366 Hence we need to ensure that locations have playback objects. */
367 if (!m_playback_obj)
368 {
369 replay_into (r);
370 }
371 gcc_assert (m_playback_obj);
372 return static_cast <playback::location *> (m_playback_obj);
373 }
374
375 private:
376 string * make_debug_string ();
377
378 private:
379 string *m_filename;
380 int m_line;
381 int m_column;
382 };
383
384 class type : public memento
385 {
386 public:
387 type *get_pointer ();
388 type *get_const ();
389 type *get_volatile ();
390
391 /* Get the type obtained when dereferencing this type.
392
393 This will return NULL if it's not valid to dereference this type.
394 The caller is responsible for setting an error. */
395 virtual type *dereference () = 0;
396
397 /* Dynamic casts. */
398 virtual function_type *dyn_cast_function_type () { return NULL; }
399 virtual function_type *as_a_function_type() { gcc_unreachable (); return NULL; }
400 virtual struct_ *dyn_cast_struct () { return NULL; }
401
402 /* Is it typesafe to copy to this type from rtype? */
403 virtual bool accepts_writes_from (type *rtype)
404 {
405 gcc_assert (rtype);
406 return this == rtype->unqualified ();
407 }
408
409 /* Strip off "const" etc */
410 virtual type *unqualified ()
411 {
412 return this;
413 }
414
415 virtual bool is_int () const = 0;
416 virtual bool is_float () const = 0;
417 virtual bool is_bool () const = 0;
418 virtual type *is_pointer () = 0;
419 virtual type *is_array () = 0;
420
421 bool is_numeric () const
422 {
423 return is_int () || is_float () || is_bool ();
424 }
425
426 playback::type *
427 playback_type ()
428 {
429 return static_cast <playback::type *> (m_playback_obj);
430 }
431
432 protected:
433 type (context *ctxt)
434 : memento (ctxt),
435 m_pointer_to_this_type (NULL)
436 {}
437
438 private:
439 type *m_pointer_to_this_type;
440 };
441
442 /* Result of "gcc_jit_type_get_type". */
443 class memento_of_get_type : public type
444 {
445 public:
446 memento_of_get_type (context *ctxt,
447 enum gcc_jit_types kind)
448 : type (ctxt),
449 m_kind (kind) {}
450
451 type *dereference ();
452
453 bool accepts_writes_from (type *rtype)
454 {
455 if (m_kind == GCC_JIT_TYPE_VOID_PTR)
456 if (rtype->is_pointer ())
457 {
458 /* LHS (this) is type (void *), and the RHS is a pointer:
459 accept it: */
460 return true;
461 }
462
463 return type::accepts_writes_from (rtype);
464 }
465
466 bool is_int () const;
467 bool is_float () const;
468 bool is_bool () const;
469 type *is_pointer () { return dereference (); }
470 type *is_array () { return NULL; }
471
472 public:
473 void replay_into (replayer *r);
474
475 private:
476 string * make_debug_string ();
477
478 private:
479 enum gcc_jit_types m_kind;
480 };
481
482 /* Result of "gcc_jit_type_get_pointer". */
483 class memento_of_get_pointer : public type
484 {
485 public:
486 memento_of_get_pointer (type *other_type)
487 : type (other_type->m_ctxt),
488 m_other_type (other_type) {}
489
490 type *dereference () { return m_other_type; }
491
492 bool accepts_writes_from (type *rtype);
493
494 void replay_into (replayer *r);
495
496 bool is_int () const { return false; }
497 bool is_float () const { return false; }
498 bool is_bool () const { return false; }
499 type *is_pointer () { return m_other_type; }
500 type *is_array () { return NULL; }
501
502 private:
503 string * make_debug_string ();
504
505 private:
506 type *m_other_type;
507 };
508
509 /* Result of "gcc_jit_type_get_const". */
510 class memento_of_get_const : public type
511 {
512 public:
513 memento_of_get_const (type *other_type)
514 : type (other_type->m_ctxt),
515 m_other_type (other_type) {}
516
517 type *dereference () { return m_other_type->dereference (); }
518
519 bool accepts_writes_from (type */*rtype*/)
520 {
521 /* Can't write to a "const". */
522 return false;
523 }
524
525 /* Strip off the "const", giving the underlying type. */
526 type *unqualified () { return m_other_type; }
527
528 bool is_int () const { return m_other_type->is_int (); }
529 bool is_float () const { return m_other_type->is_float (); }
530 bool is_bool () const { return m_other_type->is_bool (); }
531 type *is_pointer () { return m_other_type->is_pointer (); }
532 type *is_array () { return m_other_type->is_array (); }
533
534 void replay_into (replayer *);
535
536 private:
537 string * make_debug_string ();
538
539 private:
540 type *m_other_type;
541 };
542
543 /* Result of "gcc_jit_type_get_volatile". */
544 class memento_of_get_volatile : public type
545 {
546 public:
547 memento_of_get_volatile (type *other_type)
548 : type (other_type->m_ctxt),
549 m_other_type (other_type) {}
550
551 type *dereference () { return m_other_type->dereference (); }
552
553 /* Strip off the "volatile", giving the underlying type. */
554 type *unqualified () { return m_other_type; }
555
556 bool is_int () const { return m_other_type->is_int (); }
557 bool is_float () const { return m_other_type->is_float (); }
558 bool is_bool () const { return m_other_type->is_bool (); }
559 type *is_pointer () { return m_other_type->is_pointer (); }
560 type *is_array () { return m_other_type->is_array (); }
561
562 void replay_into (replayer *);
563
564 private:
565 string * make_debug_string ();
566
567 private:
568 type *m_other_type;
569 };
570
571 class array_type : public type
572 {
573 public:
574 array_type (context *ctxt,
575 location *loc,
576 type *element_type,
577 int num_elements)
578 : type (ctxt),
579 m_loc (loc),
580 m_element_type (element_type),
581 m_num_elements (num_elements)
582 {}
583
584 type *dereference ();
585
586 bool is_int () const { return false; }
587 bool is_float () const { return false; }
588 bool is_bool () const { return false; }
589 type *is_pointer () { return NULL; }
590 type *is_array () { return m_element_type; }
591
592 void replay_into (replayer *);
593
594 private:
595 string * make_debug_string ();
596
597 private:
598 location *m_loc;
599 type *m_element_type;
600 int m_num_elements;
601 };
602
603 class function_type : public type
604 {
605 public:
606 function_type (context *ctxt,
607 type *return_type,
608 int num_params,
609 type **param_types,
610 int is_variadic);
611
612 type *dereference ();
613 function_type *dyn_cast_function_type () { return this; }
614 function_type *as_a_function_type () { return this; }
615
616 bool is_int () const { return false; }
617 bool is_float () const { return false; }
618 bool is_bool () const { return false; }
619 type *is_pointer () { return NULL; }
620 type *is_array () { return NULL; }
621
622 void replay_into (replayer *);
623
624 type * get_return_type () const { return m_return_type; }
625 vec<type *> get_param_types () const { return m_param_types; }
626 int is_variadic () const { return m_is_variadic; }
627
628 string * make_debug_string_with_ptr ();
629
630 private:
631 string * make_debug_string ();
632 string * make_debug_string_with (const char *);
633
634 private:
635 type *m_return_type;
636 vec<type *> m_param_types;
637 int m_is_variadic;
638 };
639
640 class field : public memento
641 {
642 public:
643 field (context *ctxt,
644 location *loc,
645 type *type,
646 string *name)
647 : memento (ctxt),
648 m_loc (loc),
649 m_type (type),
650 m_name (name),
651 m_container (NULL)
652 {}
653
654 type * get_type () const { return m_type; }
655
656 compound_type * get_container () const { return m_container; }
657 void set_container (compound_type *c) { m_container = c; }
658
659 void replay_into (replayer *);
660
661 void write_to_dump (dump &d);
662
663 playback::field *
664 playback_field () const
665 {
666 return static_cast <playback::field *> (m_playback_obj);
667 }
668
669 private:
670 string * make_debug_string ();
671
672 private:
673 location *m_loc;
674 type *m_type;
675 string *m_name;
676 compound_type *m_container;
677 };
678
679 /* Base class for struct_ and union_ */
680 class compound_type : public type
681 {
682 public:
683 compound_type (context *ctxt,
684 location *loc,
685 string *name);
686
687 string *get_name () const { return m_name; }
688 location *get_loc () const { return m_loc; }
689 fields * get_fields () { return m_fields; }
690
691 void
692 set_fields (location *loc,
693 int num_fields,
694 field **fields);
695
696 type *dereference ();
697
698 bool is_int () const { return false; }
699 bool is_float () const { return false; }
700 bool is_bool () const { return false; }
701 type *is_pointer () { return NULL; }
702 type *is_array () { return NULL; }
703
704 playback::compound_type *
705 playback_compound_type ()
706 {
707 return static_cast <playback::compound_type *> (m_playback_obj);
708 }
709
710 private:
711 location *m_loc;
712 string *m_name;
713 fields *m_fields;
714 };
715
716 class struct_ : public compound_type
717 {
718 public:
719 struct_ (context *ctxt,
720 location *loc,
721 string *name);
722
723 struct_ *dyn_cast_struct () { return this; }
724
725 type *
726 as_type () { return this; }
727
728 void replay_into (replayer *r);
729
730 private:
731 string * make_debug_string ();
732
733 };
734
735 // memento of struct_::set_fields
736 class fields : public memento
737 {
738 public:
739 fields (compound_type *struct_or_union,
740 int num_fields,
741 field **fields);
742
743 void replay_into (replayer *r);
744
745 void write_to_dump (dump &d);
746
747 private:
748 string * make_debug_string ();
749
750 private:
751 compound_type *m_struct_or_union;
752 vec<field *> m_fields;
753 };
754
755 class union_ : public compound_type
756 {
757 public:
758 union_ (context *ctxt,
759 location *loc,
760 string *name);
761
762 void replay_into (replayer *r);
763
764 private:
765 string * make_debug_string ();
766
767 private:
768 location *m_loc;
769 string *m_name;
770 fields *m_fields;
771 };
772
773 class rvalue : public memento
774 {
775 public:
776 rvalue (context *ctxt,
777 location *loc,
778 type *type_)
779 : memento (ctxt),
780 m_loc (loc),
781 m_type (type_)
782 {
783 gcc_assert (type_);
784 }
785
786 /* Get the recording::type of this rvalue.
787
788 Implements the post-error-checking part of
789 gcc_jit_rvalue_get_type. */
790 type * get_type () const { return m_type; }
791
792 playback::rvalue *
793 playback_rvalue () const
794 {
795 return static_cast <playback::rvalue *> (m_playback_obj);
796 }
797 rvalue *
798 access_field (location *loc,
799 field *field);
800
801 lvalue *
802 dereference_field (location *loc,
803 field *field);
804
805 lvalue *
806 dereference (location *loc);
807
808 protected:
809 location *m_loc;
810 type *m_type;
811 };
812
813 class lvalue : public rvalue
814 {
815 public:
816 lvalue (context *ctxt,
817 location *loc,
818 type *type_)
819 : rvalue (ctxt, loc, type_)
820 {}
821
822 playback::lvalue *
823 playback_lvalue () const
824 {
825 return static_cast <playback::lvalue *> (m_playback_obj);
826 }
827
828 lvalue *
829 access_field (location *loc,
830 field *field);
831
832 rvalue *
833 get_address (location *loc);
834
835 rvalue *
836 as_rvalue () { return this; }
837 };
838
839 class param : public lvalue
840 {
841 public:
842 param (context *ctxt,
843 location *loc,
844 type *type,
845 string *name)
846 : lvalue (ctxt, loc, type),
847 m_name (name) {}
848
849 lvalue *
850 as_lvalue () { return this; }
851
852 void replay_into (replayer *r);
853
854 playback::param *
855 playback_param () const
856 {
857 return static_cast <playback::param *> (m_playback_obj);
858 }
859
860 private:
861 string * make_debug_string () { return m_name; }
862
863 private:
864 string *m_name;
865 };
866
867 class function : public memento
868 {
869 public:
870 function (context *ctxt,
871 location *loc,
872 enum gcc_jit_function_kind kind,
873 type *return_type,
874 string *name,
875 int num_params,
876 param **params,
877 int is_variadic,
878 enum built_in_function builtin_id);
879
880 void replay_into (replayer *r);
881
882 playback::function *
883 playback_function () const
884 {
885 return static_cast <playback::function *> (m_playback_obj);
886 }
887
888 enum gcc_jit_function_kind get_kind () const { return m_kind; }
889
890 lvalue *
891 new_local (location *loc,
892 type *type,
893 const char *name);
894
895 block*
896 new_block (const char *name);
897
898 type *get_return_type () const { return m_return_type; }
899 string * get_name () const { return m_name; }
900 vec<param *> get_params () const { return m_params; }
901
902 /* Get the given param by index.
903 Implements the post-error-checking part of
904 gcc_jit_function_get_param. */
905 param *get_param (int i) const { return m_params[i]; }
906
907 bool is_variadic () const { return m_is_variadic; }
908
909 void write_to_dump (dump &d);
910
911 void validate ();
912
913 void dump_to_dot (const char *path);
914
915 private:
916 string * make_debug_string ();
917
918 private:
919 location *m_loc;
920 enum gcc_jit_function_kind m_kind;
921 type *m_return_type;
922 string *m_name;
923 vec<param *> m_params;
924 int m_is_variadic;
925 enum built_in_function m_builtin_id;
926 vec<local *> m_locals;
927 vec<block *> m_blocks;
928 };
929
930 class block : public memento
931 {
932 public:
933 block (function *func, int index, string *name)
934 : memento (func->m_ctxt),
935 m_func (func),
936 m_index (index),
937 m_name (name),
938 m_statements (),
939 m_has_been_terminated (false),
940 m_is_reachable (false)
941 {
942 }
943
944 /* Get the recording::function containing this block.
945 Implements the post-error-checking part of
946 gcc_jit_block_get_function. */
947 function *get_function () { return m_func; }
948
949 bool has_been_terminated () { return m_has_been_terminated; }
950 bool is_reachable () { return m_is_reachable; }
951
952 void
953 add_eval (location *loc,
954 rvalue *rvalue);
955
956 void
957 add_assignment (location *loc,
958 lvalue *lvalue,
959 rvalue *rvalue);
960
961 void
962 add_assignment_op (location *loc,
963 lvalue *lvalue,
964 enum gcc_jit_binary_op op,
965 rvalue *rvalue);
966
967 void
968 add_comment (location *loc,
969 const char *text);
970
971 void
972 end_with_conditional (location *loc,
973 rvalue *boolval,
974 block *on_true,
975 block *on_false);
976
977 void
978 end_with_jump (location *loc,
979 block *target);
980
981 void
982 end_with_return (location *loc,
983 rvalue *rvalue);
984
985 playback::block *
986 playback_block () const
987 {
988 return static_cast <playback::block *> (m_playback_obj);
989 }
990
991 void write_to_dump (dump &d);
992
993 bool validate ();
994
995 location *get_loc () const;
996
997 statement *get_first_statement () const;
998 statement *get_last_statement () const;
999
1000 int get_successor_blocks (block **next1, block **next2) const;
1001
1002 private:
1003 string * make_debug_string ();
1004
1005 void replay_into (replayer *r);
1006
1007 void dump_to_dot (pretty_printer *pp);
1008 void dump_edges_to_dot (pretty_printer *pp);
1009
1010 private:
1011 function *m_func;
1012 int m_index;
1013 string *m_name;
1014 vec<statement *> m_statements;
1015 bool m_has_been_terminated;
1016 bool m_is_reachable;
1017
1018 friend class function;
1019 };
1020
1021 class global : public lvalue
1022 {
1023 public:
1024 global (context *ctxt,
1025 location *loc,
1026 type *type,
1027 string *name)
1028 : lvalue (ctxt, loc, type),
1029 m_name (name)
1030 {}
1031
1032 void replay_into (replayer *);
1033
1034 private:
1035 string * make_debug_string () { return m_name; }
1036
1037 private:
1038 string *m_name;
1039 };
1040
1041 class memento_of_new_rvalue_from_int : public rvalue
1042 {
1043 public:
1044 memento_of_new_rvalue_from_int (context *ctxt,
1045 location *loc,
1046 type *numeric_type,
1047 int value)
1048 : rvalue (ctxt, loc, numeric_type),
1049 m_value (value) {}
1050
1051 void replay_into (replayer *r);
1052
1053 private:
1054 string * make_debug_string ();
1055
1056 private:
1057 int m_value;
1058 };
1059
1060 class memento_of_new_rvalue_from_double : public rvalue
1061 {
1062 public:
1063 memento_of_new_rvalue_from_double (context *ctxt,
1064 location *loc,
1065 type *numeric_type,
1066 double value)
1067 : rvalue (ctxt, loc, numeric_type),
1068 m_value (value)
1069 {}
1070
1071 void replay_into (replayer *);
1072
1073 private:
1074 string * make_debug_string ();
1075
1076 private:
1077 double m_value;
1078 };
1079
1080 class memento_of_new_rvalue_from_ptr : public rvalue
1081 {
1082 public:
1083 memento_of_new_rvalue_from_ptr (context *ctxt,
1084 location *loc,
1085 type *pointer_type,
1086 void *value)
1087 : rvalue (ctxt, loc, pointer_type),
1088 m_value (value)
1089 {}
1090
1091 void replay_into (replayer *);
1092
1093 private:
1094 string * make_debug_string ();
1095
1096 private:
1097 void *m_value;
1098 };
1099
1100 class memento_of_new_string_literal : public rvalue
1101 {
1102 public:
1103 memento_of_new_string_literal (context *ctxt,
1104 location *loc,
1105 string *value)
1106 : rvalue (ctxt, loc, ctxt->get_type (GCC_JIT_TYPE_CONST_CHAR_PTR)),
1107 m_value (value) {}
1108
1109 void replay_into (replayer *r);
1110
1111 private:
1112 string * make_debug_string ();
1113
1114 private:
1115 string *m_value;
1116 };
1117
1118 class unary_op : public rvalue
1119 {
1120 public:
1121 unary_op (context *ctxt,
1122 location *loc,
1123 enum gcc_jit_unary_op op,
1124 type *result_type,
1125 rvalue *a)
1126 : rvalue (ctxt, loc, result_type),
1127 m_op (op),
1128 m_a (a)
1129 {}
1130
1131 void replay_into (replayer *r);
1132
1133 private:
1134 string * make_debug_string ();
1135
1136 private:
1137 enum gcc_jit_unary_op m_op;
1138 rvalue *m_a;
1139 };
1140
1141 class binary_op : public rvalue
1142 {
1143 public:
1144 binary_op (context *ctxt,
1145 location *loc,
1146 enum gcc_jit_binary_op op,
1147 type *result_type,
1148 rvalue *a, rvalue *b)
1149 : rvalue (ctxt, loc, result_type),
1150 m_op (op),
1151 m_a (a),
1152 m_b (b) {}
1153
1154 void replay_into (replayer *r);
1155
1156 private:
1157 string * make_debug_string ();
1158
1159 private:
1160 enum gcc_jit_binary_op m_op;
1161 rvalue *m_a;
1162 rvalue *m_b;
1163 };
1164
1165 class comparison : public rvalue
1166 {
1167 public:
1168 comparison (context *ctxt,
1169 location *loc,
1170 enum gcc_jit_comparison op,
1171 rvalue *a, rvalue *b)
1172 : rvalue (ctxt, loc, ctxt->get_type (GCC_JIT_TYPE_BOOL)),
1173 m_op (op),
1174 m_a (a),
1175 m_b (b)
1176 {}
1177
1178 void replay_into (replayer *r);
1179
1180 private:
1181 string * make_debug_string ();
1182
1183 private:
1184 enum gcc_jit_comparison m_op;
1185 rvalue *m_a;
1186 rvalue *m_b;
1187 };
1188
1189 class cast : public rvalue
1190 {
1191 public:
1192 cast (context *ctxt,
1193 location *loc,
1194 rvalue *a,
1195 type *type_)
1196 : rvalue (ctxt, loc, type_),
1197 m_rvalue (a)
1198 {}
1199
1200 void replay_into (replayer *r);
1201
1202 private:
1203 string * make_debug_string ();
1204
1205 private:
1206 rvalue *m_rvalue;
1207 };
1208
1209 class call : public rvalue
1210 {
1211 public:
1212 call (context *ctxt,
1213 location *loc,
1214 function *func,
1215 int numargs,
1216 rvalue **args);
1217
1218 void replay_into (replayer *r);
1219
1220 private:
1221 string * make_debug_string ();
1222
1223 private:
1224 function *m_func;
1225 vec<rvalue *> m_args;
1226 };
1227
1228 class call_through_ptr : public rvalue
1229 {
1230 public:
1231 call_through_ptr (context *ctxt,
1232 location *loc,
1233 rvalue *fn_ptr,
1234 int numargs,
1235 rvalue **args);
1236
1237 void replay_into (replayer *r);
1238
1239 private:
1240 string * make_debug_string ();
1241
1242 private:
1243 rvalue *m_fn_ptr;
1244 vec<rvalue *> m_args;
1245 };
1246
1247 class array_access : public lvalue
1248 {
1249 public:
1250 array_access (context *ctxt,
1251 location *loc,
1252 rvalue *ptr,
1253 rvalue *index)
1254 : lvalue (ctxt, loc, ptr->get_type ()->dereference ()),
1255 m_ptr (ptr),
1256 m_index (index)
1257 {}
1258
1259 void replay_into (replayer *r);
1260
1261 private:
1262 string * make_debug_string ();
1263
1264 private:
1265 rvalue *m_ptr;
1266 rvalue *m_index;
1267 };
1268
1269 class access_field_of_lvalue : public lvalue
1270 {
1271 public:
1272 access_field_of_lvalue (context *ctxt,
1273 location *loc,
1274 lvalue *val,
1275 field *field)
1276 : lvalue (ctxt, loc, field->get_type ()),
1277 m_lvalue (val),
1278 m_field (field)
1279 {}
1280
1281 void replay_into (replayer *r);
1282
1283 private:
1284 string * make_debug_string ();
1285
1286 private:
1287 lvalue *m_lvalue;
1288 field *m_field;
1289 };
1290
1291 class access_field_rvalue : public rvalue
1292 {
1293 public:
1294 access_field_rvalue (context *ctxt,
1295 location *loc,
1296 rvalue *val,
1297 field *field)
1298 : rvalue (ctxt, loc, field->get_type ()),
1299 m_rvalue (val),
1300 m_field (field)
1301 {}
1302
1303 void replay_into (replayer *r);
1304
1305 private:
1306 string * make_debug_string ();
1307
1308 private:
1309 rvalue *m_rvalue;
1310 field *m_field;
1311 };
1312
1313 class dereference_field_rvalue : public lvalue
1314 {
1315 public:
1316 dereference_field_rvalue (context *ctxt,
1317 location *loc,
1318 rvalue *val,
1319 field *field)
1320 : lvalue (ctxt, loc, field->get_type ()),
1321 m_rvalue (val),
1322 m_field (field)
1323 {}
1324
1325 void replay_into (replayer *r);
1326
1327 private:
1328 string * make_debug_string ();
1329
1330 private:
1331 rvalue *m_rvalue;
1332 field *m_field;
1333 };
1334
1335 class dereference_rvalue : public lvalue
1336 {
1337 public:
1338 dereference_rvalue (context *ctxt,
1339 location *loc,
1340 rvalue *val)
1341 : lvalue (ctxt, loc, val->get_type ()->dereference ()),
1342 m_rvalue (val) {}
1343
1344 void replay_into (replayer *r);
1345
1346 private:
1347 string * make_debug_string ();
1348
1349 private:
1350 rvalue *m_rvalue;
1351 };
1352
1353 class get_address_of_lvalue : public rvalue
1354 {
1355 public:
1356 get_address_of_lvalue (context *ctxt,
1357 location *loc,
1358 lvalue *val)
1359 : rvalue (ctxt, loc, val->get_type ()->get_pointer ()),
1360 m_lvalue (val)
1361 {}
1362
1363 void replay_into (replayer *r);
1364
1365 private:
1366 string * make_debug_string ();
1367
1368 private:
1369 lvalue *m_lvalue;
1370 };
1371
1372 class local : public lvalue
1373 {
1374 public:
1375 local (function *func, location *loc, type *type_, string *name)
1376 : lvalue (func->m_ctxt, loc, type_),
1377 m_func (func),
1378 m_name (name) {}
1379
1380 void replay_into (replayer *r);
1381
1382 void write_to_dump (dump &d);
1383
1384 private:
1385 string * make_debug_string () { return m_name; }
1386
1387 private:
1388 function *m_func;
1389 string *m_name;
1390 };
1391
1392 class statement : public memento
1393 {
1394 public:
1395 virtual int get_successor_blocks (block **out_next1,
1396 block **out_next2) const;
1397
1398 void write_to_dump (dump &d);
1399
1400 location *get_loc () const { return m_loc; }
1401
1402 protected:
1403 statement (block *b, location *loc)
1404 : memento (b->m_ctxt),
1405 m_block (b),
1406 m_loc (loc) {}
1407
1408 block *get_block () const { return m_block; }
1409
1410 playback::location *
1411 playback_location (replayer *r) const
1412 {
1413 return ::gcc::jit::recording::playback_location (r, m_loc);
1414 }
1415
1416 private:
1417 block *m_block;
1418 location *m_loc;
1419 };
1420
1421 class eval : public statement
1422 {
1423 public:
1424 eval (block *b,
1425 location *loc,
1426 rvalue *rvalue)
1427 : statement (b, loc),
1428 m_rvalue (rvalue) {}
1429
1430 void replay_into (replayer *r);
1431
1432 private:
1433 string * make_debug_string ();
1434
1435 private:
1436 rvalue *m_rvalue;
1437 };
1438
1439 class assignment : public statement
1440 {
1441 public:
1442 assignment (block *b,
1443 location *loc,
1444 lvalue *lvalue,
1445 rvalue *rvalue)
1446 : statement (b, loc),
1447 m_lvalue (lvalue),
1448 m_rvalue (rvalue) {}
1449
1450 void replay_into (replayer *r);
1451
1452 private:
1453 string * make_debug_string ();
1454
1455 private:
1456 lvalue *m_lvalue;
1457 rvalue *m_rvalue;
1458 };
1459
1460 class assignment_op : public statement
1461 {
1462 public:
1463 assignment_op (block *b,
1464 location *loc,
1465 lvalue *lvalue,
1466 enum gcc_jit_binary_op op,
1467 rvalue *rvalue)
1468 : statement (b, loc),
1469 m_lvalue (lvalue),
1470 m_op (op),
1471 m_rvalue (rvalue) {}
1472
1473 void replay_into (replayer *r);
1474
1475 private:
1476 string * make_debug_string ();
1477
1478 private:
1479 lvalue *m_lvalue;
1480 enum gcc_jit_binary_op m_op;
1481 rvalue *m_rvalue;
1482 };
1483
1484 class comment : public statement
1485 {
1486 public:
1487 comment (block *b,
1488 location *loc,
1489 string *text)
1490 : statement (b, loc),
1491 m_text (text) {}
1492
1493 void replay_into (replayer *r);
1494
1495 private:
1496 string * make_debug_string ();
1497
1498 private:
1499 string *m_text;
1500 };
1501
1502 class conditional : public statement
1503 {
1504 public:
1505 conditional (block *b,
1506 location *loc,
1507 rvalue *boolval,
1508 block *on_true,
1509 block *on_false)
1510 : statement (b, loc),
1511 m_boolval (boolval),
1512 m_on_true (on_true),
1513 m_on_false (on_false) {}
1514
1515 void replay_into (replayer *r);
1516
1517 int get_successor_blocks (block **out_next1,
1518 block **out_next2) const;
1519
1520 private:
1521 string * make_debug_string ();
1522
1523 private:
1524 rvalue *m_boolval;
1525 block *m_on_true;
1526 block *m_on_false;
1527 };
1528
1529 class jump : public statement
1530 {
1531 public:
1532 jump (block *b,
1533 location *loc,
1534 block *target)
1535 : statement (b, loc),
1536 m_target (target) {}
1537
1538 void replay_into (replayer *r);
1539
1540 int get_successor_blocks (block **out_next1,
1541 block **out_next2) const;
1542
1543 private:
1544 string * make_debug_string ();
1545
1546 private:
1547 block *m_target;
1548 };
1549
1550 class return_ : public statement
1551 {
1552 public:
1553 return_ (block *b,
1554 location *loc,
1555 rvalue *rvalue)
1556 : statement (b, loc),
1557 m_rvalue (rvalue) {}
1558
1559 void replay_into (replayer *r);
1560
1561 int get_successor_blocks (block **out_next1,
1562 block **out_next2) const;
1563
1564 private:
1565 string * make_debug_string ();
1566
1567 private:
1568 rvalue *m_rvalue;
1569 };
1570
1571 } // namespace gcc::jit::recording
1572
1573 /* The result of JIT-compilation. */
1574 class result
1575 {
1576 public:
1577 result(void *dso_handle);
1578
1579 virtual ~result();
1580
1581 void *
1582 get_code (const char *funcname);
1583
1584 private:
1585 void *m_dso_handle;
1586 };
1587
1588 } // namespace gcc::jit
1589
1590 } // namespace gcc
1591
1592 #endif /* JIT_RECORDING_H */
1593