1 // Copyright 2015 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 #![crate_name = "rustc_platform_intrinsics"]
12 #![unstable(feature = "rustc_private", issue = "27812")]
13 #![crate_type = "dylib"]
14 #![crate_type = "rlib"]
15 #![feature(staged_api, rustc_private)]
17 extern crate rustc_llvm as llvm;
20 use rustc::middle::ty;
22 pub struct Intrinsic {
23 pub inputs: Vec<Type>,
26 pub definition: IntrinsicDef,
29 #[derive(Clone, Hash, Eq, PartialEq)]
32 Integer(/* signed */ bool, u8, /* llvm width */ u8),
34 Pointer(Box<Type>, Option<Box<Type>>, /* const */ bool),
35 Vector(Box<Type>, Option<Box<Type>>, u8),
36 Aggregate(bool, Vec<Type>),
39 pub enum IntrinsicDef {
43 fn i(width: u8) -> Type { Type::Integer(true, width, width) }
44 fn i_(width: u8, llvm_width: u8) -> Type { Type::Integer(true, width, llvm_width) }
45 fn u(width: u8) -> Type { Type::Integer(false, width, width) }
47 fn u_(width: u8, llvm_width: u8) -> Type { Type::Integer(false, width, llvm_width) }
48 fn f(width: u8) -> Type { Type::Float(width) }
49 fn v(x: Type, length: u8) -> Type { Type::Vector(Box::new(x), None, length) }
50 fn v_(x: Type, bitcast: Type, length: u8) -> Type {
51 Type::Vector(Box::new(x), Some(Box::new(bitcast)), length)
53 fn agg(flatten: bool, types: Vec<Type>) -> Type {
54 Type::Aggregate(flatten, types)
56 fn p(const_: bool, elem: Type, llvm_elem: Option<Type>) -> Type {
57 Type::Pointer(Box::new(elem), llvm_elem.map(Box::new), const_)
68 pub fn find<'tcx>(tcx: &ty::ctxt<'tcx>, name: &str) -> Option<Intrinsic> {
69 if name.starts_with("x86_") {
71 } else if name.starts_with("arm_") {
73 } else if name.starts_with("aarch64_") {
74 aarch64::find(tcx, name)