Loom C API
Public Loom compiler C API
Loading...
Searching...
No Matches
base.h
Go to the documentation of this file.
1// Copyright 2026 The IREE Authors
2//
3// Licensed under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
7#ifndef LOOMC_BASE_H_
8#define LOOMC_BASE_H_
9
10#include <stdbool.h>
11#include <stddef.h>
12#include <stdint.h>
13#include <string.h>
14
21
22#ifdef __cplusplus
23extern "C" {
24#endif
25
27#if defined(_WIN32) && defined(LOOMC_BUILDING_SHARED_LIBRARY)
28#define LOOMC_API_EXPORT __declspec(dllexport)
29#elif defined(_WIN32) && defined(LOOMC_USING_SHARED_LIBRARY)
30#define LOOMC_API_EXPORT __declspec(dllimport)
31#elif defined(LOOMC_BUILDING_SHARED_LIBRARY)
32#define LOOMC_API_EXPORT __attribute__((visibility("default")))
33#else
34#define LOOMC_API_EXPORT
35#endif
36
38#define LOOMC_API_PTR
39
45typedef size_t loomc_host_size_t;
46
48#define LOOMC_HOST_SIZE_MAX ((loomc_host_size_t)(SIZE_MAX))
49
55typedef struct iree_status_handle_t* loomc_status_t;
56
70
74static inline loomc_string_view_t loomc_string_view_empty(void) {
75 loomc_string_view_t value = {NULL, 0};
76 return value;
77}
78
83static inline bool loomc_string_view_is_empty(loomc_string_view_t value) {
84 return value.data == NULL || value.size == 0;
85}
86
92static inline loomc_string_view_t loomc_make_string_view(
93 const char* data, loomc_host_size_t size) {
94 loomc_string_view_t value = {data, size};
95 return value;
96}
97
102static inline loomc_string_view_t loomc_make_cstring_view(const char* data) {
103 loomc_string_view_t value = {data, data ? strlen(data) : 0};
104 return value;
105}
106
112static inline bool loomc_string_view_equal(loomc_string_view_t lhs,
114 if (lhs.size != rhs.size) {
115 return false;
116 }
117 if (lhs.size == 0) {
118 return true;
119 }
120 return memcmp(lhs.data, rhs.data, lhs.size) == 0;
121}
122
135
139static inline loomc_byte_span_t loomc_byte_span_empty(void) {
140 loomc_byte_span_t value = {NULL, 0};
141 return value;
142}
143
148static inline bool loomc_byte_span_is_empty(loomc_byte_span_t span) {
149 return span.data == NULL || span.data_length == 0;
150}
151
158static inline loomc_byte_span_t loomc_make_byte_span(
159 const void* data, loomc_host_size_t data_length) {
160 loomc_byte_span_t value = {(const uint8_t*)data, data_length};
161 return value;
162}
163
165typedef struct loomc_dimension3_t {
167 uint32_t x;
168
170 uint32_t y;
171
173 uint32_t z;
175
181typedef enum loomc_structure_type_e {
184
187
190
193
196
199
202
205
208
211
214
217
220
223
226
229
232
235
238
241
244
247
250
253
256
259
262
265
268
271
274
277
280
284
298
325
328enum {
331
334
337
340};
341
342#if !defined(IREE_ALLOCATOR_ALLOC_PARAMS_T_DEFINED_)
344#define IREE_ALLOCATOR_ALLOC_PARAMS_T_DEFINED_
346typedef struct iree_allocator_alloc_params_t {
350#else
352typedef struct iree_allocator_alloc_params_t loomc_allocator_alloc_params_t;
353#endif // !IREE_ALLOCATOR_ALLOC_PARAMS_T_DEFINED_
354
368 void* self, loomc_allocator_command_t command, const void* params,
369 void** inout_ptr);
370
382
387static inline bool loomc_allocator_is_valid(loomc_allocator_t allocator) {
388 return allocator.ctl != NULL;
389}
390
395
408 loomc_allocator_t allocator, loomc_host_size_t byte_length, void** out_ptr);
409
422 loomc_allocator_t allocator, loomc_host_size_t byte_length, void** out_ptr);
423
440 loomc_string_view_t* out_string);
441
451 void* ptr);
452
453#ifdef __cplusplus
454} // extern "C"
455#endif
456
457#endif // LOOMC_BASE_H_
#define LOOMC_API_EXPORT
Exports a public Loom C API symbol from a shared library build.
Definition base.h:34
loomc_allocator_t loomc_allocator_system(void)
Returns a process-global system allocator.
size_t loomc_host_size_t
Host allocation and container size type.
Definition base.h:45
loomc_status_t(* loomc_allocator_ctl_fn_t)(void *self, loomc_allocator_command_t command, const void *params, void **inout_ptr)
Host allocation control callback.
Definition base.h:367
loomc_structure_type_t
Structure type values used by extensible public descriptors.
Definition base.h:181
@ LOOMC_STRUCTURE_TYPE_AMDGPU_PROFILE_OPTIONS
loomc_amdgpu_profile_options_t.
Definition base.h:264
@ LOOMC_STRUCTURE_TYPE_CONTEXT_TARGET_OPTIONS
loomc_context_target_options_t.
Definition base.h:219
@ LOOMC_STRUCTURE_TYPE_OPTION_DICT
loomc_option_dict_t.
Definition base.h:237
@ LOOMC_STRUCTURE_TYPE_SPIRV_PROFILE_OPTIONS
loomc_spirv_profile_options_t.
Definition base.h:231
@ LOOMC_STRUCTURE_TYPE_COMPILE_REPORT_OPTIONS
loomc_compile_report_options_t.
Definition base.h:273
@ LOOMC_STRUCTURE_TYPE_IREE_HAL_PROFILE_OPTIONS
loomc_iree_hal_profile_options_t.
Definition base.h:252
@ LOOMC_STRUCTURE_TYPE_ARTIFACT_MANIFEST_OPTIONS
loomc_artifact_manifest_options_t.
Definition base.h:270
@ LOOMC_STRUCTURE_TYPE_TARGET_PIPELINE_OPTIONS
loomc_target_pipeline_options_t.
Definition base.h:222
@ LOOMC_STRUCTURE_TYPE_MODULE_DESERIALIZE_OPTIONS
loomc_module_deserialize_options_t.
Definition base.h:207
@ LOOMC_STRUCTURE_TYPE_SPIRV_IREE_HAL_PROFILE_OPTIONS
loomc_spirv_iree_hal_profile_options_t.
Definition base.h:255
@ LOOMC_STRUCTURE_TYPE_LINK_OPTIONS
loomc_link_options_t.
Definition base.h:201
@ LOOMC_STRUCTURE_TYPE_MODULE_SERIALIZE_OPTIONS
loomc_module_serialize_options_t.
Definition base.h:204
@ LOOMC_STRUCTURE_TYPE_LINKER_OPTIONS
loomc_linker_options_t.
Definition base.h:198
@ LOOMC_STRUCTURE_TYPE_SPIRV_VULKANINFO_PROFILE_OPTIONS
loomc_spirv_vulkaninfo_profile_options_t.
Definition base.h:240
@ LOOMC_STRUCTURE_TYPE_MODULE_FUNCTION_QUERY_OPTIONS
loomc_module_function_query_options_t.
Definition base.h:258
@ LOOMC_STRUCTURE_TYPE_SOURCE_OPTIONS
loomc_source_options_t.
Definition base.h:186
@ LOOMC_STRUCTURE_TYPE_TARGET_SPECIALIZATION_OPTIONS
loomc_target_specialization_options_t.
Definition base.h:228
@ LOOMC_STRUCTURE_TYPE_MODULE_GLOBAL_QUERY_OPTIONS
loomc_module_global_query_options_t.
Definition base.h:261
@ LOOMC_STRUCTURE_TYPE_AMDGPU_EMIT_OPTIONS
loomc_amdgpu_emit_options_t.
Definition base.h:267
@ LOOMC_STRUCTURE_TYPE_LINK_INDEX_BUILDER_OPTIONS
loomc_link_index_builder_options_t.
Definition base.h:195
@ LOOMC_STRUCTURE_TYPE_SPIRV_VULKAN_FUNCTION_TABLE
loomc_spirv_vulkan_function_table_t.
Definition base.h:246
@ LOOMC_STRUCTURE_TYPE_SOURCE_LOAD_OPTIONS
loomc_source_load_options_t.
Definition base.h:243
@ LOOMC_STRUCTURE_TYPE_SPIRV_VULKAN_PROFILE_OPTIONS
loomc_spirv_vulkan_profile_options_t.
Definition base.h:249
@ LOOMC_STRUCTURE_TYPE_WORKSPACE_OPTIONS
loomc_workspace_options_t.
Definition base.h:189
@ LOOMC_STRUCTURE_TYPE_NONE
No structure type was supplied.
Definition base.h:183
@ LOOMC_STRUCTURE_TYPE_SPIRV_EMIT_OPTIONS
loomc_spirv_emit_options_t.
Definition base.h:225
@ LOOMC_STRUCTURE_TYPE_PASS_PROGRAM_OPTIONS
loomc_pass_program_options_t.
Definition base.h:216
@ LOOMC_STRUCTURE_TYPE_COMPILER_OPTIONS
loomc_compiler_options_t.
Definition base.h:210
@ LOOMC_STRUCTURE_TYPE_CONTEXT_OPTIONS
loomc_context_options_t.
Definition base.h:192
@ LOOMC_STRUCTURE_TYPE_COMPILE_OPTIONS
loomc_compile_options_t.
Definition base.h:213
@ LOOMC_STRUCTURE_TYPE_EMIT_OPTIONS
loomc_emit_options_t.
Definition base.h:234
@ LOOMC_STRUCTURE_TYPE_LAUNCH_CONFIG
loomc_launch_config_t.
Definition base.h:279
@ LOOMC_STRUCTURE_TYPE_AMDGPU_IREE_HAL_PROFILE_OPTIONS
loomc_amdgpu_iree_hal_profile_options_t.
Definition base.h:282
@ LOOMC_STRUCTURE_TYPE_SANITIZER_OPTIONS
loomc_sanitizer_options_t.
Definition base.h:276
void loomc_allocator_free(loomc_allocator_t allocator, void *ptr)
Frees memory previously returned by allocator.
#define LOOMC_API_PTR
Marks a public callback function pointer type.
Definition base.h:38
@ LOOMC_ALLOCATOR_COMMAND_REALLOC
Resizes an existing allocation.
Definition base.h:336
@ LOOMC_ALLOCATOR_COMMAND_MALLOC
Allocates memory without requiring zero initialization.
Definition base.h:330
@ LOOMC_ALLOCATOR_COMMAND_CALLOC
Allocates memory and zeros it before returning.
Definition base.h:333
@ LOOMC_ALLOCATOR_COMMAND_FREE
Frees an existing allocation.
Definition base.h:339
struct iree_status_handle_t * loomc_status_t
Opaque status handle.
Definition base.h:55
loomc_status_t loomc_allocator_malloc(loomc_allocator_t allocator, loomc_host_size_t byte_length, void **out_ptr)
Allocates zero-initialized memory from allocator.
loomc_status_t loomc_allocator_malloc_uninitialized(loomc_allocator_t allocator, loomc_host_size_t byte_length, void **out_ptr)
Allocates uninitialized memory from allocator.
uint32_t loomc_allocator_command_t
Controls the behavior of a loomc_allocator_ctl_fn_t callback.
Definition base.h:327
loomc_status_t loomc_string_view_clone(loomc_string_view_t source, loomc_allocator_t allocator, loomc_string_view_t *out_string)
Copies a string view into allocator-owned storage.
Allocation parameters passed to loomc_allocator_ctl_fn_t callbacks.
Definition base.h:346
loomc_host_size_t byte_length
Minimum allocation size in bytes.
Definition base.h:348
Host allocator used for persistent Loom object storage.
Definition base.h:375
loomc_allocator_ctl_fn_t ctl
Callback implementing allocation commands.
Definition base.h:380
void * self
Callback-owned state pointer.
Definition base.h:377
Non-owning view over immutable bytes.
Definition base.h:128
loomc_host_size_t data_length
Number of bytes in data.
Definition base.h:133
const uint8_t * data
First byte of the span, or NULL when the span is empty.
Definition base.h:130
Three-dimensional unsigned extent used by Loom C API structs.
Definition base.h:165
uint32_t z
Extent along the z dimension.
Definition base.h:173
uint32_t x
Extent along the x dimension.
Definition base.h:167
uint32_t y
Extent along the y dimension.
Definition base.h:170
Ordered loose string option dictionary.
Definition base.h:309
loomc_host_size_t structure_size
Size of this structure in bytes.
Definition base.h:314
const loomc_option_entry_t * entries
Ordered option entries.
Definition base.h:320
loomc_structure_type_t type
Structure type. Must be LOOMC_STRUCTURE_TYPE_OPTION_DICT.
Definition base.h:311
const void * next
Next invocation option extension.
Definition base.h:317
loomc_host_size_t entry_count
Number of entries in entries.
Definition base.h:323
One loose string option entry.
Definition base.h:291
loomc_string_view_t key
Canonical option key.
Definition base.h:293
loomc_string_view_t value
Option value.
Definition base.h:296
Non-owning string view over bytes that need not be NUL-terminated.
Definition base.h:63
const char * data
First byte of the string, or NULL when the view is empty.
Definition base.h:65
loomc_host_size_t size
Number of bytes in data.
Definition base.h:68