Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Partially move cg_ssa towards using a single builder #94123

Merged
merged 4 commits into from
Feb 24, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Remove FunctionCx::new_block
  • Loading branch information
bjorn3 committed Feb 20, 2022
commit e142cdf4f6c3d18cb8f2f9ecfa386873a1910050
46 changes: 24 additions & 22 deletions compiler/rustc_codegen_ssa/src/mir/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,10 @@ impl<'a, 'tcx> TerminatorCodegenHelper<'tcx> {

debug!("llblock: creating cleanup trampoline for {:?}", target);
let name = &format!("{:?}_cleanup_trampoline_{:?}", self.bb, target);
let mut trampoline = fx.new_block(name);
trampoline.cleanup_ret(self.funclet(fx).unwrap(), Some(lltarget));
trampoline.llbb()
let trampoline = Bx::append_block(fx.cx, fx.llfn, name);
let mut trampoline_bx = Bx::build(fx.cx, trampoline);
trampoline_bx.cleanup_ret(self.funclet(fx).unwrap(), Some(lltarget));
trampoline
} else {
lltarget
}
Expand Down Expand Up @@ -1358,16 +1359,20 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
// bar();
// }
Some(&mir::TerminatorKind::Abort) => {
let mut cs_bx = self.new_block(&format!("cs_funclet{:?}", bb));
let mut cp_bx = self.new_block(&format!("cp_funclet{:?}", bb));
ret_llbb = cs_bx.llbb();
let cs_bb =
Bx::append_block(self.cx, self.llfn, &format!("cs_funclet{:?}", bb));
let cp_bb =
Bx::append_block(self.cx, self.llfn, &format!("cp_funclet{:?}", bb));
ret_llbb = cs_bb;

let cs = cs_bx.catch_switch(None, None, &[cp_bx.llbb()]);
let mut cs_bx = Bx::build(self.cx, cs_bb);
let cs = cs_bx.catch_switch(None, None, &[cp_bb]);

// The "null" here is actually a RTTI type descriptor for the
// C++ personality function, but `catch (...)` has no type so
// it's null. The 64 here is actually a bitfield which
// represents that this is a catch-all block.
let mut cp_bx = Bx::build(self.cx, cp_bb);
let null = cp_bx.const_null(
cp_bx.type_i8p_ext(cp_bx.cx().data_layout().instruction_address_space),
);
Expand All @@ -1376,16 +1381,19 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
cp_bx.br(llbb);
}
_ => {
let mut cleanup_bx = self.new_block(&format!("funclet_{:?}", bb));
ret_llbb = cleanup_bx.llbb();
let cleanup_bb =
Bx::append_block(self.cx, self.llfn, &format!("funclet_{:?}", bb));
ret_llbb = cleanup_bb;
let mut cleanup_bx = Bx::build(self.cx, cleanup_bb);
funclet = cleanup_bx.cleanup_pad(None, &[]);
cleanup_bx.br(llbb);
}
}
self.funclets[bb] = Some(funclet);
ret_llbb
} else {
let mut bx = self.new_block("cleanup");
let bb = Bx::append_block(self.cx, self.llfn, "cleanup");
let mut bx = Bx::build(self.cx, bb);

let llpersonality = self.cx.eh_personality();
let llretty = self.landing_pad_type();
Expand All @@ -1407,18 +1415,20 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {

fn unreachable_block(&mut self) -> Bx::BasicBlock {
self.unreachable_block.unwrap_or_else(|| {
let mut bx = self.new_block("unreachable");
let llbb = Bx::append_block(self.cx, self.llfn, "unreachable");
let mut bx = Bx::build(self.cx, llbb);
bx.unreachable();
self.unreachable_block = Some(bx.llbb());
bx.llbb()
self.unreachable_block = Some(llbb);
llbb
})
}

fn double_unwind_guard(&mut self) -> Bx::BasicBlock {
self.double_unwind_guard.unwrap_or_else(|| {
assert!(!base::wants_msvc_seh(self.cx.sess()));

let mut bx = self.new_block("abort");
let llbb = Bx::append_block(self.cx, self.llfn, "abort");
let mut bx = Bx::build(self.cx, llbb);
self.set_debug_loc(&mut bx, mir::SourceInfo::outermost(self.mir.span));

let llpersonality = self.cx.eh_personality();
Expand All @@ -1436,20 +1446,12 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
bx.apply_attrs_to_cleanup_callsite(llret);

bx.unreachable();
let llbb = bx.llbb();

self.double_unwind_guard = Some(llbb);
llbb
})
}

// FIXME(eddyb) replace with `append_sibling_block`
// (which requires having a `Bx` already, and not all callers do).
fn new_block(&self, name: &str) -> Bx {
let llbb = Bx::append_block(self.cx, self.llfn, name);
Bx::build(self.cx, llbb)
}

/// Get the backend `BasicBlock` for a MIR `BasicBlock`, either already
/// cached in `self.cached_llbbs`, or created on demand (and cached).
// FIXME(eddyb) rename `llbb` and other `ll`-prefixed things to use a
Expand Down