@@ -22,7 +22,7 @@ use rustc_errors::DiagMessage;
2222use rustc_hash:: FxHashMap ;
2323use rustc_middle:: dep_graph:: DepContext ;
2424use rustc_middle:: ty:: layout:: {
25- FnAbiError , FnAbiOf , FnAbiRequest , HasTyCtxt , HasTypingEnv , LayoutError ,
25+ FnAbiError , FnAbiOf , FnAbiRequest , HasTyCtxt , HasTypingEnv , LayoutError , LayoutOf ,
2626} ;
2727use rustc_middle:: ty:: layout:: { FnAbiOfHelpers , LayoutOfHelpers } ;
2828use rustc_middle:: ty:: { Ty , TypeVisitableExt } ;
@@ -40,6 +40,10 @@ use rustc_target::callconv::FnAbi;
4040use rustc_target:: spec:: { HasTargetSpec , Target } ;
4141use tracing:: { debug, trace} ;
4242
43+ /// "There is a total of 64 KB constant memory on a device."
44+ /// <https://docs.nvidia.com/cuda/archive/12.8.1/pdf/CUDA_C_Best_Practices_Guide.pdf>
45+ const CONSTANT_MEMORY_SIZE_LIMIT_BYTES : u64 = 64 * 1024 ;
46+
4347pub ( crate ) struct CodegenCx < ' ll , ' tcx > {
4448 pub tcx : TyCtxt < ' tcx > ,
4549
@@ -267,7 +271,16 @@ impl<'ll, 'tcx> CodegenCx<'ll, 'tcx> {
267271 }
268272
269273 if !is_mutable && self . type_is_freeze ( ty) {
270- AddressSpace ( 4 )
274+ let layout = self . layout_of ( ty) ;
275+ if layout. size . bytes ( ) > CONSTANT_MEMORY_SIZE_LIMIT_BYTES {
276+ self . tcx . sess . dcx ( ) . warn ( format ! (
277+ "static `{}` exceeds the constant-memory limit; placing in global memory (performance may be reduced)" ,
278+ instance
279+ ) ) ;
280+ AddressSpace :: DATA
281+ } else {
282+ AddressSpace ( 4 )
283+ }
271284 } else {
272285 AddressSpace :: DATA
273286 }
0 commit comments