55from llvmlite import ir as llvmir
66from numba .core import cgutils , types
77
8+ from numba_dpex .core .utils .itanium_mangler import mangle_c
9+
810
911class LLVMTypes :
1012 """
@@ -21,6 +23,44 @@ class LLVMTypes:
2123 void_t = llvmir .VoidType ()
2224
2325
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+
2464def get_llvm_type (context , type ):
2565 """Returns the LLVM Value corresponding to a Numba type.
2666
0 commit comments