Skip to content

Commit 696080e

Browse files
committed
[TODO(eddyb) recursion needs this!!!] [HACK(eddyb) this works now but requires the preceding commit] linker/inline: don't rescan inlined callee blocks.
1 parent 6f54c86 commit 696080e

1 file changed

Lines changed: 10 additions & 13 deletions

File tree

  • crates/rustc_codegen_spirv/src/linker

crates/rustc_codegen_spirv/src/linker/inline.rs

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -574,22 +574,22 @@ impl Inliner<'_, '_> {
574574
) {
575575
let mut block_idx = 0;
576576
while block_idx < function.blocks.len() {
577-
// If we successfully inlined a block, then repeat processing on the same block, in
578-
// case the newly inlined block has more inlined calls.
579-
// TODO: This is quadratic
580-
if !self.inline_block(function, block_idx, functions) {
581-
// TODO(eddyb) skip past the inlined callee without rescanning it.
582-
block_idx += 1;
577+
match self.inline_block(function, block_idx, functions) {
578+
Some(post_call_block_idx) => block_idx = post_call_block_idx,
579+
None => block_idx += 1,
583580
}
584581
}
585582
}
586583

584+
// HACK(eddyb) returns `Some(post_call_block_idx)` in case of success, where
585+
// `post_call_block_idx` is the index of the first block of the `caller`,
586+
// that follows all the inlined callee's blocks.
587587
fn inline_block(
588588
&mut self,
589589
caller: &mut Function,
590590
block_idx: usize,
591591
functions: &[Result<Function, FuncIsBeingInlined>],
592-
) -> bool {
592+
) -> Option<usize> {
593593
// Find the first inlined OpFunctionCall
594594
let call = caller.blocks[block_idx]
595595
.instructions
@@ -629,10 +629,7 @@ impl Inliner<'_, '_> {
629629
}
630630
}
631631
});
632-
let (call_index, call_inst, callee) = match call {
633-
None => return false,
634-
Some(call) => call,
635-
};
632+
let (call_index, call_inst, callee) = call?;
636633

637634
// Propagate "may abort" from callee to caller (i.e. as aborts get inlined).
638635
if self
@@ -784,8 +781,8 @@ impl Inliner<'_, '_> {
784781
}
785782

786783
// Insert the post-call block, after all the inlined callee blocks.
784+
let post_call_block_idx = pre_call_block_idx + num_non_entry_inlined_callee_blocks + 1;
787785
{
788-
let post_call_block_idx = pre_call_block_idx + num_non_entry_inlined_callee_blocks + 1;
789786
let post_call_block = Block {
790787
label: Some(Instruction::new(Op::Label, None, Some(return_jump), vec![])),
791788
instructions: post_call_block_insts,
@@ -928,7 +925,7 @@ impl Inliner<'_, '_> {
928925
);
929926
}
930927

931-
true
928+
Some(post_call_block_idx)
932929
}
933930

934931
fn add_clone_id_rules(&mut self, rewrite_rules: &mut FxHashMap<Word, Word>, blocks: &[Block]) {

0 commit comments

Comments
 (0)