@@ -13,7 +13,7 @@ use crate::trace;
1313use crate :: { FxHashMap , FxHashSet } ;
1414use alloc:: vec:: Vec ;
1515use cranelift_control:: ControlPlane ;
16- use cranelift_entity:: { EntitySet , SecondaryMap , packed_option:: ReservedValue } ;
16+ use cranelift_entity:: { SecondaryMap , packed_option:: ReservedValue } ;
1717use smallvec:: { SmallVec , smallvec} ;
1818
1919pub ( crate ) struct Elaborator < ' a > {
@@ -224,12 +224,12 @@ impl<'a> Elaborator<'a> {
224224 best_map : & mut SecondaryMap < Value , BestEntry > ,
225225 value : Value ,
226226 seen_this_traversal : & mut FxHashSet < Value > ,
227- ) -> ( BestEntry , SecondaryMap < Value , BestEntry > ) {
227+ ) -> ( BestEntry , FxHashMap < Value , BestEntry > ) {
228228 let def = dfg. value_def ( value) ;
229229 trace ! ( "computing best for value {:?} def {:?}" , value, def) ;
230230
231231 match def {
232- // Traverse both union options, backtracking the state of subexpression we've seen on
232+ // Traverse both union options, backtracking the state of subexpressions we've seen on
233233 // each traversal. Pick the lower-cost option.
234234 ValueDef :: Union ( x, y) => {
235235 let ( best_value_x, new_seen_x) =
@@ -242,7 +242,7 @@ impl<'a> Elaborator<'a> {
242242 // Usually, y will be better. But if not, choose x and restore seen_this_traversal state
243243 if best_value_x. 0 < best_value_y. 0 {
244244 for x_val in new_seen_x. keys ( ) {
245- seen_this_traversal. insert ( x_val. clone ( ) ) ;
245+ seen_this_traversal. insert ( * x_val) ;
246246 }
247247 for y_val in new_seen_y. keys ( ) {
248248 seen_this_traversal. remove ( & y_val) ;
@@ -254,12 +254,9 @@ impl<'a> Elaborator<'a> {
254254
255255 // Params always have 0 cost
256256 ValueDef :: Param ( _, _) => {
257- let mut just_this = SecondaryMap :: with_default ( BestEntry (
258- Cost :: infinity ( ) ,
259- Value :: reserved_value ( ) ,
260- ) ) ;
257+ let mut just_this= FxHashMap :: default ( ) ;
261258 let best = BestEntry ( Cost :: zero ( ) , value) ;
262- just_this[ value] = best;
259+ just_this. insert ( value, best) ;
263260 return ( best, just_this) ;
264261 }
265262
@@ -271,26 +268,19 @@ impl<'a> Elaborator<'a> {
271268 if is_inserted || is_already_in_elaborated || seen_this_traversal. contains ( & value) {
272269 // Note: if we're counting the cost as zero here, we don't want to overwrite the saved
273270 // best cost to zero (we previously must have added some non-zero cost).
274- let empty = SecondaryMap :: with_default ( BestEntry (
275- Cost :: infinity ( ) ,
276- Value :: reserved_value ( ) ,
277- ) ) ;
278271 trace ! (
279272 " -> cost of value {} is now 0, seen before along this traversal" ,
280273 value
281274 ) ;
282- return ( BestEntry ( Cost :: zero ( ) , value) , empty ) ;
275+ return ( BestEntry ( Cost :: zero ( ) , value) , FxHashMap :: default ( ) ) ;
283276 } else {
284277 // We are seeing a new instruction for this traversal, add it to our traversal-local
285278 // seen set
286279 seen_this_traversal. insert ( value) ;
287280 // Now calculate the cost of the arguments.
288281 let inst_data = dfg. insts [ inst] ;
289282 let mut operand_costs = Vec :: new ( ) ;
290- let mut union_of_new_seen = SecondaryMap :: with_default ( BestEntry (
291- Cost :: infinity ( ) ,
292- Value :: reserved_value ( ) ,
293- ) ) ;
283+ let mut union_of_new_seen = FxHashMap :: default ( ) ;
294284 for arg in dfg. inst_values ( inst) {
295285 let ( best, new_seen) = Self :: best_value_traversal (
296286 dfg,
@@ -300,7 +290,7 @@ impl<'a> Elaborator<'a> {
300290 seen_this_traversal,
301291 ) ;
302292 for ( v, e) in new_seen. iter ( ) {
303- union_of_new_seen[ v ] = * e ;
293+ union_of_new_seen. insert ( * v , * e ) ;
304294 }
305295 operand_costs. push ( best. 0 ) ;
306296 }
@@ -310,7 +300,7 @@ impl<'a> Elaborator<'a> {
310300 let cost = Cost :: of_pure_op ( inst_data. opcode ( ) , operand_costs) ;
311301 // Add this operation, with cost, to local best map
312302 let best = BestEntry ( cost, value) ;
313- union_of_new_seen[ value] = best;
303+ union_of_new_seen. insert ( value, best) ;
314304 trace ! ( " -> cost of value {} = {:?}" , value, cost) ;
315305
316306 // AVH TODO REMOVE
@@ -352,7 +342,7 @@ impl<'a> Elaborator<'a> {
352342 Self :: best_value_traversal ( dfg, layout, best_map, value, & mut seen_this_traversal) ;
353343 best_map[ value] = best;
354344 for ( v, best) in new_seen. iter ( ) {
355- best_map[ v] = * best;
345+ best_map[ * v] = * best;
356346 }
357347 return best;
358348 }
@@ -618,8 +608,7 @@ impl<'a> Elaborator<'a> {
618608 }
619609 }
620610
621- let arg_values: & [ ElaboratedValue ] =
622- & self . elab_result_stack [ arg_idx..] . to_owned ( ) ;
611+ let arg_values: & [ ElaboratedValue ] = & self . elab_result_stack [ arg_idx..] ;
623612
624613 // Now we need to place `inst` at the computed
625614 // location (just before `before`). Note that
0 commit comments