@@ -271,17 +271,30 @@ impl<'ll, 'tcx> CodegenCx<'ll, 'tcx> {
271
271
}
272
272
273
273
if !is_mutable && self . type_is_freeze ( ty) {
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
- // Global memory
274
+ if !self . codegen_args . use_constant_memory_space {
275
+ // We aren't using constant memory, so put the instance in global memory.
281
276
AddressSpace ( 1 )
282
277
} else {
283
- // Constant memory
284
- AddressSpace ( 4 )
278
+ // We are using constant memory, see if the instance will fit.
279
+ //
280
+ // FIXME(@LegNeato) ideally we keep track of what we have put into
281
+ // constant memory and when it is filled up spill instead of only
282
+ // spilling when a static is big. We'll probably want some packing
283
+ // strategy controlled by the user...for example, if you have one large
284
+ // static and many small ones, you might want the small ones to all be
285
+ // in constant memory or just the big one depending on your workload.
286
+ let layout = self . layout_of ( ty) ;
287
+ if layout. size . bytes ( ) > CONSTANT_MEMORY_SIZE_LIMIT_BYTES {
288
+ self . tcx . sess . dcx ( ) . warn ( format ! (
289
+ "static `{}` exceeds the constant memory limit; placing in global memory (performance may be reduced)" ,
290
+ instance
291
+ ) ) ;
292
+ // Place instance in global memory if it is too big for constant memory.
293
+ AddressSpace ( 1 )
294
+ } else {
295
+ // Place instance in constant memory if it fits.
296
+ AddressSpace ( 4 )
297
+ }
285
298
}
286
299
} else {
287
300
AddressSpace :: DATA
@@ -534,6 +547,7 @@ impl<'ll, 'tcx> CodegenCx<'ll, 'tcx> {
534
547
pub struct CodegenArgs {
535
548
pub nvvm_options : Vec < NvvmOption > ,
536
549
pub override_libm : bool ,
550
+ pub use_constant_memory_space : bool ,
537
551
pub final_module_path : Option < PathBuf > ,
538
552
}
539
553
@@ -552,6 +566,8 @@ impl CodegenArgs {
552
566
cg_args. nvvm_options . push ( flag) ;
553
567
} else if arg == "--override-libm" {
554
568
cg_args. override_libm = true ;
569
+ } else if arg == "--use-constant-memory-space" {
570
+ cg_args. use_constant_memory_space = true ;
555
571
} else if arg == "--final-module-path" {
556
572
cg_args. final_module_path = Some ( PathBuf :: from (
557
573
args. get ( idx + 1 ) . expect ( "No path for --final-module-path" ) ,
0 commit comments