@@ -13,12 +13,15 @@ use std::collections::BTreeMap;
13
13
use std:: fmt;
14
14
use std:: ops:: Not ;
15
15
16
- use rustc_data_structures:: fx:: FxHashSet ;
16
+ use rustc_data_structures:: fx:: { FxHashSet , FxHasher } ;
17
17
18
18
use cranelift_codegen:: cursor:: { Cursor , FuncCursor } ;
19
19
use cranelift_codegen:: ir:: { InstructionData , Opcode , ValueDef } ;
20
20
use cranelift_codegen:: ir:: immediates:: Offset32 ;
21
21
22
+ use hashbrown:: HashSet ;
23
+ use std:: hash:: BuildHasherDefault ;
24
+
22
25
use crate :: prelude:: * ;
23
26
24
27
/// Workaround for `StackSlot` not implementing `Ord`.
@@ -45,9 +48,9 @@ impl Ord for OrdStackSlot {
45
48
46
49
#[ derive( Debug , Default ) ]
47
50
struct 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 > > ,
51
54
}
52
55
53
56
impl StackSlotUsage {
@@ -313,17 +316,19 @@ fn remove_unused_stack_addr_and_stack_load(opt_ctx: &mut OptimizeContext<'_>) {
313
316
314
317
// Replace all unused stack_addr and stack_load instructions with nop.
315
318
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
316
323
for stack_slot_users in opt_ctx. stack_slot_usage_map . values_mut ( ) {
317
324
stack_slot_users
318
325
. 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 ) ) )
321
327
. for_each ( |inst| StackSlotUsage :: remove_unused_stack_addr ( & mut func, inst) ) ;
322
328
323
329
stack_slot_users
324
330
. 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 ) ) )
327
332
. for_each ( |inst| StackSlotUsage :: remove_unused_load ( & mut func, inst) ) ;
328
333
}
329
334
}
0 commit comments