@@ -658,16 +658,15 @@ pub(crate) unsafe fn llvm_optimize(
658658 let first_arg_name = str:: from_utf8 ( & c_name) . unwrap ( ) ;
659659 // We might call llvm_optimize (and thus this code) multiple times on the same IR,
660660 // but we shouldn't add this helper ptr multiple times.
661+ // FIXME(offload): This could break if the user calls his first argument `dyn_ptr`.
661662 if first_arg_name == "dyn_ptr" {
662663 return ;
663664 }
664665
665666 // Create the new parameter list, with ptr as the first argument
666667 let mut new_param_types = Vec :: with_capacity ( old_param_count as usize + 1 ) ;
667668 new_param_types. push ( cx. type_ptr ( ) ) ;
668- for old_param in old_param_types {
669- new_param_types. push ( old_param) ;
670- }
669+ new_param_types. extend ( old_param_types) ;
671670
672671 // Create the new function type
673672 let ret_ty = unsafe { llvm:: LLVMGetReturnType ( old_fn_ty) } ;
@@ -701,10 +700,11 @@ pub(crate) unsafe fn llvm_optimize(
701700 llvm:: set_value_name ( new_fn, & name) ;
702701 }
703702
704- let consider_offload = config. offload . contains ( & config:: Offload :: Enable ) ;
705- if consider_offload && ( cgcx. target_arch == "amdgpu" || cgcx. target_arch == "nvptx64" ) {
703+ if cgcx. target_is_like_gpu && config. offload . contains ( & config:: Offload :: Enable ) {
706704 let cx =
707705 SimpleCx :: new ( module. module_llvm . llmod ( ) , module. module_llvm . llcx , cgcx. pointer_size ) ;
706+ // For now we only support up to 10 kernels named kernel_0 ... kernel_9, a follow-up PR is
707+ // introducing a proper offload intrinsic to solve this limitation.
708708 for num in 0 ..9 {
709709 let name = format ! ( "kernel_{num}" ) ;
710710 if let Some ( kernel) = cx. get_function ( & name) {
0 commit comments