Skip to content

Commit e6d7a8d

Browse files
committed
Remove build_sibling_block
1 parent 6d7aa47 commit e6d7a8d

File tree

6 files changed

+68
-60
lines changed

6 files changed

+68
-60
lines changed

compiler/rustc_codegen_gcc/src/builder.rs

+9-12
Original file line numberDiff line numberDiff line change
@@ -390,11 +390,6 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
390390
bx
391391
}
392392

393-
fn build_sibling_block(&mut self, name: &str) -> Self {
394-
let block = self.append_sibling_block(name);
395-
Self::build(self.cx, block)
396-
}
397-
398393
fn llbb(&self) -> Block<'gcc> {
399394
self.block.expect("block")
400395
}
@@ -880,28 +875,30 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
880875
let start = dest.project_index(&mut self, zero).llval;
881876
let end = dest.project_index(&mut self, count).llval;
882877

883-
let mut header_bx = self.build_sibling_block("repeat_loop_header");
884-
let mut body_bx = self.build_sibling_block("repeat_loop_body");
885-
let next_bx = self.build_sibling_block("repeat_loop_next");
878+
let header_bb = self.append_sibling_block("repeat_loop_header");
879+
let body_bb = self.append_sibling_block("repeat_loop_body");
880+
let next_bb = self.append_sibling_block("repeat_loop_next");
886881

887882
let ptr_type = start.get_type();
888883
let current = self.llbb().get_function().new_local(None, ptr_type, "loop_var");
889884
let current_val = current.to_rvalue();
890885
self.assign(current, start);
891886

892-
self.br(header_bx.llbb());
887+
self.br(header_bb);
893888

889+
let mut header_bx = Builder::build(self.cx, header_bb);
894890
let keep_going = header_bx.icmp(IntPredicate::IntNE, current_val, end);
895-
header_bx.cond_br(keep_going, body_bx.llbb(), next_bx.llbb());
891+
header_bx.cond_br(keep_going, body_bb, next_bb);
896892

893+
let mut body_bx = Builder::build(self.cx, body_bb);
897894
let align = dest.align.restrict_for_offset(dest.layout.field(self.cx(), 0).size);
898895
cg_elem.val.store(&mut body_bx, PlaceRef::new_sized_aligned(current_val, cg_elem.layout, align));
899896

900897
let next = body_bx.inbounds_gep(self.backend_type(cg_elem.layout), current.to_rvalue(), &[self.const_usize(1)]);
901898
body_bx.llbb().add_assignment(None, current, next);
902-
body_bx.br(header_bx.llbb());
899+
body_bx.br(header_bb);
903900

904-
next_bx
901+
Builder::build(self.cx, next_bb)
905902
}
906903

907904
fn range_metadata(&mut self, _load: RValue<'gcc>, _range: WrappingRange) {

compiler/rustc_codegen_llvm/src/builder.rs

+11-13
Original file line numberDiff line numberDiff line change
@@ -166,11 +166,6 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
166166
Self::append_block(self.cx, self.llfn(), name)
167167
}
168168

169-
fn build_sibling_block(&mut self, name: &str) -> Self {
170-
let llbb = self.append_sibling_block(name);
171-
Self::build(self.cx, llbb)
172-
}
173-
174169
fn ret_void(&mut self) {
175170
unsafe {
176171
llvm::LLVMBuildRetVoid(self.llbuilder);
@@ -544,16 +539,19 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
544539
let start = dest.project_index(&mut self, zero).llval;
545540
let end = dest.project_index(&mut self, count).llval;
546541

547-
let mut header_bx = self.build_sibling_block("repeat_loop_header");
548-
let mut body_bx = self.build_sibling_block("repeat_loop_body");
549-
let next_bx = self.build_sibling_block("repeat_loop_next");
542+
let header_bb = self.append_sibling_block("repeat_loop_header");
543+
let body_bb = self.append_sibling_block("repeat_loop_body");
544+
let next_bb = self.append_sibling_block("repeat_loop_next");
545+
546+
self.br(header_bb);
550547

551-
self.br(header_bx.llbb());
548+
let mut header_bx = Self::build(self.cx, header_bb);
552549
let current = header_bx.phi(self.val_ty(start), &[start], &[self.llbb()]);
553550

554551
let keep_going = header_bx.icmp(IntPredicate::IntNE, current, end);
555-
header_bx.cond_br(keep_going, body_bx.llbb(), next_bx.llbb());
552+
header_bx.cond_br(keep_going, body_bb, next_bb);
556553

554+
let mut body_bx = Self::build(self.cx, body_bb);
557555
let align = dest.align.restrict_for_offset(dest.layout.field(self.cx(), 0).size);
558556
cg_elem
559557
.val
@@ -564,10 +562,10 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
564562
current,
565563
&[self.const_usize(1)],
566564
);
567-
body_bx.br(header_bx.llbb());
568-
header_bx.add_incoming_to_phi(current, next, body_bx.llbb());
565+
body_bx.br(header_bb);
566+
header_bx.add_incoming_to_phi(current, next, body_bb);
569567

570-
next_bx
568+
Self::build(self.cx, next_bb)
571569
}
572570

573571
fn range_metadata(&mut self, load: &'ll Value, range: WrappingRange) {

compiler/rustc_codegen_llvm/src/intrinsic.rs

+26-16
Original file line numberDiff line numberDiff line change
@@ -452,11 +452,11 @@ fn codegen_msvc_try<'ll>(
452452
let (llty, llfn) = get_rust_try_fn(bx, &mut |mut bx| {
453453
bx.set_personality_fn(bx.eh_personality());
454454

455-
let mut normal = bx.build_sibling_block("normal");
456-
let mut catchswitch = bx.build_sibling_block("catchswitch");
457-
let mut catchpad_rust = bx.build_sibling_block("catchpad_rust");
458-
let mut catchpad_foreign = bx.build_sibling_block("catchpad_foreign");
459-
let mut caught = bx.build_sibling_block("caught");
455+
let normal = bx.append_sibling_block("normal");
456+
let catchswitch = bx.append_sibling_block("catchswitch");
457+
let catchpad_rust = bx.append_sibling_block("catchpad_rust");
458+
let catchpad_foreign = bx.append_sibling_block("catchpad_foreign");
459+
let caught = bx.append_sibling_block("caught");
460460

461461
let try_func = llvm::get_param(bx.llfn(), 0);
462462
let data = llvm::get_param(bx.llfn(), 1);
@@ -520,12 +520,13 @@ fn codegen_msvc_try<'ll>(
520520
let ptr_align = bx.tcx().data_layout.pointer_align.abi;
521521
let slot = bx.alloca(bx.type_i8p(), ptr_align);
522522
let try_func_ty = bx.type_func(&[bx.type_i8p()], bx.type_void());
523-
bx.invoke(try_func_ty, try_func, &[data], normal.llbb(), catchswitch.llbb(), None);
523+
bx.invoke(try_func_ty, try_func, &[data], normal, catchswitch, None);
524524

525+
let mut normal = Builder::build(bx.cx, normal);
525526
normal.ret(bx.const_i32(0));
526527

527-
let cs =
528-
catchswitch.catch_switch(None, None, &[catchpad_rust.llbb(), catchpad_foreign.llbb()]);
528+
let mut catchswitch = Builder::build(bx.cx, catchswitch);
529+
let cs = catchswitch.catch_switch(None, None, &[catchpad_rust, catchpad_foreign]);
529530

530531
// We can't use the TypeDescriptor defined in libpanic_unwind because it
531532
// might be in another DLL and the SEH encoding only supports specifying
@@ -558,20 +559,23 @@ fn codegen_msvc_try<'ll>(
558559
// since our exception object effectively contains a Box.
559560
//
560561
// Source: MicrosoftCXXABI::getAddrOfCXXCatchHandlerType in clang
562+
let mut catchpad_rust = Builder::build(bx.cx, catchpad_rust);
561563
let flags = bx.const_i32(8);
562564
let funclet = catchpad_rust.catch_pad(cs, &[tydesc, flags, slot]);
563565
let ptr = catchpad_rust.load(bx.type_i8p(), slot, ptr_align);
564566
let catch_ty = bx.type_func(&[bx.type_i8p(), bx.type_i8p()], bx.type_void());
565567
catchpad_rust.call(catch_ty, catch_func, &[data, ptr], Some(&funclet));
566-
catchpad_rust.catch_ret(&funclet, caught.llbb());
568+
catchpad_rust.catch_ret(&funclet, caught);
567569

568570
// The flag value of 64 indicates a "catch-all".
571+
let mut catchpad_foreign = Builder::build(bx.cx, catchpad_foreign);
569572
let flags = bx.const_i32(64);
570573
let null = bx.const_null(bx.type_i8p());
571574
let funclet = catchpad_foreign.catch_pad(cs, &[null, flags, null]);
572575
catchpad_foreign.call(catch_ty, catch_func, &[data, null], Some(&funclet));
573-
catchpad_foreign.catch_ret(&funclet, caught.llbb());
576+
catchpad_foreign.catch_ret(&funclet, caught);
574577

578+
let mut caught = Builder::build(bx.cx, caught);
575579
caught.ret(bx.const_i32(1));
576580
});
577581

@@ -613,14 +617,16 @@ fn codegen_gnu_try<'ll>(
613617
// (%ptr, _) = landingpad
614618
// call %catch_func(%data, %ptr)
615619
// ret 1
616-
let mut then = bx.build_sibling_block("then");
617-
let mut catch = bx.build_sibling_block("catch");
620+
let then = bx.append_sibling_block("then");
621+
let catch = bx.append_sibling_block("catch");
618622

619623
let try_func = llvm::get_param(bx.llfn(), 0);
620624
let data = llvm::get_param(bx.llfn(), 1);
621625
let catch_func = llvm::get_param(bx.llfn(), 2);
622626
let try_func_ty = bx.type_func(&[bx.type_i8p()], bx.type_void());
623-
bx.invoke(try_func_ty, try_func, &[data], then.llbb(), catch.llbb(), None);
627+
bx.invoke(try_func_ty, try_func, &[data], then, catch, None);
628+
629+
let mut then = Builder::build(bx.cx, then);
624630
then.ret(bx.const_i32(0));
625631

626632
// Type indicator for the exception being thrown.
@@ -629,6 +635,7 @@ fn codegen_gnu_try<'ll>(
629635
// being thrown. The second value is a "selector" indicating which of
630636
// the landing pad clauses the exception's type had been matched to.
631637
// rust_try ignores the selector.
638+
let mut catch = Builder::build(bx.cx, catch);
632639
let lpad_ty = bx.type_struct(&[bx.type_i8p(), bx.type_i32()], false);
633640
let vals = catch.landing_pad(lpad_ty, bx.eh_personality(), 1);
634641
let tydesc = bx.const_null(bx.type_i8p());
@@ -674,21 +681,24 @@ fn codegen_emcc_try<'ll>(
674681
// %catch_data[1] = %is_rust_panic
675682
// call %catch_func(%data, %catch_data)
676683
// ret 1
677-
let mut then = bx.build_sibling_block("then");
678-
let mut catch = bx.build_sibling_block("catch");
684+
let then = bx.append_sibling_block("then");
685+
let catch = bx.append_sibling_block("catch");
679686

680687
let try_func = llvm::get_param(bx.llfn(), 0);
681688
let data = llvm::get_param(bx.llfn(), 1);
682689
let catch_func = llvm::get_param(bx.llfn(), 2);
683690
let try_func_ty = bx.type_func(&[bx.type_i8p()], bx.type_void());
684-
bx.invoke(try_func_ty, try_func, &[data], then.llbb(), catch.llbb(), None);
691+
bx.invoke(try_func_ty, try_func, &[data], then, catch, None);
692+
693+
let mut then = Builder::build(bx.cx, then);
685694
then.ret(bx.const_i32(0));
686695

687696
// Type indicator for the exception being thrown.
688697
//
689698
// The first value in this tuple is a pointer to the exception object
690699
// being thrown. The second value is a "selector" indicating which of
691700
// the landing pad clauses the exception's type had been matched to.
701+
let mut catch = Builder::build(bx.cx, catch);
692702
let tydesc = bx.eh_catch_typeinfo();
693703
let lpad_ty = bx.type_struct(&[bx.type_i8p(), bx.type_i32()], false);
694704
let vals = catch.landing_pad(lpad_ty, bx.eh_personality(), 2);

compiler/rustc_codegen_llvm/src/va_arg.rs

+12-8
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,10 @@ fn emit_aapcs_va_arg<'ll, 'tcx>(
102102
let va_list_ty = va_list_layout.llvm_type(bx);
103103
let layout = bx.cx.layout_of(target_ty);
104104

105-
let mut maybe_reg = bx.build_sibling_block("va_arg.maybe_reg");
106-
let mut in_reg = bx.build_sibling_block("va_arg.in_reg");
107-
let mut on_stack = bx.build_sibling_block("va_arg.on_stack");
108-
let mut end = bx.build_sibling_block("va_arg.end");
105+
let maybe_reg = bx.append_sibling_block("va_arg.maybe_reg");
106+
let in_reg = bx.append_sibling_block("va_arg.in_reg");
107+
let on_stack = bx.append_sibling_block("va_arg.on_stack");
108+
let end = bx.append_sibling_block("va_arg.end");
109109
let zero = bx.const_i32(0);
110110
let offset_align = Align::from_bytes(4).unwrap();
111111

@@ -125,12 +125,13 @@ fn emit_aapcs_va_arg<'ll, 'tcx>(
125125
// if the offset >= 0 then the value will be on the stack
126126
let mut reg_off_v = bx.load(bx.type_i32(), reg_off, offset_align);
127127
let use_stack = bx.icmp(IntPredicate::IntSGE, reg_off_v, zero);
128-
bx.cond_br(use_stack, on_stack.llbb(), maybe_reg.llbb());
128+
bx.cond_br(use_stack, on_stack, maybe_reg);
129129

130130
// The value at this point might be in a register, but there is a chance that
131131
// it could be on the stack so we have to update the offset and then check
132132
// the offset again.
133133

134+
let mut maybe_reg = Builder::build(bx.cx, maybe_reg);
134135
if gr_type && layout.align.abi.bytes() > 8 {
135136
reg_off_v = maybe_reg.add(reg_off_v, bx.const_i32(15));
136137
reg_off_v = maybe_reg.and(reg_off_v, bx.const_i32(-16));
@@ -142,8 +143,9 @@ fn emit_aapcs_va_arg<'ll, 'tcx>(
142143
// Check to see if we have overflowed the registers as a result of this.
143144
// If we have then we need to use the stack for this value
144145
let use_stack = maybe_reg.icmp(IntPredicate::IntSGT, new_reg_off_v, zero);
145-
maybe_reg.cond_br(use_stack, on_stack.llbb(), in_reg.llbb());
146+
maybe_reg.cond_br(use_stack, on_stack, in_reg);
146147

148+
let mut in_reg = Builder::build(bx.cx, in_reg);
147149
let top_type = bx.type_i8p();
148150
let top = in_reg.struct_gep(va_list_ty, va_list_addr, reg_top_index);
149151
let top = in_reg.load(top_type, top, bx.tcx().data_layout.pointer_align.abi);
@@ -158,13 +160,15 @@ fn emit_aapcs_va_arg<'ll, 'tcx>(
158160
let reg_type = layout.llvm_type(bx);
159161
let reg_addr = in_reg.bitcast(reg_addr, bx.cx.type_ptr_to(reg_type));
160162
let reg_value = in_reg.load(reg_type, reg_addr, layout.align.abi);
161-
in_reg.br(end.llbb());
163+
in_reg.br(end);
162164

163165
// On Stack block
166+
let mut on_stack = Builder::build(bx.cx, on_stack);
164167
let stack_value =
165168
emit_ptr_va_arg(&mut on_stack, list, target_ty, false, Align::from_bytes(8).unwrap(), true);
166-
on_stack.br(end.llbb());
169+
on_stack.br(end);
167170

171+
let mut end = Builder::build(bx.cx, end);
168172
let val = end.phi(
169173
layout.immediate_llvm_type(bx),
170174
&[reg_value, stack_value],

compiler/rustc_codegen_ssa/src/mir/block.rs

+10-8
Original file line numberDiff line numberDiff line change
@@ -452,15 +452,15 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
452452

453453
// Create the failure block and the conditional branch to it.
454454
let lltarget = helper.llblock(self, target);
455-
let panic_block = bx.build_sibling_block("panic");
455+
let panic_block = bx.append_sibling_block("panic");
456456
if expected {
457-
bx.cond_br(cond, lltarget, panic_block.llbb());
457+
bx.cond_br(cond, lltarget, panic_block);
458458
} else {
459-
bx.cond_br(cond, panic_block.llbb(), lltarget);
459+
bx.cond_br(cond, panic_block, lltarget);
460460
}
461461

462462
// After this point, bx is the block for the call to panic.
463-
bx = panic_block;
463+
bx = Bx::build(self.cx, panic_block);
464464
self.set_debug_loc(&mut bx, terminator.source_info);
465465

466466
// Get the location information.
@@ -908,10 +908,11 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
908908

909909
// Test whether the function pointer is associated with the type identifier.
910910
let cond = bx.type_test(fn_ptr, typeid_metadata);
911-
let mut bx_pass = bx.build_sibling_block("type_test.pass");
912-
let mut bx_fail = bx.build_sibling_block("type_test.fail");
913-
bx.cond_br(cond, bx_pass.llbb(), bx_fail.llbb());
911+
let bb_pass = bx.append_sibling_block("type_test.pass");
912+
let bb_fail = bx.append_sibling_block("type_test.fail");
913+
bx.cond_br(cond, bb_pass, bb_fail);
914914

915+
let mut bx_pass = Bx::build(self.cx, bb_pass);
915916
helper.do_call(
916917
self,
917918
&mut bx_pass,
@@ -922,6 +923,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
922923
cleanup,
923924
);
924925

926+
let mut bx_fail = Bx::build(self.cx, bb_fail);
925927
bx_fail.abort();
926928
bx_fail.unreachable();
927929

@@ -1441,7 +1443,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
14411443
})
14421444
}
14431445

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

compiler/rustc_codegen_ssa/src/traits/builder.rs

-3
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,6 @@ pub trait BuilderMethods<'a, 'tcx>:
5353

5454
fn append_sibling_block(&mut self, name: &str) -> Self::BasicBlock;
5555

56-
// FIXME(eddyb) replace with callers using `append_sibling_block`.
57-
fn build_sibling_block(&mut self, name: &str) -> Self;
58-
5956
fn ret_void(&mut self);
6057
fn ret(&mut self, v: Self::Value);
6158
fn br(&mut self, dest: Self::BasicBlock);

0 commit comments

Comments
 (0)