2013-05-21 14:25:44 -05:00
|
|
|
// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
2014-03-21 20:05:05 -05:00
|
|
|
#![allow(non_uppercase_pattern_statics)]
|
2013-09-30 10:44:58 -05:00
|
|
|
|
2014-01-22 13:03:02 -06:00
|
|
|
use arena::TypedArena;
|
2013-05-21 14:25:44 -05:00
|
|
|
use lib::llvm::{SequentiallyConsistent, Acquire, Release, Xchg};
|
make C-like enums immediate
This fixes two existing bugs along the way:
* The `transmute` intrinsic did not correctly handle casts of immediate
aggregates like newtype structs and tuples.
* The code for calling foreign functions used the wrong type to create
an `alloca` temporary
enum Foo { A, B }
fn foo() -> Foo { A }
Before:
; Function Attrs: nounwind uwtable
define void @_ZN3foo18hbedc642d5d9cf5aag4v0.0E(%enum.Foo* noalias nocapture sret, { i64, %tydesc*, i8*, i8*, i8 }* nocapture readnone) #0 {
"function top level":
%2 = getelementptr inbounds %enum.Foo* %0, i64 0, i32 0
store i64 0, i64* %2, align 8
ret void
}
After:
; Function Attrs: nounwind readnone uwtable
define %enum.Foo @_ZN3foo18hbedc642d5d9cf5aag4v0.0E({ i64, %tydesc*, i8*, i8*, i8 }* nocapture readnone) #0 {
"function top level":
ret %enum.Foo zeroinitializer
}
2013-10-03 05:19:02 -05:00
|
|
|
use lib::llvm::{ValueRef, Pointer, Array, Struct};
|
2013-05-21 14:25:44 -05:00
|
|
|
use lib;
|
|
|
|
use middle::trans::base::*;
|
|
|
|
use middle::trans::build::*;
|
|
|
|
use middle::trans::common::*;
|
|
|
|
use middle::trans::datum::*;
|
2014-02-13 23:07:09 -06:00
|
|
|
use middle::trans::glue;
|
2013-05-21 14:25:44 -05:00
|
|
|
use middle::trans::type_of::*;
|
|
|
|
use middle::trans::type_of;
|
|
|
|
use middle::trans::machine;
|
2014-02-13 23:07:09 -06:00
|
|
|
use middle::trans::machine::llsize_of;
|
|
|
|
use middle::trans::type_::Type;
|
2013-05-21 14:25:44 -05:00
|
|
|
use middle::ty;
|
|
|
|
use syntax::ast;
|
|
|
|
use syntax::ast_map;
|
2014-02-13 23:07:09 -06:00
|
|
|
use syntax::parse::token;
|
2013-10-23 20:15:14 -05:00
|
|
|
use util::ppaux::ty_to_str;
|
2013-05-21 14:25:44 -05:00
|
|
|
|
2014-03-06 10:47:24 -06:00
|
|
|
pub fn get_simple_intrinsic(ccx: &CrateContext, item: &ast::ForeignItem) -> Option<ValueRef> {
|
2014-02-13 23:07:09 -06:00
|
|
|
let name = match token::get_ident(item.ident).get() {
|
|
|
|
"sqrtf32" => "llvm.sqrt.f32",
|
|
|
|
"sqrtf64" => "llvm.sqrt.f64",
|
|
|
|
"powif32" => "llvm.powi.f32",
|
|
|
|
"powif64" => "llvm.powi.f64",
|
|
|
|
"sinf32" => "llvm.sin.f32",
|
|
|
|
"sinf64" => "llvm.sin.f64",
|
|
|
|
"cosf32" => "llvm.cos.f32",
|
|
|
|
"cosf64" => "llvm.cos.f64",
|
|
|
|
"powf32" => "llvm.pow.f32",
|
|
|
|
"powf64" => "llvm.pow.f64",
|
|
|
|
"expf32" => "llvm.exp.f32",
|
|
|
|
"expf64" => "llvm.exp.f64",
|
|
|
|
"exp2f32" => "llvm.exp2.f32",
|
|
|
|
"exp2f64" => "llvm.exp2.f64",
|
|
|
|
"logf32" => "llvm.log.f32",
|
|
|
|
"logf64" => "llvm.log.f64",
|
|
|
|
"log10f32" => "llvm.log10.f32",
|
|
|
|
"log10f64" => "llvm.log10.f64",
|
|
|
|
"log2f32" => "llvm.log2.f32",
|
|
|
|
"log2f64" => "llvm.log2.f64",
|
|
|
|
"fmaf32" => "llvm.fma.f32",
|
|
|
|
"fmaf64" => "llvm.fma.f64",
|
|
|
|
"fabsf32" => "llvm.fabs.f32",
|
|
|
|
"fabsf64" => "llvm.fabs.f64",
|
|
|
|
"copysignf32" => "llvm.copysign.f32",
|
|
|
|
"copysignf64" => "llvm.copysign.f64",
|
|
|
|
"floorf32" => "llvm.floor.f32",
|
|
|
|
"floorf64" => "llvm.floor.f64",
|
|
|
|
"ceilf32" => "llvm.ceil.f32",
|
|
|
|
"ceilf64" => "llvm.ceil.f64",
|
|
|
|
"truncf32" => "llvm.trunc.f32",
|
|
|
|
"truncf64" => "llvm.trunc.f64",
|
|
|
|
"rintf32" => "llvm.rint.f32",
|
|
|
|
"rintf64" => "llvm.rint.f64",
|
|
|
|
"nearbyintf32" => "llvm.nearbyint.f32",
|
|
|
|
"nearbyintf64" => "llvm.nearbyint.f64",
|
|
|
|
"roundf32" => "llvm.round.f32",
|
|
|
|
"roundf64" => "llvm.round.f64",
|
|
|
|
"ctpop8" => "llvm.ctpop.i8",
|
|
|
|
"ctpop16" => "llvm.ctpop.i16",
|
|
|
|
"ctpop32" => "llvm.ctpop.i32",
|
|
|
|
"ctpop64" => "llvm.ctpop.i64",
|
|
|
|
"bswap16" => "llvm.bswap.i16",
|
|
|
|
"bswap32" => "llvm.bswap.i32",
|
|
|
|
"bswap64" => "llvm.bswap.i64",
|
|
|
|
_ => return None
|
|
|
|
};
|
2014-04-09 18:56:31 -05:00
|
|
|
Some(ccx.get_intrinsic(&name))
|
2014-01-29 17:44:14 -06:00
|
|
|
}
|
|
|
|
|
2014-03-06 10:47:24 -06:00
|
|
|
pub fn trans_intrinsic(ccx: &CrateContext,
|
2013-05-21 14:25:44 -05:00
|
|
|
decl: ValueRef,
|
2014-01-09 07:05:33 -06:00
|
|
|
item: &ast::ForeignItem,
|
2014-04-20 12:04:57 -05:00
|
|
|
substs: ¶m_substs,
|
2013-05-21 14:25:44 -05:00
|
|
|
ref_id: Option<ast::NodeId>) {
|
2014-02-13 23:07:09 -06:00
|
|
|
debug!("trans_intrinsic(item.ident={})", token::get_ident(item.ident));
|
2013-05-21 14:25:44 -05:00
|
|
|
|
2014-01-07 10:54:58 -06:00
|
|
|
fn with_overflow_instrinsic(bcx: &Block, name: &'static str, t: ty::t) {
|
2013-05-21 14:25:44 -05:00
|
|
|
let first_real_arg = bcx.fcx.arg_pos(0u);
|
|
|
|
let a = get_param(bcx.fcx.llfn, first_real_arg);
|
|
|
|
let b = get_param(bcx.fcx.llfn, first_real_arg + 1);
|
2014-04-09 18:56:31 -05:00
|
|
|
let llfn = bcx.ccx().get_intrinsic(&name);
|
2013-05-21 14:25:44 -05:00
|
|
|
|
|
|
|
// convert `i1` to a `bool`, and write to the out parameter
|
2013-09-12 23:14:17 -05:00
|
|
|
let val = Call(bcx, llfn, [a, b], []);
|
2013-05-21 14:25:44 -05:00
|
|
|
let result = ExtractValue(bcx, val, 0);
|
2014-03-15 15:29:34 -05:00
|
|
|
let overflow = ZExt(bcx, ExtractValue(bcx, val, 1), Type::bool(bcx.ccx()));
|
2013-10-02 07:53:02 -05:00
|
|
|
let ret = C_undef(type_of::type_of(bcx.ccx(), t));
|
2013-05-21 14:25:44 -05:00
|
|
|
let ret = InsertValue(bcx, ret, result, 0);
|
|
|
|
let ret = InsertValue(bcx, ret, overflow, 1);
|
make small (<= size_of::<int>()) tuples immediate
fn foo() -> (u32, u8, u8, u8, u8) {
(4, 5, 6, 7, 8)
}
Before:
; Function Attrs: nounwind uwtable
define void @_ZN3foo18hbb616262f874f8daf4v0.0E({ i32, i8, i8, i8, i8 }* noalias nocapture sret, { i64, %tydesc*, i8*, i8*, i8 }* nocapture readnone) #0 {
"function top level":
%2 = getelementptr inbounds { i32, i8, i8, i8, i8 }* %0, i64 0, i32 0
store i32 4, i32* %2, align 4
%3 = getelementptr inbounds { i32, i8, i8, i8, i8 }* %0, i64 0, i32 1
store i8 5, i8* %3, align 4
%4 = getelementptr inbounds { i32, i8, i8, i8, i8 }* %0, i64 0, i32 2
store i8 6, i8* %4, align 1
%5 = getelementptr inbounds { i32, i8, i8, i8, i8 }* %0, i64 0, i32 3
store i8 7, i8* %5, align 2
%6 = getelementptr inbounds { i32, i8, i8, i8, i8 }* %0, i64 0, i32 4
store i8 8, i8* %6, align 1
ret void
}
After:
; Function Attrs: nounwind readnone uwtable
define { i32, i8, i8, i8, i8 } @_ZN3foo18hbb616262f874f8daf4v0.0E({ i64, %tydesc*, i8*, i8*, i8 }* nocapture readnone) #0 {
"function top level":
ret { i32, i8, i8, i8, i8 } { i32 4, i8 5, i8 6, i8 7, i8 8 }
}
2013-09-30 17:29:42 -05:00
|
|
|
|
|
|
|
if type_is_immediate(bcx.ccx(), t) {
|
|
|
|
Ret(bcx, ret);
|
|
|
|
} else {
|
|
|
|
let retptr = get_param(bcx.fcx.llfn, bcx.fcx.out_arg_pos());
|
|
|
|
Store(bcx, ret, retptr);
|
|
|
|
RetVoid(bcx);
|
|
|
|
}
|
2013-05-21 14:25:44 -05:00
|
|
|
}
|
|
|
|
|
2014-01-07 10:54:58 -06:00
|
|
|
fn volatile_load_intrinsic(bcx: &Block) {
|
2013-12-28 08:01:53 -06:00
|
|
|
let first_real_arg = bcx.fcx.arg_pos(0u);
|
|
|
|
let src = get_param(bcx.fcx.llfn, first_real_arg);
|
|
|
|
|
|
|
|
let val = VolatileLoad(bcx, src);
|
|
|
|
Ret(bcx, val);
|
|
|
|
}
|
|
|
|
|
2014-01-07 10:54:58 -06:00
|
|
|
fn volatile_store_intrinsic(bcx: &Block) {
|
2013-12-28 08:01:53 -06:00
|
|
|
let first_real_arg = bcx.fcx.arg_pos(0u);
|
|
|
|
let dst = get_param(bcx.fcx.llfn, first_real_arg);
|
|
|
|
let val = get_param(bcx.fcx.llfn, first_real_arg + 1);
|
|
|
|
|
|
|
|
VolatileStore(bcx, val, dst);
|
|
|
|
RetVoid(bcx);
|
|
|
|
}
|
|
|
|
|
2014-04-22 18:51:14 -05:00
|
|
|
fn copy_intrinsic(bcx: &Block, allow_overlap: bool, volatile: bool, tp_ty: ty::t) {
|
2013-05-21 14:25:44 -05:00
|
|
|
let ccx = bcx.ccx();
|
|
|
|
let lltp_ty = type_of::type_of(ccx, tp_ty);
|
2014-03-15 15:29:34 -05:00
|
|
|
let align = C_i32(ccx, machine::llalign_of_min(ccx, lltp_ty) as i32);
|
2013-11-03 15:54:58 -06:00
|
|
|
let size = machine::llsize_of(ccx, lltp_ty);
|
|
|
|
let int_size = machine::llbitsize_of_real(ccx, ccx.int_type);
|
|
|
|
let name = if allow_overlap {
|
|
|
|
if int_size == 32 {
|
|
|
|
"llvm.memmove.p0i8.p0i8.i32"
|
|
|
|
} else {
|
|
|
|
"llvm.memmove.p0i8.p0i8.i64"
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if int_size == 32 {
|
|
|
|
"llvm.memcpy.p0i8.p0i8.i32"
|
|
|
|
} else {
|
|
|
|
"llvm.memcpy.p0i8.p0i8.i64"
|
|
|
|
}
|
2013-05-21 14:25:44 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
let decl = bcx.fcx.llfn;
|
|
|
|
let first_real_arg = bcx.fcx.arg_pos(0u);
|
2014-03-15 15:29:34 -05:00
|
|
|
let dst_ptr = PointerCast(bcx, get_param(decl, first_real_arg), Type::i8p(ccx));
|
|
|
|
let src_ptr = PointerCast(bcx, get_param(decl, first_real_arg + 1), Type::i8p(ccx));
|
2013-05-21 14:25:44 -05:00
|
|
|
let count = get_param(decl, first_real_arg + 2);
|
2014-04-09 18:56:31 -05:00
|
|
|
let llfn = ccx.get_intrinsic(&name);
|
2014-04-22 18:51:14 -05:00
|
|
|
Call(bcx, llfn, [dst_ptr, src_ptr, Mul(bcx, size, count), align, C_i1(ccx, volatile)], []);
|
2013-05-21 14:25:44 -05:00
|
|
|
RetVoid(bcx);
|
|
|
|
}
|
|
|
|
|
2014-04-22 18:51:14 -05:00
|
|
|
fn memset_intrinsic(bcx: &Block, volatile: bool, tp_ty: ty::t) {
|
2013-05-21 14:25:44 -05:00
|
|
|
let ccx = bcx.ccx();
|
|
|
|
let lltp_ty = type_of::type_of(ccx, tp_ty);
|
2014-03-15 15:29:34 -05:00
|
|
|
let align = C_i32(ccx, machine::llalign_of_min(ccx, lltp_ty) as i32);
|
2013-11-03 15:54:58 -06:00
|
|
|
let size = machine::llsize_of(ccx, lltp_ty);
|
|
|
|
let name = if machine::llbitsize_of_real(ccx, ccx.int_type) == 32 {
|
|
|
|
"llvm.memset.p0i8.i32"
|
|
|
|
} else {
|
|
|
|
"llvm.memset.p0i8.i64"
|
2013-05-21 14:25:44 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
let decl = bcx.fcx.llfn;
|
|
|
|
let first_real_arg = bcx.fcx.arg_pos(0u);
|
2014-03-15 15:29:34 -05:00
|
|
|
let dst_ptr = PointerCast(bcx, get_param(decl, first_real_arg), Type::i8p(ccx));
|
2013-05-21 14:25:44 -05:00
|
|
|
let val = get_param(decl, first_real_arg + 1);
|
|
|
|
let count = get_param(decl, first_real_arg + 2);
|
2014-04-09 18:56:31 -05:00
|
|
|
let llfn = ccx.get_intrinsic(&name);
|
2014-04-22 18:51:14 -05:00
|
|
|
Call(bcx, llfn, [dst_ptr, val, Mul(bcx, size, count), align, C_i1(ccx, volatile)], []);
|
2013-05-21 14:25:44 -05:00
|
|
|
RetVoid(bcx);
|
|
|
|
}
|
|
|
|
|
2014-01-07 10:54:58 -06:00
|
|
|
fn count_zeros_intrinsic(bcx: &Block, name: &'static str) {
|
2013-05-21 14:25:44 -05:00
|
|
|
let x = get_param(bcx.fcx.llfn, bcx.fcx.arg_pos(0u));
|
2014-03-15 15:29:34 -05:00
|
|
|
let y = C_i1(bcx.ccx(), false);
|
2014-04-09 18:56:31 -05:00
|
|
|
let llfn = bcx.ccx().get_intrinsic(&name);
|
2013-09-30 12:37:22 -05:00
|
|
|
let llcall = Call(bcx, llfn, [x, y], []);
|
|
|
|
Ret(bcx, llcall);
|
2013-05-21 14:25:44 -05:00
|
|
|
}
|
|
|
|
|
2014-03-15 15:29:34 -05:00
|
|
|
let output_type = ty::ty_fn_ret(ty::node_id_to_type(ccx.tcx(), item.id));
|
2013-05-21 14:25:44 -05:00
|
|
|
|
2014-01-22 13:03:02 -06:00
|
|
|
let arena = TypedArena::new();
|
2014-02-13 23:07:09 -06:00
|
|
|
let fcx = new_fn_ctxt(ccx, decl, item.id, false, output_type,
|
2014-04-20 12:04:57 -05:00
|
|
|
Some(&*substs), Some(item.span), &arena);
|
|
|
|
init_function(&fcx, true, output_type);
|
2013-05-21 14:25:44 -05:00
|
|
|
|
|
|
|
set_always_inline(fcx.llfn);
|
|
|
|
|
2014-03-28 12:29:55 -05:00
|
|
|
let mut bcx = fcx.entry_bcx.borrow().clone().unwrap();
|
2013-05-21 14:25:44 -05:00
|
|
|
let first_real_arg = fcx.arg_pos(0u);
|
|
|
|
|
2014-02-13 23:07:09 -06:00
|
|
|
let name = token::get_ident(item.ident);
|
2013-05-21 14:25:44 -05:00
|
|
|
|
|
|
|
// This requires that atomic intrinsics follow a specific naming pattern:
|
|
|
|
// "atomic_<operation>[_<ordering>], and no ordering means SeqCst
|
2014-02-13 23:07:09 -06:00
|
|
|
if name.get().starts_with("atomic_") {
|
2014-03-04 12:02:49 -06:00
|
|
|
let split: Vec<&str> = name.get().split('_').collect();
|
2013-05-21 14:25:44 -05:00
|
|
|
assert!(split.len() >= 2, "Atomic intrinsic not correct format");
|
|
|
|
let order = if split.len() == 2 {
|
|
|
|
lib::llvm::SequentiallyConsistent
|
|
|
|
} else {
|
2014-03-08 14:36:22 -06:00
|
|
|
match *split.get(2) {
|
2013-05-21 14:25:44 -05:00
|
|
|
"relaxed" => lib::llvm::Monotonic,
|
|
|
|
"acq" => lib::llvm::Acquire,
|
|
|
|
"rel" => lib::llvm::Release,
|
|
|
|
"acqrel" => lib::llvm::AcquireRelease,
|
2014-03-05 08:36:01 -06:00
|
|
|
_ => ccx.sess().fatal("unknown ordering in atomic intrinsic")
|
2013-05-21 14:25:44 -05:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-03-08 14:36:22 -06:00
|
|
|
match *split.get(1) {
|
2013-05-21 14:25:44 -05:00
|
|
|
"cxchg" => {
|
2014-03-31 16:43:19 -05:00
|
|
|
// See include/llvm/IR/Instructions.h for their implementation
|
|
|
|
// of this, I assume that it's good enough for us to use for
|
|
|
|
// now.
|
|
|
|
let strongest_failure_ordering = match order {
|
|
|
|
lib::llvm::NotAtomic | lib::llvm::Unordered =>
|
|
|
|
ccx.sess().fatal("cmpxchg must be atomic"),
|
|
|
|
lib::llvm::Monotonic | lib::llvm::Release =>
|
|
|
|
lib::llvm::Monotonic,
|
|
|
|
lib::llvm::Acquire | lib::llvm::AcquireRelease =>
|
|
|
|
lib::llvm::Acquire,
|
|
|
|
lib::llvm::SequentiallyConsistent =>
|
|
|
|
lib::llvm::SequentiallyConsistent,
|
|
|
|
};
|
2013-05-21 14:25:44 -05:00
|
|
|
let old = AtomicCmpXchg(bcx, get_param(decl, first_real_arg),
|
|
|
|
get_param(decl, first_real_arg + 1u),
|
|
|
|
get_param(decl, first_real_arg + 2u),
|
2014-03-31 16:43:19 -05:00
|
|
|
order, strongest_failure_ordering);
|
2013-05-21 14:25:44 -05:00
|
|
|
Ret(bcx, old);
|
|
|
|
}
|
|
|
|
"load" => {
|
|
|
|
let old = AtomicLoad(bcx, get_param(decl, first_real_arg),
|
|
|
|
order);
|
|
|
|
Ret(bcx, old);
|
|
|
|
}
|
|
|
|
"store" => {
|
|
|
|
AtomicStore(bcx, get_param(decl, first_real_arg + 1u),
|
|
|
|
get_param(decl, first_real_arg),
|
|
|
|
order);
|
|
|
|
RetVoid(bcx);
|
|
|
|
}
|
|
|
|
"fence" => {
|
|
|
|
AtomicFence(bcx, order);
|
|
|
|
RetVoid(bcx);
|
|
|
|
}
|
|
|
|
op => {
|
|
|
|
// These are all AtomicRMW ops
|
|
|
|
let atom_op = match op {
|
|
|
|
"xchg" => lib::llvm::Xchg,
|
|
|
|
"xadd" => lib::llvm::Add,
|
|
|
|
"xsub" => lib::llvm::Sub,
|
|
|
|
"and" => lib::llvm::And,
|
|
|
|
"nand" => lib::llvm::Nand,
|
|
|
|
"or" => lib::llvm::Or,
|
|
|
|
"xor" => lib::llvm::Xor,
|
|
|
|
"max" => lib::llvm::Max,
|
|
|
|
"min" => lib::llvm::Min,
|
|
|
|
"umax" => lib::llvm::UMax,
|
|
|
|
"umin" => lib::llvm::UMin,
|
2014-03-05 08:36:01 -06:00
|
|
|
_ => ccx.sess().fatal("unknown atomic operation")
|
2013-05-21 14:25:44 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
let old = AtomicRMW(bcx, atom_op, get_param(decl, first_real_arg),
|
|
|
|
get_param(decl, first_real_arg + 1u),
|
|
|
|
order);
|
|
|
|
Ret(bcx, old);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fcx.cleanup();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-02-13 23:07:09 -06:00
|
|
|
match name.get() {
|
2013-10-14 20:51:03 -05:00
|
|
|
"abort" => {
|
2014-04-09 18:56:31 -05:00
|
|
|
let llfn = bcx.ccx().get_intrinsic(&("llvm.trap"));
|
2013-10-14 20:51:03 -05:00
|
|
|
Call(bcx, llfn, [], []);
|
2013-11-03 01:28:32 -05:00
|
|
|
Unreachable(bcx);
|
2013-10-14 20:51:03 -05:00
|
|
|
}
|
2013-11-22 09:12:56 -06:00
|
|
|
"breakpoint" => {
|
2014-04-09 18:56:31 -05:00
|
|
|
let llfn = bcx.ccx().get_intrinsic(&("llvm.debugtrap"));
|
2013-11-22 09:12:56 -06:00
|
|
|
Call(bcx, llfn, [], []);
|
|
|
|
RetVoid(bcx);
|
|
|
|
}
|
2013-05-21 14:25:44 -05:00
|
|
|
"size_of" => {
|
2014-05-07 06:20:15 -05:00
|
|
|
let tp_ty = *substs.substs.tps.get(0);
|
2013-05-21 14:25:44 -05:00
|
|
|
let lltp_ty = type_of::type_of(ccx, tp_ty);
|
2014-01-30 16:19:19 -06:00
|
|
|
Ret(bcx, C_uint(ccx, machine::llsize_of_real(ccx, lltp_ty) as uint));
|
2013-05-21 14:25:44 -05:00
|
|
|
}
|
2014-01-15 13:39:08 -06:00
|
|
|
"move_val_init" => {
|
2013-05-21 14:25:44 -05:00
|
|
|
// Create a datum reflecting the value being moved.
|
|
|
|
// Use `appropriate_mode` so that the datum is by ref
|
|
|
|
// if the value is non-immediate. Note that, with
|
|
|
|
// intrinsics, there are no argument cleanups to
|
2014-01-15 13:39:08 -06:00
|
|
|
// concern ourselves with, so we can use an rvalue datum.
|
2014-05-07 06:20:15 -05:00
|
|
|
let tp_ty = *substs.substs.tps.get(0);
|
2014-01-15 13:39:08 -06:00
|
|
|
let mode = appropriate_rvalue_mode(ccx, tp_ty);
|
2013-05-21 14:25:44 -05:00
|
|
|
let src = Datum {val: get_param(decl, first_real_arg + 1u),
|
2014-01-15 13:39:08 -06:00
|
|
|
ty: tp_ty,
|
|
|
|
kind: Rvalue(mode)};
|
|
|
|
bcx = src.store_to(bcx, get_param(decl, first_real_arg));
|
2013-05-21 14:25:44 -05:00
|
|
|
RetVoid(bcx);
|
|
|
|
}
|
|
|
|
"min_align_of" => {
|
2014-05-07 06:20:15 -05:00
|
|
|
let tp_ty = *substs.substs.tps.get(0);
|
2013-05-21 14:25:44 -05:00
|
|
|
let lltp_ty = type_of::type_of(ccx, tp_ty);
|
2014-01-30 16:19:19 -06:00
|
|
|
Ret(bcx, C_uint(ccx, machine::llalign_of_min(ccx, lltp_ty) as uint));
|
2013-05-21 14:25:44 -05:00
|
|
|
}
|
|
|
|
"pref_align_of"=> {
|
2014-05-07 06:20:15 -05:00
|
|
|
let tp_ty = *substs.substs.tps.get(0);
|
2013-05-21 14:25:44 -05:00
|
|
|
let lltp_ty = type_of::type_of(ccx, tp_ty);
|
2014-01-30 16:19:19 -06:00
|
|
|
Ret(bcx, C_uint(ccx, machine::llalign_of_pref(ccx, lltp_ty) as uint));
|
2013-05-21 14:25:44 -05:00
|
|
|
}
|
|
|
|
"get_tydesc" => {
|
2014-05-07 06:20:15 -05:00
|
|
|
let tp_ty = *substs.substs.tps.get(0);
|
2013-05-21 14:25:44 -05:00
|
|
|
let static_ti = get_tydesc(ccx, tp_ty);
|
2014-04-21 19:45:16 -05:00
|
|
|
glue::lazily_emit_visit_glue(ccx, &*static_ti);
|
2013-05-21 14:25:44 -05:00
|
|
|
|
|
|
|
// FIXME (#3730): ideally this shouldn't need a cast,
|
|
|
|
// but there's a circularity between translating rust types to llvm
|
|
|
|
// types and having a tydesc type available. So I can't directly access
|
|
|
|
// the llvm type of intrinsic::TyDesc struct.
|
|
|
|
let userland_tydesc_ty = type_of::type_of(ccx, output_type);
|
|
|
|
let td = PointerCast(bcx, static_ti.tydesc, userland_tydesc_ty);
|
|
|
|
Ret(bcx, td);
|
|
|
|
}
|
2013-10-30 18:32:33 -05:00
|
|
|
"type_id" => {
|
2014-01-31 14:17:03 -06:00
|
|
|
let hash = ty::hash_crate_independent(
|
2014-03-15 15:29:34 -05:00
|
|
|
ccx.tcx(),
|
2014-05-07 06:20:15 -05:00
|
|
|
*substs.substs.tps.get(0),
|
2014-02-24 21:45:20 -06:00
|
|
|
&ccx.link_meta.crate_hash);
|
2013-11-27 16:51:11 -06:00
|
|
|
// NB: This needs to be kept in lockstep with the TypeId struct in
|
|
|
|
// libstd/unstable/intrinsics.rs
|
2014-03-15 15:29:34 -05:00
|
|
|
let val = C_named_struct(type_of::type_of(ccx, output_type),
|
|
|
|
[C_u64(ccx, hash)]);
|
2013-12-20 22:36:07 -06:00
|
|
|
match bcx.fcx.llretptr.get() {
|
2013-11-27 16:51:11 -06:00
|
|
|
Some(ptr) => {
|
|
|
|
Store(bcx, val, ptr);
|
|
|
|
RetVoid(bcx);
|
|
|
|
},
|
|
|
|
None => Ret(bcx, val)
|
|
|
|
}
|
2013-10-30 18:32:33 -05:00
|
|
|
}
|
2013-05-21 14:25:44 -05:00
|
|
|
"init" => {
|
2014-05-07 06:20:15 -05:00
|
|
|
let tp_ty = *substs.substs.tps.get(0);
|
2013-05-21 14:25:44 -05:00
|
|
|
let lltp_ty = type_of::type_of(ccx, tp_ty);
|
2013-12-20 22:36:07 -06:00
|
|
|
match bcx.fcx.llretptr.get() {
|
2013-05-21 14:25:44 -05:00
|
|
|
Some(ptr) => { Store(bcx, C_null(lltp_ty), ptr); RetVoid(bcx); }
|
|
|
|
None if ty::type_is_nil(tp_ty) => RetVoid(bcx),
|
|
|
|
None => Ret(bcx, C_null(lltp_ty)),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"uninit" => {
|
|
|
|
// Do nothing, this is effectively a no-op
|
2014-05-07 06:20:15 -05:00
|
|
|
let retty = *substs.substs.tps.get(0);
|
2014-01-16 18:10:17 -06:00
|
|
|
if type_is_immediate(ccx, retty) && !return_type_is_void(ccx, retty) {
|
2013-05-21 14:25:44 -05:00
|
|
|
unsafe {
|
|
|
|
Ret(bcx, lib::llvm::llvm::LLVMGetUndef(type_of(ccx, retty).to_ref()));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
RetVoid(bcx)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"forget" => {
|
|
|
|
RetVoid(bcx);
|
|
|
|
}
|
|
|
|
"transmute" => {
|
2014-05-07 06:20:15 -05:00
|
|
|
let (in_type, out_type) = (*substs.substs.tps.get(0),
|
|
|
|
*substs.substs.tps.get(1));
|
2013-05-21 14:25:44 -05:00
|
|
|
let llintype = type_of::type_of(ccx, in_type);
|
|
|
|
let llouttype = type_of::type_of(ccx, out_type);
|
|
|
|
|
|
|
|
let in_type_size = machine::llbitsize_of_real(ccx, llintype);
|
|
|
|
let out_type_size = machine::llbitsize_of_real(ccx, llouttype);
|
|
|
|
if in_type_size != out_type_size {
|
2014-02-13 23:07:09 -06:00
|
|
|
let sp = match ccx.tcx.map.get(ref_id.unwrap()) {
|
|
|
|
ast_map::NodeExpr(e) => e.span,
|
|
|
|
_ => fail!("transmute has non-expr arg"),
|
2013-05-21 14:25:44 -05:00
|
|
|
};
|
2014-03-05 08:36:01 -06:00
|
|
|
ccx.sess().span_fatal(sp,
|
2014-03-04 00:00:46 -06:00
|
|
|
format!("transmute called on types with different sizes: \
|
|
|
|
{intype} ({insize, plural, =1{# bit} other{# bits}}) to \
|
|
|
|
{outtype} ({outsize, plural, =1{# bit} other{# bits}})",
|
2014-03-15 15:29:34 -05:00
|
|
|
intype = ty_to_str(ccx.tcx(), in_type),
|
2014-03-04 00:00:46 -06:00
|
|
|
insize = in_type_size as uint,
|
2014-03-15 15:29:34 -05:00
|
|
|
outtype = ty_to_str(ccx.tcx(), out_type),
|
2014-05-16 12:45:16 -05:00
|
|
|
outsize = out_type_size as uint).as_slice());
|
2013-05-21 14:25:44 -05:00
|
|
|
}
|
|
|
|
|
2014-01-16 18:10:17 -06:00
|
|
|
if !return_type_is_void(ccx, out_type) {
|
2013-05-21 14:25:44 -05:00
|
|
|
let llsrcval = get_param(decl, first_real_arg);
|
make small (<= size_of::<int>()) tuples immediate
fn foo() -> (u32, u8, u8, u8, u8) {
(4, 5, 6, 7, 8)
}
Before:
; Function Attrs: nounwind uwtable
define void @_ZN3foo18hbb616262f874f8daf4v0.0E({ i32, i8, i8, i8, i8 }* noalias nocapture sret, { i64, %tydesc*, i8*, i8*, i8 }* nocapture readnone) #0 {
"function top level":
%2 = getelementptr inbounds { i32, i8, i8, i8, i8 }* %0, i64 0, i32 0
store i32 4, i32* %2, align 4
%3 = getelementptr inbounds { i32, i8, i8, i8, i8 }* %0, i64 0, i32 1
store i8 5, i8* %3, align 4
%4 = getelementptr inbounds { i32, i8, i8, i8, i8 }* %0, i64 0, i32 2
store i8 6, i8* %4, align 1
%5 = getelementptr inbounds { i32, i8, i8, i8, i8 }* %0, i64 0, i32 3
store i8 7, i8* %5, align 2
%6 = getelementptr inbounds { i32, i8, i8, i8, i8 }* %0, i64 0, i32 4
store i8 8, i8* %6, align 1
ret void
}
After:
; Function Attrs: nounwind readnone uwtable
define { i32, i8, i8, i8, i8 } @_ZN3foo18hbb616262f874f8daf4v0.0E({ i64, %tydesc*, i8*, i8*, i8 }* nocapture readnone) #0 {
"function top level":
ret { i32, i8, i8, i8, i8 } { i32 4, i8 5, i8 6, i8 7, i8 8 }
}
2013-09-30 17:29:42 -05:00
|
|
|
if type_is_immediate(ccx, in_type) {
|
2013-12-20 22:36:07 -06:00
|
|
|
match fcx.llretptr.get() {
|
2013-05-21 14:25:44 -05:00
|
|
|
Some(llretptr) => {
|
|
|
|
Store(bcx, llsrcval, PointerCast(bcx, llretptr, llintype.ptr_to()));
|
|
|
|
RetVoid(bcx);
|
|
|
|
}
|
|
|
|
None => match (llintype.kind(), llouttype.kind()) {
|
|
|
|
(Pointer, other) | (other, Pointer) if other != Pointer => {
|
|
|
|
let tmp = Alloca(bcx, llouttype, "");
|
|
|
|
Store(bcx, llsrcval, PointerCast(bcx, tmp, llintype.ptr_to()));
|
make C-like enums immediate
This fixes two existing bugs along the way:
* The `transmute` intrinsic did not correctly handle casts of immediate
aggregates like newtype structs and tuples.
* The code for calling foreign functions used the wrong type to create
an `alloca` temporary
enum Foo { A, B }
fn foo() -> Foo { A }
Before:
; Function Attrs: nounwind uwtable
define void @_ZN3foo18hbedc642d5d9cf5aag4v0.0E(%enum.Foo* noalias nocapture sret, { i64, %tydesc*, i8*, i8*, i8 }* nocapture readnone) #0 {
"function top level":
%2 = getelementptr inbounds %enum.Foo* %0, i64 0, i32 0
store i64 0, i64* %2, align 8
ret void
}
After:
; Function Attrs: nounwind readnone uwtable
define %enum.Foo @_ZN3foo18hbedc642d5d9cf5aag4v0.0E({ i64, %tydesc*, i8*, i8*, i8 }* nocapture readnone) #0 {
"function top level":
ret %enum.Foo zeroinitializer
}
2013-10-03 05:19:02 -05:00
|
|
|
Ret(bcx, Load(bcx, tmp));
|
|
|
|
}
|
|
|
|
(Array, _) | (_, Array) | (Struct, _) | (_, Struct) => {
|
|
|
|
let tmp = Alloca(bcx, llouttype, "");
|
|
|
|
Store(bcx, llsrcval, PointerCast(bcx, tmp, llintype.ptr_to()));
|
|
|
|
Ret(bcx, Load(bcx, tmp));
|
2013-09-30 12:37:22 -05:00
|
|
|
}
|
|
|
|
_ => {
|
|
|
|
let llbitcast = BitCast(bcx, llsrcval, llouttype);
|
|
|
|
Ret(bcx, llbitcast)
|
2013-05-21 14:25:44 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
make small (<= size_of::<int>()) tuples immediate
fn foo() -> (u32, u8, u8, u8, u8) {
(4, 5, 6, 7, 8)
}
Before:
; Function Attrs: nounwind uwtable
define void @_ZN3foo18hbb616262f874f8daf4v0.0E({ i32, i8, i8, i8, i8 }* noalias nocapture sret, { i64, %tydesc*, i8*, i8*, i8 }* nocapture readnone) #0 {
"function top level":
%2 = getelementptr inbounds { i32, i8, i8, i8, i8 }* %0, i64 0, i32 0
store i32 4, i32* %2, align 4
%3 = getelementptr inbounds { i32, i8, i8, i8, i8 }* %0, i64 0, i32 1
store i8 5, i8* %3, align 4
%4 = getelementptr inbounds { i32, i8, i8, i8, i8 }* %0, i64 0, i32 2
store i8 6, i8* %4, align 1
%5 = getelementptr inbounds { i32, i8, i8, i8, i8 }* %0, i64 0, i32 3
store i8 7, i8* %5, align 2
%6 = getelementptr inbounds { i32, i8, i8, i8, i8 }* %0, i64 0, i32 4
store i8 8, i8* %6, align 1
ret void
}
After:
; Function Attrs: nounwind readnone uwtable
define { i32, i8, i8, i8, i8 } @_ZN3foo18hbb616262f874f8daf4v0.0E({ i64, %tydesc*, i8*, i8*, i8 }* nocapture readnone) #0 {
"function top level":
ret { i32, i8, i8, i8, i8 } { i32 4, i8 5, i8 6, i8 7, i8 8 }
}
2013-09-30 17:29:42 -05:00
|
|
|
} else if type_is_immediate(ccx, out_type) {
|
2013-05-21 14:25:44 -05:00
|
|
|
let llsrcptr = PointerCast(bcx, llsrcval, llouttype.ptr_to());
|
2013-09-30 12:37:22 -05:00
|
|
|
let ll_load = Load(bcx, llsrcptr);
|
|
|
|
Ret(bcx, ll_load);
|
2013-05-21 14:25:44 -05:00
|
|
|
} else {
|
|
|
|
// NB: Do not use a Load and Store here. This causes massive
|
|
|
|
// code bloat when `transmute` is used on large structural
|
|
|
|
// types.
|
2013-12-20 22:36:07 -06:00
|
|
|
let lldestptr = fcx.llretptr.get().unwrap();
|
2014-03-15 15:29:34 -05:00
|
|
|
let lldestptr = PointerCast(bcx, lldestptr, Type::i8p(ccx));
|
|
|
|
let llsrcptr = PointerCast(bcx, llsrcval, Type::i8p(ccx));
|
2013-05-21 14:25:44 -05:00
|
|
|
|
|
|
|
let llsize = llsize_of(ccx, llintype);
|
|
|
|
call_memcpy(bcx, lldestptr, llsrcptr, llsize, 1);
|
|
|
|
RetVoid(bcx);
|
|
|
|
};
|
|
|
|
} else {
|
|
|
|
RetVoid(bcx);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"needs_drop" => {
|
2014-05-07 06:20:15 -05:00
|
|
|
let tp_ty = *substs.substs.tps.get(0);
|
2014-03-15 15:29:34 -05:00
|
|
|
Ret(bcx, C_bool(ccx, ty::type_needs_drop(ccx.tcx(), tp_ty)));
|
2013-05-21 14:25:44 -05:00
|
|
|
}
|
2013-11-05 13:50:33 -06:00
|
|
|
"owns_managed" => {
|
2014-05-07 06:20:15 -05:00
|
|
|
let tp_ty = *substs.substs.tps.get(0);
|
2014-03-15 15:29:34 -05:00
|
|
|
Ret(bcx, C_bool(ccx, ty::type_contents(ccx.tcx(), tp_ty).owns_managed()));
|
2013-05-21 14:25:44 -05:00
|
|
|
}
|
|
|
|
"visit_tydesc" => {
|
|
|
|
let td = get_param(decl, first_real_arg);
|
|
|
|
let visitor = get_param(decl, first_real_arg + 1u);
|
2014-03-15 15:29:34 -05:00
|
|
|
let td = PointerCast(bcx, td, ccx.tydesc_type().ptr_to());
|
2014-02-06 00:07:06 -06:00
|
|
|
glue::call_visit_glue(bcx, visitor, td, None);
|
2013-05-21 14:25:44 -05:00
|
|
|
RetVoid(bcx);
|
|
|
|
}
|
|
|
|
"offset" => {
|
|
|
|
let ptr = get_param(decl, first_real_arg);
|
|
|
|
let offset = get_param(decl, first_real_arg + 1);
|
2013-09-30 12:37:22 -05:00
|
|
|
let lladdr = InBoundsGEP(bcx, ptr, [offset]);
|
|
|
|
Ret(bcx, lladdr);
|
2013-05-21 14:25:44 -05:00
|
|
|
}
|
2014-05-07 06:20:15 -05:00
|
|
|
"copy_nonoverlapping_memory" => {
|
|
|
|
copy_intrinsic(bcx, false, false, *substs.substs.tps.get(0))
|
|
|
|
}
|
|
|
|
"copy_memory" => {
|
|
|
|
copy_intrinsic(bcx, true, false, *substs.substs.tps.get(0))
|
|
|
|
}
|
|
|
|
"set_memory" => {
|
|
|
|
memset_intrinsic(bcx, false, *substs.substs.tps.get(0))
|
|
|
|
}
|
2014-04-22 18:51:14 -05:00
|
|
|
|
|
|
|
"volatile_copy_nonoverlapping_memory" =>
|
2014-05-07 06:20:15 -05:00
|
|
|
copy_intrinsic(bcx, false, true, *substs.substs.tps.get(0)),
|
|
|
|
"volatile_copy_memory" => copy_intrinsic(bcx, true, true, *substs.substs.tps.get(0)),
|
|
|
|
"volatile_set_memory" => memset_intrinsic(bcx, true, *substs.substs.tps.get(0)),
|
2014-04-22 18:51:14 -05:00
|
|
|
|
2013-05-21 14:25:44 -05:00
|
|
|
"ctlz8" => count_zeros_intrinsic(bcx, "llvm.ctlz.i8"),
|
|
|
|
"ctlz16" => count_zeros_intrinsic(bcx, "llvm.ctlz.i16"),
|
|
|
|
"ctlz32" => count_zeros_intrinsic(bcx, "llvm.ctlz.i32"),
|
|
|
|
"ctlz64" => count_zeros_intrinsic(bcx, "llvm.ctlz.i64"),
|
|
|
|
"cttz8" => count_zeros_intrinsic(bcx, "llvm.cttz.i8"),
|
|
|
|
"cttz16" => count_zeros_intrinsic(bcx, "llvm.cttz.i16"),
|
|
|
|
"cttz32" => count_zeros_intrinsic(bcx, "llvm.cttz.i32"),
|
|
|
|
"cttz64" => count_zeros_intrinsic(bcx, "llvm.cttz.i64"),
|
|
|
|
|
2013-12-28 08:01:53 -06:00
|
|
|
"volatile_load" => volatile_load_intrinsic(bcx),
|
|
|
|
"volatile_store" => volatile_store_intrinsic(bcx),
|
|
|
|
|
make small (<= size_of::<int>()) tuples immediate
fn foo() -> (u32, u8, u8, u8, u8) {
(4, 5, 6, 7, 8)
}
Before:
; Function Attrs: nounwind uwtable
define void @_ZN3foo18hbb616262f874f8daf4v0.0E({ i32, i8, i8, i8, i8 }* noalias nocapture sret, { i64, %tydesc*, i8*, i8*, i8 }* nocapture readnone) #0 {
"function top level":
%2 = getelementptr inbounds { i32, i8, i8, i8, i8 }* %0, i64 0, i32 0
store i32 4, i32* %2, align 4
%3 = getelementptr inbounds { i32, i8, i8, i8, i8 }* %0, i64 0, i32 1
store i8 5, i8* %3, align 4
%4 = getelementptr inbounds { i32, i8, i8, i8, i8 }* %0, i64 0, i32 2
store i8 6, i8* %4, align 1
%5 = getelementptr inbounds { i32, i8, i8, i8, i8 }* %0, i64 0, i32 3
store i8 7, i8* %5, align 2
%6 = getelementptr inbounds { i32, i8, i8, i8, i8 }* %0, i64 0, i32 4
store i8 8, i8* %6, align 1
ret void
}
After:
; Function Attrs: nounwind readnone uwtable
define { i32, i8, i8, i8, i8 } @_ZN3foo18hbb616262f874f8daf4v0.0E({ i64, %tydesc*, i8*, i8*, i8 }* nocapture readnone) #0 {
"function top level":
ret { i32, i8, i8, i8, i8 } { i32 4, i8 5, i8 6, i8 7, i8 8 }
}
2013-09-30 17:29:42 -05:00
|
|
|
"i8_add_with_overflow" =>
|
|
|
|
with_overflow_instrinsic(bcx, "llvm.sadd.with.overflow.i8", output_type),
|
|
|
|
"i16_add_with_overflow" =>
|
|
|
|
with_overflow_instrinsic(bcx, "llvm.sadd.with.overflow.i16", output_type),
|
|
|
|
"i32_add_with_overflow" =>
|
|
|
|
with_overflow_instrinsic(bcx, "llvm.sadd.with.overflow.i32", output_type),
|
|
|
|
"i64_add_with_overflow" =>
|
|
|
|
with_overflow_instrinsic(bcx, "llvm.sadd.with.overflow.i64", output_type),
|
|
|
|
|
|
|
|
"u8_add_with_overflow" =>
|
|
|
|
with_overflow_instrinsic(bcx, "llvm.uadd.with.overflow.i8", output_type),
|
|
|
|
"u16_add_with_overflow" =>
|
|
|
|
with_overflow_instrinsic(bcx, "llvm.uadd.with.overflow.i16", output_type),
|
|
|
|
"u32_add_with_overflow" =>
|
|
|
|
with_overflow_instrinsic(bcx, "llvm.uadd.with.overflow.i32", output_type),
|
|
|
|
"u64_add_with_overflow" =>
|
|
|
|
with_overflow_instrinsic(bcx, "llvm.uadd.with.overflow.i64", output_type),
|
|
|
|
|
|
|
|
"i8_sub_with_overflow" =>
|
|
|
|
with_overflow_instrinsic(bcx, "llvm.ssub.with.overflow.i8", output_type),
|
|
|
|
"i16_sub_with_overflow" =>
|
|
|
|
with_overflow_instrinsic(bcx, "llvm.ssub.with.overflow.i16", output_type),
|
|
|
|
"i32_sub_with_overflow" =>
|
|
|
|
with_overflow_instrinsic(bcx, "llvm.ssub.with.overflow.i32", output_type),
|
|
|
|
"i64_sub_with_overflow" =>
|
|
|
|
with_overflow_instrinsic(bcx, "llvm.ssub.with.overflow.i64", output_type),
|
|
|
|
|
|
|
|
"u8_sub_with_overflow" =>
|
|
|
|
with_overflow_instrinsic(bcx, "llvm.usub.with.overflow.i8", output_type),
|
|
|
|
"u16_sub_with_overflow" =>
|
|
|
|
with_overflow_instrinsic(bcx, "llvm.usub.with.overflow.i16", output_type),
|
|
|
|
"u32_sub_with_overflow" =>
|
|
|
|
with_overflow_instrinsic(bcx, "llvm.usub.with.overflow.i32", output_type),
|
|
|
|
"u64_sub_with_overflow" =>
|
|
|
|
with_overflow_instrinsic(bcx, "llvm.usub.with.overflow.i64", output_type),
|
|
|
|
|
|
|
|
"i8_mul_with_overflow" =>
|
|
|
|
with_overflow_instrinsic(bcx, "llvm.smul.with.overflow.i8", output_type),
|
|
|
|
"i16_mul_with_overflow" =>
|
|
|
|
with_overflow_instrinsic(bcx, "llvm.smul.with.overflow.i16", output_type),
|
|
|
|
"i32_mul_with_overflow" =>
|
|
|
|
with_overflow_instrinsic(bcx, "llvm.smul.with.overflow.i32", output_type),
|
|
|
|
"i64_mul_with_overflow" =>
|
|
|
|
with_overflow_instrinsic(bcx, "llvm.smul.with.overflow.i64", output_type),
|
|
|
|
|
|
|
|
"u8_mul_with_overflow" =>
|
|
|
|
with_overflow_instrinsic(bcx, "llvm.umul.with.overflow.i8", output_type),
|
|
|
|
"u16_mul_with_overflow" =>
|
|
|
|
with_overflow_instrinsic(bcx, "llvm.umul.with.overflow.i16", output_type),
|
|
|
|
"u32_mul_with_overflow" =>
|
|
|
|
with_overflow_instrinsic(bcx, "llvm.umul.with.overflow.i32", output_type),
|
|
|
|
"u64_mul_with_overflow" =>
|
|
|
|
with_overflow_instrinsic(bcx, "llvm.umul.with.overflow.i64", output_type),
|
2013-05-21 14:25:44 -05:00
|
|
|
|
|
|
|
_ => {
|
|
|
|
// Could we make this an enum rather than a string? does it get
|
|
|
|
// checked earlier?
|
2014-03-05 08:36:01 -06:00
|
|
|
ccx.sess().span_bug(item.span, "unknown intrinsic");
|
2013-05-21 14:25:44 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
fcx.cleanup();
|
|
|
|
}
|