@@ -319,6 +319,13 @@ fn merge_codegen_units<'tcx>(
319319 let mut cgu_contents: UnordMap < Symbol , Vec < Symbol > > =
320320 codegen_units. iter ( ) . map ( |cgu| ( cgu. name ( ) , vec ! [ cgu. name( ) ] ) ) . collect ( ) ;
321321
322+ // When compiling compiler_builtins, we do not want to put multiple intrinsics in a CGU.
323+ // There may be mergeable CGUs under this constraint, but just skipping over merging is much
324+ // simpler.
325+ if cx. tcx . is_compiler_builtins ( LOCAL_CRATE ) {
326+ return cgu_contents;
327+ }
328+
322329 // If N is the maximum number of CGUs, and the CGUs are sorted from largest
323330 // to smallest, we repeatedly find which CGU in codegen_units[N..] has the
324331 // greatest overlap of inlined items with codegen_units[N-1], merge that
@@ -680,6 +687,16 @@ fn compute_codegen_unit_name<'tcx>(
680687 mono_item : MonoItem < ' tcx > ,
681688 cache : & mut CguNameCache ,
682689) -> Symbol {
690+ // When compiling compiler_builtins, we do not want to put multiple intrinsics in a CGU.
691+ // Using the symbol name as the CGU name puts every GloballyShared item in its own CGU, but in
692+ // an optimized build we actually want every item in the crate that isn't an intrinsic to get
693+ // LocalCopy so that it is easy to inline away. In an unoptimized build, this CGU naming
694+ // strategy probably generates more CGUs than we strictly need. But it is simple.
695+ if tcx. is_compiler_builtins ( LOCAL_CRATE ) {
696+ let name = mono_item. symbol_name ( tcx) ;
697+ return Symbol :: intern ( name. name ) ;
698+ }
699+
683700 let Some ( def_id) = characteristic_def_id_of_mono_item ( tcx, mono_item) else {
684701 return fallback_cgu_name ( name_builder) ;
685702 } ;
0 commit comments