ipa-cp.c (ipcp_cloning_candidate_p): Use opt_for_fn.
[gcc.git] / gcc / jit / jit-common.h
1 /* Core of implementation of libgccjit.so
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_COMMON_H
22 #define JIT_COMMON_H
23
24 #include "libgccjit.h"
25
26 #include "tree.h"
27 #include "tree-iterator.h"
28
29 #ifdef GCC_VERSION
30 #if GCC_VERSION >= 4001
31 #define GNU_PRINTF(M, N) __attribute__ ((format (gnu_printf, (M), (N))))
32 #else
33 #define GNU_PRINTF(M, N)
34 #endif
35 #endif
36
37 const int NUM_GCC_JIT_TYPES = GCC_JIT_TYPE_FILE_PTR + 1;
38
39 /* This comment is included by the docs.
40
41 In order to allow jit objects to be usable outside of a compile
42 whilst working with the existing structure of GCC's code the
43 C API is implemented in terms of a gcc::jit::recording::context,
44 which records the calls made to it.
45
46 When a gcc_jit_context is compiled, the recording context creates a
47 playback context. The playback context invokes the bulk of the GCC
48 code, and within the "frontend" parsing hook, plays back the recorded
49 API calls, creating GCC tree objects.
50
51 So there are two parallel families of classes: those relating to
52 recording, and those relating to playback:
53
54 * Visibility: recording objects are exposed back to client code,
55 whereas playback objects are internal to the library.
56
57 * Lifetime: recording objects have a lifetime equal to that of the
58 recording context that created them, whereas playback objects only
59 exist within the frontend hook.
60
61 * Memory allocation: recording objects are allocated by the recording
62 context, and automatically freed by it when the context is released,
63 whereas playback objects are allocated within the GC heap, and
64 garbage-collected; they can own GC-references.
65
66 * Integration with rest of GCC: recording objects are unrelated to the
67 rest of GCC, whereas playback objects are wrappers around "tree"
68 instances. Hence you can't ask a recording rvalue or lvalue what its
69 type is, whereas you can for a playback rvalue of lvalue (since it
70 can work with the underlying GCC tree nodes).
71
72 * Instancing: There can be multiple recording contexts "alive" at once
73 (albeit it only one compiling at once), whereas there can only be one
74 playback context alive at one time (since it interacts with the GC).
75
76 Ultimately if GCC could support multiple GC heaps and contexts, and
77 finer-grained initialization, then this recording vs playback
78 distinction could be eliminated.
79
80 During a playback, we associate objects from the recording with
81 their counterparts during this playback. For simplicity, we store this
82 within the recording objects, as ``void *m_playback_obj``, casting it to
83 the appropriate playback object subclass. For these casts to make
84 sense, the two class hierarchies need to have the same structure.
85
86 Note that the playback objects that ``m_playback_obj`` points to are
87 GC-allocated, but the recording objects don't own references:
88 these associations only exist within a part of the code where
89 the GC doesn't collect, and are set back to NULL before the GC can
90 run.
91
92 End of comment for inclusion in the docs. */
93
94 namespace gcc {
95
96 namespace jit {
97
98 class result;
99 class dump;
100
101 namespace recording {
102
103 /* Recording types. */
104
105 /* Indentation indicates inheritance: */
106 class context;
107 class builtins_manager; // declared within jit-builtins.h
108 class memento;
109 class string;
110 class location;
111 class type;
112 class function_type;
113 class compound_type;
114 class struct_;
115 class union_;
116 class field;
117 class fields;
118 class function;
119 class block;
120 class rvalue;
121 class lvalue;
122 class local;
123 class global;
124 class param;
125 class statement;
126
127 /* End of recording types. */
128 }
129
130 namespace playback {
131 /* Playback types. */
132
133 /* Indentation indicates inheritance: */
134 class context;
135 class wrapper;
136 class type;
137 class compound_type;
138 class field;
139 class function;
140 class block;
141 class rvalue;
142 class lvalue;
143 class param;
144 class source_file;
145 class source_line;
146 class location;
147
148 /* End of playback types. */
149 }
150
151 typedef playback::context replayer;
152
153 class dump
154 {
155 public:
156 dump (recording::context &ctxt,
157 const char *filename,
158 bool update_locations);
159 ~dump ();
160
161 void write (const char *fmt, ...)
162 GNU_PRINTF(2, 3);
163
164 bool update_locations () const { return m_update_locations; }
165
166 recording::location *
167 make_location () const;
168
169 private:
170 recording::context &m_ctxt;
171 const char *m_filename;
172 bool m_update_locations;
173 int m_line;
174 int m_column;
175 FILE *m_file;
176 };
177
178 } // namespace gcc::jit
179
180 } // namespace gcc
181
182 #endif /* JIT_COMMON_H */