@@ -3,7 +3,6 @@ use rspirv::spirv::{Op};
3
3
use rustc_data_structures:: fx:: { FxHashMap , FxHashSet } ;
4
4
use rustc_session:: Session ;
5
5
6
- // bool is if this needs stored
7
6
#[ derive( Debug , Clone , PartialEq ) ]
8
7
struct NormalizedInstructions {
9
8
vars : Vec < Instruction > ,
@@ -38,6 +37,7 @@ impl NormalizedInstructions {
38
37
for inst in & mut self . insts {
39
38
Self :: fix_instruction ( self . root , inst, & mut id_map, bound, new_root) ;
40
39
}
40
+ self . root = new_root;
41
41
}
42
42
43
43
fn fix_instruction (
@@ -139,40 +139,36 @@ fn inline_global_varaibles_rec(module: &mut Module) -> super::Result<bool> {
139
139
} ;
140
140
for i in 1 ..inst. operands . len ( ) {
141
141
let key = ( function_id, i as u32 - 1 ) ;
142
+ // default to invalid to avoid duplicated code
143
+ let mut is_invalid = true ;
142
144
match & inst. operands [ i] {
143
145
& Operand :: IdRef ( w) => match & function_args. get ( & key) {
144
146
None => {
145
147
match get_const_arg_insts ( bound, & variables, & insts, & ref_stores, w) {
146
148
Some ( insts) => {
149
+ is_invalid = false ;
147
150
function_args. insert ( key, FunctionArg :: Insts ( insts) ) ;
148
151
}
149
- None => {
150
- function_args. insert ( key, FunctionArg :: Invalid ) ;
151
- }
152
+ None => { }
152
153
}
153
154
}
154
155
Some ( FunctionArg :: Insts ( w2) ) => {
155
156
let new_insts =
156
157
get_const_arg_insts ( bound, & variables, & insts, & ref_stores, w) ;
157
158
match new_insts {
158
159
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;
165
161
}
162
+ None => { }
166
163
}
167
164
}
168
- _ => {
169
- function_args. insert ( key, FunctionArg :: Invalid ) ;
170
- }
165
+ _ => { }
171
166
} ,
172
- _ => {
173
- function_args. insert ( key, FunctionArg :: Invalid ) ;
174
- }
167
+ _ => { }
175
168
} ;
169
+ if is_invalid {
170
+ function_args. insert ( key, FunctionArg :: Invalid ) ;
171
+ }
176
172
}
177
173
}
178
174
}
@@ -312,7 +308,6 @@ fn get_const_arg_insts(
312
308
let fake_root = bound;
313
309
bound += 1 ;
314
310
res. fix_ids ( & mut bound, fake_root) ;
315
- res. root = fake_root;
316
311
Some ( res)
317
312
}
318
313
0 commit comments