diff options
| author | bors <bors@rust-lang.org> | 2022-02-24 12:28:19 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2022-02-24 12:28:19 +0000 |
| commit | 3d127e2040b57157936f5f24e114a8b4c9a505ef (patch) | |
| tree | eda8d0fab2d62b7abbf0fde7d455c9d2bd979093 /compiler/rustc_codegen_gcc/src | |
| parent | 7ccfe2ff1d59666dc0188dfd5847304fec257565 (diff) | |
| parent | 96cf7999ab64ead0c06384da51eb8586ffebfc1e (diff) | |
| download | rust-3d127e2040b57157936f5f24e114a8b4c9a505ef.tar.gz rust-3d127e2040b57157936f5f24e114a8b4c9a505ef.zip | |
Auto merge of #94123 - bjorn3:cg_ssa_singleton_builder, r=tmiasko
Partially move cg_ssa towards using a single builder Not all codegen backends can handle hopping between blocks well. For example Cranelift requires blocks to be terminated before switching to building a new block. Rust-gpu requires a `RefCell` to allow hopping between blocks and cg_gcc currently has a buggy implementation of hopping between blocks. This PR reduces the amount of cases where cg_ssa switches between blocks before they are finished and mostly fixes the block hopping in cg_gcc. (~~only `scalar_to_backend` doesn't handle it correctly yet in cg_gcc~~ fixed that one.) `@antoyo` please review the cg_gcc changes.
Diffstat (limited to 'compiler/rustc_codegen_gcc/src')
| -rw-r--r-- | compiler/rustc_codegen_gcc/src/builder.rs | 35 |
1 files changed, 19 insertions, 16 deletions
diff --git a/compiler/rustc_codegen_gcc/src/builder.rs b/compiler/rustc_codegen_gcc/src/builder.rs index ffb77e16a14..b430dc329cb 100644 --- a/compiler/rustc_codegen_gcc/src/builder.rs +++ b/compiler/rustc_codegen_gcc/src/builder.rs @@ -390,11 +390,6 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> { bx } - fn build_sibling_block(&mut self, name: &str) -> Self { - let block = self.append_sibling_block(name); - Self::build(self.cx, block) - } - fn llbb(&self) -> Block<'gcc> { self.block.expect("block") } @@ -409,6 +404,11 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> { func.new_block(name) } + fn switch_to_block(&mut self, block: Self::BasicBlock) { + *self.cx.current_block.borrow_mut() = Some(block); + self.block = Some(block); + } + fn ret_void(&mut self) { self.llbb().end_with_void_return(None) } @@ -880,28 +880,31 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> { let start = dest.project_index(&mut self, zero).llval; let end = dest.project_index(&mut self, count).llval; - let mut header_bx = self.build_sibling_block("repeat_loop_header"); - let mut body_bx = self.build_sibling_block("repeat_loop_body"); - let next_bx = self.build_sibling_block("repeat_loop_next"); + let header_bb = self.append_sibling_block("repeat_loop_header"); + let body_bb = self.append_sibling_block("repeat_loop_body"); + let next_bb = self.append_sibling_block("repeat_loop_next"); let ptr_type = start.get_type(); let current = self.llbb().get_function().new_local(None, ptr_type, "loop_var"); let current_val = current.to_rvalue(); self.assign(current, start); - self.br(header_bx.llbb()); + self.br(header_bb); - let keep_going = header_bx.icmp(IntPredicate::IntNE, current_val, end); - header_bx.cond_br(keep_going, body_bx.llbb(), next_bx.llbb()); + self.switch_to_block(header_bb); + let keep_going = self.icmp(IntPredicate::IntNE, current_val, end); + self.cond_br(keep_going, body_bb, next_bb); + self.switch_to_block(body_bb); let align = dest.align.restrict_for_offset(dest.layout.field(self.cx(), 0).size); - cg_elem.val.store(&mut body_bx, PlaceRef::new_sized_aligned(current_val, cg_elem.layout, align)); + cg_elem.val.store(&mut self, PlaceRef::new_sized_aligned(current_val, cg_elem.layout, align)); - let next = body_bx.inbounds_gep(self.backend_type(cg_elem.layout), current.to_rvalue(), &[self.const_usize(1)]); - body_bx.llbb().add_assignment(None, current, next); - body_bx.br(header_bx.llbb()); + let next = self.inbounds_gep(self.backend_type(cg_elem.layout), current.to_rvalue(), &[self.const_usize(1)]); + self.llbb().add_assignment(None, current, next); + self.br(header_bb); - next_bx + self.switch_to_block(next_bb); + self } fn range_metadata(&mut self, _load: RValue<'gcc>, _range: WrappingRange) { |
