1 /* A pure C API to enable client code to embed GCC as a JIT-compiler. 2 Copyright (C) 2013-2019 Free Software Foundation, Inc. 3 4 This file is part of GCC. 5 6 GCC is free software; you can redistribute it and/or modify it 7 under the terms of the GNU General Public License as published by 8 the Free Software Foundation; either version 3, or (at your option) 9 any later version. 10 11 GCC is distributed in the hope that it will be useful, but 12 WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 General Public License for more details. 15 16 You should have received a copy of the GNU General Public License 17 along with GCC; see the file COPYING3. If not see 18 <http://www.gnu.org/licenses/>. */ 19 20 #ifndef LIBGCCJIT_H 21 #define LIBGCCJIT_H 22 23 #include <stdio.h> 24 25 #ifdef __cplusplus 26 extern "C" { 27 #endif /* __cplusplus */ 28 29 /********************************************************************** 30 Data structures. 31 **********************************************************************/ 32 /* All structs within the API are opaque. */ 33 34 /* A gcc_jit_context encapsulates the state of a compilation. 35 You can set up options on it, and add types, functions and code, using 36 the API below. 37 38 Invoking gcc_jit_context_compile on it gives you a gcc_jit_result * 39 (or NULL), representing in-memory machine code. 40 41 You can call gcc_jit_context_compile repeatedly on one context, giving 42 multiple independent results. 43 44 Similarly, you can call gcc_jit_context_compile_to_file on a context 45 to compile to disk. 46 47 Eventually you can call gcc_jit_context_release to clean up the 48 context; any in-memory results created from it are still usable, and 49 should be cleaned up via gcc_jit_result_release. */ 50 typedef struct gcc_jit_context gcc_jit_context; 51 52 /* A gcc_jit_result encapsulates the result of an in-memory compilation. */ 53 typedef struct gcc_jit_result gcc_jit_result; 54 55 /* An object created within a context. Such objects are automatically 56 cleaned up when the context is released. 57 58 The class hierarchy looks like this: 59 60 +- gcc_jit_object 61 +- gcc_jit_location 62 +- gcc_jit_type 63 +- gcc_jit_struct 64 +- gcc_jit_field 65 +- gcc_jit_function 66 +- gcc_jit_block 67 +- gcc_jit_rvalue 68 +- gcc_jit_lvalue 69 +- gcc_jit_param 70 +- gcc_jit_case 71 */ 72 typedef struct gcc_jit_object gcc_jit_object; 73 74 /* A gcc_jit_location encapsulates a source code location, so that 75 you can (optionally) associate locations in your language with 76 statements in the JIT-compiled code, allowing the debugger to 77 single-step through your language. 78 79 Note that to do so, you also need to enable 80 GCC_JIT_BOOL_OPTION_DEBUGINFO 81 on the gcc_jit_context. 82 83 gcc_jit_location instances are optional; you can always pass 84 NULL. */ 85 typedef struct gcc_jit_location gcc_jit_location; 86 87 /* A gcc_jit_type encapsulates a type e.g. "int" or a "struct foo*". */ 88 typedef struct gcc_jit_type gcc_jit_type; 89 90 /* A gcc_jit_field encapsulates a field within a struct; it is used 91 when creating a struct type (using gcc_jit_context_new_struct_type). 92 Fields cannot be shared between structs. */ 93 typedef struct gcc_jit_field gcc_jit_field; 94 95 /* A gcc_jit_struct encapsulates a struct type, either one that we have 96 the layout for, or an opaque type. */ 97 typedef struct gcc_jit_struct gcc_jit_struct; 98 99 /* A gcc_jit_function encapsulates a function: either one that you're 100 creating yourself, or a reference to one that you're dynamically 101 linking to within the rest of the process. */ 102 typedef struct gcc_jit_function gcc_jit_function; 103 104 /* A gcc_jit_block encapsulates a "basic block" of statements within a 105 function (i.e. with one entry point and one exit point). 106 107 Every block within a function must be terminated with a conditional, 108 a branch, or a return. 109 110 The blocks within a function form a directed graph. 111 112 The entrypoint to the function is the first block created within 113 it. 114 115 All of the blocks in a function must be reachable via some path from 116 the first block. 117 118 It's OK to have more than one "return" from a function (i.e. multiple 119 blocks that terminate by returning). */ 120 typedef struct gcc_jit_block gcc_jit_block; 121 122 /* A gcc_jit_rvalue is an expression within your code, with some type. */ 123 typedef struct gcc_jit_rvalue gcc_jit_rvalue; 124 125 /* A gcc_jit_lvalue is a storage location within your code (e.g. a 126 variable, a parameter, etc). It is also a gcc_jit_rvalue; use 127 gcc_jit_lvalue_as_rvalue to cast. */ 128 typedef struct gcc_jit_lvalue gcc_jit_lvalue; 129 130 /* A gcc_jit_param is a function parameter, used when creating a 131 gcc_jit_function. It is also a gcc_jit_lvalue (and thus also an 132 rvalue); use gcc_jit_param_as_lvalue to convert. */ 133 typedef struct gcc_jit_param gcc_jit_param; 134 135 /* A gcc_jit_case is for use when building multiway branches via 136 gcc_jit_block_end_with_switch and represents a range of integer 137 values (or an individual integer value) together with an associated 138 destination block. */ 139 typedef struct gcc_jit_case gcc_jit_case; 140 141 /* Acquire a JIT-compilation context. */ 142 extern gcc_jit_context * 143 gcc_jit_context_acquire (void); 144 145 /* Release the context. After this call, it's no longer valid to use 146 the ctxt. */ 147 extern void 148 gcc_jit_context_release (gcc_jit_context *ctxt); 149 150 /* Options present in the initial release of libgccjit. 151 These were handled using enums. */ 152 153 /* Options taking string values. */ 154 enum gcc_jit_str_option 155 { 156 /* The name of the program, for use as a prefix when printing error 157 messages to stderr. If NULL, or default, "libgccjit.so" is used. */ 158 GCC_JIT_STR_OPTION_PROGNAME, 159 160 GCC_JIT_NUM_STR_OPTIONS 161 }; 162 163 /* Options taking int values. */ 164 enum gcc_jit_int_option 165 { 166 /* How much to optimize the code. 167 Valid values are 0-3, corresponding to GCC's command-line options 168 -O0 through -O3. 169 170 The default value is 0 (unoptimized). */ 171 GCC_JIT_INT_OPTION_OPTIMIZATION_LEVEL, 172 173 GCC_JIT_NUM_INT_OPTIONS 174 }; 175 176 /* Options taking boolean values. 177 These all default to "false". */ 178 enum gcc_jit_bool_option 179 { 180 /* If true, gcc_jit_context_compile will attempt to do the right 181 thing so that if you attach a debugger to the process, it will 182 be able to inspect variables and step through your code. 183 184 Note that you can't step through code unless you set up source 185 location information for the code (by creating and passing in 186 gcc_jit_location instances). */ 187 GCC_JIT_BOOL_OPTION_DEBUGINFO, 188 189 /* If true, gcc_jit_context_compile will dump its initial "tree" 190 representation of your code to stderr (before any 191 optimizations). */ 192 GCC_JIT_BOOL_OPTION_DUMP_INITIAL_TREE, 193 194 /* If true, gcc_jit_context_compile will dump the "gimple" 195 representation of your code to stderr, before any optimizations 196 are performed. The dump resembles C code. */ 197 GCC_JIT_BOOL_OPTION_DUMP_INITIAL_GIMPLE, 198 199 /* If true, gcc_jit_context_compile will dump the final 200 generated code to stderr, in the form of assembly language. */ 201 GCC_JIT_BOOL_OPTION_DUMP_GENERATED_CODE, 202 203 /* If true, gcc_jit_context_compile will print information to stderr 204 on the actions it is performing, followed by a profile showing 205 the time taken and memory usage of each phase. 206 */ 207 GCC_JIT_BOOL_OPTION_DUMP_SUMMARY, 208 209 /* If true, gcc_jit_context_compile will dump copious 210 amount of information on what it's doing to various 211 files within a temporary directory. Use 212 GCC_JIT_BOOL_OPTION_KEEP_INTERMEDIATES (see below) to 213 see the results. The files are intended to be human-readable, 214 but the exact files and their formats are subject to change. 215 */ 216 GCC_JIT_BOOL_OPTION_DUMP_EVERYTHING, 217 218 /* If true, libgccjit will aggressively run its garbage collector, to 219 shake out bugs (greatly slowing down the compile). This is likely 220 to only be of interest to developers *of* the library. It is 221 used when running the selftest suite. */ 222 GCC_JIT_BOOL_OPTION_SELFCHECK_GC, 223 224 /* If true, gcc_jit_context_release will not clean up 225 intermediate files written to the filesystem, and will display 226 their location on stderr. */ 227 GCC_JIT_BOOL_OPTION_KEEP_INTERMEDIATES, 228 229 GCC_JIT_NUM_BOOL_OPTIONS 230 }; 231 232 /* Set a string option on the given context. 233 234 The context takes a copy of the string, so the 235 (const char *) buffer is not needed anymore after the call 236 returns. */ 237 extern void 238 gcc_jit_context_set_str_option (gcc_jit_context *ctxt, 239 enum gcc_jit_str_option opt, 240 const char *value); 241 242 /* Set an int option on the given context. */ 243 extern void 244 gcc_jit_context_set_int_option (gcc_jit_context *ctxt, 245 enum gcc_jit_int_option opt, 246 int value); 247 248 /* Set a boolean option on the given context. 249 250 Zero is "false" (the default), non-zero is "true". */ 251 extern void 252 gcc_jit_context_set_bool_option (gcc_jit_context *ctxt, 253 enum gcc_jit_bool_option opt, 254 int value); 255 256 /* Options added after the initial release of libgccjit. 257 These are handled by providing an entrypoint per option, 258 rather than by extending the enum gcc_jit_*_option, 259 so that client code that use these new options can be identified 260 from binary metadata. */ 261 262 /* By default, libgccjit will issue an error about unreachable blocks 263 within a function. 264 265 This option can be used to disable that error. 266 267 This entrypoint was added in LIBGCCJIT_ABI_2; you can test for 268 its presence using 269 #ifdef LIBGCCJIT_HAVE_gcc_jit_context_set_bool_allow_unreachable_blocks 270 */ 271 272 extern void 273 gcc_jit_context_set_bool_allow_unreachable_blocks (gcc_jit_context *ctxt, 274 int bool_value); 275 276 /* Pre-canned feature macro to indicate the presence of 277 gcc_jit_context_set_bool_allow_unreachable_blocks. This can be 278 tested for with #ifdef. */ 279 #define LIBGCCJIT_HAVE_gcc_jit_context_set_bool_allow_unreachable_blocks 280 281 /* Implementation detail: 282 libgccjit internally generates assembler, and uses "driver" code 283 for converting it to other formats (e.g. shared libraries). 284 285 By default, libgccjit will use an embedded copy of the driver 286 code. 287 288 This option can be used to instead invoke an external driver executable 289 as a subprocess. 290 291 This entrypoint was added in LIBGCCJIT_ABI_5; you can test for 292 its presence using 293 #ifdef LIBGCCJIT_HAVE_gcc_jit_context_set_bool_use_external_driver 294 */ 295 296 extern void 297 gcc_jit_context_set_bool_use_external_driver (gcc_jit_context *ctxt, 298 int bool_value); 299 300 /* Pre-canned feature macro to indicate the presence of 301 gcc_jit_context_set_bool_use_external_driver. This can be 302 tested for with #ifdef. */ 303 #define LIBGCCJIT_HAVE_gcc_jit_context_set_bool_use_external_driver 304 305 /* Add an arbitrary gcc command-line option to the context. 306 The context takes a copy of the string, so the 307 (const char *) optname is not needed anymore after the call 308 returns. 309 310 Note that only some options are likely to be meaningful; there is no 311 "frontend" within libgccjit, so typically only those affecting 312 optimization and code-generation are likely to be useful. 313 314 This entrypoint was added in LIBGCCJIT_ABI_1; you can test for 315 its presence using 316 #ifdef LIBGCCJIT_HAVE_gcc_jit_context_add_command_line_option 317 */ 318 319 extern void 320 gcc_jit_context_add_command_line_option (gcc_jit_context *ctxt, 321 const char *optname); 322 323 /* Pre-canned feature-test macro for detecting the presence of 324 gcc_jit_context_add_command_line_option within libgccjit.h. */ 325 326 #define LIBGCCJIT_HAVE_gcc_jit_context_add_command_line_option 327 328 /* Add an arbitrary gcc driver option to the context. 329 The context takes a copy of the string, so the 330 (const char *) optname is not needed anymore after the call 331 returns. 332 333 Note that only some options are likely to be meaningful; there is no 334 "frontend" within libgccjit, so typically only those affecting 335 assembler and linker are likely to be useful. 336 337 This entrypoint was added in LIBGCCJIT_ABI_11; you can test for 338 its presence using 339 #ifdef LIBGCCJIT_HAVE_gcc_jit_context_add_driver_option 340 */ 341 extern void 342 gcc_jit_context_add_driver_option (gcc_jit_context *ctxt, 343 const char *optname); 344 345 /* Pre-canned feature-test macro for detecting the presence of 346 gcc_jit_context_add_driver_option within libgccjit.h. */ 347 348 #define LIBGCCJIT_HAVE_gcc_jit_context_add_driver_option 349 350 /* Compile the context to in-memory machine code. 351 352 This can be called more that once on a given context, 353 although any errors that occur will block further compilation. */ 354 355 extern gcc_jit_result * 356 gcc_jit_context_compile (gcc_jit_context *ctxt); 357 358 /* Kinds of ahead-of-time compilation, for use with 359 gcc_jit_context_compile_to_file. */ 360 361 enum gcc_jit_output_kind 362 { 363 /* Compile the context to an assembler file. */ 364 GCC_JIT_OUTPUT_KIND_ASSEMBLER, 365 366 /* Compile the context to an object file. */ 367 GCC_JIT_OUTPUT_KIND_OBJECT_FILE, 368 369 /* Compile the context to a dynamic library. */ 370 GCC_JIT_OUTPUT_KIND_DYNAMIC_LIBRARY, 371 372 /* Compile the context to an executable. */ 373 GCC_JIT_OUTPUT_KIND_EXECUTABLE 374 }; 375 376 /* Compile the context to a file of the given kind. 377 378 This can be called more that once on a given context, 379 although any errors that occur will block further compilation. */ 380 381 extern void 382 gcc_jit_context_compile_to_file (gcc_jit_context *ctxt, 383 enum gcc_jit_output_kind output_kind, 384 const char *output_path); 385 386 /* To help with debugging: dump a C-like representation to the given path, 387 describing what's been set up on the context. 388 389 If "update_locations" is true, then also set up gcc_jit_location 390 information throughout the context, pointing at the dump file as if it 391 were a source file. This may be of use in conjunction with 392 GCC_JIT_BOOL_OPTION_DEBUGINFO to allow stepping through the code in a 393 debugger. */ 394 extern void 395 gcc_jit_context_dump_to_file (gcc_jit_context *ctxt, 396 const char *path, 397 int update_locations); 398 399 /* To help with debugging; enable ongoing logging of the context's 400 activity to the given FILE *. 401 402 The caller remains responsible for closing "logfile". 403 404 Params "flags" and "verbosity" are reserved for future use, and 405 must both be 0 for now. */ 406 extern void 407 gcc_jit_context_set_logfile (gcc_jit_context *ctxt, 408 FILE *logfile, 409 int flags, 410 int verbosity); 411 412 /* To be called after any API call, this gives the first error message 413 that occurred on the context. 414 415 The returned string is valid for the rest of the lifetime of the 416 context. 417 418 If no errors occurred, this will be NULL. */ 419 extern const char * 420 gcc_jit_context_get_first_error (gcc_jit_context *ctxt); 421 422 /* To be called after any API call, this gives the last error message 423 that occurred on the context. 424 425 If no errors occurred, this will be NULL. 426 427 If non-NULL, the returned string is only guaranteed to be valid until 428 the next call to libgccjit relating to this context. */ 429 extern const char * 430 gcc_jit_context_get_last_error (gcc_jit_context *ctxt); 431 432 /* Locate a given function within the built machine code. 433 This will need to be cast to a function pointer of the 434 correct type before it can be called. */ 435 extern void * 436 gcc_jit_result_get_code (gcc_jit_result *result, 437 const char *funcname); 438 439 /* Locate a given global within the built machine code. 440 It must have been created using GCC_JIT_GLOBAL_EXPORTED. 441 This is a ptr to the global, so e.g. for an int this is an int *. */ 442 extern void * 443 gcc_jit_result_get_global (gcc_jit_result *result, 444 const char *name); 445 446 /* Once we're done with the code, this unloads the built .so file. 447 This cleans up the result; after calling this, it's no longer 448 valid to use the result. */ 449 extern void 450 gcc_jit_result_release (gcc_jit_result *result); 451 452 453 /********************************************************************** 454 Functions for creating "contextual" objects. 455 456 All objects created by these functions share the lifetime of the context 457 they are created within, and are automatically cleaned up for you when 458 you call gcc_jit_context_release on the context. 459 460 Note that this means you can't use references to them after you've 461 released their context. 462 463 All (const char *) string arguments passed to these functions are 464 copied, so you don't need to keep them around. 465 466 You create code by adding a sequence of statements to blocks. 467 **********************************************************************/ 468 469 /********************************************************************** 470 The base class of "contextual" object. 471 **********************************************************************/ 472 /* Which context is "obj" within? */ 473 extern gcc_jit_context * 474 gcc_jit_object_get_context (gcc_jit_object *obj); 475 476 /* Get a human-readable description of this object. 477 The string buffer is created the first time this is called on a given 478 object, and persists until the object's context is released. */ 479 extern const char * 480 gcc_jit_object_get_debug_string (gcc_jit_object *obj); 481 482 /********************************************************************** 483 Debugging information. 484 **********************************************************************/ 485 486 /* Creating source code locations for use by the debugger. 487 Line and column numbers are 1-based. */ 488 extern gcc_jit_location * 489 gcc_jit_context_new_location (gcc_jit_context *ctxt, 490 const char *filename, 491 int line, 492 int column); 493 494 /* Upcasting from location to object. */ 495 extern gcc_jit_object * 496 gcc_jit_location_as_object (gcc_jit_location *loc); 497 498 499 /********************************************************************** 500 Types. 501 **********************************************************************/ 502 503 /* Upcasting from type to object. */ 504 extern gcc_jit_object * 505 gcc_jit_type_as_object (gcc_jit_type *type); 506 507 /* Access to specific types. */ 508 enum gcc_jit_types 509 { 510 /* C's "void" type. */ 511 GCC_JIT_TYPE_VOID, 512 513 /* "void *". */ 514 GCC_JIT_TYPE_VOID_PTR, 515 516 /* C++'s bool type; also C99's "_Bool" type, aka "bool" if using 517 stdbool.h. */ 518 GCC_JIT_TYPE_BOOL, 519 520 /* Various integer types. */ 521 522 /* C's "char" (of some signedness) and the variants where the 523 signedness is specified. */ 524 GCC_JIT_TYPE_CHAR, 525 GCC_JIT_TYPE_SIGNED_CHAR, 526 GCC_JIT_TYPE_UNSIGNED_CHAR, 527 528 /* C's "short" and "unsigned short". */ 529 GCC_JIT_TYPE_SHORT, /* signed */ 530 GCC_JIT_TYPE_UNSIGNED_SHORT, 531 532 /* C's "int" and "unsigned int". */ 533 GCC_JIT_TYPE_INT, /* signed */ 534 GCC_JIT_TYPE_UNSIGNED_INT, 535 536 /* C's "long" and "unsigned long". */ 537 GCC_JIT_TYPE_LONG, /* signed */ 538 GCC_JIT_TYPE_UNSIGNED_LONG, 539 540 /* C99's "long long" and "unsigned long long". */ 541 GCC_JIT_TYPE_LONG_LONG, /* signed */ 542 GCC_JIT_TYPE_UNSIGNED_LONG_LONG, 543 544 /* Floating-point types */ 545 546 GCC_JIT_TYPE_FLOAT, 547 GCC_JIT_TYPE_DOUBLE, 548 GCC_JIT_TYPE_LONG_DOUBLE, 549 550 /* C type: (const char *). */ 551 GCC_JIT_TYPE_CONST_CHAR_PTR, 552 553 /* The C "size_t" type. */ 554 GCC_JIT_TYPE_SIZE_T, 555 556 /* C type: (FILE *) */ 557 GCC_JIT_TYPE_FILE_PTR, 558 559 /* Complex numbers. */ 560 GCC_JIT_TYPE_COMPLEX_FLOAT, 561 GCC_JIT_TYPE_COMPLEX_DOUBLE, 562 GCC_JIT_TYPE_COMPLEX_LONG_DOUBLE 563 564 }; 565 566 extern gcc_jit_type * 567 gcc_jit_context_get_type (gcc_jit_context *ctxt, 568 enum gcc_jit_types type_); 569 570 /* Get the integer type of the given size and signedness. */ 571 extern gcc_jit_type * 572 gcc_jit_context_get_int_type (gcc_jit_context *ctxt, 573 int num_bytes, int is_signed); 574 575 /* Constructing new types. */ 576 577 /* Given type "T", get type "T*". */ 578 extern gcc_jit_type * 579 gcc_jit_type_get_pointer (gcc_jit_type *type); 580 581 /* Given type "T", get type "const T". */ 582 extern gcc_jit_type * 583 gcc_jit_type_get_const (gcc_jit_type *type); 584 585 /* Given type "T", get type "volatile T". */ 586 extern gcc_jit_type * 587 gcc_jit_type_get_volatile (gcc_jit_type *type); 588 589 /* Given type "T", get type "T[N]" (for a constant N). */ 590 extern gcc_jit_type * 591 gcc_jit_context_new_array_type (gcc_jit_context *ctxt, 592 gcc_jit_location *loc, 593 gcc_jit_type *element_type, 594 int num_elements); 595 596 /* Struct-handling. */ 597 598 /* Create a field, for use within a struct or union. */ 599 extern gcc_jit_field * 600 gcc_jit_context_new_field (gcc_jit_context *ctxt, 601 gcc_jit_location *loc, 602 gcc_jit_type *type, 603 const char *name); 604 605 /* Upcasting from field to object. */ 606 extern gcc_jit_object * 607 gcc_jit_field_as_object (gcc_jit_field *field); 608 609 /* Create a struct type from an array of fields. */ 610 extern gcc_jit_struct * 611 gcc_jit_context_new_struct_type (gcc_jit_context *ctxt, 612 gcc_jit_location *loc, 613 const char *name, 614 int num_fields, 615 gcc_jit_field **fields); 616 617 /* Create an opaque struct type. */ 618 extern gcc_jit_struct * 619 gcc_jit_context_new_opaque_struct (gcc_jit_context *ctxt, 620 gcc_jit_location *loc, 621 const char *name); 622 623 /* Upcast a struct to a type. */ 624 extern gcc_jit_type * 625 gcc_jit_struct_as_type (gcc_jit_struct *struct_type); 626 627 /* Populating the fields of a formerly-opaque struct type. 628 This can only be called once on a given struct type. */ 629 extern void 630 gcc_jit_struct_set_fields (gcc_jit_struct *struct_type, 631 gcc_jit_location *loc, 632 int num_fields, 633 gcc_jit_field **fields); 634 635 /* Unions work similarly to structs. */ 636 extern gcc_jit_type * 637 gcc_jit_context_new_union_type (gcc_jit_context *ctxt, 638 gcc_jit_location *loc, 639 const char *name, 640 int num_fields, 641 gcc_jit_field **fields); 642 643 /* Function pointers. */ 644 645 extern gcc_jit_type * 646 gcc_jit_context_new_function_ptr_type (gcc_jit_context *ctxt, 647 gcc_jit_location *loc, 648 gcc_jit_type *return_type, 649 int num_params, 650 gcc_jit_type **param_types, 651 int is_variadic); 652 653 /********************************************************************** 654 Constructing functions. 655 **********************************************************************/ 656 /* Create a function param. */ 657 extern gcc_jit_param * 658 gcc_jit_context_new_param (gcc_jit_context *ctxt, 659 gcc_jit_location *loc, 660 gcc_jit_type *type, 661 const char *name); 662 663 /* Upcasting from param to object. */ 664 extern gcc_jit_object * 665 gcc_jit_param_as_object (gcc_jit_param *param); 666 667 /* Upcasting from param to lvalue. */ 668 extern gcc_jit_lvalue * 669 gcc_jit_param_as_lvalue (gcc_jit_param *param); 670 671 /* Upcasting from param to rvalue. */ 672 extern gcc_jit_rvalue * 673 gcc_jit_param_as_rvalue (gcc_jit_param *param); 674 675 /* Kinds of function. */ 676 enum gcc_jit_function_kind 677 { 678 /* Function is defined by the client code and visible 679 by name outside of the JIT. */ 680 GCC_JIT_FUNCTION_EXPORTED, 681 682 /* Function is defined by the client code, but is invisible 683 outside of the JIT. Analogous to a "static" function. */ 684 GCC_JIT_FUNCTION_INTERNAL, 685 686 /* Function is not defined by the client code; we're merely 687 referring to it. Analogous to using an "extern" function from a 688 header file. */ 689 GCC_JIT_FUNCTION_IMPORTED, 690 691 /* Function is only ever inlined into other functions, and is 692 invisible outside of the JIT. 693 694 Analogous to prefixing with "inline" and adding 695 __attribute__((always_inline)). 696 697 Inlining will only occur when the optimization level is 698 above 0; when optimization is off, this is essentially the 699 same as GCC_JIT_FUNCTION_INTERNAL. */ 700 GCC_JIT_FUNCTION_ALWAYS_INLINE 701 }; 702 703 /* Create a function. */ 704 extern gcc_jit_function * 705 gcc_jit_context_new_function (gcc_jit_context *ctxt, 706 gcc_jit_location *loc, 707 enum gcc_jit_function_kind kind, 708 gcc_jit_type *return_type, 709 const char *name, 710 int num_params, 711 gcc_jit_param **params, 712 int is_variadic); 713 714 /* Create a reference to a builtin function (sometimes called 715 intrinsic functions). */ 716 extern gcc_jit_function * 717 gcc_jit_context_get_builtin_function (gcc_jit_context *ctxt, 718 const char *name); 719 720 /* Upcasting from function to object. */ 721 extern gcc_jit_object * 722 gcc_jit_function_as_object (gcc_jit_function *func); 723 724 /* Get a specific param of a function by index. */ 725 extern gcc_jit_param * 726 gcc_jit_function_get_param (gcc_jit_function *func, int index); 727 728 /* Emit the function in graphviz format. */ 729 extern void 730 gcc_jit_function_dump_to_dot (gcc_jit_function *func, 731 const char *path); 732 733 /* Create a block. 734 735 The name can be NULL, or you can give it a meaningful name, which 736 may show up in dumps of the internal representation, and in error 737 messages. */ 738 extern gcc_jit_block * 739 gcc_jit_function_new_block (gcc_jit_function *func, 740 const char *name); 741 742 /* Upcasting from block to object. */ 743 extern gcc_jit_object * 744 gcc_jit_block_as_object (gcc_jit_block *block); 745 746 /* Which function is this block within? */ 747 extern gcc_jit_function * 748 gcc_jit_block_get_function (gcc_jit_block *block); 749 750 /********************************************************************** 751 lvalues, rvalues and expressions. 752 **********************************************************************/ 753 enum gcc_jit_global_kind 754 { 755 /* Global is defined by the client code and visible 756 by name outside of this JIT context via gcc_jit_result_get_global. */ 757 GCC_JIT_GLOBAL_EXPORTED, 758 759 /* Global is defined by the client code, but is invisible 760 outside of this JIT context. Analogous to a "static" global. */ 761 GCC_JIT_GLOBAL_INTERNAL, 762 763 /* Global is not defined by the client code; we're merely 764 referring to it. Analogous to using an "extern" global from a 765 header file. */ 766 GCC_JIT_GLOBAL_IMPORTED 767 }; 768 769 extern gcc_jit_lvalue * 770 gcc_jit_context_new_global (gcc_jit_context *ctxt, 771 gcc_jit_location *loc, 772 enum gcc_jit_global_kind kind, 773 gcc_jit_type *type, 774 const char *name); 775 776 /* Upcasting. */ 777 extern gcc_jit_object * 778 gcc_jit_lvalue_as_object (gcc_jit_lvalue *lvalue); 779 780 extern gcc_jit_rvalue * 781 gcc_jit_lvalue_as_rvalue (gcc_jit_lvalue *lvalue); 782 783 extern gcc_jit_object * 784 gcc_jit_rvalue_as_object (gcc_jit_rvalue *rvalue); 785 786 extern gcc_jit_type * 787 gcc_jit_rvalue_get_type (gcc_jit_rvalue *rvalue); 788 789 /* Integer constants. */ 790 extern gcc_jit_rvalue * 791 gcc_jit_context_new_rvalue_from_int (gcc_jit_context *ctxt, 792 gcc_jit_type *numeric_type, 793 int value); 794 795 extern gcc_jit_rvalue * 796 gcc_jit_context_new_rvalue_from_long (gcc_jit_context *ctxt, 797 gcc_jit_type *numeric_type, 798 long value); 799 800 extern gcc_jit_rvalue * 801 gcc_jit_context_zero (gcc_jit_context *ctxt, 802 gcc_jit_type *numeric_type); 803 804 extern gcc_jit_rvalue * 805 gcc_jit_context_one (gcc_jit_context *ctxt, 806 gcc_jit_type *numeric_type); 807 808 /* Floating-point constants. */ 809 extern gcc_jit_rvalue * 810 gcc_jit_context_new_rvalue_from_double (gcc_jit_context *ctxt, 811 gcc_jit_type *numeric_type, 812 double value); 813 814 /* Pointers. */ 815 extern gcc_jit_rvalue * 816 gcc_jit_context_new_rvalue_from_ptr (gcc_jit_context *ctxt, 817 gcc_jit_type *pointer_type, 818 void *value); 819 820 extern gcc_jit_rvalue * 821 gcc_jit_context_null (gcc_jit_context *ctxt, 822 gcc_jit_type *pointer_type); 823 824 /* String literals. */ 825 extern gcc_jit_rvalue * 826 gcc_jit_context_new_string_literal (gcc_jit_context *ctxt, 827 const char *value); 828 829 enum gcc_jit_unary_op 830 { 831 /* Negate an arithmetic value; analogous to: 832 -(EXPR) 833 in C. */ 834 GCC_JIT_UNARY_OP_MINUS, 835 836 /* Bitwise negation of an integer value (one's complement); analogous 837 to: 838 ~(EXPR) 839 in C. */ 840 GCC_JIT_UNARY_OP_BITWISE_NEGATE, 841 842 /* Logical negation of an arithmetic or pointer value; analogous to: 843 !(EXPR) 844 in C. */ 845 GCC_JIT_UNARY_OP_LOGICAL_NEGATE, 846 847 /* Absolute value of an arithmetic expression; analogous to: 848 abs (EXPR) 849 in C. */ 850 GCC_JIT_UNARY_OP_ABS 851 852 }; 853 854 extern gcc_jit_rvalue * 855 gcc_jit_context_new_unary_op (gcc_jit_context *ctxt, 856 gcc_jit_location *loc, 857 enum gcc_jit_unary_op op, 858 gcc_jit_type *result_type, 859 gcc_jit_rvalue *rvalue); 860 861 enum gcc_jit_binary_op 862 { 863 /* Addition of arithmetic values; analogous to: 864 (EXPR_A) + (EXPR_B) 865 in C. 866 For pointer addition, use gcc_jit_context_new_array_access. */ 867 GCC_JIT_BINARY_OP_PLUS, 868 869 /* Subtraction of arithmetic values; analogous to: 870 (EXPR_A) - (EXPR_B) 871 in C. */ 872 GCC_JIT_BINARY_OP_MINUS, 873 874 /* Multiplication of a pair of arithmetic values; analogous to: 875 (EXPR_A) * (EXPR_B) 876 in C. */ 877 GCC_JIT_BINARY_OP_MULT, 878 879 /* Quotient of division of arithmetic values; analogous to: 880 (EXPR_A) / (EXPR_B) 881 in C. 882 The result type affects the kind of division: if the result type is 883 integer-based, then the result is truncated towards zero, whereas 884 a floating-point result type indicates floating-point division. */ 885 GCC_JIT_BINARY_OP_DIVIDE, 886 887 /* Remainder of division of arithmetic values; analogous to: 888 (EXPR_A) % (EXPR_B) 889 in C. */ 890 GCC_JIT_BINARY_OP_MODULO, 891 892 /* Bitwise AND; analogous to: 893 (EXPR_A) & (EXPR_B) 894 in C. */ 895 GCC_JIT_BINARY_OP_BITWISE_AND, 896 897 /* Bitwise exclusive OR; analogous to: 898 (EXPR_A) ^ (EXPR_B) 899 in C. */ 900 GCC_JIT_BINARY_OP_BITWISE_XOR, 901 902 /* Bitwise inclusive OR; analogous to: 903 (EXPR_A) | (EXPR_B) 904 in C. */ 905 GCC_JIT_BINARY_OP_BITWISE_OR, 906 907 /* Logical AND; analogous to: 908 (EXPR_A) && (EXPR_B) 909 in C. */ 910 GCC_JIT_BINARY_OP_LOGICAL_AND, 911 912 /* Logical OR; analogous to: 913 (EXPR_A) || (EXPR_B) 914 in C. */ 915 GCC_JIT_BINARY_OP_LOGICAL_OR, 916 917 /* Left shift; analogous to: 918 (EXPR_A) << (EXPR_B) 919 in C. */ 920 GCC_JIT_BINARY_OP_LSHIFT, 921 922 /* Right shift; analogous to: 923 (EXPR_A) >> (EXPR_B) 924 in C. */ 925 GCC_JIT_BINARY_OP_RSHIFT 926 }; 927 928 extern gcc_jit_rvalue * 929 gcc_jit_context_new_binary_op (gcc_jit_context *ctxt, 930 gcc_jit_location *loc, 931 enum gcc_jit_binary_op op, 932 gcc_jit_type *result_type, 933 gcc_jit_rvalue *a, gcc_jit_rvalue *b); 934 935 /* (Comparisons are treated as separate from "binary_op" to save 936 you having to specify the result_type). */ 937 938 enum gcc_jit_comparison 939 { 940 /* (EXPR_A) == (EXPR_B). */ 941 GCC_JIT_COMPARISON_EQ, 942 943 /* (EXPR_A) != (EXPR_B). */ 944 GCC_JIT_COMPARISON_NE, 945 946 /* (EXPR_A) < (EXPR_B). */ 947 GCC_JIT_COMPARISON_LT, 948 949 /* (EXPR_A) <=(EXPR_B). */ 950 GCC_JIT_COMPARISON_LE, 951 952 /* (EXPR_A) > (EXPR_B). */ 953 GCC_JIT_COMPARISON_GT, 954 955 /* (EXPR_A) >= (EXPR_B). */ 956 GCC_JIT_COMPARISON_GE 957 }; 958 959 extern gcc_jit_rvalue * 960 gcc_jit_context_new_comparison (gcc_jit_context *ctxt, 961 gcc_jit_location *loc, 962 enum gcc_jit_comparison op, 963 gcc_jit_rvalue *a, gcc_jit_rvalue *b); 964 965 /* Function calls. */ 966 967 /* Call of a specific function. */ 968 extern gcc_jit_rvalue * 969 gcc_jit_context_new_call (gcc_jit_context *ctxt, 970 gcc_jit_location *loc, 971 gcc_jit_function *func, 972 int numargs , gcc_jit_rvalue **args); 973 974 /* Call through a function pointer. */ 975 extern gcc_jit_rvalue * 976 gcc_jit_context_new_call_through_ptr (gcc_jit_context *ctxt, 977 gcc_jit_location *loc, 978 gcc_jit_rvalue *fn_ptr, 979 int numargs, gcc_jit_rvalue **args); 980 981 /* Type-coercion. 982 983 Currently only a limited set of conversions are possible: 984 int <-> float 985 int <-> bool */ 986 extern gcc_jit_rvalue * 987 gcc_jit_context_new_cast (gcc_jit_context *ctxt, 988 gcc_jit_location *loc, 989 gcc_jit_rvalue *rvalue, 990 gcc_jit_type *type); 991 992 extern gcc_jit_lvalue * 993 gcc_jit_context_new_array_access (gcc_jit_context *ctxt, 994 gcc_jit_location *loc, 995 gcc_jit_rvalue *ptr, 996 gcc_jit_rvalue *index); 997 998 /* Field access is provided separately for both lvalues and rvalues. */ 999 1000 /* Accessing a field of an lvalue of struct type, analogous to: 1001 (EXPR).field = ...; 1002 in C. */ 1003 extern gcc_jit_lvalue * 1004 gcc_jit_lvalue_access_field (gcc_jit_lvalue *struct_or_union, 1005 gcc_jit_location *loc, 1006 gcc_jit_field *field); 1007 1008 /* Accessing a field of an rvalue of struct type, analogous to: 1009 (EXPR).field 1010 in C. */ 1011 extern gcc_jit_rvalue * 1012 gcc_jit_rvalue_access_field (gcc_jit_rvalue *struct_or_union, 1013 gcc_jit_location *loc, 1014 gcc_jit_field *field); 1015 1016 /* Accessing a field of an rvalue of pointer type, analogous to: 1017 (EXPR)->field 1018 in C, itself equivalent to (*EXPR).FIELD */ 1019 extern gcc_jit_lvalue * 1020 gcc_jit_rvalue_dereference_field (gcc_jit_rvalue *ptr, 1021 gcc_jit_location *loc, 1022 gcc_jit_field *field); 1023 1024 /* Dereferencing a pointer; analogous to: 1025 *(EXPR) 1026 */ 1027 extern gcc_jit_lvalue * 1028 gcc_jit_rvalue_dereference (gcc_jit_rvalue *rvalue, 1029 gcc_jit_location *loc); 1030 1031 /* Taking the address of an lvalue; analogous to: 1032 &(EXPR) 1033 in C. */ 1034 extern gcc_jit_rvalue * 1035 gcc_jit_lvalue_get_address (gcc_jit_lvalue *lvalue, 1036 gcc_jit_location *loc); 1037 1038 extern gcc_jit_lvalue * 1039 gcc_jit_function_new_local (gcc_jit_function *func, 1040 gcc_jit_location *loc, 1041 gcc_jit_type *type, 1042 const char *name); 1043 1044 /********************************************************************** 1045 Statement-creation. 1046 **********************************************************************/ 1047 1048 /* Add evaluation of an rvalue, discarding the result 1049 (e.g. a function call that "returns" void). 1050 1051 This is equivalent to this C code: 1052 1053 (void)expression; 1054 */ 1055 extern void 1056 gcc_jit_block_add_eval (gcc_jit_block *block, 1057 gcc_jit_location *loc, 1058 gcc_jit_rvalue *rvalue); 1059 1060 /* Add evaluation of an rvalue, assigning the result to the given 1061 lvalue. 1062 1063 This is roughly equivalent to this C code: 1064 1065 lvalue = rvalue; 1066 */ 1067 extern void 1068 gcc_jit_block_add_assignment (gcc_jit_block *block, 1069 gcc_jit_location *loc, 1070 gcc_jit_lvalue *lvalue, 1071 gcc_jit_rvalue *rvalue); 1072 1073 /* Add evaluation of an rvalue, using the result to modify an 1074 lvalue. 1075 1076 This is analogous to "+=" and friends: 1077 1078 lvalue += rvalue; 1079 lvalue *= rvalue; 1080 lvalue /= rvalue; 1081 etc */ 1082 extern void 1083 gcc_jit_block_add_assignment_op (gcc_jit_block *block, 1084 gcc_jit_location *loc, 1085 gcc_jit_lvalue *lvalue, 1086 enum gcc_jit_binary_op op, 1087 gcc_jit_rvalue *rvalue); 1088 1089 /* Add a no-op textual comment to the internal representation of the 1090 code. It will be optimized away, but will be visible in the dumps 1091 seen via 1092 GCC_JIT_BOOL_OPTION_DUMP_INITIAL_TREE 1093 and 1094 GCC_JIT_BOOL_OPTION_DUMP_INITIAL_GIMPLE, 1095 and thus may be of use when debugging how your project's internal 1096 representation gets converted to the libgccjit IR. */ 1097 extern void 1098 gcc_jit_block_add_comment (gcc_jit_block *block, 1099 gcc_jit_location *loc, 1100 const char *text); 1101 1102 /* Terminate a block by adding evaluation of an rvalue, branching on the 1103 result to the appropriate successor block. 1104 1105 This is roughly equivalent to this C code: 1106 1107 if (boolval) 1108 goto on_true; 1109 else 1110 goto on_false; 1111 1112 block, boolval, on_true, and on_false must be non-NULL. */ 1113 extern void 1114 gcc_jit_block_end_with_conditional (gcc_jit_block *block, 1115 gcc_jit_location *loc, 1116 gcc_jit_rvalue *boolval, 1117 gcc_jit_block *on_true, 1118 gcc_jit_block *on_false); 1119 1120 /* Terminate a block by adding a jump to the given target block. 1121 1122 This is roughly equivalent to this C code: 1123 1124 goto target; 1125 */ 1126 extern void 1127 gcc_jit_block_end_with_jump (gcc_jit_block *block, 1128 gcc_jit_location *loc, 1129 gcc_jit_block *target); 1130 1131 /* Terminate a block by adding evaluation of an rvalue, returning the value. 1132 1133 This is roughly equivalent to this C code: 1134 1135 return expression; 1136 */ 1137 extern void 1138 gcc_jit_block_end_with_return (gcc_jit_block *block, 1139 gcc_jit_location *loc, 1140 gcc_jit_rvalue *rvalue); 1141 1142 /* Terminate a block by adding a valueless return, for use within a function 1143 with "void" return type. 1144 1145 This is equivalent to this C code: 1146 1147 return; 1148 */ 1149 extern void 1150 gcc_jit_block_end_with_void_return (gcc_jit_block *block, 1151 gcc_jit_location *loc); 1152 1153 /* Create a new gcc_jit_case instance for use in a switch statement. 1154 min_value and max_value must be constants of integer type. 1155 1156 This API entrypoint was added in LIBGCCJIT_ABI_3; you can test for its 1157 presence using 1158 #ifdef LIBGCCJIT_HAVE_SWITCH_STATEMENTS 1159 */ 1160 extern gcc_jit_case * 1161 gcc_jit_context_new_case (gcc_jit_context *ctxt, 1162 gcc_jit_rvalue *min_value, 1163 gcc_jit_rvalue *max_value, 1164 gcc_jit_block *dest_block); 1165 1166 /* Upcasting from case to object. 1167 1168 This API entrypoint was added in LIBGCCJIT_ABI_3; you can test for its 1169 presence using 1170 #ifdef LIBGCCJIT_HAVE_SWITCH_STATEMENTS 1171 */ 1172 1173 extern gcc_jit_object * 1174 gcc_jit_case_as_object (gcc_jit_case *case_); 1175 1176 /* Terminate a block by adding evalation of an rvalue, then performing 1177 a multiway branch. 1178 1179 This is roughly equivalent to this C code: 1180 1181 switch (expr) 1182 { 1183 default: 1184 goto default_block; 1185 1186 case C0.min_value ... C0.max_value: 1187 goto C0.dest_block; 1188 1189 case C1.min_value ... C1.max_value: 1190 goto C1.dest_block; 1191 1192 ...etc... 1193 1194 case C[N - 1].min_value ... C[N - 1].max_value: 1195 goto C[N - 1].dest_block; 1196 } 1197 1198 block, expr, default_block and cases must all be non-NULL. 1199 1200 expr must be of the same integer type as all of the min_value 1201 and max_value within the cases. 1202 1203 num_cases must be >= 0. 1204 1205 The ranges of the cases must not overlap (or have duplicate 1206 values). 1207 1208 This API entrypoint was added in LIBGCCJIT_ABI_3; you can test for its 1209 presence using 1210 #ifdef LIBGCCJIT_HAVE_SWITCH_STATEMENTS 1211 */ 1212 1213 extern void 1214 gcc_jit_block_end_with_switch (gcc_jit_block *block, 1215 gcc_jit_location *loc, 1216 gcc_jit_rvalue *expr, 1217 gcc_jit_block *default_block, 1218 int num_cases, 1219 gcc_jit_case **cases); 1220 1221 /* Pre-canned feature macro to indicate the presence of 1222 gcc_jit_block_end_with_switch, gcc_jit_case_as_object, and 1223 gcc_jit_context_new_case. 1224 1225 This can be tested for with #ifdef. */ 1226 #define LIBGCCJIT_HAVE_SWITCH_STATEMENTS 1227 1228 /********************************************************************** 1229 Nested contexts. 1230 **********************************************************************/ 1231 1232 /* Given an existing JIT context, create a child context. 1233 1234 The child inherits a copy of all option-settings from the parent. 1235 1236 The child can reference objects created within the parent, but not 1237 vice-versa. 1238 1239 The lifetime of the child context must be bounded by that of the 1240 parent: you should release a child context before releasing the parent 1241 context. 1242 1243 If you use a function from a parent context within a child context, 1244 you have to compile the parent context before you can compile the 1245 child context, and the gcc_jit_result of the parent context must 1246 outlive the gcc_jit_result of the child context. 1247 1248 This allows caching of shared initializations. For example, you could 1249 create types and declarations of global functions in a parent context 1250 once within a process, and then create child contexts whenever a 1251 function or loop becomes hot. Each such child context can be used for 1252 JIT-compiling just one function or loop, but can reference types 1253 and helper functions created within the parent context. 1254 1255 Contexts can be arbitrarily nested, provided the above rules are 1256 followed, but it's probably not worth going above 2 or 3 levels, and 1257 there will likely be a performance hit for such nesting. */ 1258 1259 extern gcc_jit_context * 1260 gcc_jit_context_new_child_context (gcc_jit_context *parent_ctxt); 1261 1262 /********************************************************************** 1263 Implementation support. 1264 **********************************************************************/ 1265 1266 /* Write C source code into "path" that can be compiled into a 1267 self-contained executable (i.e. with libgccjit as the only dependency). 1268 The generated code will attempt to replay the API calls that have been 1269 made into the given context. 1270 1271 This may be useful when debugging the library or client code, for 1272 reducing a complicated recipe for reproducing a bug into a simpler 1273 form. 1274 1275 Typically you need to supply the option "-Wno-unused-variable" when 1276 compiling the generated file (since the result of each API call is 1277 assigned to a unique variable within the generated C source, and not 1278 all are necessarily then used). */ 1279 1280 extern void 1281 gcc_jit_context_dump_reproducer_to_file (gcc_jit_context *ctxt, 1282 const char *path); 1283 1284 /* Enable the dumping of a specific set of internal state from the 1285 compilation, capturing the result in-memory as a buffer. 1286 1287 Parameter "dumpname" corresponds to the equivalent gcc command-line 1288 option, without the "-fdump-" prefix. 1289 For example, to get the equivalent of "-fdump-tree-vrp1", supply 1290 "tree-vrp1". 1291 The context directly stores the dumpname as a (const char *), so the 1292 passed string must outlive the context. 1293 1294 gcc_jit_context_compile and gcc_jit_context_to_file 1295 will capture the dump as a dynamically-allocated buffer, writing 1296 it to ``*out_ptr``. 1297 1298 The caller becomes responsible for calling 1299 free (*out_ptr) 1300 each time that gcc_jit_context_compile or gcc_jit_context_to_file 1301 are called. *out_ptr will be written to, either with the address of a 1302 buffer, or with NULL if an error occurred. 1303 1304 This API entrypoint is likely to be less stable than the others. 1305 In particular, both the precise dumpnames, and the format and content 1306 of the dumps are subject to change. 1307 1308 It exists primarily for writing the library's own test suite. */ 1309 1310 extern void 1311 gcc_jit_context_enable_dump (gcc_jit_context *ctxt, 1312 const char *dumpname, 1313 char **out_ptr); 1314 1315 /********************************************************************** 1316 Timing support. 1317 **********************************************************************/ 1318 1319 /* The timing API was added in LIBGCCJIT_ABI_4; you can test for its 1320 presence using 1321 #ifdef LIBGCCJIT_HAVE_TIMING_API 1322 */ 1323 #define LIBGCCJIT_HAVE_TIMING_API 1324 1325 typedef struct gcc_jit_timer gcc_jit_timer; 1326 1327 /* Create a gcc_jit_timer instance, and start timing. 1328 1329 This API entrypoint was added in LIBGCCJIT_ABI_4; you can test for its 1330 presence using 1331 #ifdef LIBGCCJIT_HAVE_TIMING_API 1332 */ 1333 extern gcc_jit_timer * 1334 gcc_jit_timer_new (void); 1335 1336 /* Release a gcc_jit_timer instance. 1337 1338 This API entrypoint was added in LIBGCCJIT_ABI_4; you can test for its 1339 presence using 1340 #ifdef LIBGCCJIT_HAVE_TIMING_API 1341 */ 1342 extern void 1343 gcc_jit_timer_release (gcc_jit_timer *timer); 1344 1345 /* Associate a gcc_jit_timer instance with a context. 1346 1347 This API entrypoint was added in LIBGCCJIT_ABI_4; you can test for its 1348 presence using 1349 #ifdef LIBGCCJIT_HAVE_TIMING_API 1350 */ 1351 extern void 1352 gcc_jit_context_set_timer (gcc_jit_context *ctxt, 1353 gcc_jit_timer *timer); 1354 1355 /* Get the timer associated with a context (if any). 1356 1357 This API entrypoint was added in LIBGCCJIT_ABI_4; you can test for its 1358 presence using 1359 #ifdef LIBGCCJIT_HAVE_TIMING_API 1360 */ 1361 1362 extern gcc_jit_timer * 1363 gcc_jit_context_get_timer (gcc_jit_context *ctxt); 1364 1365 /* Push the given item onto the timing stack. 1366 1367 This API entrypoint was added in LIBGCCJIT_ABI_4; you can test for its 1368 presence using 1369 #ifdef LIBGCCJIT_HAVE_TIMING_API 1370 */ 1371 1372 extern void 1373 gcc_jit_timer_push (gcc_jit_timer *timer, 1374 const char *item_name); 1375 1376 /* Pop the top item from the timing stack. 1377 1378 This API entrypoint was added in LIBGCCJIT_ABI_4; you can test for its 1379 presence using 1380 #ifdef LIBGCCJIT_HAVE_TIMING_API 1381 */ 1382 1383 extern void 1384 gcc_jit_timer_pop (gcc_jit_timer *timer, 1385 const char *item_name); 1386 1387 /* Print timing information to the given stream about activity since 1388 the timer was started. 1389 1390 This API entrypoint was added in LIBGCCJIT_ABI_4; you can test for its 1391 presence using 1392 #ifdef LIBGCCJIT_HAVE_TIMING_API 1393 */ 1394 1395 extern void 1396 gcc_jit_timer_print (gcc_jit_timer *timer, 1397 FILE *f_out); 1398 1399 1400 #define LIBGCCJIT_HAVE_gcc_jit_rvalue_set_bool_require_tail_call 1401 1402 /* Mark/clear a call as needing tail-call optimization. 1403 1404 This API entrypoint was added in LIBGCCJIT_ABI_6; you can test for its 1405 presence using 1406 #ifdef LIBGCCJIT_HAVE_gcc_jit_rvalue_set_bool_require_tail_call 1407 */ 1408 extern void 1409 gcc_jit_rvalue_set_bool_require_tail_call (gcc_jit_rvalue *call, 1410 int require_tail_call); 1411 1412 #define LIBGCCJIT_HAVE_gcc_jit_type_get_aligned 1413 1414 /* Given type "T", get type: 1415 1416 T __attribute__ ((aligned (ALIGNMENT_IN_BYTES))) 1417 1418 The alignment must be a power of two. 1419 1420 This API entrypoint was added in LIBGCCJIT_ABI_7; you can test for its 1421 presence using 1422 #ifdef LIBGCCJIT_HAVE_gcc_jit_type_get_aligned 1423 */ 1424 extern gcc_jit_type * 1425 gcc_jit_type_get_aligned (gcc_jit_type *type, 1426 size_t alignment_in_bytes); 1427 1428 #define LIBGCCJIT_HAVE_gcc_jit_type_get_vector 1429 1430 /* Given type "T", get type: 1431 1432 T __attribute__ ((vector_size (sizeof(T) * num_units)) 1433 1434 T must be integral/floating point; num_units must be a power of two. 1435 1436 This API entrypoint was added in LIBGCCJIT_ABI_8; you can test for its 1437 presence using 1438 #ifdef LIBGCCJIT_HAVE_gcc_jit_type_get_vector 1439 */ 1440 extern gcc_jit_type * 1441 gcc_jit_type_get_vector (gcc_jit_type *type, size_t num_units); 1442 1443 1444 #define LIBGCCJIT_HAVE_gcc_jit_function_get_address 1445 1446 /* Get the address of a function as an rvalue, of function pointer 1447 type. 1448 1449 This API entrypoint was added in LIBGCCJIT_ABI_9; you can test for its 1450 presence using 1451 #ifdef LIBGCCJIT_HAVE_gcc_jit_function_get_address 1452 */ 1453 extern gcc_jit_rvalue * 1454 gcc_jit_function_get_address (gcc_jit_function *fn, 1455 gcc_jit_location *loc); 1456 1457 1458 #define LIBGCCJIT_HAVE_gcc_jit_context_new_rvalue_from_vector 1459 1460 /* Build a vector rvalue from an array of elements. 1461 1462 "vec_type" should be a vector type, created using gcc_jit_type_get_vector. 1463 1464 This API entrypoint was added in LIBGCCJIT_ABI_10; you can test for its 1465 presence using 1466 #ifdef LIBGCCJIT_HAVE_gcc_jit_context_new_rvalue_from_vector 1467 */ 1468 extern gcc_jit_rvalue * 1469 gcc_jit_context_new_rvalue_from_vector (gcc_jit_context *ctxt, 1470 gcc_jit_location *loc, 1471 gcc_jit_type *vec_type, 1472 size_t num_elements, 1473 gcc_jit_rvalue **elements); 1474 1475 #ifdef __cplusplus 1476 } 1477 #endif /* __cplusplus */ 1478 1479 #endif /* LIBGCCJIT_H */ 1480