ac,radeonsi: fix compilations issues with LLVM 11
[mesa.git] / src / amd / llvm / ac_llvm_util.h
1 /*
2 * Copyright 2016 Bas Nieuwenhuizen
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the
6 * "Software"), to deal in the Software without restriction, including
7 * without limitation the rights to use, copy, modify, merge, publish,
8 * distribute, sub license, and/or sell copies of the Software, and to
9 * permit persons to whom the Software is furnished to do so, subject to
10 * the following conditions:
11 *
12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
13 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
14 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
15 * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
16 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
17 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
18 * USE OR OTHER DEALINGS IN THE SOFTWARE.
19 *
20 * The above copyright notice and this permission notice (including the
21 * next paragraph) shall be included in all copies or substantial portions
22 * of the Software.
23 *
24 */
25
26 #ifndef AC_LLVM_UTIL_H
27 #define AC_LLVM_UTIL_H
28
29 #include <stdbool.h>
30 #include <llvm-c/TargetMachine.h>
31 #include <llvm/Config/llvm-config.h>
32
33 #include "amd_family.h"
34
35 #ifdef __cplusplus
36 extern "C" {
37 #endif
38
39 #if LLVM_VERSION_MAJOR < 11
40 #define LLVMFixedVectorTypeKind LLVMVectorTypeKind
41 #endif
42
43 struct ac_compiler_passes;
44
45 enum ac_func_attr {
46 AC_FUNC_ATTR_ALWAYSINLINE = (1 << 0),
47 AC_FUNC_ATTR_INREG = (1 << 2),
48 AC_FUNC_ATTR_NOALIAS = (1 << 3),
49 AC_FUNC_ATTR_NOUNWIND = (1 << 4),
50 AC_FUNC_ATTR_READNONE = (1 << 5),
51 AC_FUNC_ATTR_READONLY = (1 << 6),
52 AC_FUNC_ATTR_WRITEONLY = (1 << 7),
53 AC_FUNC_ATTR_INACCESSIBLE_MEM_ONLY = (1 << 8),
54 AC_FUNC_ATTR_CONVERGENT = (1 << 9),
55
56 /* Legacy intrinsic that needs attributes on function declarations
57 * and they must match the internal LLVM definition exactly, otherwise
58 * intrinsic selection fails.
59 */
60 AC_FUNC_ATTR_LEGACY = (1u << 31),
61 };
62
63 enum ac_target_machine_options {
64 AC_TM_SUPPORTS_SPILL = (1 << 0),
65 AC_TM_FORCE_ENABLE_XNACK = (1 << 1),
66 AC_TM_FORCE_DISABLE_XNACK = (1 << 2),
67 AC_TM_PROMOTE_ALLOCA_TO_SCRATCH = (1 << 3),
68 AC_TM_CHECK_IR = (1 << 4),
69 AC_TM_ENABLE_GLOBAL_ISEL = (1 << 5),
70 AC_TM_CREATE_LOW_OPT = (1 << 6),
71 AC_TM_NO_LOAD_STORE_OPT = (1 << 7),
72 AC_TM_WAVE32 = (1 << 8),
73 };
74
75 enum ac_float_mode {
76 AC_FLOAT_MODE_DEFAULT,
77 AC_FLOAT_MODE_DEFAULT_OPENGL,
78 AC_FLOAT_MODE_DENORM_FLUSH_TO_ZERO,
79 };
80
81 /* Per-thread persistent LLVM objects. */
82 struct ac_llvm_compiler {
83 LLVMTargetLibraryInfoRef target_library_info;
84 LLVMPassManagerRef passmgr;
85
86 /* Default compiler. */
87 LLVMTargetMachineRef tm;
88 struct ac_compiler_passes *passes;
89
90 /* Wave32 compiler for GFX10. */
91 LLVMTargetMachineRef tm_wave32;
92 struct ac_compiler_passes *passes_wave32;
93
94 /* Optional compiler for faster compilation with fewer optimizations.
95 * LLVM modules can be created with "tm" too. There is no difference.
96 */
97 LLVMTargetMachineRef low_opt_tm; /* uses -O1 instead of -O2 */
98 struct ac_compiler_passes *low_opt_passes;
99 };
100
101 const char *ac_get_llvm_processor_name(enum radeon_family family);
102 void ac_add_attr_dereferenceable(LLVMValueRef val, uint64_t bytes);
103 bool ac_is_sgpr_param(LLVMValueRef param);
104 void ac_add_function_attr(LLVMContextRef ctx, LLVMValueRef function,
105 int attr_idx, enum ac_func_attr attr);
106 void ac_add_func_attributes(LLVMContextRef ctx, LLVMValueRef function,
107 unsigned attrib_mask);
108 void ac_dump_module(LLVMModuleRef module);
109
110 LLVMValueRef ac_llvm_get_called_value(LLVMValueRef call);
111 bool ac_llvm_is_function(LLVMValueRef v);
112 LLVMModuleRef ac_create_module(LLVMTargetMachineRef tm, LLVMContextRef ctx);
113
114 LLVMBuilderRef ac_create_builder(LLVMContextRef ctx,
115 enum ac_float_mode float_mode);
116 bool ac_disable_inexact_math(LLVMBuilderRef builder);
117 void ac_restore_inexact_math(LLVMBuilderRef builder, bool value);
118
119 void
120 ac_llvm_add_target_dep_function_attr(LLVMValueRef F,
121 const char *name, unsigned value);
122 void ac_llvm_set_workgroup_size(LLVMValueRef F, unsigned size);
123
124 static inline unsigned
125 ac_get_load_intr_attribs(bool can_speculate)
126 {
127 /* READNONE means writes can't affect it, while READONLY means that
128 * writes can affect it. */
129 return can_speculate ? AC_FUNC_ATTR_READNONE :
130 AC_FUNC_ATTR_READONLY;
131 }
132
133 unsigned
134 ac_count_scratch_private_memory(LLVMValueRef function);
135
136 LLVMTargetLibraryInfoRef ac_create_target_library_info(const char *triple);
137 void ac_dispose_target_library_info(LLVMTargetLibraryInfoRef library_info);
138 void ac_init_llvm_once(void);
139
140
141 bool ac_init_llvm_compiler(struct ac_llvm_compiler *compiler,
142 enum radeon_family family,
143 enum ac_target_machine_options tm_options);
144 void ac_destroy_llvm_compiler(struct ac_llvm_compiler *compiler);
145
146 struct ac_compiler_passes *ac_create_llvm_passes(LLVMTargetMachineRef tm);
147 void ac_destroy_llvm_passes(struct ac_compiler_passes *p);
148 bool ac_compile_module_to_elf(struct ac_compiler_passes *p, LLVMModuleRef module,
149 char **pelf_buffer, size_t *pelf_size);
150 void ac_llvm_add_barrier_noop_pass(LLVMPassManagerRef passmgr);
151 void ac_enable_global_isel(LLVMTargetMachineRef tm);
152
153 static inline bool
154 ac_has_vec3_support(enum chip_class chip, bool use_format)
155 {
156 if (chip == GFX6 && !use_format) {
157 /* GFX6 only supports vec3 with load/store format. */
158 return false;
159 }
160
161 return LLVM_VERSION_MAJOR >= 9;
162 }
163
164 #ifdef __cplusplus
165 }
166 #endif
167
168 #endif /* AC_LLVM_UTIL_H */