Skip to content

Commit 9233366

Browse files
committed
clean up misc. uses of get_dataptr/get_meta
1 parent 6d54e0e commit 9233366

File tree

2 files changed

+82
-136
lines changed

2 files changed

+82
-136
lines changed

src/librustc_trans/base.rs

Lines changed: 3 additions & 124 deletions
Original file line numberDiff line numberDiff line change
@@ -255,124 +255,6 @@ pub fn bin_op_to_fcmp_predicate(op: hir::BinOp_) -> llvm::RealPredicate {
255255
}
256256
}
257257

258-
pub fn compare_fat_ptrs<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
259-
lhs_addr: ValueRef,
260-
lhs_extra: ValueRef,
261-
rhs_addr: ValueRef,
262-
rhs_extra: ValueRef,
263-
_t: Ty<'tcx>,
264-
op: hir::BinOp_,
265-
debug_loc: DebugLoc)
266-
-> ValueRef {
267-
match op {
268-
hir::BiEq => {
269-
let addr_eq = ICmp(bcx, llvm::IntEQ, lhs_addr, rhs_addr, debug_loc);
270-
let extra_eq = ICmp(bcx, llvm::IntEQ, lhs_extra, rhs_extra, debug_loc);
271-
And(bcx, addr_eq, extra_eq, debug_loc)
272-
}
273-
hir::BiNe => {
274-
let addr_eq = ICmp(bcx, llvm::IntNE, lhs_addr, rhs_addr, debug_loc);
275-
let extra_eq = ICmp(bcx, llvm::IntNE, lhs_extra, rhs_extra, debug_loc);
276-
Or(bcx, addr_eq, extra_eq, debug_loc)
277-
}
278-
hir::BiLe | hir::BiLt | hir::BiGe | hir::BiGt => {
279-
// a OP b ~ a.0 STRICT(OP) b.0 | (a.0 == b.0 && a.1 OP a.1)
280-
let (op, strict_op) = match op {
281-
hir::BiLt => (llvm::IntULT, llvm::IntULT),
282-
hir::BiLe => (llvm::IntULE, llvm::IntULT),
283-
hir::BiGt => (llvm::IntUGT, llvm::IntUGT),
284-
hir::BiGe => (llvm::IntUGE, llvm::IntUGT),
285-
_ => bug!(),
286-
};
287-
288-
let addr_eq = ICmp(bcx, llvm::IntEQ, lhs_addr, rhs_addr, debug_loc);
289-
let extra_op = ICmp(bcx, op, lhs_extra, rhs_extra, debug_loc);
290-
let addr_eq_extra_op = And(bcx, addr_eq, extra_op, debug_loc);
291-
292-
let addr_strict = ICmp(bcx, strict_op, lhs_addr, rhs_addr, debug_loc);
293-
Or(bcx, addr_strict, addr_eq_extra_op, debug_loc)
294-
}
295-
_ => {
296-
bug!("unexpected fat ptr binop");
297-
}
298-
}
299-
}
300-
301-
pub fn compare_scalar_types<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
302-
lhs: ValueRef,
303-
rhs: ValueRef,
304-
t: Ty<'tcx>,
305-
op: hir::BinOp_,
306-
debug_loc: DebugLoc)
307-
-> ValueRef {
308-
match t.sty {
309-
ty::TyTuple(ref tys) if tys.is_empty() => {
310-
// We don't need to do actual comparisons for nil.
311-
// () == () holds but () < () does not.
312-
match op {
313-
hir::BiEq | hir::BiLe | hir::BiGe => return C_bool(bcx.ccx(), true),
314-
hir::BiNe | hir::BiLt | hir::BiGt => return C_bool(bcx.ccx(), false),
315-
// refinements would be nice
316-
_ => bug!("compare_scalar_types: must be a comparison operator"),
317-
}
318-
}
319-
ty::TyBool => {
320-
// FIXME(#36856) -- using `from_immediate` forces these booleans into `i8`,
321-
// which works around some LLVM bugs
322-
ICmp(bcx,
323-
bin_op_to_icmp_predicate(op, false),
324-
from_immediate(bcx, lhs),
325-
from_immediate(bcx, rhs),
326-
debug_loc)
327-
}
328-
ty::TyFnDef(..) | ty::TyFnPtr(_) | ty::TyUint(_) | ty::TyChar => {
329-
ICmp(bcx,
330-
bin_op_to_icmp_predicate(op, false),
331-
lhs,
332-
rhs,
333-
debug_loc)
334-
}
335-
ty::TyRawPtr(mt) if common::type_is_sized(bcx.tcx(), mt.ty) => {
336-
ICmp(bcx,
337-
bin_op_to_icmp_predicate(op, false),
338-
lhs,
339-
rhs,
340-
debug_loc)
341-
}
342-
ty::TyRawPtr(_) => {
343-
let lhs_addr = Load(bcx, GEPi(bcx, lhs, &[0, abi::FAT_PTR_ADDR]));
344-
let lhs_extra = Load(bcx, GEPi(bcx, lhs, &[0, abi::FAT_PTR_EXTRA]));
345-
346-
let rhs_addr = Load(bcx, GEPi(bcx, rhs, &[0, abi::FAT_PTR_ADDR]));
347-
let rhs_extra = Load(bcx, GEPi(bcx, rhs, &[0, abi::FAT_PTR_EXTRA]));
348-
compare_fat_ptrs(bcx,
349-
lhs_addr,
350-
lhs_extra,
351-
rhs_addr,
352-
rhs_extra,
353-
t,
354-
op,
355-
debug_loc)
356-
}
357-
ty::TyInt(_) => {
358-
ICmp(bcx,
359-
bin_op_to_icmp_predicate(op, true),
360-
lhs,
361-
rhs,
362-
debug_loc)
363-
}
364-
ty::TyFloat(_) => {
365-
FCmp(bcx,
366-
bin_op_to_fcmp_predicate(op),
367-
lhs,
368-
rhs,
369-
debug_loc)
370-
}
371-
// Should never get here, because t is scalar.
372-
_ => bug!("non-scalar type passed to compare_scalar_types"),
373-
}
374-
}
375-
376258
pub fn compare_simd_types<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
377259
lhs: ValueRef,
378260
rhs: ValueRef,
@@ -693,12 +575,9 @@ pub fn store_ty<'blk, 'tcx>(cx: Block<'blk, 'tcx>, v: ValueRef, dst: ValueRef, t
693575
debug!("store_ty: {:?} : {:?} <- {:?}", Value(dst), t, Value(v));
694576

695577
if common::type_is_fat_ptr(cx.tcx(), t) {
696-
Store(cx,
697-
ExtractValue(cx, v, abi::FAT_PTR_ADDR),
698-
get_dataptr(cx, dst));
699-
Store(cx,
700-
ExtractValue(cx, v, abi::FAT_PTR_EXTRA),
701-
get_meta(cx, dst));
578+
let lladdr = ExtractValue(cx, v, abi::FAT_PTR_ADDR);
579+
let llextra = ExtractValue(cx, v, abi::FAT_PTR_EXTRA);
580+
store_fat_ptr(cx, lladdr, llextra, dst, t);
702581
} else {
703582
Store(cx, from_immediate(cx, v), dst);
704583
}

src/librustc_trans/mir/rvalue.rs

Lines changed: 79 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use common::{self, val_ty, C_bool, C_null, C_uint, BlockAndBuilder, Result};
2020
use debuginfo::DebugLoc;
2121
use adt;
2222
use machine;
23+
use type_::Type;
2324
use type_of;
2425
use tvec;
2526
use value::Value;
@@ -382,13 +383,10 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
382383
match (lhs.val, rhs.val) {
383384
(OperandValue::Pair(lhs_addr, lhs_extra),
384385
OperandValue::Pair(rhs_addr, rhs_extra)) => {
385-
bcx.with_block(|bcx| {
386-
base::compare_fat_ptrs(bcx,
387-
lhs_addr, lhs_extra,
388-
rhs_addr, rhs_extra,
389-
lhs.ty, op.to_hir_binop(),
390-
debug_loc)
391-
})
386+
self.trans_fat_ptr_binop(&bcx, op,
387+
lhs_addr, lhs_extra,
388+
rhs_addr, rhs_extra,
389+
lhs.ty)
392390
}
393391
_ => bug!()
394392
}
@@ -485,6 +483,8 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
485483
input_ty: Ty<'tcx>) -> ValueRef {
486484
let is_float = input_ty.is_fp();
487485
let is_signed = input_ty.is_signed();
486+
let is_nil = input_ty.is_nil();
487+
let is_bool = input_ty.is_bool();
488488
match op {
489489
mir::BinOp::Add => if is_float {
490490
bcx.fadd(lhs, rhs)
@@ -535,12 +535,79 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
535535
DebugLoc::None)
536536
})
537537
}
538-
mir::BinOp::Eq | mir::BinOp::Lt | mir::BinOp::Gt |
539-
mir::BinOp::Ne | mir::BinOp::Le | mir::BinOp::Ge => {
540-
bcx.with_block(|bcx| {
541-
base::compare_scalar_types(bcx, lhs, rhs, input_ty,
542-
op.to_hir_binop(), DebugLoc::None)
538+
mir::BinOp::Ne | mir::BinOp::Lt | mir::BinOp::Gt |
539+
mir::BinOp::Eq | mir::BinOp::Le | mir::BinOp::Ge => if is_nil {
540+
C_bool(bcx.ccx(), match op {
541+
mir::BinOp::Ne | mir::BinOp::Lt | mir::BinOp::Gt => false,
542+
mir::BinOp::Eq | mir::BinOp::Le | mir::BinOp::Ge => true,
543+
_ => unreachable!()
543544
})
545+
} else if is_float {
546+
bcx.fcmp(
547+
base::bin_op_to_fcmp_predicate(op.to_hir_binop()),
548+
lhs, rhs
549+
)
550+
} else {
551+
let (lhs, rhs) = if is_bool {
552+
// FIXME(#36856) -- extend the bools into `i8` because
553+
// LLVM's i1 comparisons are broken.
554+
(bcx.zext(lhs, Type::i8(bcx.ccx())),
555+
bcx.zext(rhs, Type::i8(bcx.ccx())))
556+
} else {
557+
(lhs, rhs)
558+
};
559+
560+
bcx.icmp(
561+
base::bin_op_to_icmp_predicate(op.to_hir_binop(), is_signed),
562+
lhs, rhs
563+
)
564+
}
565+
}
566+
}
567+
568+
pub fn trans_fat_ptr_binop(&mut self,
569+
bcx: &BlockAndBuilder<'bcx, 'tcx>,
570+
op: mir::BinOp,
571+
lhs_addr: ValueRef,
572+
lhs_extra: ValueRef,
573+
rhs_addr: ValueRef,
574+
rhs_extra: ValueRef,
575+
_input_ty: Ty<'tcx>)
576+
-> ValueRef {
577+
match op {
578+
mir::BinOp::Eq => {
579+
bcx.and(
580+
bcx.icmp(llvm::IntEQ, lhs_addr, rhs_addr),
581+
bcx.icmp(llvm::IntEQ, lhs_extra, rhs_extra)
582+
)
583+
}
584+
mir::BinOp::Ne => {
585+
bcx.or(
586+
bcx.icmp(llvm::IntNE, lhs_addr, rhs_addr),
587+
bcx.icmp(llvm::IntNE, lhs_extra, rhs_extra)
588+
)
589+
}
590+
mir::BinOp::Le | mir::BinOp::Lt |
591+
mir::BinOp::Ge | mir::BinOp::Gt => {
592+
// a OP b ~ a.0 STRICT(OP) b.0 | (a.0 == b.0 && a.1 OP a.1)
593+
let (op, strict_op) = match op {
594+
mir::BinOp::Lt => (llvm::IntULT, llvm::IntULT),
595+
mir::BinOp::Le => (llvm::IntULE, llvm::IntULT),
596+
mir::BinOp::Gt => (llvm::IntUGT, llvm::IntUGT),
597+
mir::BinOp::Ge => (llvm::IntUGE, llvm::IntUGT),
598+
_ => bug!(),
599+
};
600+
601+
bcx.or(
602+
bcx.icmp(strict_op, lhs_addr, rhs_addr),
603+
bcx.and(
604+
bcx.icmp(llvm::IntEQ, lhs_addr, rhs_addr),
605+
bcx.icmp(op, lhs_extra, rhs_extra)
606+
)
607+
)
608+
}
609+
_ => {
610+
bug!("unexpected fat ptr binop");
544611
}
545612
}
546613
}

0 commit comments

Comments
 (0)