2 * Copyright 2016 Bas Nieuwenhuizen
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:
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.
20 * The above copyright notice and this permission notice (including the
21 * next paragraph) shall be included in all copies or substantial portions
26 #ifndef AC_LLVM_UTIL_H
27 #define AC_LLVM_UTIL_H
30 #include <llvm-c/TargetMachine.h>
32 #include "amd_family.h"
39 AC_FUNC_ATTR_ALWAYSINLINE
= (1 << 0),
40 AC_FUNC_ATTR_INREG
= (1 << 2),
41 AC_FUNC_ATTR_NOALIAS
= (1 << 3),
42 AC_FUNC_ATTR_NOUNWIND
= (1 << 4),
43 AC_FUNC_ATTR_READNONE
= (1 << 5),
44 AC_FUNC_ATTR_READONLY
= (1 << 6),
45 AC_FUNC_ATTR_WRITEONLY
= (1 << 7),
46 AC_FUNC_ATTR_INACCESSIBLE_MEM_ONLY
= (1 << 8),
47 AC_FUNC_ATTR_CONVERGENT
= (1 << 9),
49 /* Legacy intrinsic that needs attributes on function declarations
50 * and they must match the internal LLVM definition exactly, otherwise
51 * intrinsic selection fails.
53 AC_FUNC_ATTR_LEGACY
= (1u << 31),
56 enum ac_target_machine_options
{
57 AC_TM_SUPPORTS_SPILL
= (1 << 0),
58 AC_TM_SISCHED
= (1 << 1),
59 AC_TM_FORCE_ENABLE_XNACK
= (1 << 2),
60 AC_TM_FORCE_DISABLE_XNACK
= (1 << 3),
61 AC_TM_PROMOTE_ALLOCA_TO_SCRATCH
= (1 << 4),
62 AC_TM_CHECK_IR
= (1 << 5),
66 AC_FLOAT_MODE_DEFAULT
,
67 AC_FLOAT_MODE_NO_SIGNED_ZEROS_FP_MATH
,
68 AC_FLOAT_MODE_UNSAFE_FP_MATH
,
71 /* Per-thread persistent LLVM objects. */
72 struct ac_llvm_compiler
{
73 LLVMTargetMachineRef tm
;
74 LLVMTargetLibraryInfoRef target_library_info
;
75 LLVMPassManagerRef passmgr
;
78 const char *ac_get_llvm_processor_name(enum radeon_family family
);
79 LLVMTargetMachineRef
ac_create_target_machine(enum radeon_family family
,
80 enum ac_target_machine_options tm_options
,
81 const char **out_triple
);
83 LLVMTargetRef
ac_get_llvm_target(const char *triple
);
84 void ac_add_attr_dereferenceable(LLVMValueRef val
, uint64_t bytes
);
85 bool ac_is_sgpr_param(LLVMValueRef param
);
86 void ac_add_function_attr(LLVMContextRef ctx
, LLVMValueRef function
,
87 int attr_idx
, enum ac_func_attr attr
);
88 void ac_add_func_attributes(LLVMContextRef ctx
, LLVMValueRef function
,
89 unsigned attrib_mask
);
90 void ac_dump_module(LLVMModuleRef module
);
92 LLVMValueRef
ac_llvm_get_called_value(LLVMValueRef call
);
93 bool ac_llvm_is_function(LLVMValueRef v
);
94 LLVMModuleRef
ac_create_module(LLVMTargetMachineRef tm
, LLVMContextRef ctx
);
96 LLVMBuilderRef
ac_create_builder(LLVMContextRef ctx
,
97 enum ac_float_mode float_mode
);
100 ac_llvm_add_target_dep_function_attr(LLVMValueRef F
,
101 const char *name
, unsigned value
);
103 static inline unsigned
104 ac_get_load_intr_attribs(bool can_speculate
)
106 /* READNONE means writes can't affect it, while READONLY means that
107 * writes can affect it. */
108 return can_speculate
? AC_FUNC_ATTR_READNONE
:
109 AC_FUNC_ATTR_READONLY
;
112 static inline unsigned
113 ac_get_store_intr_attribs(bool writeonly_memory
)
115 return writeonly_memory
? AC_FUNC_ATTR_INACCESSIBLE_MEM_ONLY
:
116 AC_FUNC_ATTR_WRITEONLY
;
120 ac_count_scratch_private_memory(LLVMValueRef function
);
122 LLVMPassManagerRef
ac_create_passmgr(LLVMTargetLibraryInfoRef target_library_info
,
124 LLVMTargetLibraryInfoRef
ac_create_target_library_info(const char *triple
);
125 void ac_dispose_target_library_info(LLVMTargetLibraryInfoRef library_info
);
126 void ac_init_llvm_once(void);
129 bool ac_init_llvm_compiler(struct ac_llvm_compiler
*compiler
,
130 enum radeon_family family
,
131 enum ac_target_machine_options tm_options
);
132 void ac_destroy_llvm_compiler(struct ac_llvm_compiler
*compiler
);
138 #endif /* AC_LLVM_UTIL_H */