@@ -271,17 +271,30 @@ impl<'ll, 'tcx> CodegenCx<'ll, 'tcx> {
271271 }
272272
273273 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.
281276 AddressSpace ( 1 )
282277 } 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+ }
285298 }
286299 } else {
287300 AddressSpace :: DATA
@@ -534,6 +547,7 @@ impl<'ll, 'tcx> CodegenCx<'ll, 'tcx> {
534547pub struct CodegenArgs {
535548 pub nvvm_options : Vec < NvvmOption > ,
536549 pub override_libm : bool ,
550+ pub use_constant_memory_space : bool ,
537551 pub final_module_path : Option < PathBuf > ,
538552}
539553
@@ -552,6 +566,8 @@ impl CodegenArgs {
552566 cg_args. nvvm_options . push ( flag) ;
553567 } else if arg == "--override-libm" {
554568 cg_args. override_libm = true ;
569+ } else if arg == "--use-constant-memory-space" {
570+ cg_args. use_constant_memory_space = true ;
555571 } else if arg == "--final-module-path" {
556572 cg_args. final_module_path = Some ( PathBuf :: from (
557573 args. get ( idx + 1 ) . expect ( "No path for --final-module-path" ) ,
0 commit comments