1bf215546Sopenharmony_ci/*
2bf215546Sopenharmony_ci * Copyright © Microsoft Corporation
3bf215546Sopenharmony_ci *
4bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a
5bf215546Sopenharmony_ci * copy of this software and associated documentation files (the "Software"),
6bf215546Sopenharmony_ci * to deal in the Software without restriction, including without limitation
7bf215546Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8bf215546Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the
9bf215546Sopenharmony_ci * Software is furnished to do so, subject to the following conditions:
10bf215546Sopenharmony_ci *
11bf215546Sopenharmony_ci * The above copyright notice and this permission notice (including the next
12bf215546Sopenharmony_ci * paragraph) shall be included in all copies or substantial portions of the
13bf215546Sopenharmony_ci * Software.
14bf215546Sopenharmony_ci *
15bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16bf215546Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17bf215546Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18bf215546Sopenharmony_ci * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19bf215546Sopenharmony_ci * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20bf215546Sopenharmony_ci * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21bf215546Sopenharmony_ci * IN THE SOFTWARE.
22bf215546Sopenharmony_ci */
23bf215546Sopenharmony_ci
24bf215546Sopenharmony_ci#ifndef MESA_CLC_HELPERS_H
25bf215546Sopenharmony_ci#define MESA_CLC_HELPERS_H
26bf215546Sopenharmony_ci
27bf215546Sopenharmony_ci#include "nir_types.h"
28bf215546Sopenharmony_ci
29bf215546Sopenharmony_ci#include "clc.h"
30bf215546Sopenharmony_ci#include "util/u_string.h"
31bf215546Sopenharmony_ci
32bf215546Sopenharmony_ci#include <assert.h>
33bf215546Sopenharmony_ci#include <stddef.h>
34bf215546Sopenharmony_ci#include <stdio.h>
35bf215546Sopenharmony_ci#include <stdint.h>
36bf215546Sopenharmony_ci
37bf215546Sopenharmony_ci#ifdef __cplusplus
38bf215546Sopenharmony_ciextern "C" {
39bf215546Sopenharmony_ci#endif
40bf215546Sopenharmony_ci
41bf215546Sopenharmony_civoid
42bf215546Sopenharmony_ciclc_initialize_llvm(void);
43bf215546Sopenharmony_ci
44bf215546Sopenharmony_cibool
45bf215546Sopenharmony_ciclc_spirv_get_kernels_info(const struct clc_binary *spvbin,
46bf215546Sopenharmony_ci                           const struct clc_kernel_info **kernels,
47bf215546Sopenharmony_ci                           unsigned *num_kernels,
48bf215546Sopenharmony_ci                           const struct clc_parsed_spec_constant **spec_constants,
49bf215546Sopenharmony_ci                           unsigned *num_spec_constants,
50bf215546Sopenharmony_ci                           const struct clc_logger *logger);
51bf215546Sopenharmony_ci
52bf215546Sopenharmony_civoid
53bf215546Sopenharmony_ciclc_free_kernels_info(const struct clc_kernel_info *kernels,
54bf215546Sopenharmony_ci                      unsigned num_kernels);
55bf215546Sopenharmony_ci
56bf215546Sopenharmony_ciint
57bf215546Sopenharmony_ciclc_c_to_spir(const struct clc_compile_args *args,
58bf215546Sopenharmony_ci              const struct clc_logger *logger,
59bf215546Sopenharmony_ci              struct clc_binary *out_spir);
60bf215546Sopenharmony_ci
61bf215546Sopenharmony_ciint
62bf215546Sopenharmony_ciclc_spir_to_spirv(const struct clc_binary *in_spir,
63bf215546Sopenharmony_ci                  const struct clc_logger *logger,
64bf215546Sopenharmony_ci                  struct clc_binary *out_spirv);
65bf215546Sopenharmony_ci
66bf215546Sopenharmony_ciint
67bf215546Sopenharmony_ciclc_c_to_spirv(const struct clc_compile_args *args,
68bf215546Sopenharmony_ci               const struct clc_logger *logger,
69bf215546Sopenharmony_ci               struct clc_binary *out_spirv);
70bf215546Sopenharmony_ci
71bf215546Sopenharmony_ciint
72bf215546Sopenharmony_ciclc_link_spirv_binaries(const struct clc_linker_args *args,
73bf215546Sopenharmony_ci                        const struct clc_logger *logger,
74bf215546Sopenharmony_ci                        struct clc_binary *out_spirv);
75bf215546Sopenharmony_ci
76bf215546Sopenharmony_ciint
77bf215546Sopenharmony_ciclc_spirv_specialize(const struct clc_binary *in_spirv,
78bf215546Sopenharmony_ci                     const struct clc_parsed_spirv *parsed_data,
79bf215546Sopenharmony_ci                     const struct clc_spirv_specialization_consts *consts,
80bf215546Sopenharmony_ci                     struct clc_binary *out_spirv);
81bf215546Sopenharmony_ci
82bf215546Sopenharmony_civoid
83bf215546Sopenharmony_ciclc_dump_spirv(const struct clc_binary *spvbin, FILE *f);
84bf215546Sopenharmony_ci
85bf215546Sopenharmony_civoid
86bf215546Sopenharmony_ciclc_free_spir_binary(struct clc_binary *spir);
87bf215546Sopenharmony_ci
88bf215546Sopenharmony_civoid
89bf215546Sopenharmony_ciclc_free_spirv_binary(struct clc_binary *spvbin);
90bf215546Sopenharmony_ci
91bf215546Sopenharmony_ci#define clc_log(logger, level, fmt, ...) do {        \
92bf215546Sopenharmony_ci      if (!logger || !logger->level) break;          \
93bf215546Sopenharmony_ci      char *_msg = NULL;                             \
94bf215546Sopenharmony_ci      asprintf(&_msg, fmt, ##__VA_ARGS__);           \
95bf215546Sopenharmony_ci      assert(_msg);                                  \
96bf215546Sopenharmony_ci      logger->level(logger->priv, _msg);             \
97bf215546Sopenharmony_ci      free(_msg);                                    \
98bf215546Sopenharmony_ci   } while (0)
99bf215546Sopenharmony_ci
100bf215546Sopenharmony_ci#define clc_error(logger, fmt, ...) clc_log(logger, error, fmt, ##__VA_ARGS__)
101bf215546Sopenharmony_ci#define clc_warning(logger, fmt, ...) clc_log(logger, warning, fmt, ##__VA_ARGS__)
102bf215546Sopenharmony_ci
103bf215546Sopenharmony_ci#ifdef __cplusplus
104bf215546Sopenharmony_ci}
105bf215546Sopenharmony_ci#endif
106bf215546Sopenharmony_ci
107bf215546Sopenharmony_ci#endif /* MESA_CLC_HELPERS_H */
108