Skip to content

Commit c665c62

Browse files
eddybLegNeato
authored andcommitted
linker/inline: also run mem2reg on every fully-inlined function.
1 parent 3c3912e commit c665c62

File tree

1 file changed

+39
-0
lines changed
  • crates/rustc_codegen_spirv/src/linker

1 file changed

+39
-0
lines changed

crates/rustc_codegen_spirv/src/linker/inline.rs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,32 @@ pub fn inline(sess: &Session, module: &mut Module) -> super::Result<()> {
133133
.map(Ok)
134134
.collect();
135135

136+
let mut mem2reg_pointer_to_pointee = FxHashMap::default();
137+
let mut mem2reg_constants = FxHashMap::default();
138+
{
139+
let mut u32 = None;
140+
for inst in &module.types_global_values {
141+
match inst.class.opcode {
142+
Op::TypePointer => {
143+
mem2reg_pointer_to_pointee
144+
.insert(inst.result_id.unwrap(), inst.operands[1].unwrap_id_ref());
145+
}
146+
Op::TypeInt
147+
if inst.operands[0].unwrap_literal_bit32() == 32
148+
&& inst.operands[1].unwrap_literal_bit32() == 0 =>
149+
{
150+
assert!(u32.is_none());
151+
u32 = Some(inst.result_id.unwrap());
152+
}
153+
Op::Constant if u32.is_some() && inst.result_type == u32 => {
154+
let value = inst.operands[0].unwrap_literal_bit32();
155+
mem2reg_constants.insert(inst.result_id.unwrap(), value);
156+
}
157+
_ => {}
158+
}
159+
}
160+
}
161+
136162
// Inline functions in post-order (aka inside-out aka bottom-up) - that is,
137163
// callees are processed before their callers, to avoid duplicating work.
138164
for func_idx in call_graph.post_order() {
@@ -145,6 +171,19 @@ pub fn inline(sess: &Session, module: &mut Module) -> super::Result<()> {
145171
}
146172
.remove_duplicate_debuginfo_in_function(&mut function);
147173

174+
{
175+
super::simple_passes::block_ordering_pass(&mut function);
176+
// Note: mem2reg requires functions to be in RPO order (i.e. block_ordering_pass)
177+
super::mem2reg::mem2reg(
178+
inliner.header,
179+
&mut module.types_global_values,
180+
&mem2reg_pointer_to_pointee,
181+
&mem2reg_constants,
182+
&mut function,
183+
);
184+
super::destructure_composites::destructure_composites(&mut function);
185+
}
186+
148187
functions[func_idx] = Ok(function);
149188
}
150189

0 commit comments

Comments
 (0)