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