2
2
3
3
use crate :: transform:: { InnerInPlaceTransform as _, Transformer } ;
4
4
use crate :: {
5
- spv, AttrSet , Const , ConstDef , ConstKind , Context , ControlNode , ControlNodeDef ,
6
- ControlNodeKind , ControlNodeOutputDecl , ControlRegion , ControlRegionDef ,
7
- EntityOrientedDenseMap , FuncDefBody , FxIndexMap , FxIndexSet , SelectionKind , Type , TypeKind ,
8
- Value ,
5
+ AttrSet , Const , ConstDef , ConstKind , Context , ControlNode , ControlNodeDef , ControlNodeKind ,
6
+ ControlNodeOutputDecl , ControlRegion , ControlRegionDef , EntityOrientedDenseMap , FuncDefBody ,
7
+ FxIndexMap , FxIndexSet , SelectionKind , Type , TypeKind , Value , spv,
9
8
} ;
10
9
use itertools:: { Either , Itertools } ;
11
10
use smallvec:: SmallVec ;
@@ -85,20 +84,17 @@ impl ControlFlowGraph {
85
84
func_def_body : & FuncDefBody ,
86
85
) -> impl DoubleEndedIterator < Item = ControlRegion > {
87
86
let mut post_order = SmallVec :: < [ _ ; 8 ] > :: new ( ) ;
88
- self . traverse_whole_func (
89
- func_def_body,
90
- & mut TraversalState {
91
- incoming_edge_counts : EntityOrientedDenseMap :: new ( ) ,
87
+ self . traverse_whole_func ( func_def_body, & mut TraversalState {
88
+ incoming_edge_counts : EntityOrientedDenseMap :: new ( ) ,
92
89
93
- pre_order_visit : |_| { } ,
94
- post_order_visit : |region| post_order. push ( region) ,
90
+ pre_order_visit : |_| { } ,
91
+ post_order_visit : |region| post_order. push ( region) ,
95
92
96
- // NOTE(eddyb) this doesn't impact semantics, but combined with
97
- // the final reversal, it should keep targets in the original
98
- // order in the cases when they didn't get deduplicated.
99
- reverse_targets : true ,
100
- } ,
101
- ) ;
93
+ // NOTE(eddyb) this doesn't impact semantics, but combined with
94
+ // the final reversal, it should keep targets in the original
95
+ // order in the cases when they didn't get deduplicated.
96
+ reverse_targets : true ,
97
+ } ) ;
102
98
post_order. into_iter ( ) . rev ( )
103
99
}
104
100
}
@@ -912,13 +908,10 @@ impl DeferredEdgeBundleSet {
912
908
Err ( new_deferred) => {
913
909
assert ! ( new_deferred. edge_bundle. target == target) ;
914
910
assert ! ( matches!( new_deferred. condition, LazyCond :: True ) ) ;
915
- (
916
- None ,
917
- DeferredEdgeBundleSet :: Always {
918
- target,
919
- edge_bundle : new_deferred. edge_bundle . with_target ( ( ) ) ,
920
- } ,
921
- )
911
+ ( None , DeferredEdgeBundleSet :: Always {
912
+ target,
913
+ edge_bundle : new_deferred. edge_bundle . with_target ( ( ) ) ,
914
+ } )
922
915
}
923
916
}
924
917
}
@@ -927,17 +920,14 @@ impl DeferredEdgeBundleSet {
927
920
for ( i, ( & target, deferred) ) in target_to_deferred. iter_mut ( ) . enumerate ( ) {
928
921
// HACK(eddyb) "take" `deferred` so it can be passed to
929
922
// `matches` (and put back if that returned `Err`).
930
- let taken_deferred = mem:: replace (
931
- deferred,
932
- DeferredEdgeBundle {
933
- condition : LazyCond :: False ,
934
- edge_bundle : IncomingEdgeBundle {
935
- target : Default :: default ( ) ,
936
- accumulated_count : Default :: default ( ) ,
937
- target_inputs : Default :: default ( ) ,
938
- } ,
923
+ let taken_deferred = mem:: replace ( deferred, DeferredEdgeBundle {
924
+ condition : LazyCond :: False ,
925
+ edge_bundle : IncomingEdgeBundle {
926
+ target : Default :: default ( ) ,
927
+ accumulated_count : Default :: default ( ) ,
928
+ target_inputs : Default :: default ( ) ,
939
929
} ,
940
- ) ;
930
+ } ) ;
941
931
942
932
match matches ( taken_deferred. with_target ( target) ) {
943
933
Ok ( x) => {
@@ -1123,16 +1113,13 @@ impl<'a> Structurizer<'a> {
1123
1113
// in the general case (but special-cased because this is very
1124
1114
// close to being structurizable, just needs a bit of plumbing).
1125
1115
let mut control_inst_on_exit_from = EntityOrientedDenseMap :: new ( ) ;
1126
- control_inst_on_exit_from. insert (
1127
- self . func_def_body . body ,
1128
- ControlInst {
1129
- attrs : AttrSet :: default ( ) ,
1130
- kind : ControlInstKind :: Unreachable ,
1131
- inputs : [ ] . into_iter ( ) . collect ( ) ,
1132
- targets : [ ] . into_iter ( ) . collect ( ) ,
1133
- target_inputs : FxIndexMap :: default ( ) ,
1134
- } ,
1135
- ) ;
1116
+ control_inst_on_exit_from. insert ( self . func_def_body . body , ControlInst {
1117
+ attrs : AttrSet :: default ( ) ,
1118
+ kind : ControlInstKind :: Unreachable ,
1119
+ inputs : [ ] . into_iter ( ) . collect ( ) ,
1120
+ targets : [ ] . into_iter ( ) . collect ( ) ,
1121
+ target_inputs : FxIndexMap :: default ( ) ,
1122
+ } ) ;
1136
1123
self . func_def_body . unstructured_cfg = Some ( ControlFlowGraph {
1137
1124
control_inst_on_exit_from,
1138
1125
loop_merge_to_loop_header : Default :: default ( ) ,
@@ -1148,15 +1135,13 @@ impl<'a> Structurizer<'a> {
1148
1135
1149
1136
_ => {
1150
1137
// Repair all the regions that remain unclaimed, including the body.
1151
- let structurize_region_state =
1152
- mem:: take ( & mut self . structurize_region_state ) . into_iter ( ) . chain ( [ (
1153
- self . func_def_body . body ,
1154
- StructurizeRegionState :: Ready {
1155
- accumulated_backedge_count : IncomingEdgeCount :: default ( ) ,
1138
+ let structurize_region_state = mem:: take ( & mut self . structurize_region_state )
1139
+ . into_iter ( )
1140
+ . chain ( [ ( self . func_def_body . body , StructurizeRegionState :: Ready {
1141
+ accumulated_backedge_count : IncomingEdgeCount :: default ( ) ,
1156
1142
1157
- region_deferred_edges : func_body_deferred_edges,
1158
- } ,
1159
- ) ] ) ;
1143
+ region_deferred_edges : func_body_deferred_edges,
1144
+ } ) ] ) ;
1160
1145
for ( target, state) in structurize_region_state {
1161
1146
if let StructurizeRegionState :: Ready { region_deferred_edges, .. } = state {
1162
1147
self . rebuild_cfg_from_unclaimed_region_deferred_edges (
@@ -1559,13 +1544,11 @@ impl<'a> Structurizer<'a> {
1559
1544
. map ( |backedge| backedge. accumulated_count )
1560
1545
. unwrap_or_default ( ) ;
1561
1546
1562
- let old_state = self . structurize_region_state . insert (
1563
- region,
1564
- StructurizeRegionState :: Ready {
1547
+ let old_state =
1548
+ self . structurize_region_state . insert ( region, StructurizeRegionState :: Ready {
1565
1549
accumulated_backedge_count,
1566
1550
region_deferred_edges : deferred_edges,
1567
- } ,
1568
- ) ;
1551
+ } ) ;
1569
1552
if !matches ! ( old_state, Some ( StructurizeRegionState :: InProgress ) ) {
1570
1553
unreachable ! (
1571
1554
"cfg::Structurizer::structurize_region: \
0 commit comments