5
5
from llvmlite import ir as llvmir
6
6
from numba .core import cgutils , types
7
7
8
+ from numba_dpex .core .utils .itanium_mangler import mangle_c
9
+
8
10
9
11
class LLVMTypes :
10
12
"""
@@ -21,6 +23,44 @@ class LLVMTypes:
21
23
void_t = llvmir .VoidType ()
22
24
23
25
26
+ def declare_function (context , builder , name , sig , cargs , mangler = mangle_c ):
27
+ """Insert declaration for a opencl builtin function.
28
+ Uses the Itanium mangler.
29
+
30
+ Args
31
+ ----
32
+ context: target context
33
+
34
+ builder: llvm builder
35
+
36
+ name: str
37
+ symbol name
38
+
39
+ sig: signature
40
+ function signature of the symbol being declared
41
+
42
+ cargs: sequence of str
43
+ C type names for the arguments
44
+
45
+ mangler: a mangler function
46
+ function to use to mangle the symbol
47
+
48
+ """
49
+ mod = builder .module
50
+ if sig .return_type == types .void :
51
+ llretty = llvmir .VoidType ()
52
+ else :
53
+ llretty = context .get_value_type (sig .return_type )
54
+ llargs = [context .get_value_type (t ) for t in sig .args ]
55
+ fnty = llvmir .FunctionType (llretty , llargs )
56
+ mangled = mangler (name , cargs )
57
+ fn = cgutils .get_or_insert_function (mod , fnty , mangled )
58
+ from numba_dpex import spirv_kernel_target
59
+
60
+ fn .calling_convention = spirv_kernel_target .CC_SPIR_FUNC
61
+ return fn
62
+
63
+
24
64
def get_llvm_type (context , type ):
25
65
"""Returns the LLVM Value corresponding to a Numba type.
26
66
0 commit comments