1 // Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 use llvm::{self, ValueRef};
12 use rustc::ty::{self, Ty};
13 use rustc::ty::cast::{CastTy, IntTy};
14 use rustc::ty::layout::{Layout, LayoutTyper};
15 use rustc::mir::tcx::LvalueTy;
17 use middle::lang_items::ExchangeMallocFnLangItem;
22 use common::{self, val_ty, C_bool, C_null, C_uint};
23 use common::{C_integral};
32 use super::MirContext;
33 use super::constant::const_scalar_checked_binop;
34 use super::operand::{OperandRef, OperandValue};
35 use super::lvalue::LvalueRef;
37 impl<'a, 'tcx> MirContext<'a, 'tcx> {
38 pub fn trans_rvalue(&mut self,
39 bcx: Builder<'a, 'tcx>,
40 dest: LvalueRef<'tcx>,
41 rvalue: &mir::Rvalue<'tcx>)
44 debug!("trans_rvalue(dest.llval={:?}, rvalue={:?})",
45 Value(dest.llval), rvalue);
48 mir::Rvalue::Use(ref operand) => {
49 let tr_operand = self.trans_operand(&bcx, operand);
50 // FIXME: consider not copying constants through stack. (fixable by translating
51 // constants into OperandValue::Ref, why don’t we do that yet if we don’t?)
52 self.store_operand(&bcx, dest.llval, dest.alignment.to_align(), tr_operand);
56 mir::Rvalue::Cast(mir::CastKind::Unsize, ref source, cast_ty) => {
57 let cast_ty = self.monomorphize(&cast_ty);
59 if common::type_is_fat_ptr(bcx.ccx, cast_ty) {
60 // into-coerce of a thin pointer to a fat pointer - just
61 // use the operand path.
62 let (bcx, temp) = self.trans_rvalue_operand(bcx, rvalue);
63 self.store_operand(&bcx, dest.llval, dest.alignment.to_align(), temp);
67 // Unsize of a nontrivial struct. I would prefer for
68 // this to be eliminated by MIR translation, but
69 // `CoerceUnsized` can be passed by a where-clause,
70 // so the (generic) MIR may not be able to expand it.
71 let operand = self.trans_operand(&bcx, source);
72 let operand = operand.pack_if_pair(&bcx);
73 let llref = match operand.val {
74 OperandValue::Pair(..) => bug!(),
75 OperandValue::Immediate(llval) => {
76 // unsize from an immediate structure. We don't
77 // really need a temporary alloca here, but
78 // avoiding it would require us to have
79 // `coerce_unsized_into` use extractvalue to
80 // index into the struct, and this case isn't
81 // important enough for it.
82 debug!("trans_rvalue: creating ugly alloca");
83 let scratch = LvalueRef::alloca(&bcx, operand.ty, "__unsize_temp");
84 base::store_ty(&bcx, llval, scratch.llval, scratch.alignment, operand.ty);
87 OperandValue::Ref(llref, align) => {
88 LvalueRef::new_sized_ty(llref, operand.ty, align)
91 base::coerce_unsized_into(&bcx, &llref, &dest);
95 mir::Rvalue::Repeat(ref elem, ref count) => {
96 let tr_elem = self.trans_operand(&bcx, elem);
97 let size = count.as_u64(bcx.tcx().sess.target.uint_type);
98 let size = C_uint(bcx.ccx, size);
99 let base = base::get_dataptr(&bcx, dest.llval);
100 tvec::slice_for_each(&bcx, base, tr_elem.ty, size, |bcx, llslot, loop_bb| {
101 self.store_operand(bcx, llslot, dest.alignment.to_align(), tr_elem);
106 mir::Rvalue::Aggregate(ref kind, ref operands) => {
108 mir::AggregateKind::Adt(adt_def, variant_index, substs, active_field_index) => {
109 let discr = adt_def.discriminant_for_variant(bcx.tcx(), variant_index)
110 .to_u128_unchecked() as u64;
111 let dest_ty = dest.ty.to_ty(bcx.tcx());
112 adt::trans_set_discr(&bcx, dest_ty, dest.llval, discr);
113 for (i, operand) in operands.iter().enumerate() {
114 let op = self.trans_operand(&bcx, operand);
115 // Do not generate stores and GEPis for zero-sized fields.
116 if !common::type_is_zero_size(bcx.ccx, op.ty) {
117 let mut val = LvalueRef::new_sized(
118 dest.llval, dest.ty, dest.alignment);
119 let field_index = active_field_index.unwrap_or(i);
120 val.ty = LvalueTy::Downcast {
122 substs: self.monomorphize(&substs),
123 variant_index: variant_index,
125 let (lldest_i, align) = val.trans_field_ptr(&bcx, field_index);
126 self.store_operand(&bcx, lldest_i, align.to_align(), op);
131 // If this is a tuple or closure, we need to translate GEP indices.
132 let layout = bcx.ccx.layout_of(dest.ty.to_ty(bcx.tcx()));
133 let translation = if let Layout::Univariant { ref variant, .. } = *layout {
134 Some(&variant.memory_index)
138 let alignment = dest.alignment;
139 for (i, operand) in operands.iter().enumerate() {
140 let op = self.trans_operand(&bcx, operand);
141 // Do not generate stores and GEPis for zero-sized fields.
142 if !common::type_is_zero_size(bcx.ccx, op.ty) {
143 // Note: perhaps this should be StructGep, but
144 // note that in some cases the values here will
145 // not be structs but arrays.
146 let i = if let Some(ref t) = translation {
151 let dest = bcx.gepi(dest.llval, &[0, i]);
152 self.store_operand(&bcx, dest, alignment.to_align(), op);
161 assert!(self.rvalue_creates_operand(rvalue));
162 let (bcx, temp) = self.trans_rvalue_operand(bcx, rvalue);
163 self.store_operand(&bcx, dest.llval, dest.alignment.to_align(), temp);
169 pub fn trans_rvalue_operand(&mut self,
170 bcx: Builder<'a, 'tcx>,
171 rvalue: &mir::Rvalue<'tcx>)
172 -> (Builder<'a, 'tcx>, OperandRef<'tcx>)
174 assert!(self.rvalue_creates_operand(rvalue), "cannot trans {:?} to operand", rvalue);
177 mir::Rvalue::Cast(ref kind, ref source, cast_ty) => {
178 let operand = self.trans_operand(&bcx, source);
179 debug!("cast operand is {:?}", operand);
180 let cast_ty = self.monomorphize(&cast_ty);
182 let val = match *kind {
183 mir::CastKind::ReifyFnPointer => {
184 match operand.ty.sty {
185 ty::TyFnDef(def_id, substs, _) => {
186 OperandValue::Immediate(
187 callee::resolve_and_get_fn(bcx.ccx, def_id, substs))
190 bug!("{} cannot be reified to a fn ptr", operand.ty)
194 mir::CastKind::ClosureFnPointer => {
195 match operand.ty.sty {
196 ty::TyClosure(def_id, substs) => {
197 let instance = monomorphize::resolve_closure(
198 bcx.ccx.shared(), def_id, substs, ty::ClosureKind::FnOnce);
199 OperandValue::Immediate(callee::get_fn(bcx.ccx, instance))
202 bug!("{} cannot be cast to a fn ptr", operand.ty)
206 mir::CastKind::UnsafeFnPointer => {
207 // this is a no-op at the LLVM level
210 mir::CastKind::Unsize => {
211 // unsize targets other than to a fat pointer currently
212 // can't be operands.
213 assert!(common::type_is_fat_ptr(bcx.ccx, cast_ty));
216 OperandValue::Pair(lldata, llextra) => {
217 // unsize from a fat pointer - this is a
218 // "trait-object-to-supertrait" coercion, for
220 // &'a fmt::Debug+Send => &'a fmt::Debug,
221 // So we need to pointercast the base to ensure
222 // the types match up.
223 let llcast_ty = type_of::fat_ptr_base_ty(bcx.ccx, cast_ty);
224 let lldata = bcx.pointercast(lldata, llcast_ty);
225 OperandValue::Pair(lldata, llextra)
227 OperandValue::Immediate(lldata) => {
229 let (lldata, llextra) = base::unsize_thin_ptr(&bcx, lldata,
230 operand.ty, cast_ty);
231 OperandValue::Pair(lldata, llextra)
233 OperandValue::Ref(..) => {
234 bug!("by-ref operand {:?} in trans_rvalue_operand",
239 mir::CastKind::Misc if common::type_is_fat_ptr(bcx.ccx, operand.ty) => {
240 let ll_cast_ty = type_of::immediate_type_of(bcx.ccx, cast_ty);
241 let ll_from_ty = type_of::immediate_type_of(bcx.ccx, operand.ty);
242 if let OperandValue::Pair(data_ptr, meta_ptr) = operand.val {
243 if common::type_is_fat_ptr(bcx.ccx, cast_ty) {
244 let ll_cft = ll_cast_ty.field_types();
245 let ll_fft = ll_from_ty.field_types();
246 let data_cast = bcx.pointercast(data_ptr, ll_cft[0]);
247 assert_eq!(ll_cft[1].kind(), ll_fft[1].kind());
248 OperandValue::Pair(data_cast, meta_ptr)
249 } else { // cast to thin-ptr
250 // Cast of fat-ptr to thin-ptr is an extraction of data-ptr and
251 // pointer-cast of that pointer to desired pointer type.
252 let llval = bcx.pointercast(data_ptr, ll_cast_ty);
253 OperandValue::Immediate(llval)
256 bug!("Unexpected non-Pair operand")
259 mir::CastKind::Misc => {
260 debug_assert!(common::type_is_immediate(bcx.ccx, cast_ty));
261 let r_t_in = CastTy::from_ty(operand.ty).expect("bad input type for cast");
262 let r_t_out = CastTy::from_ty(cast_ty).expect("bad output type for cast");
263 let ll_t_in = type_of::immediate_type_of(bcx.ccx, operand.ty);
264 let ll_t_out = type_of::immediate_type_of(bcx.ccx, cast_ty);
265 let llval = operand.immediate();
266 let l = bcx.ccx.layout_of(operand.ty);
267 let signed = if let Layout::CEnum { signed, min, max, .. } = *l {
269 // We want `table[e as usize]` to not
270 // have bound checks, and this is the most
271 // convenient place to put the `assume`.
273 base::call_assume(&bcx, bcx.icmp(
276 C_integral(common::val_ty(llval), max, false)
282 operand.ty.is_signed()
285 let newval = match (r_t_in, r_t_out) {
286 (CastTy::Int(_), CastTy::Int(_)) => {
287 bcx.intcast(llval, ll_t_out, signed)
289 (CastTy::Float, CastTy::Float) => {
290 let srcsz = ll_t_in.float_width();
291 let dstsz = ll_t_out.float_width();
293 bcx.fpext(llval, ll_t_out)
294 } else if srcsz > dstsz {
295 bcx.fptrunc(llval, ll_t_out)
300 (CastTy::Ptr(_), CastTy::Ptr(_)) |
301 (CastTy::FnPtr, CastTy::Ptr(_)) |
302 (CastTy::RPtr(_), CastTy::Ptr(_)) =>
303 bcx.pointercast(llval, ll_t_out),
304 (CastTy::Ptr(_), CastTy::Int(_)) |
305 (CastTy::FnPtr, CastTy::Int(_)) =>
306 bcx.ptrtoint(llval, ll_t_out),
307 (CastTy::Int(_), CastTy::Ptr(_)) =>
308 bcx.inttoptr(llval, ll_t_out),
309 (CastTy::Int(_), CastTy::Float) if signed =>
310 bcx.sitofp(llval, ll_t_out),
311 (CastTy::Int(_), CastTy::Float) =>
312 bcx.uitofp(llval, ll_t_out),
313 (CastTy::Float, CastTy::Int(IntTy::I)) =>
314 bcx.fptosi(llval, ll_t_out),
315 (CastTy::Float, CastTy::Int(_)) =>
316 bcx.fptoui(llval, ll_t_out),
317 _ => bug!("unsupported cast: {:?} to {:?}", operand.ty, cast_ty)
319 OperandValue::Immediate(newval)
322 let operand = OperandRef {
329 mir::Rvalue::Ref(_, bk, ref lvalue) => {
330 let tr_lvalue = self.trans_lvalue(&bcx, lvalue);
332 let ty = tr_lvalue.ty.to_ty(bcx.tcx());
333 let ref_ty = bcx.tcx().mk_ref(
334 bcx.tcx().mk_region(ty::ReErased),
335 ty::TypeAndMut { ty: ty, mutbl: bk.to_mutbl_lossy() }
338 // Note: lvalues are indirect, so storing the `llval` into the
339 // destination effectively creates a reference.
340 let operand = if bcx.ccx.shared().type_is_sized(ty) {
342 val: OperandValue::Immediate(tr_lvalue.llval),
347 val: OperandValue::Pair(tr_lvalue.llval,
355 mir::Rvalue::Len(ref lvalue) => {
356 let tr_lvalue = self.trans_lvalue(&bcx, lvalue);
357 let operand = OperandRef {
358 val: OperandValue::Immediate(tr_lvalue.len(bcx.ccx)),
359 ty: bcx.tcx().types.usize,
364 mir::Rvalue::BinaryOp(op, ref lhs, ref rhs) => {
365 let lhs = self.trans_operand(&bcx, lhs);
366 let rhs = self.trans_operand(&bcx, rhs);
367 let llresult = if common::type_is_fat_ptr(bcx.ccx, lhs.ty) {
368 match (lhs.val, rhs.val) {
369 (OperandValue::Pair(lhs_addr, lhs_extra),
370 OperandValue::Pair(rhs_addr, rhs_extra)) => {
371 self.trans_fat_ptr_binop(&bcx, op,
380 self.trans_scalar_binop(&bcx, op,
381 lhs.immediate(), rhs.immediate(),
384 let operand = OperandRef {
385 val: OperandValue::Immediate(llresult),
386 ty: op.ty(bcx.tcx(), lhs.ty, rhs.ty),
390 mir::Rvalue::CheckedBinaryOp(op, ref lhs, ref rhs) => {
391 let lhs = self.trans_operand(&bcx, lhs);
392 let rhs = self.trans_operand(&bcx, rhs);
393 let result = self.trans_scalar_checked_binop(&bcx, op,
394 lhs.immediate(), rhs.immediate(),
396 let val_ty = op.ty(bcx.tcx(), lhs.ty, rhs.ty);
397 let operand_ty = bcx.tcx().intern_tup(&[val_ty, bcx.tcx().types.bool], false);
398 let operand = OperandRef {
406 mir::Rvalue::UnaryOp(op, ref operand) => {
407 let operand = self.trans_operand(&bcx, operand);
408 let lloperand = operand.immediate();
409 let is_float = operand.ty.is_fp();
410 let llval = match op {
411 mir::UnOp::Not => bcx.not(lloperand),
412 mir::UnOp::Neg => if is_float {
419 val: OperandValue::Immediate(llval),
424 mir::Rvalue::Discriminant(ref lvalue) => {
425 let discr_lvalue = self.trans_lvalue(&bcx, lvalue);
426 let enum_ty = discr_lvalue.ty.to_ty(bcx.tcx());
427 let discr_ty = rvalue.ty(&*self.mir, bcx.tcx());
428 let discr_type = type_of::immediate_type_of(bcx.ccx, discr_ty);
429 let discr = adt::trans_get_discr(&bcx, enum_ty, discr_lvalue.llval,
430 discr_lvalue.alignment, Some(discr_type), true);
432 val: OperandValue::Immediate(discr),
437 mir::Rvalue::Box(content_ty) => {
438 let content_ty: Ty<'tcx> = self.monomorphize(&content_ty);
439 let llty = type_of::type_of(bcx.ccx, content_ty);
440 let llsize = machine::llsize_of(bcx.ccx, llty);
441 let align = bcx.ccx.align_of(content_ty);
442 let llalign = C_uint(bcx.ccx, align);
443 let llty_ptr = llty.ptr_to();
444 let box_ty = bcx.tcx().mk_box(content_ty);
447 let def_id = match bcx.tcx().lang_items.require(ExchangeMallocFnLangItem) {
450 bcx.sess().fatal(&format!("allocation of `{}` {}", box_ty, s));
453 let instance = ty::Instance::mono(bcx.tcx(), def_id);
454 let r = callee::get_fn(bcx.ccx, instance);
455 let val = bcx.pointercast(bcx.call(r, &[llsize, llalign], None), llty_ptr);
457 let operand = OperandRef {
458 val: OperandValue::Immediate(val),
463 mir::Rvalue::Use(ref operand) => {
464 let operand = self.trans_operand(&bcx, operand);
467 mir::Rvalue::Repeat(..) |
468 mir::Rvalue::Aggregate(..) => {
469 // According to `rvalue_creates_operand`, only ZST
470 // aggregate rvalues are allowed to be operands.
471 let ty = rvalue.ty(self.mir, self.ccx.tcx());
472 (bcx, OperandRef::new_zst(self.ccx, self.monomorphize(&ty)))
477 pub fn trans_scalar_binop(&mut self,
478 bcx: &Builder<'a, 'tcx>,
482 input_ty: Ty<'tcx>) -> ValueRef {
483 let is_float = input_ty.is_fp();
484 let is_signed = input_ty.is_signed();
485 let is_nil = input_ty.is_nil();
486 let is_bool = input_ty.is_bool();
488 mir::BinOp::Add => if is_float {
493 mir::BinOp::Sub => if is_float {
498 mir::BinOp::Mul => if is_float {
503 mir::BinOp::Div => if is_float {
505 } else if is_signed {
510 mir::BinOp::Rem => if is_float {
512 } else if is_signed {
517 mir::BinOp::BitOr => bcx.or(lhs, rhs),
518 mir::BinOp::BitAnd => bcx.and(lhs, rhs),
519 mir::BinOp::BitXor => bcx.xor(lhs, rhs),
520 mir::BinOp::Shl => common::build_unchecked_lshift(bcx, lhs, rhs),
521 mir::BinOp::Shr => common::build_unchecked_rshift(bcx, input_ty, lhs, rhs),
522 mir::BinOp::Ne | mir::BinOp::Lt | mir::BinOp::Gt |
523 mir::BinOp::Eq | mir::BinOp::Le | mir::BinOp::Ge => if is_nil {
524 C_bool(bcx.ccx, match op {
525 mir::BinOp::Ne | mir::BinOp::Lt | mir::BinOp::Gt => false,
526 mir::BinOp::Eq | mir::BinOp::Le | mir::BinOp::Ge => true,
531 base::bin_op_to_fcmp_predicate(op.to_hir_binop()),
535 let (lhs, rhs) = if is_bool {
536 // FIXME(#36856) -- extend the bools into `i8` because
537 // LLVM's i1 comparisons are broken.
538 (bcx.zext(lhs, Type::i8(bcx.ccx)),
539 bcx.zext(rhs, Type::i8(bcx.ccx)))
545 base::bin_op_to_icmp_predicate(op.to_hir_binop(), is_signed),
552 pub fn trans_fat_ptr_binop(&mut self,
553 bcx: &Builder<'a, 'tcx>,
564 bcx.icmp(llvm::IntEQ, lhs_addr, rhs_addr),
565 bcx.icmp(llvm::IntEQ, lhs_extra, rhs_extra)
570 bcx.icmp(llvm::IntNE, lhs_addr, rhs_addr),
571 bcx.icmp(llvm::IntNE, lhs_extra, rhs_extra)
574 mir::BinOp::Le | mir::BinOp::Lt |
575 mir::BinOp::Ge | mir::BinOp::Gt => {
576 // a OP b ~ a.0 STRICT(OP) b.0 | (a.0 == b.0 && a.1 OP a.1)
577 let (op, strict_op) = match op {
578 mir::BinOp::Lt => (llvm::IntULT, llvm::IntULT),
579 mir::BinOp::Le => (llvm::IntULE, llvm::IntULT),
580 mir::BinOp::Gt => (llvm::IntUGT, llvm::IntUGT),
581 mir::BinOp::Ge => (llvm::IntUGE, llvm::IntUGT),
586 bcx.icmp(strict_op, lhs_addr, rhs_addr),
588 bcx.icmp(llvm::IntEQ, lhs_addr, rhs_addr),
589 bcx.icmp(op, lhs_extra, rhs_extra)
594 bug!("unexpected fat ptr binop");
599 pub fn trans_scalar_checked_binop(&mut self,
600 bcx: &Builder<'a, 'tcx>,
604 input_ty: Ty<'tcx>) -> OperandValue {
605 // This case can currently arise only from functions marked
606 // with #[rustc_inherit_overflow_checks] and inlined from
607 // another crate (mostly core::num generic/#[inline] fns),
608 // while the current crate doesn't use overflow checks.
609 if !bcx.ccx.check_overflow() {
610 let val = self.trans_scalar_binop(bcx, op, lhs, rhs, input_ty);
611 return OperandValue::Pair(val, C_bool(bcx.ccx, false));
614 // First try performing the operation on constants, which
615 // will only succeed if both operands are constant.
616 // This is necessary to determine when an overflow Assert
617 // will always panic at runtime, and produce a warning.
618 if let Some((val, of)) = const_scalar_checked_binop(bcx.tcx(), op, lhs, rhs, input_ty) {
619 return OperandValue::Pair(val, C_bool(bcx.ccx, of));
622 let (val, of) = match op {
623 // These are checked using intrinsics
624 mir::BinOp::Add | mir::BinOp::Sub | mir::BinOp::Mul => {
626 mir::BinOp::Add => OverflowOp::Add,
627 mir::BinOp::Sub => OverflowOp::Sub,
628 mir::BinOp::Mul => OverflowOp::Mul,
631 let intrinsic = get_overflow_intrinsic(oop, bcx, input_ty);
632 let res = bcx.call(intrinsic, &[lhs, rhs], None);
634 (bcx.extract_value(res, 0),
635 bcx.extract_value(res, 1))
637 mir::BinOp::Shl | mir::BinOp::Shr => {
638 let lhs_llty = val_ty(lhs);
639 let rhs_llty = val_ty(rhs);
640 let invert_mask = common::shift_mask_val(&bcx, lhs_llty, rhs_llty, true);
641 let outer_bits = bcx.and(rhs, invert_mask);
643 let of = bcx.icmp(llvm::IntNE, outer_bits, C_null(rhs_llty));
644 let val = self.trans_scalar_binop(bcx, op, lhs, rhs, input_ty);
649 bug!("Operator `{:?}` is not a checkable operator", op)
653 OperandValue::Pair(val, of)
656 pub fn rvalue_creates_operand(&self, rvalue: &mir::Rvalue<'tcx>) -> bool {
658 mir::Rvalue::Ref(..) |
659 mir::Rvalue::Len(..) |
660 mir::Rvalue::Cast(..) | // (*)
661 mir::Rvalue::BinaryOp(..) |
662 mir::Rvalue::CheckedBinaryOp(..) |
663 mir::Rvalue::UnaryOp(..) |
664 mir::Rvalue::Discriminant(..) |
665 mir::Rvalue::Box(..) |
666 mir::Rvalue::Use(..) => // (*)
668 mir::Rvalue::Repeat(..) |
669 mir::Rvalue::Aggregate(..) => {
670 let ty = rvalue.ty(self.mir, self.ccx.tcx());
671 let ty = self.monomorphize(&ty);
672 common::type_is_zero_size(self.ccx, ty)
676 // (*) this is only true if the type is suitable
680 #[derive(Copy, Clone)]
685 fn get_overflow_intrinsic(oop: OverflowOp, bcx: &Builder, ty: Ty) -> ValueRef {
686 use syntax::ast::IntTy::*;
687 use syntax::ast::UintTy::*;
688 use rustc::ty::{TyInt, TyUint};
692 let new_sty = match ty.sty {
693 TyInt(Is) => match &tcx.sess.target.target.target_pointer_width[..] {
697 _ => panic!("unsupported target word size")
699 TyUint(Us) => match &tcx.sess.target.target.target_pointer_width[..] {
703 _ => panic!("unsupported target word size")
705 ref t @ TyUint(_) | ref t @ TyInt(_) => t.clone(),
706 _ => panic!("tried to get overflow intrinsic for op applied to non-int type")
709 let name = match oop {
710 OverflowOp::Add => match new_sty {
711 TyInt(I8) => "llvm.sadd.with.overflow.i8",
712 TyInt(I16) => "llvm.sadd.with.overflow.i16",
713 TyInt(I32) => "llvm.sadd.with.overflow.i32",
714 TyInt(I64) => "llvm.sadd.with.overflow.i64",
715 TyInt(I128) => "llvm.sadd.with.overflow.i128",
717 TyUint(U8) => "llvm.uadd.with.overflow.i8",
718 TyUint(U16) => "llvm.uadd.with.overflow.i16",
719 TyUint(U32) => "llvm.uadd.with.overflow.i32",
720 TyUint(U64) => "llvm.uadd.with.overflow.i64",
721 TyUint(U128) => "llvm.uadd.with.overflow.i128",
725 OverflowOp::Sub => match new_sty {
726 TyInt(I8) => "llvm.ssub.with.overflow.i8",
727 TyInt(I16) => "llvm.ssub.with.overflow.i16",
728 TyInt(I32) => "llvm.ssub.with.overflow.i32",
729 TyInt(I64) => "llvm.ssub.with.overflow.i64",
730 TyInt(I128) => "llvm.ssub.with.overflow.i128",
732 TyUint(U8) => "llvm.usub.with.overflow.i8",
733 TyUint(U16) => "llvm.usub.with.overflow.i16",
734 TyUint(U32) => "llvm.usub.with.overflow.i32",
735 TyUint(U64) => "llvm.usub.with.overflow.i64",
736 TyUint(U128) => "llvm.usub.with.overflow.i128",
740 OverflowOp::Mul => match new_sty {
741 TyInt(I8) => "llvm.smul.with.overflow.i8",
742 TyInt(I16) => "llvm.smul.with.overflow.i16",
743 TyInt(I32) => "llvm.smul.with.overflow.i32",
744 TyInt(I64) => "llvm.smul.with.overflow.i64",
745 TyInt(I128) => "llvm.smul.with.overflow.i128",
747 TyUint(U8) => "llvm.umul.with.overflow.i8",
748 TyUint(U16) => "llvm.umul.with.overflow.i16",
749 TyUint(U32) => "llvm.umul.with.overflow.i32",
750 TyUint(U64) => "llvm.umul.with.overflow.i64",
751 TyUint(U128) => "llvm.umul.with.overflow.i128",
757 bcx.ccx.get_intrinsic(&name)