22
33use crate :: transform:: { InnerInPlaceTransform as _, Transformer } ;
44use crate :: {
5- AttrSet , Const , ConstDef , ConstKind , Context , ControlNode , ControlNodeDef , ControlNodeKind ,
6- ControlNodeOutputDecl , EntityOrientedDenseMap , FuncDefBody , FxIndexMap , FxIndexSet , Region ,
7- RegionDef , SelectionKind , Type , TypeKind , Value , spv,
5+ AttrSet , Const , ConstDef , ConstKind , Context , EntityOrientedDenseMap , FuncDefBody , FxIndexMap ,
6+ FxIndexSet , Node , NodeDef , NodeKind , NodeOutputDecl , Region , RegionDef , SelectionKind , Type ,
7+ TypeKind , Value , spv,
88} ;
99use itertools:: { Either , Itertools } ;
1010use smallvec:: SmallVec ;
@@ -666,7 +666,7 @@ impl<T> DeferredEdgeBundle<T> {
666666
667667/// A recipe for computing a control-flow-sensitive (boolean) condition [`Value`],
668668/// potentially requiring merging through an arbitrary number of `Select`s
669- /// (via per-case outputs and [`Value::ControlNodeOutput `], for each `Select`).
669+ /// (via per-case outputs and [`Value::NodeOutput `], for each `Select`).
670670///
671671/// This should largely be equivalent to eagerly generating all region outputs
672672/// that might be needed, and then removing the unused ones, but this way we
@@ -686,7 +686,7 @@ enum LazyCond {
686686
687687enum LazyCondMerge {
688688 Select {
689- control_node : ControlNode ,
689+ node : Node ,
690690 // FIXME(eddyb) the lowest level of `LazyCond` ends up containing only
691691 // `LazyCond::{Undef,False,True}`, and that could more efficiently be
692692 // expressed using e.g. bitsets, but the `Rc` in `LazyCond::Merge`
@@ -956,7 +956,7 @@ impl DeferredEdgeBundleSet {
956956/// - merging into a larger region (i.e. its nearest dominator)
957957//
958958// FIXME(eddyb) consider never having to claim the function body itself,
959- // by wrapping the CFG in a `ControlNode ` instead.
959+ // by wrapping the CFG in a `Node ` instead.
960960struct ClaimedRegion {
961961 // FIXME(eddyb) find a way to clarify that this can differ from the target
962962 // of `try_claim_edge_bundle`, and also that `deferred_edges` are from the
@@ -965,10 +965,10 @@ struct ClaimedRegion {
965965
966966 /// The [`Value`]s that `Value::RegionInput { region: structured_body, .. }`
967967 /// will get on entry into `structured_body`, when this region ends up
968- /// merged into a larger region, or as a child of a new [`ControlNode `].
968+ /// merged into a larger region, or as a child of a new [`Node `].
969969 //
970970 // FIXME(eddyb) don't replace `Value::RegionInput { region: structured_body, .. }`
971- // with `region_inputs` when `structured_body` ends up a `ControlNode ` child,
971+ // with `region_inputs` when `structured_body` ends up a `Node ` child,
972972 // but instead make all `Region`s entirely hermetic wrt inputs.
973973 structured_body_inputs : SmallVec < [ Value ; 2 ] > ,
974974
@@ -1072,7 +1072,7 @@ impl<'a> Structurizer<'a> {
10721072 }
10731073
10741074 // FIXME(eddyb) it might work much better to have the unstructured CFG
1075- // wrapped in a `ControlNode ` inside the function body, instead.
1075+ // wrapped in a `Node ` inside the function body, instead.
10761076 let func_body_deferred_edges = {
10771077 let func_entry_pseudo_edge = {
10781078 let target = self . func_def_body . body ;
@@ -1228,7 +1228,7 @@ impl<'a> Structurizer<'a> {
12281228 backedge;
12291229 let body = target;
12301230
1231- // HACK(eddyb) due to `Loop` `ControlNode `s not being hermetic on
1231+ // HACK(eddyb) due to `Loop` `Node `s not being hermetic on
12321232 // the output side yet (i.e. they still have SSA-like semantics),
12331233 // it gets wrapped in a `Region`, which can be as hermetic as
12341234 // the loop body itself was originally.
@@ -1241,7 +1241,7 @@ impl<'a> Structurizer<'a> {
12411241 // starting as `initial_inputs` and being replaced with body outputs
12421242 // after every loop iteration.
12431243 //
1244- // FIXME(eddyb) `Loop` `ControlNode `s should be changed to be hermetic
1244+ // FIXME(eddyb) `Loop` `Node `s should be changed to be hermetic
12451245 // and have the loop state be output from the whole node itself,
12461246 // for any outside uses of values defined within the loop body.
12471247 let body_def = self . func_def_body . at_mut ( body) . def ( ) ;
@@ -1295,20 +1295,18 @@ impl<'a> Structurizer<'a> {
12951295 assert_eq ! ( body_def. outputs. len( ) , body_def. inputs. len( ) ) ;
12961296
12971297 let repeat_condition = self . materialize_lazy_cond ( & repeat_condition) ;
1298- let loop_node = self . func_def_body . control_nodes . define (
1298+ let loop_node = self . func_def_body . nodes . define (
12991299 self . cx ,
1300- ControlNodeDef {
1301- kind : ControlNodeKind :: Loop { initial_inputs, body, repeat_condition } ,
1300+ NodeDef {
1301+ kind : NodeKind :: Loop { initial_inputs, body, repeat_condition } ,
13021302 outputs : [ ] . into_iter ( ) . collect ( ) ,
13031303 }
13041304 . into ( ) ,
13051305 ) ;
13061306
13071307 let wrapper_region_def = & mut self . func_def_body . regions [ wrapper_region] ;
13081308 wrapper_region_def. inputs = original_input_decls;
1309- wrapper_region_def
1310- . children
1311- . insert_last ( loop_node, & mut self . func_def_body . control_nodes ) ;
1309+ wrapper_region_def. children . insert_last ( loop_node, & mut self . func_def_body . nodes ) ;
13121310
13131311 // HACK(eddyb) we've treated loop exits as extra "false edges", so
13141312 // here they have to be added to the loop (potentially unlocking
@@ -1372,7 +1370,7 @@ impl<'a> Structurizer<'a> {
13721370 ) ;
13731371
13741372 // Start with the concatenation of `region` and `control_inst_on_exit`,
1375- // always appending `ControlNode `s (including the children of entire
1373+ // always appending `Node `s (including the children of entire
13761374 // `ClaimedRegion`s) to `region`'s definition itself.
13771375 let mut deferred_edges = {
13781376 let ControlInst { attrs, kind, inputs, targets, target_inputs } = control_inst_on_exit;
@@ -1426,8 +1424,8 @@ impl<'a> Structurizer<'a> {
14261424 assert_eq ! ( ( inputs. len( ) , target_regions. len( ) ) , ( 0 , 0 ) ) ;
14271425
14281426 // FIXME(eddyb) this may result in lost optimizations over
1429- // actually encoding it in `ControlNode `/`Region`
1430- // (e.g. a new `ControlNodeKind `, or replacing region `outputs`),
1427+ // actually encoding it in `Node `/`Region`
1428+ // (e.g. a new `NodeKind `, or replacing region `outputs`),
14311429 // but it's simpler to handle it like this.
14321430 //
14331431 // NOTE(eddyb) actually, this encoding is lossless *during*
@@ -1448,17 +1446,17 @@ impl<'a> Structurizer<'a> {
14481446 ControlInstKind :: ExitInvocation ( kind) => {
14491447 assert_eq ! ( target_regions. len( ) , 0 ) ;
14501448
1451- let control_node = self . func_def_body . control_nodes . define (
1449+ let node = self . func_def_body . nodes . define (
14521450 self . cx ,
1453- ControlNodeDef {
1454- kind : ControlNodeKind :: ExitInvocation { kind, inputs } ,
1451+ NodeDef {
1452+ kind : NodeKind :: ExitInvocation { kind, inputs } ,
14551453 outputs : [ ] . into_iter ( ) . collect ( ) ,
14561454 }
14571455 . into ( ) ,
14581456 ) ;
14591457 self . func_def_body . regions [ region]
14601458 . children
1461- . insert_last ( control_node , & mut self . func_def_body . control_nodes ) ;
1459+ . insert_last ( node , & mut self . func_def_body . nodes ) ;
14621460
14631461 DeferredEdgeBundleSet :: Unreachable
14641462 }
@@ -1558,7 +1556,7 @@ impl<'a> Structurizer<'a> {
15581556 }
15591557 }
15601558
1561- /// Append to `parent_region` a new `Select` [`ControlNode `] built from
1559+ /// Append to `parent_region` a new `Select` [`Node `] built from
15621560 /// partially structured `cases`, merging all of their `deferred_edges`
15631561 /// together into a combined `DeferredEdgeBundleSet` (which gets returned).
15641562 //
@@ -1602,7 +1600,7 @@ impl<'a> Structurizer<'a> {
16021600 }
16031601
16041602 // Support lazily defining the `Select` node, as soon as it's necessary
1605- // (i.e. to plumb per-case dataflow through `Value::ControlNodeOutput `s),
1603+ // (i.e. to plumb per-case dataflow through `Value::NodeOutput `s),
16061604 // but also if any of the cases actually have non-empty regions, which
16071605 // is checked after the special-cases (which return w/o a `Select` at all).
16081606 //
@@ -1630,17 +1628,17 @@ impl<'a> Structurizer<'a> {
16301628 . collect ( ) ;
16311629 let scrutinee =
16321630 scrutinee. unwrap_or_else ( |lazy_cond| this. materialize_lazy_cond ( lazy_cond) ) ;
1633- let select_node = this. func_def_body . control_nodes . define (
1631+ let select_node = this. func_def_body . nodes . define (
16341632 this. cx ,
1635- ControlNodeDef {
1636- kind : ControlNodeKind :: Select { kind, scrutinee, cases } ,
1633+ NodeDef {
1634+ kind : NodeKind :: Select { kind, scrutinee, cases } ,
16371635 outputs : [ ] . into_iter ( ) . collect ( ) ,
16381636 }
16391637 . into ( ) ,
16401638 ) ;
16411639 this. func_def_body . regions [ parent_region]
16421640 . children
1643- . insert_last ( select_node, & mut this. func_def_body . control_nodes ) ;
1641+ . insert_last ( select_node, & mut this. func_def_body . nodes ) ;
16441642 select_node
16451643 } )
16461644 } ;
@@ -1797,20 +1795,20 @@ impl<'a> Structurizer<'a> {
17971795 let select_node = get_or_define_select_node ( self , & cases) ;
17981796 let output_decls = & mut self . func_def_body . at_mut ( select_node) . def ( ) . outputs ;
17991797 let output_idx = output_decls. len ( ) ;
1800- output_decls. push ( ControlNodeOutputDecl { attrs : AttrSet :: default ( ) , ty } ) ;
1798+ output_decls. push ( NodeOutputDecl { attrs : AttrSet :: default ( ) , ty } ) ;
18011799 for ( case_idx, v) in per_case_target_input. enumerate ( ) {
18021800 let v = v. unwrap_or_else ( || Value :: Const ( self . const_undef ( ty) ) ) ;
18031801
18041802 let case_region = match & self . func_def_body . at ( select_node) . def ( ) . kind {
1805- ControlNodeKind :: Select { cases, .. } => cases[ case_idx] ,
1803+ NodeKind :: Select { cases, .. } => cases[ case_idx] ,
18061804 _ => unreachable ! ( ) ,
18071805 } ;
18081806 let outputs = & mut self . func_def_body . at_mut ( case_region) . def ( ) . outputs ;
18091807 assert_eq ! ( outputs. len( ) , output_idx) ;
18101808 outputs. push ( v) ;
18111809 }
1812- Value :: ControlNodeOutput {
1813- control_node : select_node,
1810+ Value :: NodeOutput {
1811+ node : select_node,
18141812 output_idx : output_idx. try_into ( ) . unwrap ( ) ,
18151813 }
18161814 } )
@@ -1833,7 +1831,7 @@ impl<'a> Structurizer<'a> {
18331831 LazyCond :: True
18341832 } else {
18351833 LazyCond :: Merge ( Rc :: new ( LazyCondMerge :: Select {
1836- control_node : get_or_define_select_node ( self , & cases) ,
1834+ node : get_or_define_select_node ( self , & cases) ,
18371835 per_case_conds : per_case_conds. cloned ( ) . collect ( ) ,
18381836 } ) )
18391837 } ;
@@ -1853,7 +1851,7 @@ impl<'a> Structurizer<'a> {
18531851 // `region_input_rewrites`.
18541852 //
18551853 // FIXME(eddyb) don't replace `Value::RegionInput { region, .. }`
1856- // with `region_inputs` when the `region` ends up a `ControlNode ` child,
1854+ // with `region_inputs` when the `region` ends up a `Node ` child,
18571855 // but instead make all `Region`s entirely hermetic wrt inputs.
18581856 #[ allow( clippy:: manual_flatten) ]
18591857 for case in cases {
@@ -1889,7 +1887,7 @@ impl<'a> Structurizer<'a> {
18891887 // special-case (repalcing with just `cond`), that cannot be expressed
18901888 // currently in `LazyCond` itself (but maybe it should be).
18911889 LazyCond :: Merge ( merge) => {
1892- let LazyCondMerge :: Select { control_node , ref per_case_conds } = * * merge;
1890+ let LazyCondMerge :: Select { node , ref per_case_conds } = * * merge;
18931891
18941892 // HACK(eddyb) this won't actually allocate most of the time,
18951893 // and avoids complications later below, when mutating the cases.
@@ -1898,10 +1896,9 @@ impl<'a> Structurizer<'a> {
18981896 . map ( |cond| self . materialize_lazy_cond ( cond) )
18991897 . collect ( ) ;
19001898
1901- let ControlNodeDef { kind, outputs : output_decls } =
1902- & mut * self . func_def_body . control_nodes [ control_node] ;
1899+ let NodeDef { kind, outputs : output_decls } = & mut * self . func_def_body . nodes [ node] ;
19031900 let cases = match kind {
1904- ControlNodeKind :: Select { kind, scrutinee, cases } => {
1901+ NodeKind :: Select { kind, scrutinee, cases } => {
19051902 assert_eq ! ( cases. len( ) , per_case_conds. len( ) ) ;
19061903
19071904 if let SelectionKind :: BoolCond = kind {
@@ -1924,16 +1921,15 @@ impl<'a> Structurizer<'a> {
19241921 } ;
19251922
19261923 let output_idx = u32:: try_from ( output_decls. len ( ) ) . unwrap ( ) ;
1927- output_decls
1928- . push ( ControlNodeOutputDecl { attrs : AttrSet :: default ( ) , ty : self . type_bool } ) ;
1924+ output_decls. push ( NodeOutputDecl { attrs : AttrSet :: default ( ) , ty : self . type_bool } ) ;
19291925
19301926 for ( & case, cond) in cases. iter ( ) . zip_eq ( per_case_conds) {
19311927 let RegionDef { outputs, .. } = & mut self . func_def_body . regions [ case] ;
19321928 outputs. push ( cond) ;
19331929 assert_eq ! ( outputs. len( ) , output_decls. len( ) ) ;
19341930 }
19351931
1936- Value :: ControlNodeOutput { control_node , output_idx }
1932+ Value :: NodeOutput { node , output_idx }
19371933 }
19381934 }
19391935 }
@@ -1960,7 +1956,7 @@ impl<'a> Structurizer<'a> {
19601956 mem:: take ( & mut self . func_def_body . at_mut ( structured_body) . def ( ) . children ) ;
19611957 self . func_def_body . regions [ parent_region]
19621958 . children
1963- . append ( new_children, & mut self . func_def_body . control_nodes ) ;
1959+ . append ( new_children, & mut self . func_def_body . nodes ) ;
19641960 deferred_edges
19651961 }
19661962 Err ( deferred_edges) => deferred_edges,
0 commit comments