@@ -3,7 +3,6 @@ use rspirv::spirv::{Op};
33use rustc_data_structures:: fx:: { FxHashMap , FxHashSet } ;
44use rustc_session:: Session ;
55
6- // bool is if this needs stored
76#[ derive( Debug , Clone , PartialEq ) ]
87struct NormalizedInstructions {
98 vars : Vec < Instruction > ,
@@ -38,6 +37,7 @@ impl NormalizedInstructions {
3837 for inst in & mut self . insts {
3938 Self :: fix_instruction ( self . root , inst, & mut id_map, bound, new_root) ;
4039 }
40+ self . root = new_root;
4141 }
4242
4343 fn fix_instruction (
@@ -139,40 +139,36 @@ fn inline_global_varaibles_rec(module: &mut Module) -> super::Result<bool> {
139139 } ;
140140 for i in 1 ..inst. operands . len ( ) {
141141 let key = ( function_id, i as u32 - 1 ) ;
142+ // default to invalid to avoid duplicated code
143+ let mut is_invalid = true ;
142144 match & inst. operands [ i] {
143145 & Operand :: IdRef ( w) => match & function_args. get ( & key) {
144146 None => {
145147 match get_const_arg_insts ( bound, & variables, & insts, & ref_stores, w) {
146148 Some ( insts) => {
149+ is_invalid = false ;
147150 function_args. insert ( key, FunctionArg :: Insts ( insts) ) ;
148151 }
149- None => {
150- function_args. insert ( key, FunctionArg :: Invalid ) ;
151- }
152+ None => { }
152153 }
153154 }
154155 Some ( FunctionArg :: Insts ( w2) ) => {
155156 let new_insts =
156157 get_const_arg_insts ( bound, & variables, & insts, & ref_stores, w) ;
157158 match new_insts {
158159 Some ( new_insts) => {
159- if new_insts != * w2 {
160- function_args. insert ( key, FunctionArg :: Invalid ) ;
161- }
162- }
163- None => {
164- function_args. insert ( key, FunctionArg :: Invalid ) ;
160+ is_invalid = new_insts != * w2;
165161 }
162+ None => { }
166163 }
167164 }
168- _ => {
169- function_args. insert ( key, FunctionArg :: Invalid ) ;
170- }
165+ _ => { }
171166 } ,
172- _ => {
173- function_args. insert ( key, FunctionArg :: Invalid ) ;
174- }
167+ _ => { }
175168 } ;
169+ if is_invalid {
170+ function_args. insert ( key, FunctionArg :: Invalid ) ;
171+ }
176172 }
177173 }
178174 }
@@ -312,7 +308,6 @@ fn get_const_arg_insts(
312308 let fake_root = bound;
313309 bound += 1 ;
314310 res. fix_ids ( & mut bound, fake_root) ;
315- res. root = fake_root;
316311 Some ( res)
317312}
318313
0 commit comments