1
1
//! SPIR-T to SPIR-V lifting.
2
2
3
+ use crate :: cf:: { self , SelectionKind } ;
3
4
use crate :: func_at:: FuncAt ;
4
5
use crate :: spv:: { self , spec} ;
5
6
use crate :: visit:: { InnerVisit , Visitor } ;
6
7
use crate :: {
7
8
AddrSpace , Attr , AttrSet , Const , ConstDef , ConstKind , Context , DataInst , DataInstDef ,
8
9
DataInstKind , DbgSrcLoc , DeclDef , EntityList , ExportKey , Exportee , Func , FuncDecl , FuncParam ,
9
10
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 ,
12
13
} ;
13
14
use rustc_hash:: FxHashMap ;
14
15
use smallvec:: SmallVec ;
@@ -262,7 +263,7 @@ struct FuncLifting<'a> {
262
263
/// What determines the values for [`Value::RegionInput`]s, for a specific
263
264
/// region (effectively the subset of "region parents" that support inputs).
264
265
///
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`,
266
267
/// and the target [`Region`] itself has phis for its `inputs`.
267
268
enum RegionInputsSource {
268
269
FuncParams ,
@@ -299,7 +300,7 @@ struct Phi {
299
300
default_value : Option < Value > ,
300
301
}
301
302
302
- /// Similar to [`cfg ::ControlInst`], except:
303
+ /// Similar to [`cf::unstructured ::ControlInst`], except:
303
304
/// * `targets` use [`CfgPoint`]s instead of [`Region`]s, to be able to
304
305
/// reach any of the SPIR-V blocks being created during lifting
305
306
/// * φ ("phi") values can be provided for targets regardless of "which side" of
@@ -310,7 +311,7 @@ struct Phi {
310
311
struct Terminator < ' a > {
311
312
attrs : AttrSet ,
312
313
313
- kind : Cow < ' a , cfg :: ControlInstKind > ,
314
+ kind : Cow < ' a , cf :: unstructured :: ControlInstKind > ,
314
315
315
316
// FIXME(eddyb) use `Cow` or something, but ideally the "owned" case always
316
317
// has at most one input, so allocating a whole `Vec` for that seems unwise.
@@ -640,8 +641,13 @@ impl<'a> FuncLifting<'a> {
640
641
. as_ref ( )
641
642
. and_then ( |cfg| cfg. control_inst_on_exit_from . get ( region) ) ;
642
643
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;
645
651
Terminator {
646
652
attrs : * attrs,
647
653
kind : Cow :: Borrowed ( kind) ,
@@ -664,7 +670,7 @@ impl<'a> FuncLifting<'a> {
664
670
assert ! ( region == func_def_body. body) ;
665
671
Terminator {
666
672
attrs : AttrSet :: default ( ) ,
667
- kind : Cow :: Owned ( cfg :: ControlInstKind :: Return ) ,
673
+ kind : Cow :: Owned ( cf :: unstructured :: ControlInstKind :: Return ) ,
668
674
inputs : func_def_body. at_body ( ) . def ( ) . outputs . clone ( ) ,
669
675
targets : [ ] . into_iter ( ) . collect ( ) ,
670
676
target_phi_values : FxIndexMap :: default ( ) ,
@@ -683,7 +689,9 @@ impl<'a> FuncLifting<'a> {
683
689
684
690
NodeKind :: Select { kind, scrutinee, cases } => Terminator {
685
691
attrs : AttrSet :: default ( ) ,
686
- kind : Cow :: Owned ( cfg:: ControlInstKind :: SelectBranch ( kind. clone ( ) ) ) ,
692
+ kind : Cow :: Owned ( cf:: unstructured:: ControlInstKind :: SelectBranch (
693
+ kind. clone ( ) ,
694
+ ) ) ,
687
695
inputs : [ * scrutinee] . into_iter ( ) . collect ( ) ,
688
696
targets : cases
689
697
. iter ( )
@@ -696,7 +704,7 @@ impl<'a> FuncLifting<'a> {
696
704
NodeKind :: Loop { initial_inputs : _, body, repeat_condition : _ } => {
697
705
Terminator {
698
706
attrs : AttrSet :: default ( ) ,
699
- kind : Cow :: Owned ( cfg :: ControlInstKind :: Branch ) ,
707
+ kind : Cow :: Owned ( cf :: unstructured :: ControlInstKind :: Branch ) ,
700
708
inputs : [ ] . into_iter ( ) . collect ( ) ,
701
709
targets : [ CfgPoint :: RegionEntry ( * body) ] . into_iter ( ) . collect ( ) ,
702
710
target_phi_values : FxIndexMap :: default ( ) ,
@@ -716,7 +724,9 @@ impl<'a> FuncLifting<'a> {
716
724
717
725
NodeKind :: ExitInvocation { kind, inputs } => Terminator {
718
726
attrs : AttrSet :: default ( ) ,
719
- kind : Cow :: Owned ( cfg:: ControlInstKind :: ExitInvocation ( kind. clone ( ) ) ) ,
727
+ kind : Cow :: Owned ( cf:: unstructured:: ControlInstKind :: ExitInvocation (
728
+ kind. clone ( ) ,
729
+ ) ) ,
720
730
inputs : inputs. clone ( ) ,
721
731
targets : [ ] . into_iter ( ) . collect ( ) ,
722
732
target_phi_values : FxIndexMap :: default ( ) ,
@@ -743,7 +753,7 @@ impl<'a> FuncLifting<'a> {
743
753
744
754
NodeKind :: Select { .. } => Terminator {
745
755
attrs : AttrSet :: default ( ) ,
746
- kind : Cow :: Owned ( cfg :: ControlInstKind :: Branch ) ,
756
+ kind : Cow :: Owned ( cf :: unstructured :: ControlInstKind :: Branch ) ,
747
757
inputs : [ ] . into_iter ( ) . collect ( ) ,
748
758
targets : [ parent_exit] . into_iter ( ) . collect ( ) ,
749
759
target_phi_values : region_outputs
@@ -775,7 +785,7 @@ impl<'a> FuncLifting<'a> {
775
785
if is_infinite_loop {
776
786
Terminator {
777
787
attrs : AttrSet :: default ( ) ,
778
- kind : Cow :: Owned ( cfg :: ControlInstKind :: Branch ) ,
788
+ kind : Cow :: Owned ( cf :: unstructured :: ControlInstKind :: Branch ) ,
779
789
inputs : [ ] . into_iter ( ) . collect ( ) ,
780
790
targets : [ backedge] . into_iter ( ) . collect ( ) ,
781
791
target_phi_values,
@@ -784,9 +794,11 @@ impl<'a> FuncLifting<'a> {
784
794
} else {
785
795
Terminator {
786
796
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
+ ) ,
790
802
inputs : [ repeat_condition] . into_iter ( ) . collect ( ) ,
791
803
targets : [ backedge, parent_exit] . into_iter ( ) . collect ( ) ,
792
804
target_phi_values,
@@ -801,7 +813,7 @@ impl<'a> FuncLifting<'a> {
801
813
// implied edge from a `Block`'s `Entry` to its `Exit`).
802
814
( _, Some ( succ_cursor) ) => Terminator {
803
815
attrs : AttrSet :: default ( ) ,
804
- kind : Cow :: Owned ( cfg :: ControlInstKind :: Branch ) ,
816
+ kind : Cow :: Owned ( cf :: unstructured :: ControlInstKind :: Branch ) ,
805
817
inputs : [ ] . into_iter ( ) . collect ( ) ,
806
818
targets : [ succ_cursor. point ] . into_iter ( ) . collect ( ) ,
807
819
target_phi_values : FxIndexMap :: default ( ) ,
@@ -877,7 +889,7 @@ impl<'a> FuncLifting<'a> {
877
889
original_terminator;
878
890
879
891
* attrs == AttrSet :: default ( )
880
- && matches ! ( * * kind, cfg :: ControlInstKind :: Branch )
892
+ && matches ! ( * * kind, cf :: unstructured :: ControlInstKind :: Branch )
881
893
&& inputs. is_empty ( )
882
894
&& targets. len ( ) == 1
883
895
&& target_phi_values. is_empty ( )
@@ -903,7 +915,7 @@ impl<'a> FuncLifting<'a> {
903
915
new_terminator,
904
916
Terminator {
905
917
attrs : Default :: default ( ) ,
906
- kind : Cow :: Owned ( cfg :: ControlInstKind :: Unreachable ) ,
918
+ kind : Cow :: Owned ( cf :: unstructured :: ControlInstKind :: Unreachable ) ,
907
919
inputs : Default :: default ( ) ,
908
920
targets : Default :: default ( ) ,
909
921
target_phi_values : Default :: default ( ) ,
@@ -1282,26 +1294,26 @@ impl LazyInst<'_, '_> {
1282
1294
} ,
1283
1295
Self :: Terminator { parent_func, terminator } => {
1284
1296
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 => {
1287
1299
if terminator. inputs . is_empty ( ) {
1288
1300
wk. OpReturn . into ( )
1289
1301
} else {
1290
1302
wk. OpReturnValue . into ( )
1291
1303
}
1292
1304
}
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 (
1294
1309
inst,
1295
1310
) ) => inst. clone ( ) ,
1296
1311
1297
- cfg :: ControlInstKind :: Branch => wk. OpBranch . into ( ) ,
1312
+ cf :: unstructured :: ControlInstKind :: Branch => wk. OpBranch . into ( ) ,
1298
1313
1299
- cfg :: ControlInstKind :: SelectBranch ( SelectionKind :: BoolCond ) => {
1314
+ cf :: unstructured :: ControlInstKind :: SelectBranch ( SelectionKind :: BoolCond ) => {
1300
1315
wk. OpBranchConditional . into ( )
1301
1316
}
1302
- cfg:: ControlInstKind :: SelectBranch ( SelectionKind :: SpvInst ( inst) ) => {
1303
- inst. clone ( )
1304
- }
1305
1317
} ;
1306
1318
spv:: InstWithIds {
1307
1319
without_ids : inst,
0 commit comments