@@ -6,10 +6,13 @@ pub struct OffloadMetadata {
66 pub mode : TransferKind ,
77}
88
9+ // TODO(Sa4dUs): add `OMP_MAP_TARGET_PARAM = 0x20` flag only when needed
10+ #[ repr( u64 ) ]
11+ #[ derive( Debug , Copy , Clone ) ]
912pub enum TransferKind {
1013 FromGpu = 1 ,
1114 ToGpu = 2 ,
12- Both = 3 ,
15+ Both = 1 + 2 ,
1316}
1417
1518impl OffloadMetadata {
@@ -18,7 +21,10 @@ impl OffloadMetadata {
1821 }
1922
2023 pub fn from_ty < ' tcx > ( tcx : TyCtxt < ' tcx > , ty : Ty < ' tcx > ) -> Self {
21- OffloadMetadata { payload_size : get_payload_size ( tcx, ty) , mode : TransferKind :: Both }
24+ OffloadMetadata {
25+ payload_size : get_payload_size ( tcx, ty) ,
26+ mode : TransferKind :: from_ty ( tcx, ty) ,
27+ }
2228 }
2329}
2430
@@ -68,3 +74,49 @@ fn get_payload_size<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> u64 {
6874 . bytes ( ) ,
6975 }
7076}
77+
78+ impl TransferKind {
79+ pub fn from_ty < ' tcx > ( _tcx : TyCtxt < ' tcx > , ty : Ty < ' tcx > ) -> Self {
80+ // TODO(Sa4dUs): this logic is probs not fully correct, but it works for now
81+ match ty. kind ( ) {
82+ rustc_type_ir:: TyKind :: Bool
83+ | rustc_type_ir:: TyKind :: Char
84+ | rustc_type_ir:: TyKind :: Int ( _)
85+ | rustc_type_ir:: TyKind :: Uint ( _)
86+ | rustc_type_ir:: TyKind :: Float ( _) => TransferKind :: ToGpu ,
87+
88+ rustc_type_ir:: TyKind :: Adt ( _, _)
89+ | rustc_type_ir:: TyKind :: Tuple ( _)
90+ | rustc_type_ir:: TyKind :: Array ( _, _) => TransferKind :: ToGpu ,
91+
92+ rustc_type_ir:: TyKind :: RawPtr ( _, rustc_ast:: Mutability :: Not )
93+ | rustc_type_ir:: TyKind :: Ref ( _, _, rustc_ast:: Mutability :: Not ) => TransferKind :: ToGpu ,
94+
95+ rustc_type_ir:: TyKind :: RawPtr ( _, rustc_ast:: Mutability :: Mut )
96+ | rustc_type_ir:: TyKind :: Ref ( _, _, rustc_ast:: Mutability :: Mut ) => TransferKind :: Both ,
97+
98+ rustc_type_ir:: TyKind :: Slice ( _)
99+ | rustc_type_ir:: TyKind :: Str
100+ | rustc_type_ir:: TyKind :: Dynamic ( _, _) => TransferKind :: Both ,
101+
102+ rustc_type_ir:: TyKind :: FnDef ( _, _)
103+ | rustc_type_ir:: TyKind :: FnPtr ( _, _)
104+ | rustc_type_ir:: TyKind :: Closure ( _, _)
105+ | rustc_type_ir:: TyKind :: CoroutineClosure ( _, _)
106+ | rustc_type_ir:: TyKind :: Coroutine ( _, _)
107+ | rustc_type_ir:: TyKind :: CoroutineWitness ( _, _) => TransferKind :: ToGpu ,
108+
109+ rustc_type_ir:: TyKind :: Alias ( _, _)
110+ | rustc_type_ir:: TyKind :: Param ( _)
111+ | rustc_type_ir:: TyKind :: Bound ( _, _)
112+ | rustc_type_ir:: TyKind :: Placeholder ( _)
113+ | rustc_type_ir:: TyKind :: Infer ( _)
114+ | rustc_type_ir:: TyKind :: Error ( _) => TransferKind :: ToGpu ,
115+
116+ rustc_type_ir:: TyKind :: Never => TransferKind :: ToGpu ,
117+ rustc_type_ir:: TyKind :: Foreign ( _) => TransferKind :: Both ,
118+ rustc_type_ir:: TyKind :: Pat ( _, _) => TransferKind :: Both ,
119+ rustc_type_ir:: TyKind :: UnsafeBinder ( _) => TransferKind :: Both ,
120+ }
121+ }
122+ }
0 commit comments