@@ -188,6 +188,17 @@ impl<'ll, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> {
188188 codegen_offload_preload ( self , tcx, instance, args) ;
189189 }
190190
191+ fn codegen_offload_preload_mut_drop (
192+ & mut self ,
193+ preload_ty : Ty < ' tcx > ,
194+ place : PlaceRef < ' tcx , & ' ll llvm:: Value > ,
195+ ) {
196+ let tcx = self . tcx ;
197+ dbg ! ( "Dropping PreloadMut; emit offload end mapper" ) ;
198+
199+ codegen_offload_preload_mut_drop ( self , tcx, preload_ty, place) ;
200+ }
201+
191202 fn codegen_intrinsic_call (
192203 & mut self ,
193204 instance : ty:: Instance < ' tcx > ,
@@ -1911,6 +1922,55 @@ fn codegen_autodiff<'ll, 'tcx>(
19111922 ) ;
19121923}
19131924
1925+ fn codegen_offload_preload_mut_drop < ' ll , ' tcx > (
1926+ bx : & mut Builder < ' _ , ' ll , ' tcx > ,
1927+ tcx : TyCtxt < ' tcx > ,
1928+ preload_ty : Ty < ' tcx > ,
1929+ place : PlaceRef < ' tcx , & ' ll llvm:: Value > ,
1930+ ) {
1931+ let cx = bx. cx ;
1932+ dbg ! ( "Starting the PreloadMut drop handling!" ) ;
1933+ // PreloadMut<'a, T> -> extract T.
1934+ let ty:: Adt ( _adt_def, generic_args) = preload_ty. kind ( ) else {
1935+ bug ! ( "expected PreloadMut ADT, got {preload_ty:?}" ) ;
1936+ } ;
1937+
1938+ // This should be the `T` parameter of PreloadMut<'a, T>.
1939+ // If this indexes the lifetime in your tree, use the correct type arg index
1940+ // or `generic_args.types().next().unwrap()`.
1941+ let pointee_ty: Ty < ' tcx > =
1942+ generic_args. types ( ) . next ( ) . unwrap_or_else ( || bug ! ( "PreloadMut without type parameter" ) ) ;
1943+
1944+ // Load field 0: `cpu_ptr: *mut T`.
1945+ let cpu_ptr_place = place. project_field ( bx, 0 ) ;
1946+ let cpu_ptr_operand = bx. load_operand ( cpu_ptr_place) ;
1947+
1948+ let args: Vec < & ' ll Value > = match cpu_ptr_operand. val {
1949+ OperandValue :: Immediate ( ptr) => vec ! [ ptr] ,
1950+ OperandValue :: Pair ( _data, _meta) => {
1951+ bug ! ( "unsized PreloadMut drop not handled yet" )
1952+ }
1953+ _ => bug ! ( "unexpected PreloadMut cpu_ptr operand" ) ,
1954+ } ;
1955+
1956+ let meta = OffloadMetadata :: from_ty ( tcx, pointee_ty) ;
1957+ let metadata: & [ OffloadMetadata ; 1 ] = & [ meta] ;
1958+
1959+ let types: & Type = cx. layout_of ( pointee_ty) . llvm_type ( cx) ;
1960+
1961+ let offload_globals_ref = cx. offload_globals . borrow ( ) ;
1962+ let offload_globals = match offload_globals_ref. as_ref ( ) {
1963+ Some ( globals) => globals,
1964+ None => {
1965+ dbg ! ( "Have to initialize offload? This is a bug!" ) ;
1966+ return ;
1967+ }
1968+ } ;
1969+
1970+ let target_symbol = cx. generate_local_symbol_name ( "" ) ;
1971+ dbg ! ( "done for now" ) ;
1972+ }
1973+
19141974// For each PreLoad *call*, we now use some of our previous declared globals to move data to the gpu.
19151975// For now, we only handle the data transfer part of it. Consecutive calls become a no-op on the
19161976// LLVM side.
0 commit comments