Loom C API
Public Loom compiler C API
Loading...
Searching...
No Matches
compile.h File Reference

Prepared compilers and module compilation. More...

Go to the source code of this file.

Data Structures

struct  loomc_compiler_options_t
 Compiler creation options. More...
struct  loomc_compile_options_t
 Compile invocation options. More...

Typedefs

typedef struct loomc_compiler_t loomc_compiler_t
 Prepared immutable compiler.
typedef uint32_t loomc_compile_artifact_flags_t
 Bitmask of loomc_compile_artifact_flag_bits_t.

Enumerations

enum  loomc_compile_artifact_flag_bits_t { LOOMC_COMPILE_ARTIFACT_FLAG_MODULE_TEXT = 1u << 0 , LOOMC_COMPILE_ARTIFACT_FLAG_MODULE_BYTECODE = 1u << 1 , LOOMC_COMPILE_ARTIFACT_FLAG_REPORT_JSON = 1u << 2 , LOOMC_COMPILE_ARTIFACT_FLAG_LAUNCH_CONFIG = 1u << 3 }
 Compile artifact request bits. More...

Functions

loomc_status_t loomc_compiler_create (loomc_context_t *context, const loomc_compiler_options_t *options, loomc_allocator_t allocator, loomc_compiler_t **out_compiler)
 Creates a prepared immutable compiler.
loomc_status_t loomc_compile_module (loomc_compiler_t *compiler, loomc_workspace_t *workspace, const loomc_pass_program_t *pass_program, loomc_module_t *module, const loomc_compile_options_t *options, loomc_allocator_t allocator, loomc_result_t **out_result)
 Compiles a mutable module into in-memory artifacts.
void loomc_compiler_retain (loomc_compiler_t *compiler)
 Retains a prepared compiler for another owner.
void loomc_compiler_release (loomc_compiler_t *compiler)
 Releases a prepared compiler from one owner.

Detailed Description

Prepared compilers and module compilation.

A prepared compiler owns validated compile-time configuration and provider state. Compile invocations compose that compiler with a caller-selected prepared pass program, caller-owned workspace scratch, and a mutable module. Results return in-memory diagnostics, reports, and artifacts.

The core compile primitive accepts an already-formed loomc_module_t. Sources are deserialized into modules and indexes are linked into modules before compilation so each stage has independent options, diagnostics, and lifetime boundaries.

Example
Share prepared compiler state and keep scratch local to each worker:
void worker_main(loomc_compiler_t* compiler,
loomc_pass_program_t* pass_program) {
loomc_workspace_t* workspace = NULL;
loomc_status_t status =
if (!loomc_status_is_ok(status)) {
return;
}
loomc_config_binding_t bindings[] = {
{
.key = loomc_make_cstring_view("tile_m"),
.value = loomc_make_cstring_view("128"),
},
};
loomc_compile_options_t compile_options = {
.structure_size = sizeof(loomc_compile_options_t),
.config =
{
.bindings = bindings,
.binding_count = 1,
},
};
// `module` is produced by deserialization, linking, or another module
// operation. The compile invocation borrows it and may rewrite its IR, so
// this worker owns exclusive access for the duration of the call. Reuse
// compiler, pass program, and workspace for many independent module
// invocations on this worker.
loomc_result_t* result = NULL;
status = loomc_compile_module(compiler, workspace, pass_program, module,
&compile_options,
if (loomc_status_is_ok(status)) {
// Inspect diagnostics and artifacts through result.
}
}
loomc_allocator_t loomc_allocator_system(void)
Returns a process-global system allocator.
@ LOOMC_STRUCTURE_TYPE_COMPILE_OPTIONS
loomc_compile_options_t.
Definition base.h:213
struct iree_status_handle_t * loomc_status_t
Opaque status handle.
Definition base.h:55
void loomc_compiler_release(loomc_compiler_t *compiler)
Releases a prepared compiler from one owner.
loomc_status_t loomc_compile_module(loomc_compiler_t *compiler, loomc_workspace_t *workspace, const loomc_pass_program_t *pass_program, loomc_module_t *module, const loomc_compile_options_t *options, loomc_allocator_t allocator, loomc_result_t **out_result)
Compiles a mutable module into in-memory artifacts.
struct loomc_compiler_t loomc_compiler_t
Prepared immutable compiler.
Definition compile.h:99
void loomc_compiler_retain(loomc_compiler_t *compiler)
Retains a prepared compiler for another owner.
@ LOOMC_COMPILE_ARTIFACT_FLAG_REPORT_JSON
Return a JSON compile report artifact.
Definition compile.h:111
@ LOOMC_COMPILE_ARTIFACT_FLAG_MODULE_BYTECODE
Return binary Loom bytecode after successful compilation.
Definition compile.h:107
void loomc_pass_program_release(loomc_pass_program_t *pass_program)
Releases a pass program from one owner.
struct loomc_pass_program_t loomc_pass_program_t
Prepared immutable pass program.
Definition pass.h:86
void loomc_pass_program_retain(loomc_pass_program_t *pass_program)
Retains a pass program for another owner.
void loomc_result_release(loomc_result_t *result)
Releases result from one owner.
struct loomc_result_t loomc_result_t
Immutable operation result.
Definition result.h:63
Compile invocation options.
Definition compile.h:152
Single configuration key/value binding.
Definition config.h:50
loomc_status_t loomc_workspace_create(const loomc_workspace_options_t *options, loomc_allocator_t allocator, loomc_workspace_t **out_workspace)
Creates a mutable workspace for one worker at a time.
void loomc_workspace_release(loomc_workspace_t *workspace)
Releases workspace and all storage it owns.
struct loomc_workspace_t loomc_workspace_t
Mutable per-worker scratch workspace.
Definition workspace.h:54

Typedef Documentation

◆ loomc_compiler_t

Prepared immutable compiler.

A compiler is intended to be created once and reused across many invocations. It must not require repeated filesystem access on the hot path. Pass pipelines are prepared as loomc_pass_program_t handles and selected per invocation.

Thread safety
Prepared compilers are immutable after creation and may be shared across threads. Invocation-local scratch belongs in loomc_workspace_t.

Enumeration Type Documentation

◆ loomc_compile_artifact_flag_bits_t

Compile artifact request bits.

Enumerator
LOOMC_COMPILE_ARTIFACT_FLAG_MODULE_TEXT 

Return textual Loom module IR after successful compilation.

LOOMC_COMPILE_ARTIFACT_FLAG_MODULE_BYTECODE 

Return binary Loom bytecode after successful compilation.

LOOMC_COMPILE_ARTIFACT_FLAG_REPORT_JSON 

Return a JSON compile report artifact.

Reports are emitted for completed invocations, including failed results that still returned diagnostics.

LOOMC_COMPILE_ARTIFACT_FLAG_LAUNCH_CONFIG 

Return the compiled host launch-config program for all kernel entries.

The selected pass program must lower source kernel entries through the normal source-to-low boundary. The artifact contains one pure function per exported kernel and is loaded with loomc_launch_config_program_load.

Function Documentation

◆ loomc_compile_module()

loomc_status_t loomc_compile_module ( loomc_compiler_t * compiler,
loomc_workspace_t * workspace,
const loomc_pass_program_t * pass_program,
loomc_module_t * module,
const loomc_compile_options_t * options,
loomc_allocator_t allocator,
loomc_result_t ** out_result )

Compiles a mutable module into in-memory artifacts.

Parameters
compilerPrepared compiler.
workspaceInvocation-local scratch workspace.
pass_programPrepared pass program selected for this invocation.
moduleModule produced by deserialization, linking, or another module operation. The invocation borrows the module for the duration of the call and may rewrite its IR in place.
optionsCompile invocation options, or NULL for defaults.
allocatorHost allocator used for result-owned storage.
out_resultReceives a retained result for the operation.
Returns
OK when the invocation ran to a result. Non-OK statuses represent API misuse or infrastructure failures before a result could be produced.
Ownership
The caller owns out_result on an OK return and releases it with loomc_result_release.
Postcondition
The caller retains ownership of module, and the module handle remains valid after the call. Its IR contents may have been transformed by the selected pass program. Callers needing independent later invocations of the original IR provide independent module storage before compilation. A successful target-specialized invocation also retains its concrete function-version facts in the module handle for a later loomc_emit_module call. A subsequent compile replaces that state. Serialization and cloning preserve IR only and do not persist compiler facts.
Lifetime
Returned results and artifacts do not borrow from workspace and remain valid after loomc_workspace_trim.
Artifact Requests
Artifact emission is opt-in through loomc_compile_options_t. Requesting module text or bytecode serializes the transformed module into result-owned bytes. Requesting a report returns a JSON artifact with invocation metadata, result state, diagnostic count, and the count of other artifacts emitted by the invocation.
Thread safety
Calls using the same compiler and pass program may run concurrently when each call uses a distinct workspace and distinct module, or when access to shared workspaces and modules is synchronized externally. The compiler and pass program are immutable after creation.
Target Specialization
loomc_target_specialization_options_t may be attached to loomc_compile_options_t::next. Each row binds one function version to one complete profile compatible with the compiler context's target environment. Unrequested functions retain their authored targets, including generic targets, and targetless functions remain targetless.

◆ loomc_compiler_create()

loomc_status_t loomc_compiler_create ( loomc_context_t * context,
const loomc_compiler_options_t * options,
loomc_allocator_t allocator,
loomc_compiler_t ** out_compiler )

Creates a prepared immutable compiler.

Parameters
contextContext shared with modules compiled by this compiler.
optionsCompiler configuration, or NULL for defaults.
allocatorHost allocator used for compiler-owned storage.
out_compilerReceives one retained compiler on success.
Returns
OK when the compiler was created.
Ownership
The caller owns the returned reference and releases it with loomc_compiler_release.
Thread safety
The returned compiler is immutable and may be shared across worker threads.

◆ loomc_compiler_release()

void loomc_compiler_release ( loomc_compiler_t * compiler)

Releases a prepared compiler from one owner.

Parameters
compilerCompiler to release. Passing NULL is allowed.
Thread safety
Retain/release operations are intended to be safe from multiple threads. The compiler is destroyed when the final reference is released.

◆ loomc_compiler_retain()

void loomc_compiler_retain ( loomc_compiler_t * compiler)

Retains a prepared compiler for another owner.

Parameters
compilerCompiler to retain.
Thread safety
Retain/release operations are intended to be safe from multiple threads.