1
Fork 0

rustc_codegen_ssa: use more consistent naming.

Ensure:
- builders always have a `bx` suffix;
- backend basic blocks always have an `llbb` suffix,
- paired builders and basic blocks have consistent prefixes.
This commit is contained in:
Nicholas Nethercote 2022-10-19 10:34:45 +11:00
parent 7fcf850d79
commit 4e4092f8cc
2 changed files with 31 additions and 30 deletions

View file

@ -95,10 +95,10 @@ impl<'a, 'tcx> TerminatorCodegenHelper<'tcx> {
debug!("llblock: creating cleanup trampoline for {:?}", target); debug!("llblock: creating cleanup trampoline for {:?}", target);
let name = &format!("{:?}_cleanup_trampoline_{:?}", self.bb, target); let name = &format!("{:?}_cleanup_trampoline_{:?}", self.bb, target);
let trampoline = Bx::append_block(fx.cx, fx.llfn, name); let trampoline_llbb = Bx::append_block(fx.cx, fx.llfn, name);
let mut trampoline_bx = Bx::build(fx.cx, trampoline); let mut trampoline_bx = Bx::build(fx.cx, trampoline_llbb);
trampoline_bx.cleanup_ret(self.funclet(fx).unwrap(), Some(lltarget)); trampoline_bx.cleanup_ret(self.funclet(fx).unwrap(), Some(lltarget));
trampoline trampoline_llbb
} else { } else {
lltarget lltarget
} }
@ -1459,20 +1459,20 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
// bar(); // bar();
// } // }
Some(&mir::TerminatorKind::Abort) => { Some(&mir::TerminatorKind::Abort) => {
let cs_bb = let cs_llbb =
Bx::append_block(self.cx, self.llfn, &format!("cs_funclet{:?}", bb)); Bx::append_block(self.cx, self.llfn, &format!("cs_funclet{:?}", bb));
let cp_bb = let cp_llbb =
Bx::append_block(self.cx, self.llfn, &format!("cp_funclet{:?}", bb)); Bx::append_block(self.cx, self.llfn, &format!("cp_funclet{:?}", bb));
ret_llbb = cs_bb; ret_llbb = cs_llbb;
let mut cs_bx = Bx::build(self.cx, cs_bb); let mut cs_bx = Bx::build(self.cx, cs_llbb);
let cs = cs_bx.catch_switch(None, None, &[cp_bb]); let cs = cs_bx.catch_switch(None, None, &[cp_llbb]);
// The "null" here is actually a RTTI type descriptor for the // The "null" here is actually a RTTI type descriptor for the
// C++ personality function, but `catch (...)` has no type so // C++ personality function, but `catch (...)` has no type so
// it's null. The 64 here is actually a bitfield which // it's null. The 64 here is actually a bitfield which
// represents that this is a catch-all block. // represents that this is a catch-all block.
let mut cp_bx = Bx::build(self.cx, cp_bb); let mut cp_bx = Bx::build(self.cx, cp_llbb);
let null = cp_bx.const_null( let null = cp_bx.const_null(
cp_bx.type_i8p_ext(cp_bx.cx().data_layout().instruction_address_space), cp_bx.type_i8p_ext(cp_bx.cx().data_layout().instruction_address_space),
); );
@ -1481,10 +1481,10 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
cp_bx.br(llbb); cp_bx.br(llbb);
} }
_ => { _ => {
let cleanup_bb = let cleanup_llbb =
Bx::append_block(self.cx, self.llfn, &format!("funclet_{:?}", bb)); Bx::append_block(self.cx, self.llfn, &format!("funclet_{:?}", bb));
ret_llbb = cleanup_bb; ret_llbb = cleanup_llbb;
let mut cleanup_bx = Bx::build(self.cx, cleanup_bb); let mut cleanup_bx = Bx::build(self.cx, cleanup_llbb);
funclet = cleanup_bx.cleanup_pad(None, &[]); funclet = cleanup_bx.cleanup_pad(None, &[]);
cleanup_bx.br(llbb); cleanup_bx.br(llbb);
} }
@ -1492,19 +1492,20 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
self.funclets[bb] = Some(funclet); self.funclets[bb] = Some(funclet);
ret_llbb ret_llbb
} else { } else {
let bb = Bx::append_block(self.cx, self.llfn, "cleanup"); let cleanup_llbb = Bx::append_block(self.cx, self.llfn, "cleanup");
let mut bx = Bx::build(self.cx, bb); let mut cleanup_bx = Bx::build(self.cx, cleanup_llbb);
let llpersonality = self.cx.eh_personality(); let llpersonality = self.cx.eh_personality();
let llretty = self.landing_pad_type(); let llretty = self.landing_pad_type();
let lp = bx.cleanup_landing_pad(llretty, llpersonality); let lp = cleanup_bx.cleanup_landing_pad(llretty, llpersonality);
let slot = self.get_personality_slot(&mut bx); let slot = self.get_personality_slot(&mut cleanup_bx);
slot.storage_live(&mut bx); slot.storage_live(&mut cleanup_bx);
Pair(bx.extract_value(lp, 0), bx.extract_value(lp, 1)).store(&mut bx, slot); Pair(cleanup_bx.extract_value(lp, 0), cleanup_bx.extract_value(lp, 1))
.store(&mut cleanup_bx, slot);
bx.br(llbb); cleanup_bx.br(llbb);
bx.llbb() cleanup_llbb
} }
} }

View file

@ -148,10 +148,10 @@ pub fn codegen_mir<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
let debug_context = cx.create_function_debug_context(instance, &fn_abi, llfn, &mir); let debug_context = cx.create_function_debug_context(instance, &fn_abi, llfn, &mir);
let start_llbb = Bx::append_block(cx, llfn, "start"); let start_llbb = Bx::append_block(cx, llfn, "start");
let mut bx = Bx::build(cx, start_llbb); let mut start_bx = Bx::build(cx, start_llbb);
if mir.basic_blocks.iter().any(|bb| bb.is_cleanup) { if mir.basic_blocks.iter().any(|bb| bb.is_cleanup) {
bx.set_personality_fn(cx.eh_personality()); start_bx.set_personality_fn(cx.eh_personality());
} }
let cleanup_kinds = analyze::cleanup_kinds(&mir); let cleanup_kinds = analyze::cleanup_kinds(&mir);
@ -180,7 +180,7 @@ pub fn codegen_mir<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
caller_location: None, caller_location: None,
}; };
fx.per_local_var_debug_info = fx.compute_per_local_var_debug_info(&mut bx); fx.per_local_var_debug_info = fx.compute_per_local_var_debug_info(&mut start_bx);
// Evaluate all required consts; codegen later assumes that CTFE will never fail. // Evaluate all required consts; codegen later assumes that CTFE will never fail.
let mut all_consts_ok = true; let mut all_consts_ok = true;
@ -206,29 +206,29 @@ pub fn codegen_mir<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
// Allocate variable and temp allocas // Allocate variable and temp allocas
fx.locals = { fx.locals = {
let args = arg_local_refs(&mut bx, &mut fx, &memory_locals); let args = arg_local_refs(&mut start_bx, &mut fx, &memory_locals);
let mut allocate_local = |local| { let mut allocate_local = |local| {
let decl = &mir.local_decls[local]; let decl = &mir.local_decls[local];
let layout = bx.layout_of(fx.monomorphize(decl.ty)); let layout = start_bx.layout_of(fx.monomorphize(decl.ty));
assert!(!layout.ty.has_erasable_regions()); assert!(!layout.ty.has_erasable_regions());
if local == mir::RETURN_PLACE && fx.fn_abi.ret.is_indirect() { if local == mir::RETURN_PLACE && fx.fn_abi.ret.is_indirect() {
debug!("alloc: {:?} (return place) -> place", local); debug!("alloc: {:?} (return place) -> place", local);
let llretptr = bx.get_param(0); let llretptr = start_bx.get_param(0);
return LocalRef::Place(PlaceRef::new_sized(llretptr, layout)); return LocalRef::Place(PlaceRef::new_sized(llretptr, layout));
} }
if memory_locals.contains(local) { if memory_locals.contains(local) {
debug!("alloc: {:?} -> place", local); debug!("alloc: {:?} -> place", local);
if layout.is_unsized() { if layout.is_unsized() {
LocalRef::UnsizedPlace(PlaceRef::alloca_unsized_indirect(&mut bx, layout)) LocalRef::UnsizedPlace(PlaceRef::alloca_unsized_indirect(&mut start_bx, layout))
} else { } else {
LocalRef::Place(PlaceRef::alloca(&mut bx, layout)) LocalRef::Place(PlaceRef::alloca(&mut start_bx, layout))
} }
} else { } else {
debug!("alloc: {:?} -> operand", local); debug!("alloc: {:?} -> operand", local);
LocalRef::new_operand(&mut bx, layout) LocalRef::new_operand(&mut start_bx, layout)
} }
}; };
@ -240,7 +240,7 @@ pub fn codegen_mir<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
}; };
// Apply debuginfo to the newly allocated locals. // Apply debuginfo to the newly allocated locals.
fx.debug_introduce_locals(&mut bx); fx.debug_introduce_locals(&mut start_bx);
// Codegen the body of each block using reverse postorder // Codegen the body of each block using reverse postorder
for (bb, _) in traversal::reverse_postorder(&mir) { for (bb, _) in traversal::reverse_postorder(&mir) {