11//! See documentation on `CodegenCx::zombie` for a description of the zombie system.
22
3- use super :: { get_name , get_names} ;
3+ use super :: get_names;
44use crate :: custom_decorations:: { CustomDecoration , SpanRegenerator , ZombieDecoration } ;
55use crate :: custom_insts:: { self , CustomOp } ;
66use rspirv:: dr:: { Instruction , Module , Operand } ;
77use rspirv:: spirv:: { Op , Word } ;
8- use rustc_data_structures:: fx:: { FxHashMap , FxHashSet , FxIndexMap } ;
8+ use rustc_data_structures:: fx:: { FxHashMap , FxIndexMap } ;
99use rustc_errors:: Diag ;
1010use rustc_session:: Session ;
1111use rustc_span:: { DUMMY_SP , Span } ;
12- use smallvec:: SmallVec ;
13- use tracing:: { Level , debug} ;
1412
1513#[ derive( Copy , Clone ) ]
1614struct Zombie < ' a > {
@@ -322,7 +320,7 @@ impl<'a> ZombieReporter<'a> {
322320 }
323321}
324322
325- pub fn report_and_remove_zombies ( sess : & Session , module : & mut Module ) -> super :: Result < ( ) > {
323+ pub fn report_zombies ( sess : & Session , module : & Module ) -> super :: Result < ( ) > {
326324 let mut zombies = Zombies {
327325 // FIXME(eddyb) avoid repeating this across different passes/helpers.
328326 custom_ext_inst_set_import : module
@@ -341,89 +339,5 @@ pub fn report_and_remove_zombies(sess: &Session, module: &mut Module) -> super::
341339 // Note: This is O(n^2).
342340 while zombies. spread ( module) { }
343341
344- let result = ZombieReporter :: new ( sess, module, & zombies) . report_all ( ) ;
345- if tracing:: enabled!( target: "print_all_zombie" , Level :: DEBUG ) {
346- let mut span_regen = SpanRegenerator :: new ( sess. source_map ( ) , module) ;
347- for & zombie_id in zombies. id_to_zombie_kind . keys ( ) {
348- let mut zombie_leaf_id = zombie_id;
349- let mut infection_chain = SmallVec :: < [ _ ; 4 ] > :: new ( ) ;
350- loop {
351- zombie_leaf_id = match zombies. get_zombie_by_id ( zombie_leaf_id) . unwrap ( ) . kind {
352- ZombieKind :: Leaf => break ,
353- // FIXME(eddyb) this is all very lossy and should probably go away.
354- ZombieKind :: Uses ( zombie_uses) => zombie_uses[ 0 ] . used_zombie_id ,
355- } ;
356- infection_chain. push ( zombie_leaf_id) ;
357- }
358-
359- let reason = span_regen. zombie_for_id ( zombie_leaf_id) . unwrap ( ) . reason ;
360- debug ! (
361- target: "print_all_zombie" ,
362- "zombie'd %{zombie_id} because {reason}"
363- ) ;
364- if !infection_chain. is_empty ( ) {
365- debug ! (
366- target: "print_all_zombie" ,
367- " (infected via {:?})" , infection_chain
368- ) ;
369- }
370- debug ! ( target: "print_all_zombie" , "" ) ;
371- }
372- }
373-
374- if tracing:: enabled!( target: "print_zombie" , Level :: DEBUG ) {
375- let mut span_regen = SpanRegenerator :: new ( sess. source_map ( ) , module) ;
376- let names = get_names ( module) ;
377- for f in & module. functions {
378- if let Some ( zombie) = zombies. get_zombie_by_id ( f. def_id ( ) . unwrap ( ) ) {
379- let mut zombie_leaf_id = zombie. id ;
380- loop {
381- zombie_leaf_id = match zombies. get_zombie_by_id ( zombie_leaf_id) . unwrap ( ) . kind {
382- ZombieKind :: Leaf => break ,
383- // FIXME(eddyb) this is all very lossy and should probably go away.
384- ZombieKind :: Uses ( zombie_uses) => zombie_uses[ 0 ] . used_zombie_id ,
385- } ;
386- }
387-
388- let name = get_name ( & names, f. def_id ( ) . unwrap ( ) ) ;
389- let reason = span_regen. zombie_for_id ( zombie_leaf_id) . unwrap ( ) . reason ;
390- debug ! (
391- target: "print_zombie" ,
392- "function removed {name:?} because {reason:?}"
393- ) ;
394- }
395- }
396- }
397-
398- // FIXME(eddyb) this should be unnecessary, either something is unused, and
399- // it will get DCE'd *anyway*, or it caused an error.
400- {
401- // HACK(eddyb) cannot use the original map because it borrows the `Module`.
402- let all_zombies: FxHashSet < _ > = zombies. id_to_zombie_kind . into_keys ( ) . collect ( ) ;
403- let keep = |inst : & Instruction | {
404- if let Some ( result_id) = inst. result_id {
405- !all_zombies. contains ( & result_id)
406- } else {
407- let mut inst_ids = inst
408- . result_type
409- . into_iter ( )
410- . chain ( inst. operands . iter ( ) . filter_map ( |op| op. id_ref_any ( ) ) ) ;
411- !inst_ids. any ( |id| all_zombies. contains ( & id) )
412- }
413- } ;
414- module. capabilities . retain ( keep) ;
415- module. extensions . retain ( keep) ;
416- module. ext_inst_imports . retain ( keep) ;
417- module. memory_model = module. memory_model . take ( ) . filter ( keep) ;
418- module. entry_points . retain ( keep) ;
419- module. execution_modes . retain ( keep) ;
420- module. debug_string_source . retain ( keep) ;
421- module. debug_names . retain ( keep) ;
422- module. debug_module_processed . retain ( keep) ;
423- module. annotations . retain ( keep) ;
424- module. types_global_values . retain ( keep) ;
425- module. functions . retain ( |f| keep ( f. def . as_ref ( ) . unwrap ( ) ) ) ;
426- }
427-
428- result
342+ ZombieReporter :: new ( sess, module, & zombies) . report_all ( )
429343}
0 commit comments