11//! SPIR-T to SPIR-V lifting.
22
3+ use crate :: cf:: { self , SelectionKind } ;
34use crate :: func_at:: FuncAt ;
45use crate :: spv:: { self , spec} ;
56use crate :: visit:: { InnerVisit , Visitor } ;
67use crate :: {
78 AddrSpace , Attr , AttrSet , Const , ConstDef , ConstKind , Context , DataInst , DataInstDef ,
89 DataInstKind , DbgSrcLoc , DeclDef , EntityList , ExportKey , Exportee , Func , FuncDecl , FuncParam ,
910 FxIndexMap , FxIndexSet , GlobalVar , GlobalVarDefBody , Import , Module , ModuleDebugInfo ,
10- ModuleDialect , Node , NodeKind , NodeOutputDecl , OrdAssertEq , Region , RegionInputDecl ,
11- SelectionKind , Type , TypeDef , TypeKind , TypeOrConst , Value , cfg ,
11+ ModuleDialect , Node , NodeKind , NodeOutputDecl , OrdAssertEq , Region , RegionInputDecl , Type ,
12+ TypeDef , TypeKind , TypeOrConst , Value ,
1213} ;
1314use rustc_hash:: FxHashMap ;
1415use smallvec:: SmallVec ;
@@ -262,7 +263,7 @@ struct FuncLifting<'a> {
262263/// What determines the values for [`Value::RegionInput`]s, for a specific
263264/// region (effectively the subset of "region parents" that support inputs).
264265///
265- /// Note that this is not used when a [`cfg ::ControlInst`] has `target_inputs`,
266+ /// Note that this is not used when a [`cf::unstructured ::ControlInst`] has `target_inputs`,
266267/// and the target [`Region`] itself has phis for its `inputs`.
267268enum RegionInputsSource {
268269 FuncParams ,
@@ -299,7 +300,7 @@ struct Phi {
299300 default_value : Option < Value > ,
300301}
301302
302- /// Similar to [`cfg ::ControlInst`], except:
303+ /// Similar to [`cf::unstructured ::ControlInst`], except:
303304/// * `targets` use [`CfgPoint`]s instead of [`Region`]s, to be able to
304305/// reach any of the SPIR-V blocks being created during lifting
305306/// * φ ("phi") values can be provided for targets regardless of "which side" of
@@ -310,7 +311,7 @@ struct Phi {
310311struct Terminator < ' a > {
311312 attrs : AttrSet ,
312313
313- kind : Cow < ' a , cfg :: ControlInstKind > ,
314+ kind : Cow < ' a , cf :: unstructured :: ControlInstKind > ,
314315
315316 // FIXME(eddyb) use `Cow` or something, but ideally the "owned" case always
316317 // has at most one input, so allocating a whole `Vec` for that seems unwise.
@@ -640,8 +641,13 @@ impl<'a> FuncLifting<'a> {
640641 . as_ref ( )
641642 . and_then ( |cfg| cfg. control_inst_on_exit_from . get ( region) ) ;
642643 if let Some ( terminator) = unstructured_terminator {
643- let cfg:: ControlInst { attrs, kind, inputs, targets, target_inputs } =
644- terminator;
644+ let cf:: unstructured:: ControlInst {
645+ attrs,
646+ kind,
647+ inputs,
648+ targets,
649+ target_inputs,
650+ } = terminator;
645651 Terminator {
646652 attrs : * attrs,
647653 kind : Cow :: Borrowed ( kind) ,
@@ -664,7 +670,7 @@ impl<'a> FuncLifting<'a> {
664670 assert ! ( region == func_def_body. body) ;
665671 Terminator {
666672 attrs : AttrSet :: default ( ) ,
667- kind : Cow :: Owned ( cfg :: ControlInstKind :: Return ) ,
673+ kind : Cow :: Owned ( cf :: unstructured :: ControlInstKind :: Return ) ,
668674 inputs : func_def_body. at_body ( ) . def ( ) . outputs . clone ( ) ,
669675 targets : [ ] . into_iter ( ) . collect ( ) ,
670676 target_phi_values : FxIndexMap :: default ( ) ,
@@ -683,7 +689,9 @@ impl<'a> FuncLifting<'a> {
683689
684690 NodeKind :: Select { kind, scrutinee, cases } => Terminator {
685691 attrs : AttrSet :: default ( ) ,
686- kind : Cow :: Owned ( cfg:: ControlInstKind :: SelectBranch ( kind. clone ( ) ) ) ,
692+ kind : Cow :: Owned ( cf:: unstructured:: ControlInstKind :: SelectBranch (
693+ kind. clone ( ) ,
694+ ) ) ,
687695 inputs : [ * scrutinee] . into_iter ( ) . collect ( ) ,
688696 targets : cases
689697 . iter ( )
@@ -696,7 +704,7 @@ impl<'a> FuncLifting<'a> {
696704 NodeKind :: Loop { initial_inputs : _, body, repeat_condition : _ } => {
697705 Terminator {
698706 attrs : AttrSet :: default ( ) ,
699- kind : Cow :: Owned ( cfg :: ControlInstKind :: Branch ) ,
707+ kind : Cow :: Owned ( cf :: unstructured :: ControlInstKind :: Branch ) ,
700708 inputs : [ ] . into_iter ( ) . collect ( ) ,
701709 targets : [ CfgPoint :: RegionEntry ( * body) ] . into_iter ( ) . collect ( ) ,
702710 target_phi_values : FxIndexMap :: default ( ) ,
@@ -716,7 +724,9 @@ impl<'a> FuncLifting<'a> {
716724
717725 NodeKind :: ExitInvocation { kind, inputs } => Terminator {
718726 attrs : AttrSet :: default ( ) ,
719- kind : Cow :: Owned ( cfg:: ControlInstKind :: ExitInvocation ( kind. clone ( ) ) ) ,
727+ kind : Cow :: Owned ( cf:: unstructured:: ControlInstKind :: ExitInvocation (
728+ kind. clone ( ) ,
729+ ) ) ,
720730 inputs : inputs. clone ( ) ,
721731 targets : [ ] . into_iter ( ) . collect ( ) ,
722732 target_phi_values : FxIndexMap :: default ( ) ,
@@ -743,7 +753,7 @@ impl<'a> FuncLifting<'a> {
743753
744754 NodeKind :: Select { .. } => Terminator {
745755 attrs : AttrSet :: default ( ) ,
746- kind : Cow :: Owned ( cfg :: ControlInstKind :: Branch ) ,
756+ kind : Cow :: Owned ( cf :: unstructured :: ControlInstKind :: Branch ) ,
747757 inputs : [ ] . into_iter ( ) . collect ( ) ,
748758 targets : [ parent_exit] . into_iter ( ) . collect ( ) ,
749759 target_phi_values : region_outputs
@@ -775,7 +785,7 @@ impl<'a> FuncLifting<'a> {
775785 if is_infinite_loop {
776786 Terminator {
777787 attrs : AttrSet :: default ( ) ,
778- kind : Cow :: Owned ( cfg :: ControlInstKind :: Branch ) ,
788+ kind : Cow :: Owned ( cf :: unstructured :: ControlInstKind :: Branch ) ,
779789 inputs : [ ] . into_iter ( ) . collect ( ) ,
780790 targets : [ backedge] . into_iter ( ) . collect ( ) ,
781791 target_phi_values,
@@ -784,9 +794,11 @@ impl<'a> FuncLifting<'a> {
784794 } else {
785795 Terminator {
786796 attrs : AttrSet :: default ( ) ,
787- kind : Cow :: Owned ( cfg:: ControlInstKind :: SelectBranch (
788- SelectionKind :: BoolCond ,
789- ) ) ,
797+ kind : Cow :: Owned (
798+ cf:: unstructured:: ControlInstKind :: SelectBranch (
799+ SelectionKind :: BoolCond ,
800+ ) ,
801+ ) ,
790802 inputs : [ repeat_condition] . into_iter ( ) . collect ( ) ,
791803 targets : [ backedge, parent_exit] . into_iter ( ) . collect ( ) ,
792804 target_phi_values,
@@ -801,7 +813,7 @@ impl<'a> FuncLifting<'a> {
801813 // implied edge from a `Block`'s `Entry` to its `Exit`).
802814 ( _, Some ( succ_cursor) ) => Terminator {
803815 attrs : AttrSet :: default ( ) ,
804- kind : Cow :: Owned ( cfg :: ControlInstKind :: Branch ) ,
816+ kind : Cow :: Owned ( cf :: unstructured :: ControlInstKind :: Branch ) ,
805817 inputs : [ ] . into_iter ( ) . collect ( ) ,
806818 targets : [ succ_cursor. point ] . into_iter ( ) . collect ( ) ,
807819 target_phi_values : FxIndexMap :: default ( ) ,
@@ -877,7 +889,7 @@ impl<'a> FuncLifting<'a> {
877889 original_terminator;
878890
879891 * attrs == AttrSet :: default ( )
880- && matches ! ( * * kind, cfg :: ControlInstKind :: Branch )
892+ && matches ! ( * * kind, cf :: unstructured :: ControlInstKind :: Branch )
881893 && inputs. is_empty ( )
882894 && targets. len ( ) == 1
883895 && target_phi_values. is_empty ( )
@@ -903,7 +915,7 @@ impl<'a> FuncLifting<'a> {
903915 new_terminator,
904916 Terminator {
905917 attrs : Default :: default ( ) ,
906- kind : Cow :: Owned ( cfg :: ControlInstKind :: Unreachable ) ,
918+ kind : Cow :: Owned ( cf :: unstructured :: ControlInstKind :: Unreachable ) ,
907919 inputs : Default :: default ( ) ,
908920 targets : Default :: default ( ) ,
909921 target_phi_values : Default :: default ( ) ,
@@ -1282,26 +1294,26 @@ impl LazyInst<'_, '_> {
12821294 } ,
12831295 Self :: Terminator { parent_func, terminator } => {
12841296 let inst = match & * terminator. kind {
1285- cfg :: ControlInstKind :: Unreachable => wk. OpUnreachable . into ( ) ,
1286- cfg :: ControlInstKind :: Return => {
1297+ cf :: unstructured :: ControlInstKind :: Unreachable => wk. OpUnreachable . into ( ) ,
1298+ cf :: unstructured :: ControlInstKind :: Return => {
12871299 if terminator. inputs . is_empty ( ) {
12881300 wk. OpReturn . into ( )
12891301 } else {
12901302 wk. OpReturnValue . into ( )
12911303 }
12921304 }
1293- cfg:: ControlInstKind :: ExitInvocation ( cfg:: ExitInvocationKind :: SpvInst (
1305+ cf:: unstructured:: ControlInstKind :: ExitInvocation (
1306+ cf:: ExitInvocationKind :: SpvInst ( inst) ,
1307+ )
1308+ | cf:: unstructured:: ControlInstKind :: SelectBranch ( SelectionKind :: SpvInst (
12941309 inst,
12951310 ) ) => inst. clone ( ) ,
12961311
1297- cfg :: ControlInstKind :: Branch => wk. OpBranch . into ( ) ,
1312+ cf :: unstructured :: ControlInstKind :: Branch => wk. OpBranch . into ( ) ,
12981313
1299- cfg :: ControlInstKind :: SelectBranch ( SelectionKind :: BoolCond ) => {
1314+ cf :: unstructured :: ControlInstKind :: SelectBranch ( SelectionKind :: BoolCond ) => {
13001315 wk. OpBranchConditional . into ( )
13011316 }
1302- cfg:: ControlInstKind :: SelectBranch ( SelectionKind :: SpvInst ( inst) ) => {
1303- inst. clone ( )
1304- }
13051317 } ;
13061318 spv:: InstWithIds {
13071319 without_ids : inst,
0 commit comments