annotate gcc/jit/docs/topics/contexts.rst @ 131:84e7813d76e9

gcc-8.2
author mir3636
date Thu, 25 Oct 2018 07:37:49 +0900
parents 04ced10e8804
children 1830386684a0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1 .. Copyright (C) 2014-2018 Free Software Foundation, Inc.
111
kono
parents:
diff changeset
2 Originally contributed by David Malcolm <dmalcolm@redhat.com>
kono
parents:
diff changeset
3
kono
parents:
diff changeset
4 This is free software: you can redistribute it and/or modify it
kono
parents:
diff changeset
5 under the terms of the GNU General Public License as published by
kono
parents:
diff changeset
6 the Free Software Foundation, either version 3 of the License, or
kono
parents:
diff changeset
7 (at your option) any later version.
kono
parents:
diff changeset
8
kono
parents:
diff changeset
9 This program is distributed in the hope that it will be useful, but
kono
parents:
diff changeset
10 WITHOUT ANY WARRANTY; without even the implied warranty of
kono
parents:
diff changeset
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
kono
parents:
diff changeset
12 General Public License for more details.
kono
parents:
diff changeset
13
kono
parents:
diff changeset
14 You should have received a copy of the GNU General Public License
kono
parents:
diff changeset
15 along with this program. If not, see
kono
parents:
diff changeset
16 <http://www.gnu.org/licenses/>.
kono
parents:
diff changeset
17
kono
parents:
diff changeset
18 .. default-domain:: c
kono
parents:
diff changeset
19
kono
parents:
diff changeset
20 Compilation contexts
kono
parents:
diff changeset
21 ====================
kono
parents:
diff changeset
22
kono
parents:
diff changeset
23 .. type:: gcc_jit_context
kono
parents:
diff changeset
24
kono
parents:
diff changeset
25 The top-level of the API is the :c:type:`gcc_jit_context` type.
kono
parents:
diff changeset
26
kono
parents:
diff changeset
27 A :c:type:`gcc_jit_context` instance encapsulates the state of a
kono
parents:
diff changeset
28 compilation.
kono
parents:
diff changeset
29
kono
parents:
diff changeset
30 You can set up options on it, and add types, functions and code.
kono
parents:
diff changeset
31 Invoking :c:func:`gcc_jit_context_compile` on it gives you a
kono
parents:
diff changeset
32 :c:type:`gcc_jit_result`.
kono
parents:
diff changeset
33
kono
parents:
diff changeset
34 Lifetime-management
kono
parents:
diff changeset
35 -------------------
kono
parents:
diff changeset
36 Contexts are the unit of lifetime-management within the API: objects
kono
parents:
diff changeset
37 have their lifetime bounded by the context they are created within, and
kono
parents:
diff changeset
38 cleanup of such objects is done for you when the context is released.
kono
parents:
diff changeset
39
kono
parents:
diff changeset
40 .. function:: gcc_jit_context *gcc_jit_context_acquire (void)
kono
parents:
diff changeset
41
kono
parents:
diff changeset
42 This function acquires a new :c:type:`gcc_jit_context *` instance,
kono
parents:
diff changeset
43 which is independent of any others that may be present within this
kono
parents:
diff changeset
44 process.
kono
parents:
diff changeset
45
kono
parents:
diff changeset
46 .. function:: void gcc_jit_context_release (gcc_jit_context *ctxt)
kono
parents:
diff changeset
47
kono
parents:
diff changeset
48 This function releases all resources associated with the given context.
kono
parents:
diff changeset
49 Both the context itself and all of its :c:type:`gcc_jit_object *`
kono
parents:
diff changeset
50 instances are cleaned up. It should be called exactly once on a given
kono
parents:
diff changeset
51 context.
kono
parents:
diff changeset
52
kono
parents:
diff changeset
53 It is invalid to use the context or any of its "contextual" objects
kono
parents:
diff changeset
54 after calling this.
kono
parents:
diff changeset
55
kono
parents:
diff changeset
56 .. code-block:: c
kono
parents:
diff changeset
57
kono
parents:
diff changeset
58 gcc_jit_context_release (ctxt);
kono
parents:
diff changeset
59
kono
parents:
diff changeset
60 .. function:: gcc_jit_context * gcc_jit_context_new_child_context (gcc_jit_context *parent_ctxt)
kono
parents:
diff changeset
61
kono
parents:
diff changeset
62 Given an existing JIT context, create a child context.
kono
parents:
diff changeset
63
kono
parents:
diff changeset
64 The child inherits a copy of all option-settings from the parent.
kono
parents:
diff changeset
65
kono
parents:
diff changeset
66 The child can reference objects created within the parent, but not
kono
parents:
diff changeset
67 vice-versa.
kono
parents:
diff changeset
68
kono
parents:
diff changeset
69 The lifetime of the child context must be bounded by that of the
kono
parents:
diff changeset
70 parent: you should release a child context before releasing the parent
kono
parents:
diff changeset
71 context.
kono
parents:
diff changeset
72
kono
parents:
diff changeset
73 If you use a function from a parent context within a child context,
kono
parents:
diff changeset
74 you have to compile the parent context before you can compile the
kono
parents:
diff changeset
75 child context, and the gcc_jit_result of the parent context must
kono
parents:
diff changeset
76 outlive the gcc_jit_result of the child context.
kono
parents:
diff changeset
77
kono
parents:
diff changeset
78 This allows caching of shared initializations. For example, you could
kono
parents:
diff changeset
79 create types and declarations of global functions in a parent context
kono
parents:
diff changeset
80 once within a process, and then create child contexts whenever a
kono
parents:
diff changeset
81 function or loop becomes hot. Each such child context can be used for
kono
parents:
diff changeset
82 JIT-compiling just one function or loop, but can reference types
kono
parents:
diff changeset
83 and helper functions created within the parent context.
kono
parents:
diff changeset
84
kono
parents:
diff changeset
85 Contexts can be arbitrarily nested, provided the above rules are
kono
parents:
diff changeset
86 followed, but it's probably not worth going above 2 or 3 levels, and
kono
parents:
diff changeset
87 there will likely be a performance hit for such nesting.
kono
parents:
diff changeset
88
kono
parents:
diff changeset
89
kono
parents:
diff changeset
90 Thread-safety
kono
parents:
diff changeset
91 -------------
kono
parents:
diff changeset
92 Instances of :c:type:`gcc_jit_context *` created via
kono
parents:
diff changeset
93 :c:func:`gcc_jit_context_acquire` are independent from each other:
kono
parents:
diff changeset
94 only one thread may use a given context at once, but multiple threads
kono
parents:
diff changeset
95 could each have their own contexts without needing locks.
kono
parents:
diff changeset
96
kono
parents:
diff changeset
97 Contexts created via :c:func:`gcc_jit_context_new_child_context` are
kono
parents:
diff changeset
98 related to their parent context. They can be partitioned by their
kono
parents:
diff changeset
99 ultimate ancestor into independent "family trees". Only one thread
kono
parents:
diff changeset
100 within a process may use a given "family tree" of such contexts at once,
kono
parents:
diff changeset
101 and if you're using multiple threads you should provide your own locking
kono
parents:
diff changeset
102 around entire such context partitions.
kono
parents:
diff changeset
103
kono
parents:
diff changeset
104 .. _error-handling:
kono
parents:
diff changeset
105
kono
parents:
diff changeset
106 Error-handling
kono
parents:
diff changeset
107 --------------
kono
parents:
diff changeset
108 Various kinds of errors are possible when using the API, such as
kono
parents:
diff changeset
109 mismatched types in an assignment. You can only compile and get code from
kono
parents:
diff changeset
110 a context if no errors occur.
kono
parents:
diff changeset
111
kono
parents:
diff changeset
112 Errors are printed on stderr and can be queried using
kono
parents:
diff changeset
113 :c:func:`gcc_jit_context_get_first_error`.
kono
parents:
diff changeset
114
kono
parents:
diff changeset
115 They typically contain the name of the API entrypoint where the error
kono
parents:
diff changeset
116 occurred, and pertinent information on the problem:
kono
parents:
diff changeset
117
kono
parents:
diff changeset
118 .. code-block:: console
kono
parents:
diff changeset
119
kono
parents:
diff changeset
120 ./buggy-program: error: gcc_jit_block_add_assignment: mismatching types: assignment to i (type: int) from "hello world" (type: const char *)
kono
parents:
diff changeset
121
kono
parents:
diff changeset
122 In general, if an error occurs when using an API entrypoint, the
kono
parents:
diff changeset
123 entrypoint returns NULL. You don't have to check everywhere for NULL
kono
parents:
diff changeset
124 results, since the API handles a NULL being passed in for any
kono
parents:
diff changeset
125 argument by issuing another error. This typically leads to a cascade of
kono
parents:
diff changeset
126 followup error messages, but is safe (albeit verbose). The first error
kono
parents:
diff changeset
127 message is usually the one to pay attention to, since it is likely to
kono
parents:
diff changeset
128 be responsible for all of the rest:
kono
parents:
diff changeset
129
kono
parents:
diff changeset
130 .. function:: const char *\
kono
parents:
diff changeset
131 gcc_jit_context_get_first_error (gcc_jit_context *ctxt)
kono
parents:
diff changeset
132
kono
parents:
diff changeset
133 Returns the first error message that occurred on the context.
kono
parents:
diff changeset
134
kono
parents:
diff changeset
135 The returned string is valid for the rest of the lifetime of the
kono
parents:
diff changeset
136 context.
kono
parents:
diff changeset
137
kono
parents:
diff changeset
138 If no errors occurred, this will be NULL.
kono
parents:
diff changeset
139
kono
parents:
diff changeset
140 If you are wrapping the C API for a higher-level language that supports
kono
parents:
diff changeset
141 exception-handling, you may instead be interested in the last error that
kono
parents:
diff changeset
142 occurred on the context, so that you can embed this in an exception:
kono
parents:
diff changeset
143
kono
parents:
diff changeset
144 .. function:: const char *\
kono
parents:
diff changeset
145 gcc_jit_context_get_last_error (gcc_jit_context *ctxt)
kono
parents:
diff changeset
146
kono
parents:
diff changeset
147 Returns the last error message that occurred on the context.
kono
parents:
diff changeset
148
kono
parents:
diff changeset
149 If no errors occurred, this will be NULL.
kono
parents:
diff changeset
150
kono
parents:
diff changeset
151 If non-NULL, the returned string is only guaranteed to be valid until
kono
parents:
diff changeset
152 the next call to libgccjit relating to this context.
kono
parents:
diff changeset
153
kono
parents:
diff changeset
154 Debugging
kono
parents:
diff changeset
155 ---------
kono
parents:
diff changeset
156
kono
parents:
diff changeset
157 .. function:: void\
kono
parents:
diff changeset
158 gcc_jit_context_dump_to_file (gcc_jit_context *ctxt,\
kono
parents:
diff changeset
159 const char *path,\
kono
parents:
diff changeset
160 int update_locations)
kono
parents:
diff changeset
161
kono
parents:
diff changeset
162 To help with debugging: dump a C-like representation to the given path,
kono
parents:
diff changeset
163 describing what's been set up on the context.
kono
parents:
diff changeset
164
kono
parents:
diff changeset
165 If "update_locations" is true, then also set up :type:`gcc_jit_location`
kono
parents:
diff changeset
166 information throughout the context, pointing at the dump file as if it
kono
parents:
diff changeset
167 were a source file. This may be of use in conjunction with
kono
parents:
diff changeset
168 :macro:`GCC_JIT_BOOL_OPTION_DEBUGINFO` to allow stepping through the
kono
parents:
diff changeset
169 code in a debugger.
kono
parents:
diff changeset
170
kono
parents:
diff changeset
171 .. function:: void\
kono
parents:
diff changeset
172 gcc_jit_context_set_logfile (gcc_jit_context *ctxt,\
kono
parents:
diff changeset
173 FILE *logfile,\
kono
parents:
diff changeset
174 int flags,\
kono
parents:
diff changeset
175 int verbosity)
kono
parents:
diff changeset
176
kono
parents:
diff changeset
177 To help with debugging; enable ongoing logging of the context's
kono
parents:
diff changeset
178 activity to the given file.
kono
parents:
diff changeset
179
kono
parents:
diff changeset
180 For example, the following will enable logging to stderr.
kono
parents:
diff changeset
181
kono
parents:
diff changeset
182 .. code-block:: c
kono
parents:
diff changeset
183
kono
parents:
diff changeset
184 gcc_jit_context_set_logfile (ctxt, stderr, 0, 0);
kono
parents:
diff changeset
185
kono
parents:
diff changeset
186 Examples of information logged include:
kono
parents:
diff changeset
187
kono
parents:
diff changeset
188 * API calls
kono
parents:
diff changeset
189
kono
parents:
diff changeset
190 * the various steps involved within compilation
kono
parents:
diff changeset
191
kono
parents:
diff changeset
192 * activity on any :c:type:`gcc_jit_result` instances created by
kono
parents:
diff changeset
193 the context
kono
parents:
diff changeset
194
kono
parents:
diff changeset
195 * activity within any child contexts
kono
parents:
diff changeset
196
kono
parents:
diff changeset
197 An example of a log can be seen :ref:`here <example-of-log-file>`,
kono
parents:
diff changeset
198 though the precise format and kinds of information logged is subject
kono
parents:
diff changeset
199 to change.
kono
parents:
diff changeset
200
kono
parents:
diff changeset
201 The caller remains responsible for closing `logfile`, and it must not
kono
parents:
diff changeset
202 be closed until all users are released. In particular, note that
kono
parents:
diff changeset
203 child contexts and :c:type:`gcc_jit_result` instances created by
kono
parents:
diff changeset
204 the context will use the logfile.
kono
parents:
diff changeset
205
kono
parents:
diff changeset
206 There may a performance cost for logging.
kono
parents:
diff changeset
207
kono
parents:
diff changeset
208 You can turn off logging on `ctxt` by passing `NULL` for `logfile`.
kono
parents:
diff changeset
209 Doing so only affects the context; it does not affect child contexts
kono
parents:
diff changeset
210 or :c:type:`gcc_jit_result` instances already created by
kono
parents:
diff changeset
211 the context.
kono
parents:
diff changeset
212
kono
parents:
diff changeset
213 The parameters "flags" and "verbosity" are reserved for future
kono
parents:
diff changeset
214 expansion, and must be zero for now.
kono
parents:
diff changeset
215
kono
parents:
diff changeset
216 To contrast the above: :c:func:`gcc_jit_context_dump_to_file` dumps the
kono
parents:
diff changeset
217 current state of a context to the given path, whereas
kono
parents:
diff changeset
218 :c:func:`gcc_jit_context_set_logfile` enables on-going logging of
kono
parents:
diff changeset
219 future activies on a context to the given `FILE *`.
kono
parents:
diff changeset
220
kono
parents:
diff changeset
221
kono
parents:
diff changeset
222 .. function:: void\
kono
parents:
diff changeset
223 gcc_jit_context_dump_reproducer_to_file (gcc_jit_context *ctxt,\
kono
parents:
diff changeset
224 const char *path)
kono
parents:
diff changeset
225
kono
parents:
diff changeset
226 Write C source code into `path` that can be compiled into a
kono
parents:
diff changeset
227 self-contained executable (i.e. with libgccjit as the only dependency).
kono
parents:
diff changeset
228 The generated code will attempt to replay the API calls that have been
kono
parents:
diff changeset
229 made into the given context.
kono
parents:
diff changeset
230
kono
parents:
diff changeset
231 This may be useful when debugging the library or client code, for
kono
parents:
diff changeset
232 reducing a complicated recipe for reproducing a bug into a simpler
kono
parents:
diff changeset
233 form. For example, consider client code that parses some source file
kono
parents:
diff changeset
234 into some internal representation, and then walks this IR, calling into
kono
parents:
diff changeset
235 libgccjit. If this encounters a bug, a call to
kono
parents:
diff changeset
236 `gcc_jit_context_dump_reproducer_to_file` will write out C code for
kono
parents:
diff changeset
237 a much simpler executable that performs the equivalent calls into
kono
parents:
diff changeset
238 libgccjit, without needing the client code and its data.
kono
parents:
diff changeset
239
kono
parents:
diff changeset
240 Typically you need to supply :option:`-Wno-unused-variable` when
kono
parents:
diff changeset
241 compiling the generated file (since the result of each API call is
kono
parents:
diff changeset
242 assigned to a unique variable within the generated C source, and not
kono
parents:
diff changeset
243 all are necessarily then used).
kono
parents:
diff changeset
244
kono
parents:
diff changeset
245 .. function:: void\
kono
parents:
diff changeset
246 gcc_jit_context_enable_dump (gcc_jit_context *ctxt,\
kono
parents:
diff changeset
247 const char *dumpname, \
kono
parents:
diff changeset
248 char **out_ptr)
kono
parents:
diff changeset
249
kono
parents:
diff changeset
250 Enable the dumping of a specific set of internal state from the
kono
parents:
diff changeset
251 compilation, capturing the result in-memory as a buffer.
kono
parents:
diff changeset
252
kono
parents:
diff changeset
253 Parameter "dumpname" corresponds to the equivalent gcc command-line
kono
parents:
diff changeset
254 option, without the "-fdump-" prefix.
kono
parents:
diff changeset
255 For example, to get the equivalent of :option:`-fdump-tree-vrp1`,
kono
parents:
diff changeset
256 supply ``"tree-vrp1"``:
kono
parents:
diff changeset
257
kono
parents:
diff changeset
258 .. code-block:: c
kono
parents:
diff changeset
259
kono
parents:
diff changeset
260 static char *dump_vrp1;
kono
parents:
diff changeset
261
kono
parents:
diff changeset
262 void
kono
parents:
diff changeset
263 create_code (gcc_jit_context *ctxt)
kono
parents:
diff changeset
264 {
kono
parents:
diff changeset
265 gcc_jit_context_enable_dump (ctxt, "tree-vrp1", &dump_vrp1);
kono
parents:
diff changeset
266 /* (other API calls omitted for brevity) */
kono
parents:
diff changeset
267 }
kono
parents:
diff changeset
268
kono
parents:
diff changeset
269 The context directly stores the dumpname as a ``(const char *)``, so
kono
parents:
diff changeset
270 the passed string must outlive the context.
kono
parents:
diff changeset
271
kono
parents:
diff changeset
272 :func:`gcc_jit_context_compile` will capture the dump as a
kono
parents:
diff changeset
273 dynamically-allocated buffer, writing it to ``*out_ptr``.
kono
parents:
diff changeset
274
kono
parents:
diff changeset
275 The caller becomes responsible for calling:
kono
parents:
diff changeset
276
kono
parents:
diff changeset
277 .. code-block:: c
kono
parents:
diff changeset
278
kono
parents:
diff changeset
279 free (*out_ptr)
kono
parents:
diff changeset
280
kono
parents:
diff changeset
281 each time that :func:`gcc_jit_context_compile` is called.
kono
parents:
diff changeset
282 ``*out_ptr`` will be written to, either with the address of a buffer,
kono
parents:
diff changeset
283 or with ``NULL`` if an error occurred.
kono
parents:
diff changeset
284
kono
parents:
diff changeset
285 .. warning::
kono
parents:
diff changeset
286
kono
parents:
diff changeset
287 This API entrypoint is likely to be less stable than the others.
kono
parents:
diff changeset
288 In particular, both the precise dumpnames, and the format and content
kono
parents:
diff changeset
289 of the dumps are subject to change.
kono
parents:
diff changeset
290
kono
parents:
diff changeset
291 It exists primarily for writing the library's own test suite.
kono
parents:
diff changeset
292
kono
parents:
diff changeset
293 Options
kono
parents:
diff changeset
294 -------
kono
parents:
diff changeset
295
kono
parents:
diff changeset
296 Options present in the initial release of libgccjit were handled using
kono
parents:
diff changeset
297 enums, whereas those added subsequently have their own per-option API
kono
parents:
diff changeset
298 entrypoints.
kono
parents:
diff changeset
299
kono
parents:
diff changeset
300 Adding entrypoints for each new option means that client code that use
kono
parents:
diff changeset
301 the new options can be identified directly from binary metadata, which
kono
parents:
diff changeset
302 would not be possible if we instead extended the various
kono
parents:
diff changeset
303 ``enum gcc_jit_*_option``.
kono
parents:
diff changeset
304
kono
parents:
diff changeset
305 String Options
kono
parents:
diff changeset
306 **************
kono
parents:
diff changeset
307
kono
parents:
diff changeset
308 .. function:: void gcc_jit_context_set_str_option(gcc_jit_context *ctxt, \
kono
parents:
diff changeset
309 enum gcc_jit_str_option opt, \
kono
parents:
diff changeset
310 const char *value)
kono
parents:
diff changeset
311
kono
parents:
diff changeset
312 Set a string option of the context.
kono
parents:
diff changeset
313
kono
parents:
diff changeset
314 .. type:: enum gcc_jit_str_option
kono
parents:
diff changeset
315
kono
parents:
diff changeset
316 The parameter ``value`` can be NULL. If non-NULL, the call takes a
kono
parents:
diff changeset
317 copy of the underlying string, so it is valid to pass in a pointer to
kono
parents:
diff changeset
318 an on-stack buffer.
kono
parents:
diff changeset
319
kono
parents:
diff changeset
320 There is just one string option specified this way:
kono
parents:
diff changeset
321
kono
parents:
diff changeset
322 .. macro:: GCC_JIT_STR_OPTION_PROGNAME
kono
parents:
diff changeset
323
kono
parents:
diff changeset
324 The name of the program, for use as a prefix when printing error
kono
parents:
diff changeset
325 messages to stderr. If `NULL`, or default, "libgccjit.so" is used.
kono
parents:
diff changeset
326
kono
parents:
diff changeset
327 Boolean options
kono
parents:
diff changeset
328 ***************
kono
parents:
diff changeset
329
kono
parents:
diff changeset
330 .. function:: void gcc_jit_context_set_bool_option(gcc_jit_context *ctxt, \
kono
parents:
diff changeset
331 enum gcc_jit_bool_option opt, \
kono
parents:
diff changeset
332 int value)
kono
parents:
diff changeset
333
kono
parents:
diff changeset
334 Set a boolean option of the context.
kono
parents:
diff changeset
335 Zero is "false" (the default), non-zero is "true".
kono
parents:
diff changeset
336
kono
parents:
diff changeset
337 .. type:: enum gcc_jit_bool_option
kono
parents:
diff changeset
338
kono
parents:
diff changeset
339 .. macro:: GCC_JIT_BOOL_OPTION_DEBUGINFO
kono
parents:
diff changeset
340
kono
parents:
diff changeset
341 If true, :func:`gcc_jit_context_compile` will attempt to do the right
kono
parents:
diff changeset
342 thing so that if you attach a debugger to the process, it will
kono
parents:
diff changeset
343 be able to inspect variables and step through your code.
kono
parents:
diff changeset
344
kono
parents:
diff changeset
345 Note that you can't step through code unless you set up source
kono
parents:
diff changeset
346 location information for the code (by creating and passing in
kono
parents:
diff changeset
347 :type:`gcc_jit_location` instances).
kono
parents:
diff changeset
348
kono
parents:
diff changeset
349 .. macro:: GCC_JIT_BOOL_OPTION_DUMP_INITIAL_TREE
kono
parents:
diff changeset
350
kono
parents:
diff changeset
351 If true, :func:`gcc_jit_context_compile` will dump its initial
kono
parents:
diff changeset
352 "tree" representation of your code to stderr (before any
kono
parents:
diff changeset
353 optimizations).
kono
parents:
diff changeset
354
kono
parents:
diff changeset
355 Here's some sample output (from the `square` example)::
kono
parents:
diff changeset
356
kono
parents:
diff changeset
357 <statement_list 0x7f4875a62cc0
kono
parents:
diff changeset
358 type <void_type 0x7f4875a64bd0 VOID
kono
parents:
diff changeset
359 align 8 symtab 0 alias set -1 canonical type 0x7f4875a64bd0
kono
parents:
diff changeset
360 pointer_to_this <pointer_type 0x7f4875a64c78>>
kono
parents:
diff changeset
361 side-effects head 0x7f4875a761e0 tail 0x7f4875a761f8 stmts 0x7f4875a62d20 0x7f4875a62d00
kono
parents:
diff changeset
362
kono
parents:
diff changeset
363 stmt <label_expr 0x7f4875a62d20 type <void_type 0x7f4875a64bd0>
kono
parents:
diff changeset
364 side-effects
kono
parents:
diff changeset
365 arg 0 <label_decl 0x7f4875a79080 entry type <void_type 0x7f4875a64bd0>
kono
parents:
diff changeset
366 VOID file (null) line 0 col 0
kono
parents:
diff changeset
367 align 1 context <function_decl 0x7f4875a77500 square>>>
kono
parents:
diff changeset
368 stmt <return_expr 0x7f4875a62d00
kono
parents:
diff changeset
369 type <integer_type 0x7f4875a645e8 public SI
kono
parents:
diff changeset
370 size <integer_cst 0x7f4875a623a0 constant 32>
kono
parents:
diff changeset
371 unit size <integer_cst 0x7f4875a623c0 constant 4>
kono
parents:
diff changeset
372 align 32 symtab 0 alias set -1 canonical type 0x7f4875a645e8 precision 32 min <integer_cst 0x7f4875a62340 -2147483648> max <integer_cst 0x7f4875a62360 2147483647>
kono
parents:
diff changeset
373 pointer_to_this <pointer_type 0x7f4875a6b348>>
kono
parents:
diff changeset
374 side-effects
kono
parents:
diff changeset
375 arg 0 <modify_expr 0x7f4875a72a78 type <integer_type 0x7f4875a645e8>
kono
parents:
diff changeset
376 side-effects arg 0 <result_decl 0x7f4875a7a000 D.54>
kono
parents:
diff changeset
377 arg 1 <mult_expr 0x7f4875a72a50 type <integer_type 0x7f4875a645e8>
kono
parents:
diff changeset
378 arg 0 <parm_decl 0x7f4875a79000 i> arg 1 <parm_decl 0x7f4875a79000 i>>>>>
kono
parents:
diff changeset
379
kono
parents:
diff changeset
380 .. macro:: GCC_JIT_BOOL_OPTION_DUMP_INITIAL_GIMPLE
kono
parents:
diff changeset
381
kono
parents:
diff changeset
382 If true, :func:`gcc_jit_context_compile` will dump the "gimple"
kono
parents:
diff changeset
383 representation of your code to stderr, before any optimizations
kono
parents:
diff changeset
384 are performed. The dump resembles C code:
kono
parents:
diff changeset
385
kono
parents:
diff changeset
386 .. code-block:: c
kono
parents:
diff changeset
387
kono
parents:
diff changeset
388 square (signed int i)
kono
parents:
diff changeset
389 {
kono
parents:
diff changeset
390 signed int D.56;
kono
parents:
diff changeset
391
kono
parents:
diff changeset
392 entry:
kono
parents:
diff changeset
393 D.56 = i * i;
kono
parents:
diff changeset
394 return D.56;
kono
parents:
diff changeset
395 }
kono
parents:
diff changeset
396
kono
parents:
diff changeset
397 .. macro:: GCC_JIT_BOOL_OPTION_DUMP_GENERATED_CODE
kono
parents:
diff changeset
398
kono
parents:
diff changeset
399 If true, :func:`gcc_jit_context_compile` will dump the final
kono
parents:
diff changeset
400 generated code to stderr, in the form of assembly language:
kono
parents:
diff changeset
401
kono
parents:
diff changeset
402 .. code-block:: gas
kono
parents:
diff changeset
403
kono
parents:
diff changeset
404 .file "fake.c"
kono
parents:
diff changeset
405 .text
kono
parents:
diff changeset
406 .globl square
kono
parents:
diff changeset
407 .type square, @function
kono
parents:
diff changeset
408 square:
kono
parents:
diff changeset
409 .LFB0:
kono
parents:
diff changeset
410 .cfi_startproc
kono
parents:
diff changeset
411 pushq %rbp
kono
parents:
diff changeset
412 .cfi_def_cfa_offset 16
kono
parents:
diff changeset
413 .cfi_offset 6, -16
kono
parents:
diff changeset
414 movq %rsp, %rbp
kono
parents:
diff changeset
415 .cfi_def_cfa_register 6
kono
parents:
diff changeset
416 movl %edi, -4(%rbp)
kono
parents:
diff changeset
417 .L2:
kono
parents:
diff changeset
418 movl -4(%rbp), %eax
kono
parents:
diff changeset
419 imull -4(%rbp), %eax
kono
parents:
diff changeset
420 popq %rbp
kono
parents:
diff changeset
421 .cfi_def_cfa 7, 8
kono
parents:
diff changeset
422 ret
kono
parents:
diff changeset
423 .cfi_endproc
kono
parents:
diff changeset
424 .LFE0:
kono
parents:
diff changeset
425 .size square, .-square
kono
parents:
diff changeset
426 .ident "GCC: (GNU) 4.9.0 20131023 (Red Hat 0.1-%{gcc_release})"
kono
parents:
diff changeset
427 .section .note.GNU-stack,"",@progbits
kono
parents:
diff changeset
428
kono
parents:
diff changeset
429
kono
parents:
diff changeset
430 .. macro:: GCC_JIT_BOOL_OPTION_DUMP_SUMMARY
kono
parents:
diff changeset
431
kono
parents:
diff changeset
432 If true, :func:`gcc_jit_context_compile` will print information to stderr
kono
parents:
diff changeset
433 on the actions it is performing.
kono
parents:
diff changeset
434
kono
parents:
diff changeset
435 .. macro:: GCC_JIT_BOOL_OPTION_DUMP_EVERYTHING
kono
parents:
diff changeset
436
kono
parents:
diff changeset
437 If true, :func:`gcc_jit_context_compile` will dump copious
kono
parents:
diff changeset
438 amount of information on what it's doing to various
kono
parents:
diff changeset
439 files within a temporary directory. Use
kono
parents:
diff changeset
440 :macro:`GCC_JIT_BOOL_OPTION_KEEP_INTERMEDIATES` (see below) to
kono
parents:
diff changeset
441 see the results. The files are intended to be human-readable,
kono
parents:
diff changeset
442 but the exact files and their formats are subject to change.
kono
parents:
diff changeset
443
kono
parents:
diff changeset
444 .. macro:: GCC_JIT_BOOL_OPTION_SELFCHECK_GC
kono
parents:
diff changeset
445
kono
parents:
diff changeset
446 If true, libgccjit will aggressively run its garbage collector, to
kono
parents:
diff changeset
447 shake out bugs (greatly slowing down the compile). This is likely
kono
parents:
diff changeset
448 to only be of interest to developers *of* the library. It is
kono
parents:
diff changeset
449 used when running the selftest suite.
kono
parents:
diff changeset
450
kono
parents:
diff changeset
451 .. macro:: GCC_JIT_BOOL_OPTION_KEEP_INTERMEDIATES
kono
parents:
diff changeset
452
kono
parents:
diff changeset
453 If true, the :type:`gcc_jit_context` will not clean up intermediate files
kono
parents:
diff changeset
454 written to the filesystem, and will display their location on stderr.
kono
parents:
diff changeset
455
kono
parents:
diff changeset
456 .. function:: void \
kono
parents:
diff changeset
457 gcc_jit_context_set_bool_allow_unreachable_blocks (gcc_jit_context *ctxt, \
kono
parents:
diff changeset
458 int bool_value)
kono
parents:
diff changeset
459
kono
parents:
diff changeset
460 By default, libgccjit will issue an error about unreachable blocks
kono
parents:
diff changeset
461 within a function.
kono
parents:
diff changeset
462
kono
parents:
diff changeset
463 This entrypoint can be used to disable that error.
kono
parents:
diff changeset
464
kono
parents:
diff changeset
465 This entrypoint was added in :ref:`LIBGCCJIT_ABI_2`; you can test for
kono
parents:
diff changeset
466 its presence using
kono
parents:
diff changeset
467
kono
parents:
diff changeset
468 .. code-block:: c
kono
parents:
diff changeset
469
kono
parents:
diff changeset
470 #ifdef LIBGCCJIT_HAVE_gcc_jit_context_set_bool_allow_unreachable_blocks
kono
parents:
diff changeset
471
kono
parents:
diff changeset
472 .. function:: void \
kono
parents:
diff changeset
473 gcc_jit_context_set_bool_use_external_driver (gcc_jit_context *ctxt, \
kono
parents:
diff changeset
474 int bool_value)
kono
parents:
diff changeset
475
kono
parents:
diff changeset
476 libgccjit internally generates assembler, and uses "driver" code
kono
parents:
diff changeset
477 for converting it to other formats (e.g. shared libraries).
kono
parents:
diff changeset
478
kono
parents:
diff changeset
479 By default, libgccjit will use an embedded copy of the driver
kono
parents:
diff changeset
480 code.
kono
parents:
diff changeset
481
kono
parents:
diff changeset
482 This option can be used to instead invoke an external driver executable
kono
parents:
diff changeset
483 as a subprocess.
kono
parents:
diff changeset
484
kono
parents:
diff changeset
485 This entrypoint was added in :ref:`LIBGCCJIT_ABI_5`; you can test for
kono
parents:
diff changeset
486 its presence using
kono
parents:
diff changeset
487
kono
parents:
diff changeset
488 .. code-block:: c
kono
parents:
diff changeset
489
kono
parents:
diff changeset
490 #ifdef LIBGCCJIT_HAVE_gcc_jit_context_set_bool_use_external_driver
kono
parents:
diff changeset
491
kono
parents:
diff changeset
492 Integer options
kono
parents:
diff changeset
493 ***************
kono
parents:
diff changeset
494
kono
parents:
diff changeset
495 .. function:: void gcc_jit_context_set_int_option (gcc_jit_context *ctxt, \
kono
parents:
diff changeset
496 enum gcc_jit_int_option opt, \
kono
parents:
diff changeset
497 int value)
kono
parents:
diff changeset
498
kono
parents:
diff changeset
499 Set an integer option of the context.
kono
parents:
diff changeset
500
kono
parents:
diff changeset
501 .. type:: enum gcc_jit_int_option
kono
parents:
diff changeset
502
kono
parents:
diff changeset
503 There is just one integer option specified this way:
kono
parents:
diff changeset
504
kono
parents:
diff changeset
505 .. macro:: GCC_JIT_INT_OPTION_OPTIMIZATION_LEVEL
kono
parents:
diff changeset
506
kono
parents:
diff changeset
507 How much to optimize the code.
kono
parents:
diff changeset
508
kono
parents:
diff changeset
509 Valid values are 0-3, corresponding to GCC's command-line options
kono
parents:
diff changeset
510 -O0 through -O3.
kono
parents:
diff changeset
511
kono
parents:
diff changeset
512 The default value is 0 (unoptimized).
kono
parents:
diff changeset
513
kono
parents:
diff changeset
514 Additional command-line options
kono
parents:
diff changeset
515 *******************************
kono
parents:
diff changeset
516
kono
parents:
diff changeset
517 .. function:: void gcc_jit_context_add_command_line_option (gcc_jit_context *ctxt,\
kono
parents:
diff changeset
518 const char *optname)
kono
parents:
diff changeset
519
kono
parents:
diff changeset
520 Add an arbitrary gcc command-line option to the context, for use
kono
parents:
diff changeset
521 by :func:`gcc_jit_context_compile` and
kono
parents:
diff changeset
522 :func:`gcc_jit_context_compile_to_file`.
kono
parents:
diff changeset
523
kono
parents:
diff changeset
524 The parameter ``optname`` must be non-NULL. The underlying buffer is
kono
parents:
diff changeset
525 copied, so that it does not need to outlive the call.
kono
parents:
diff changeset
526
kono
parents:
diff changeset
527 Extra options added by `gcc_jit_context_add_command_line_option` are
kono
parents:
diff changeset
528 applied *after* the regular options above, potentially overriding them.
kono
parents:
diff changeset
529 Options from parent contexts are inherited by child contexts; options
kono
parents:
diff changeset
530 from the parent are applied *before* those from the child.
kono
parents:
diff changeset
531
kono
parents:
diff changeset
532 For example:
kono
parents:
diff changeset
533
kono
parents:
diff changeset
534 .. code-block:: c
kono
parents:
diff changeset
535
kono
parents:
diff changeset
536 gcc_jit_context_add_command_line_option (ctxt, "-ffast-math");
kono
parents:
diff changeset
537 gcc_jit_context_add_command_line_option (ctxt, "-fverbose-asm");
kono
parents:
diff changeset
538
kono
parents:
diff changeset
539 Note that only some options are likely to be meaningful; there is no
kono
parents:
diff changeset
540 "frontend" within libgccjit, so typically only those affecting
kono
parents:
diff changeset
541 optimization and code-generation are likely to be useful.
kono
parents:
diff changeset
542
kono
parents:
diff changeset
543 This entrypoint was added in :ref:`LIBGCCJIT_ABI_1`; you can test for
kono
parents:
diff changeset
544 its presence using
kono
parents:
diff changeset
545
kono
parents:
diff changeset
546 .. code-block:: c
kono
parents:
diff changeset
547
kono
parents:
diff changeset
548 #ifdef LIBGCCJIT_HAVE_gcc_jit_context_add_command_line_option