Skip to content

Commit b8ffc96

Browse files
committed
removed redundant functions in the codegen
1 parent 71b694c commit b8ffc96

File tree

10 files changed

+23
-59
lines changed

10 files changed

+23
-59
lines changed

compiler/rustc_codegen_llvm/src/builder.rs

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -191,17 +191,6 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
191191
cond: &'ll Value,
192192
then_llbb: &'ll BasicBlock,
193193
else_llbb: &'ll BasicBlock,
194-
) {
195-
unsafe {
196-
llvm::LLVMBuildCondBr(self.llbuilder, cond, then_llbb, else_llbb);
197-
}
198-
}
199-
200-
fn cond_br_with_cold_br(
201-
&mut self,
202-
cond: &'ll Value,
203-
then_llbb: Self::BasicBlock,
204-
else_llbb: Self::BasicBlock,
205194
cold_br: Option<bool>,
206195
) {
207196
// emit the branch instruction
@@ -637,7 +626,7 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
637626
let i = header_bx.phi(self.val_ty(zero), &[zero], &[self.llbb()]);
638627

639628
let keep_going = header_bx.icmp(IntPredicate::IntULT, i, count);
640-
header_bx.cond_br(keep_going, body_bb, next_bb);
629+
header_bx.cond_br(keep_going, body_bb, next_bb, None);
641630

642631
let mut body_bx = Self::build(self.cx, body_bb);
643632
let dest_elem = dest.project_index(&mut body_bx, i);
@@ -1588,7 +1577,7 @@ impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> {
15881577
let cond = self.type_test(llfn, typeid_metadata);
15891578
let bb_pass = self.append_sibling_block("type_test.pass");
15901579
let bb_fail = self.append_sibling_block("type_test.fail");
1591-
self.cond_br(cond, bb_pass, bb_fail);
1580+
self.cond_br(cond, bb_pass, bb_fail, None);
15921581

15931582
self.switch_to_block(bb_fail);
15941583
self.abort();

compiler/rustc_codegen_llvm/src/va_arg.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ fn emit_aapcs_va_arg<'ll, 'tcx>(
119119
// if the offset >= 0 then the value will be on the stack
120120
let mut reg_off_v = bx.load(bx.type_i32(), reg_off, offset_align);
121121
let use_stack = bx.icmp(IntPredicate::IntSGE, reg_off_v, zero);
122-
bx.cond_br(use_stack, on_stack, maybe_reg);
122+
bx.cond_br(use_stack, on_stack, maybe_reg, None);
123123

124124
// The value at this point might be in a register, but there is a chance that
125125
// it could be on the stack so we have to update the offset and then check
@@ -137,7 +137,7 @@ fn emit_aapcs_va_arg<'ll, 'tcx>(
137137
// Check to see if we have overflowed the registers as a result of this.
138138
// If we have then we need to use the stack for this value
139139
let use_stack = bx.icmp(IntPredicate::IntSGT, new_reg_off_v, zero);
140-
bx.cond_br(use_stack, on_stack, in_reg);
140+
bx.cond_br(use_stack, on_stack, in_reg, None);
141141

142142
bx.switch_to_block(in_reg);
143143
let top_type = bx.type_ptr();
@@ -203,7 +203,7 @@ fn emit_s390x_va_arg<'ll, 'tcx>(
203203
);
204204
let reg_count_v = bx.load(bx.type_i64(), reg_count, Align::from_bytes(8).unwrap());
205205
let use_regs = bx.icmp(IntPredicate::IntULT, reg_count_v, bx.const_u64(max_regs));
206-
bx.cond_br(use_regs, in_reg, in_mem);
206+
bx.cond_br(use_regs, in_reg, in_mem, None);
207207

208208
// Emit code to load the value if it was passed in a register.
209209
bx.switch_to_block(in_reg);

compiler/rustc_codegen_ssa/src/mir/block.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -335,16 +335,16 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
335335
match test_value {
336336
0 => {
337337
let cold_br = cold_br.and_then(|t| Some(!t));
338-
bx.cond_br_with_cold_br(discr.immediate(), llfalse, lltrue, cold_br);
338+
bx.cond_br(discr.immediate(), llfalse, lltrue, cold_br);
339339
}
340-
1 => bx.cond_br_with_cold_br(discr.immediate(), lltrue, llfalse, cold_br),
340+
1 => bx.cond_br(discr.immediate(), lltrue, llfalse, cold_br),
341341
_ => bug!(),
342342
}
343343
} else {
344344
let switch_llty = bx.immediate_backend_type(bx.layout_of(switch_ty));
345345
let llval = bx.const_uint_big(switch_llty, test_value);
346346
let cmp = bx.icmp(IntPredicate::IntEQ, discr.immediate(), llval);
347-
bx.cond_br_with_cold_br(cmp, lltrue, llfalse, cold_br);
347+
bx.cond_br(cmp, lltrue, llfalse, cold_br);
348348
}
349349
} else if self.cx.sess().opts.optimize == OptLevel::No
350350
&& target_iter.len() == 2
@@ -369,7 +369,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
369369
let switch_llty = bx.immediate_backend_type(bx.layout_of(switch_ty));
370370
let llval = bx.const_uint_big(switch_llty, test_value1);
371371
let cmp = bx.icmp(IntPredicate::IntEQ, discr.immediate(), llval);
372-
bx.cond_br(cmp, ll1, ll2);
372+
bx.cond_br(cmp, ll1, ll2, None);
373373
} else {
374374
bx.switch(
375375
discr.immediate(),
@@ -601,9 +601,9 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
601601
let lltarget = helper.llbb_with_cleanup(self, target);
602602
let panic_block = bx.append_sibling_block("panic");
603603
if expected {
604-
bx.cond_br(cond, lltarget, panic_block);
604+
bx.cond_br(cond, lltarget, panic_block, None);
605605
} else {
606-
bx.cond_br(cond, panic_block, lltarget);
606+
bx.cond_br(cond, panic_block, lltarget, None);
607607
}
608608

609609
// After this point, bx is the block for the call to panic.

compiler/rustc_codegen_ssa/src/traits/builder.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,6 @@ pub trait BuilderMethods<'a, 'tcx>:
6363
cond: Self::Value,
6464
then_llbb: Self::BasicBlock,
6565
else_llbb: Self::BasicBlock,
66-
);
67-
fn cond_br_with_cold_br(
68-
&mut self,
69-
cond: Self::Value,
70-
then_llbb: Self::BasicBlock,
71-
else_llbb: Self::BasicBlock,
7266
cold_br: Option<bool>,
7367
);
7468
fn switch(

compiler/rustc_middle/src/mir/terminator.rs

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,10 @@ impl SwitchTargets {
2020
Self { values, targets, cold_targets: ThinVec::new() }
2121
}
2222

23-
/// Builds a switch targets definition that jumps to `then` if the tested value equals `value`,
24-
/// and to `else_` if not.
25-
pub fn static_if(value: u128, then: BasicBlock, else_: BasicBlock) -> Self {
26-
Self {
27-
values: smallvec![value],
28-
targets: smallvec![then, else_],
29-
cold_targets: ThinVec::new(),
30-
}
31-
}
32-
3323
/// Builds a switch targets definition that jumps to `then` if the tested value equals `value`,
3424
/// and to `else_` if not.
3525
/// If cold_br is some bool value, the given outcome is considered cold (i.e., unlikely).
36-
pub fn static_if_with_cold_br(
26+
pub fn static_if(
3727
value: u128,
3828
then: BasicBlock,
3929
else_: BasicBlock,
@@ -61,7 +51,7 @@ impl SwitchTargets {
6151
}
6252
}
6353

64-
// If this switch has exactly one target, returns it.
54+
// If this switch has exactly one cold target, returns it.
6555
pub fn cold_target(&self) -> Option<usize> {
6656
if self.cold_targets.len() == 1 { Some(self.cold_targets[0]) } else { None }
6757
}
@@ -390,19 +380,15 @@ impl<'tcx> Terminator<'tcx> {
390380

391381
impl<'tcx> TerminatorKind<'tcx> {
392382
#[inline]
393-
pub fn if_(cond: Operand<'tcx>, t: BasicBlock, f: BasicBlock) -> TerminatorKind<'tcx> {
394-
TerminatorKind::SwitchInt { discr: cond, targets: SwitchTargets::static_if(0, f, t) }
395-
}
396-
397-
pub fn if_with_cold_br(
383+
pub fn if_(
398384
cond: Operand<'tcx>,
399385
t: BasicBlock,
400386
f: BasicBlock,
401387
cold_branch: Option<bool>,
402388
) -> TerminatorKind<'tcx> {
403389
TerminatorKind::SwitchInt {
404390
discr: cond,
405-
targets: SwitchTargets::static_if_with_cold_br(
391+
targets: SwitchTargets::static_if(
406392
0,
407393
f,
408394
t,

compiler/rustc_mir_build/src/build/matches/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
174174
let then_block = this.cfg.start_new_block();
175175
let else_block = this.cfg.start_new_block();
176176
let term =
177-
TerminatorKind::if_with_cold_br(operand, then_block, else_block, cold_branch);
177+
TerminatorKind::if_(operand, then_block, else_block, cold_branch);
178178

179179
let source_info = this.source_info(expr_span);
180180
this.cfg.terminate(block, source_info, term);

compiler/rustc_mir_build/src/build/matches/test.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -233,12 +233,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
233233
0 => (second_bb, first_bb, cold_br.and_then(|x| Some(!x))),
234234
v => span_bug!(test.span, "expected boolean value but got {:?}", v),
235235
};
236-
TerminatorKind::if_with_cold_br(
237-
Operand::Copy(place),
238-
true_bb,
239-
false_bb,
240-
cold_br,
241-
)
236+
TerminatorKind::if_(Operand::Copy(place), true_bb, false_bb, cold_br)
242237
} else {
243238
// The switch may be inexhaustive so we have a catch all block
244239
debug_assert_eq!(options.len() + 1, target_blocks.len());
@@ -419,7 +414,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
419414
self.cfg.terminate(
420415
block,
421416
source_info,
422-
TerminatorKind::if_(Operand::Move(result), success_block, fail_block),
417+
TerminatorKind::if_(Operand::Move(result), success_block, fail_block, None),
423418
);
424419
}
425420

@@ -562,7 +557,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
562557
self.cfg.terminate(
563558
eq_block,
564559
source_info,
565-
TerminatorKind::if_(Operand::Move(eq_result), success_block, fail_block),
560+
TerminatorKind::if_(Operand::Move(eq_result), success_block, fail_block, None),
566561
);
567562
}
568563

compiler/rustc_mir_dataflow/src/elaborate_drops.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -733,7 +733,7 @@ where
733733
is_cleanup: unwind.is_cleanup(),
734734
terminator: Some(Terminator {
735735
source_info: self.source_info,
736-
kind: TerminatorKind::if_(move_(can_go), succ, drop_block),
736+
kind: TerminatorKind::if_(move_(can_go), succ, drop_block, None),
737737
}),
738738
};
739739
let loop_block = self.elaborator.patch().new_block(loop_block);
@@ -954,7 +954,7 @@ where
954954
DropStyle::Static => on_set,
955955
DropStyle::Conditional | DropStyle::Open => {
956956
let flag = self.elaborator.get_drop_flag(self.path).unwrap();
957-
let term = TerminatorKind::if_(flag, on_set, on_unset);
957+
let term = TerminatorKind::if_(flag, on_set, on_unset, None);
958958
self.new_block(unwind, term)
959959
}
960960
}

compiler/rustc_mir_transform/src/coverage/tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ impl<'tcx> MockBlocks<'tcx> {
153153
fn switchint(&mut self, some_from_block: Option<BasicBlock>) -> BasicBlock {
154154
let switchint_kind = TerminatorKind::SwitchInt {
155155
discr: Operand::Move(Place::from(self.new_temp())),
156-
targets: SwitchTargets::static_if(0, TEMP_BLOCK, TEMP_BLOCK),
156+
targets: SwitchTargets::static_if(0, TEMP_BLOCK, TEMP_BLOCK, None),
157157
};
158158
self.add_block_from(some_from_block, switchint_kind)
159159
}

compiler/rustc_mir_transform/src/early_otherwise_branch.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ impl<'tcx> MirPass<'tcx> for EarlyOtherwiseBranch {
191191
let false_case = eq_bb;
192192
patch.patch_terminator(
193193
parent,
194-
TerminatorKind::if_(Operand::Move(Place::from(comp_temp)), true_case, false_case),
194+
TerminatorKind::if_(Operand::Move(Place::from(comp_temp)), true_case, false_case, None),
195195
);
196196

197197
// generate StorageDead for the second_discriminant_temp not in use anymore

0 commit comments

Comments
 (0)