@@ -13,12 +13,15 @@ use std::collections::BTreeMap;
1313use std:: fmt;
1414use std:: ops:: Not ;
1515
16- use rustc_data_structures:: fx:: FxHashSet ;
16+ use rustc_data_structures:: fx:: { FxHashSet , FxHasher } ;
1717
1818use cranelift_codegen:: cursor:: { Cursor , FuncCursor } ;
1919use cranelift_codegen:: ir:: { InstructionData , Opcode , ValueDef } ;
2020use cranelift_codegen:: ir:: immediates:: Offset32 ;
2121
22+ use hashbrown:: HashSet ;
23+ use std:: hash:: BuildHasherDefault ;
24+
2225use crate :: prelude:: * ;
2326
2427/// Workaround for `StackSlot` not implementing `Ord`.
@@ -45,9 +48,9 @@ impl Ord for OrdStackSlot {
4548
4649#[ derive( Debug , Default ) ]
4750struct StackSlotUsage {
48- stack_addr : FxHashSet < Inst > ,
49- stack_load : FxHashSet < Inst > ,
50- stack_store : FxHashSet < Inst > ,
51+ stack_addr : HashSet < Inst , BuildHasherDefault < FxHasher > > ,
52+ stack_load : HashSet < Inst , BuildHasherDefault < FxHasher > > ,
53+ stack_store : HashSet < Inst , BuildHasherDefault < FxHasher > > ,
5154}
5255
5356impl StackSlotUsage {
@@ -313,17 +316,19 @@ fn remove_unused_stack_addr_and_stack_load(opt_ctx: &mut OptimizeContext<'_>) {
313316
314317 // Replace all unused stack_addr and stack_load instructions with nop.
315318 let mut func = & mut opt_ctx. ctx . func ;
319+
320+ // drain_filter() on hashbrown::HashSet drains the items that do *not* match the
321+ // predicate. Once hashbrown gets updated to match the behaviour of std::drain_filter
322+ // (0.8.2), the predicate will have to be reversed
316323 for stack_slot_users in opt_ctx. stack_slot_usage_map . values_mut ( ) {
317324 stack_slot_users
318325 . stack_addr
319- . drain ( )
320- . filter ( |inst| stack_addr_load_insts_users. get ( inst) . map ( |users| users. is_empty ( ) ) . unwrap_or ( true ) )
326+ . drain_filter ( |inst| !( stack_addr_load_insts_users. get ( inst) . map ( |users| users. is_empty ( ) ) . unwrap_or ( true ) ) )
321327 . for_each ( |inst| StackSlotUsage :: remove_unused_stack_addr ( & mut func, inst) ) ;
322328
323329 stack_slot_users
324330 . stack_load
325- . drain ( )
326- . filter ( |inst| stack_addr_load_insts_users. get ( inst) . map ( |users| users. is_empty ( ) ) . unwrap_or ( true ) )
331+ . drain_filter ( |inst| !( stack_addr_load_insts_users. get ( inst) . map ( |users| users. is_empty ( ) ) . unwrap_or ( true ) ) )
327332 . for_each ( |inst| StackSlotUsage :: remove_unused_load ( & mut func, inst) ) ;
328333 }
329334}
0 commit comments