mirror of
https://github.com/rust-lang/rust.git
synced 2025-04-28 02:57:37 +00:00
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.
This commit is contained in:
commit
648d038c86
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user