1 // Copyright 2013 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.
14 use rustc::dep_graph::DepGraphSafe;
20 use monomorphize::Instance;
21 use value::{Value, ValueTrait};
23 use monomorphize::partitioning::CodegenUnit;
25 use type_of::PointeeInfo;
27 use rustc_data_structures::base_n;
28 use rustc_data_structures::small_c_str::SmallCStr;
29 use rustc::mir::mono::Stats;
30 use rustc::session::config::{self, DebugInfo};
31 use rustc::session::Session;
32 use rustc::ty::layout::{LayoutError, LayoutOf, Size, TyLayout, VariantIdx};
33 use rustc::ty::{self, Ty, TyCtxt};
34 use rustc::util::nodemap::FxHashMap;
35 use rustc_target::spec::{HasTargetSpec, Target};
38 use std::cell::{Cell, RefCell};
42 use syntax::symbol::LocalInternedString;
45 /// There is one `CodegenCx` per compilation unit. Each one has its own LLVM
46 /// `llvm::Context` so that several compilation units may be optimized in parallel.
47 /// All other LLVM data structures in the `CodegenCx` are tied to that `llvm::Context`.
48 pub struct CodegenCx<'a, 'tcx: 'a, V = &'a Value> {
49 pub tcx: TyCtxt<'a, 'tcx, 'tcx>,
50 pub check_overflow: bool,
51 pub use_dll_storage_attrs: bool,
52 pub tls_model: llvm::ThreadLocalMode,
54 pub llmod: &'a llvm::Module,
55 pub llcx: &'a llvm::Context,
56 pub stats: RefCell<Stats>,
57 pub codegen_unit: Arc<CodegenUnit<'tcx>>,
59 /// Cache instances of monomorphic and polymorphic items
60 pub instances: RefCell<FxHashMap<Instance<'tcx>, V>>,
61 /// Cache generated vtables
62 pub vtables: RefCell<FxHashMap<(Ty<'tcx>, ty::PolyExistentialTraitRef<'tcx>), V>>,
63 /// Cache of constant strings,
64 pub const_cstr_cache: RefCell<FxHashMap<LocalInternedString, V>>,
66 /// Reverse-direction for const ptrs cast from globals.
67 /// Key is a Value holding a *T,
68 /// Val is a Value holding a *[T].
70 /// Needed because LLVM loses pointer->pointee association
71 /// when we ptrcast, and we have to ptrcast during codegen
72 /// of a [T] const because we form a slice, a (*T,usize) pair, not
73 /// a pointer to an LLVM array type. Similar for trait objects.
74 pub const_unsized: RefCell<FxHashMap<V, V>>,
76 /// Cache of emitted const globals (value -> global)
77 pub const_globals: RefCell<FxHashMap<V, V>>,
79 /// List of globals for static variables which need to be passed to the
80 /// LLVM function ReplaceAllUsesWith (RAUW) when codegen is complete.
81 /// (We have to make sure we don't invalidate any Values referring
83 pub statics_to_rauw: RefCell<Vec<(V, V)>>,
85 /// Statics that will be placed in the llvm.used variable
86 /// See http://llvm.org/docs/LangRef.html#the-llvm-used-global-variable for details
87 pub used_statics: RefCell<Vec<V>>,
89 pub lltypes: RefCell<FxHashMap<(Ty<'tcx>, Option<VariantIdx>), &'a Type>>,
90 pub scalar_lltypes: RefCell<FxHashMap<Ty<'tcx>, &'a Type>>,
91 pub pointee_infos: RefCell<FxHashMap<(Ty<'tcx>, Size), Option<PointeeInfo>>>,
92 pub isize_ty: &'a Type,
94 pub dbg_cx: Option<debuginfo::CrateDebugContext<'a, 'tcx>>,
96 eh_personality: Cell<Option<V>>,
97 eh_unwind_resume: Cell<Option<V>>,
98 pub rust_try_fn: Cell<Option<V>>,
100 intrinsics: RefCell<FxHashMap<&'static str, V>>,
102 /// A counter that is used for generating local symbol names
103 local_gen_sym_counter: Cell<usize>,
106 impl<'a, 'tcx> DepGraphSafe for CodegenCx<'a, 'tcx> {
109 pub fn get_reloc_model(sess: &Session) -> llvm::RelocMode {
110 let reloc_model_arg = match sess.opts.cg.relocation_model {
111 Some(ref s) => &s[..],
112 None => &sess.target.target.options.relocation_model[..],
115 match ::back::write::RELOC_MODEL_ARGS.iter().find(
116 |&&arg| arg.0 == reloc_model_arg) {
119 sess.err(&format!("{:?} is not a valid relocation mode",
121 sess.abort_if_errors();
127 fn get_tls_model(sess: &Session) -> llvm::ThreadLocalMode {
128 let tls_model_arg = match sess.opts.debugging_opts.tls_model {
129 Some(ref s) => &s[..],
130 None => &sess.target.target.options.tls_model[..],
133 match ::back::write::TLS_MODEL_ARGS.iter().find(
134 |&&arg| arg.0 == tls_model_arg) {
137 sess.err(&format!("{:?} is not a valid TLS model",
139 sess.abort_if_errors();
145 fn is_any_library(sess: &Session) -> bool {
146 sess.crate_types.borrow().iter().any(|ty| {
147 *ty != config::CrateType::Executable
151 pub fn is_pie_binary(sess: &Session) -> bool {
152 !is_any_library(sess) && get_reloc_model(sess) == llvm::RelocMode::PIC
155 pub unsafe fn create_module(
157 llcx: &'ll llvm::Context,
159 ) -> &'ll llvm::Module {
160 let mod_name = SmallCStr::new(mod_name);
161 let llmod = llvm::LLVMModuleCreateWithNameInContext(mod_name.as_ptr(), llcx);
163 // Ensure the data-layout values hardcoded remain the defaults.
164 if sess.target.target.options.is_builtin {
165 let tm = ::back::write::create_target_machine(sess, false);
166 llvm::LLVMRustSetDataLayoutFromTargetMachine(llmod, tm);
167 llvm::LLVMRustDisposeTargetMachine(tm);
169 let data_layout = llvm::LLVMGetDataLayout(llmod);
170 let data_layout = str::from_utf8(CStr::from_ptr(data_layout).to_bytes())
171 .ok().expect("got a non-UTF8 data-layout from LLVM");
173 // Unfortunately LLVM target specs change over time, and right now we
174 // don't have proper support to work with any more than one
175 // `data_layout` than the one that is in the rust-lang/rust repo. If
176 // this compiler is configured against a custom LLVM, we may have a
177 // differing data layout, even though we should update our own to use
180 // As an interim hack, if CFG_LLVM_ROOT is not an empty string then we
181 // disable this check entirely as we may be configured with something
182 // that has a different target layout.
184 // Unsure if this will actually cause breakage when rustc is configured
188 let cfg_llvm_root = option_env!("CFG_LLVM_ROOT").unwrap_or("");
189 let custom_llvm_used = cfg_llvm_root.trim() != "";
191 if !custom_llvm_used && sess.target.target.data_layout != data_layout {
192 bug!("data-layout for builtin `{}` target, `{}`, \
193 differs from LLVM default, `{}`",
194 sess.target.target.llvm_target,
195 sess.target.target.data_layout,
200 let data_layout = SmallCStr::new(&sess.target.target.data_layout);
201 llvm::LLVMSetDataLayout(llmod, data_layout.as_ptr());
203 let llvm_target = SmallCStr::new(&sess.target.target.llvm_target);
204 llvm::LLVMRustSetNormalizedTarget(llmod, llvm_target.as_ptr());
206 if is_pie_binary(sess) {
207 llvm::LLVMRustSetModulePIELevel(llmod);
210 // If skipping the PLT is enabled, we need to add some module metadata
211 // to ensure intrinsic calls don't use it.
212 if !sess.needs_plt() {
213 let avoid_plt = "RtLibUseGOT\0".as_ptr() as *const _;
214 llvm::LLVMRustAddModuleFlag(llmod, avoid_plt, 1);
220 impl<'a, 'tcx> CodegenCx<'a, 'tcx> {
221 crate fn new(tcx: TyCtxt<'a, 'tcx, 'tcx>,
222 codegen_unit: Arc<CodegenUnit<'tcx>>,
223 llvm_module: &'a ::ModuleLlvm)
224 -> CodegenCx<'a, 'tcx> {
225 // An interesting part of Windows which MSVC forces our hand on (and
226 // apparently MinGW didn't) is the usage of `dllimport` and `dllexport`
227 // attributes in LLVM IR as well as native dependencies (in C these
228 // correspond to `__declspec(dllimport)`).
230 // Whenever a dynamic library is built by MSVC it must have its public
231 // interface specified by functions tagged with `dllexport` or otherwise
232 // they're not available to be linked against. This poses a few problems
233 // for the compiler, some of which are somewhat fundamental, but we use
234 // the `use_dll_storage_attrs` variable below to attach the `dllexport`
235 // attribute to all LLVM functions that are exported e.g. they're
236 // already tagged with external linkage). This is suboptimal for a few
239 // * If an object file will never be included in a dynamic library,
240 // there's no need to attach the dllexport attribute. Most object
241 // files in Rust are not destined to become part of a dll as binaries
242 // are statically linked by default.
243 // * If the compiler is emitting both an rlib and a dylib, the same
244 // source object file is currently used but with MSVC this may be less
245 // feasible. The compiler may be able to get around this, but it may
246 // involve some invasive changes to deal with this.
248 // The flipside of this situation is that whenever you link to a dll and
249 // you import a function from it, the import should be tagged with
250 // `dllimport`. At this time, however, the compiler does not emit
251 // `dllimport` for any declarations other than constants (where it is
252 // required), which is again suboptimal for even more reasons!
254 // * Calling a function imported from another dll without using
255 // `dllimport` causes the linker/compiler to have extra overhead (one
256 // `jmp` instruction on x86) when calling the function.
257 // * The same object file may be used in different circumstances, so a
258 // function may be imported from a dll if the object is linked into a
259 // dll, but it may be just linked against if linked into an rlib.
260 // * The compiler has no knowledge about whether native functions should
261 // be tagged dllimport or not.
263 // For now the compiler takes the perf hit (I do not have any numbers to
264 // this effect) by marking very little as `dllimport` and praying the
265 // linker will take care of everything. Fixing this problem will likely
266 // require adding a few attributes to Rust itself (feature gated at the
267 // start) and then strongly recommending static linkage on MSVC!
268 let use_dll_storage_attrs = tcx.sess.target.target.options.is_like_msvc;
270 let check_overflow = tcx.sess.overflow_checks();
272 let tls_model = get_tls_model(&tcx.sess);
274 let (llcx, llmod) = (&*llvm_module.llcx, llvm_module.llmod());
276 let dbg_cx = if tcx.sess.opts.debuginfo != DebugInfo::None {
277 let dctx = debuginfo::CrateDebugContext::new(llmod);
278 debuginfo::metadata::compile_unit_metadata(tcx,
279 &codegen_unit.name().as_str(),
286 let isize_ty = Type::ix_llcx::<Value>(llcx, tcx.data_layout.pointer_size.bits());
291 use_dll_storage_attrs,
295 stats: RefCell::new(Stats::default()),
297 instances: Default::default(),
298 vtables: Default::default(),
299 const_cstr_cache: Default::default(),
300 const_unsized: Default::default(),
301 const_globals: Default::default(),
302 statics_to_rauw: RefCell::new(Vec::new()),
303 used_statics: RefCell::new(Vec::new()),
304 lltypes: Default::default(),
305 scalar_lltypes: Default::default(),
306 pointee_infos: Default::default(),
309 eh_personality: Cell::new(None),
310 eh_unwind_resume: Cell::new(None),
311 rust_try_fn: Cell::new(None),
312 intrinsics: Default::default(),
313 local_gen_sym_counter: Cell::new(0),
318 impl<'b, 'tcx, Value : ?Sized> CodegenCx<'b, 'tcx, &'b Value> where Value : ValueTrait {
319 pub fn sess<'a>(&'a self) -> &'a Session {
323 pub fn get_intrinsic(&self, key: &str) -> &'b Value {
324 if let Some(v) = self.intrinsics.borrow().get(key).cloned() {
328 declare_intrinsic(self, key).unwrap_or_else(|| bug!("unknown intrinsic '{}'", key))
332 impl<'b, 'tcx> CodegenCx<'b, 'tcx, &'b Value> {
333 /// Generate a new symbol name with the given prefix. This symbol name must
334 /// only be used for definitions with `internal` or `private` linkage.
335 pub fn generate_local_symbol_name(&self, prefix: &str) -> String {
336 let idx = self.local_gen_sym_counter.get();
337 self.local_gen_sym_counter.set(idx + 1);
338 // Include a '.' character, so there can be no accidental conflicts with
339 // user defined names
340 let mut name = String::with_capacity(prefix.len() + 6);
341 name.push_str(prefix);
343 base_n::push_str(idx as u128, base_n::ALPHANUMERIC_ONLY, &mut name);
347 pub fn eh_personality(&self) -> &'b Value {
348 // The exception handling personality function.
350 // If our compilation unit has the `eh_personality` lang item somewhere
351 // within it, then we just need to codegen that. Otherwise, we're
352 // building an rlib which will depend on some upstream implementation of
353 // this function, so we just codegen a generic reference to it. We don't
354 // specify any of the types for the function, we just make it a symbol
355 // that LLVM can later use.
357 // Note that MSVC is a little special here in that we don't use the
358 // `eh_personality` lang item at all. Currently LLVM has support for
359 // both Dwarf and SEH unwind mechanisms for MSVC targets and uses the
360 // *name of the personality function* to decide what kind of unwind side
361 // tables/landing pads to emit. It looks like Dwarf is used by default,
362 // injecting a dependency on the `_Unwind_Resume` symbol for resuming
363 // an "exception", but for MSVC we want to force SEH. This means that we
364 // can't actually have the personality function be our standard
365 // `rust_eh_personality` function, but rather we wired it up to the
366 // CRT's custom personality function, which forces LLVM to consider
367 // landing pads as "landing pads for SEH".
368 if let Some(llpersonality) = self.eh_personality.get() {
372 let llfn = match tcx.lang_items().eh_personality() {
373 Some(def_id) if !base::wants_msvc_seh(self.sess()) => {
374 callee::resolve_and_get_fn(self, def_id, tcx.intern_substs(&[]))
377 let name = if base::wants_msvc_seh(self.sess()) {
380 "rust_eh_personality"
382 let fty = Type::variadic_func::<Value>(&[], Type::i32(self));
383 declare::declare_cfn(self, name, fty)
386 attributes::apply_target_cpu_attr(self, llfn);
387 self.eh_personality.set(Some(llfn));
391 // Returns a Value of the "eh_unwind_resume" lang item if one is defined,
392 // otherwise declares it as an external function.
393 pub fn eh_unwind_resume(&self) -> &'b Value {
395 let unwresume = &self.eh_unwind_resume;
396 if let Some(llfn) = unwresume.get() {
401 assert!(self.sess().target.target.options.custom_unwind_resume);
402 if let Some(def_id) = tcx.lang_items().eh_unwind_resume() {
403 let llfn = callee::resolve_and_get_fn(self, def_id, tcx.intern_substs(&[]));
404 unwresume.set(Some(llfn));
408 let sig = ty::Binder::bind(tcx.mk_fn_sig(
409 iter::once(tcx.mk_mut_ptr(tcx.types.u8)),
412 hir::Unsafety::Unsafe,
416 let llfn = declare::declare_fn(self, "rust_eh_unwind_resume", sig);
417 attributes::unwind(llfn, true);
418 attributes::apply_target_cpu_attr(self, llfn);
419 unwresume.set(Some(llfn));
423 pub fn type_needs_drop(&self, ty: Ty<'tcx>) -> bool {
424 common::type_needs_drop(self.tcx, ty)
427 pub fn type_is_sized(&self, ty: Ty<'tcx>) -> bool {
428 common::type_is_sized(self.tcx, ty)
431 pub fn type_is_freeze(&self, ty: Ty<'tcx>) -> bool {
432 common::type_is_freeze(self.tcx, ty)
435 pub fn type_has_metadata(&self, ty: Ty<'tcx>) -> bool {
436 use syntax_pos::DUMMY_SP;
437 if ty.is_sized(self.tcx.at(DUMMY_SP), ty::ParamEnv::reveal_all()) {
441 let tail = self.tcx.struct_tail(ty);
443 ty::Foreign(..) => false,
444 ty::Str | ty::Slice(..) | ty::Dynamic(..) => true,
445 _ => bug!("unexpected unsized tail: {:?}", tail.sty),
450 impl ty::layout::HasDataLayout for CodegenCx<'ll, 'tcx> {
451 fn data_layout(&self) -> &ty::layout::TargetDataLayout {
452 &self.tcx.data_layout
456 impl HasTargetSpec for CodegenCx<'ll, 'tcx> {
457 fn target_spec(&self) -> &Target {
458 &self.tcx.sess.target.target
462 impl ty::layout::HasTyCtxt<'tcx> for CodegenCx<'ll, 'tcx> {
463 fn tcx<'a>(&'a self) -> TyCtxt<'a, 'tcx, 'tcx> {
468 impl LayoutOf for CodegenCx<'ll, 'tcx> {
470 type TyLayout = TyLayout<'tcx>;
472 fn layout_of(&self, ty: Ty<'tcx>) -> Self::TyLayout {
473 self.tcx.layout_of(ty::ParamEnv::reveal_all().and(ty))
474 .unwrap_or_else(|e| if let LayoutError::SizeOverflow(_) = e {
475 self.sess().fatal(&e.to_string())
477 bug!("failed to get layout for `{}`: {}", ty, e)
482 /// Declare any llvm intrinsics that you might need
483 fn declare_intrinsic<Value : ?Sized>(
484 cx: &CodegenCx<'ll, '_, &'ll Value>,
486 ) -> Option<&'ll Value> where Value : ValueTrait {
488 ($name:expr, fn() -> $ret:expr) => (
490 let f = declare::declare_cfn(cx, $name, Type::func::<Value>(&[], $ret));
491 llvm::SetUnnamedAddr(f.to_llvm(), false);
492 cx.intrinsics.borrow_mut().insert($name, f.clone());
496 ($name:expr, fn(...) -> $ret:expr) => (
498 let f = declare::declare_cfn(cx, $name, Type::variadic_func::<Value>(&[], $ret));
499 llvm::SetUnnamedAddr(f.to_llvm(), false);
500 cx.intrinsics.borrow_mut().insert($name, f.clone());
504 ($name:expr, fn($($arg:expr),*) -> $ret:expr) => (
506 let f = declare::declare_cfn(cx, $name, Type::func::<Value>(&[$($arg),*], $ret));
507 llvm::SetUnnamedAddr(f.to_llvm(), false);
508 cx.intrinsics.borrow_mut().insert($name, f.clone());
513 macro_rules! mk_struct {
514 ($($field_ty:expr),*) => (Type::struct_(cx, &[$($field_ty),*], false))
517 let i8p = Type::i8p(cx);
518 let void = Type::void(cx);
519 let i1 = Type::i1(cx);
520 let t_i8 = Type::i8(cx);
521 let t_i16 = Type::i16(cx);
522 let t_i32 = Type::i32(cx);
523 let t_i64 = Type::i64(cx);
524 let t_i128 = Type::i128(cx);
525 let t_f32 = Type::f32(cx);
526 let t_f64 = Type::f64(cx);
528 let t_v2f32 = Type::vector::<Value>(t_f32, 2);
529 let t_v4f32 = Type::vector::<Value>(t_f32, 4);
530 let t_v8f32 = Type::vector::<Value>(t_f32, 8);
531 let t_v16f32 = Type::vector::<Value>(t_f32, 16);
533 let t_v2f64 = Type::vector::<Value>(t_f64, 2);
534 let t_v4f64 = Type::vector::<Value>(t_f64, 4);
535 let t_v8f64 = Type::vector::<Value>(t_f64, 8);
537 ifn!("llvm.memset.p0i8.i16", fn(i8p, t_i8, t_i16, t_i32, i1) -> void);
538 ifn!("llvm.memset.p0i8.i32", fn(i8p, t_i8, t_i32, t_i32, i1) -> void);
539 ifn!("llvm.memset.p0i8.i64", fn(i8p, t_i8, t_i64, t_i32, i1) -> void);
541 ifn!("llvm.trap", fn() -> void);
542 ifn!("llvm.debugtrap", fn() -> void);
543 ifn!("llvm.frameaddress", fn(t_i32) -> i8p);
545 ifn!("llvm.powi.f32", fn(t_f32, t_i32) -> t_f32);
546 ifn!("llvm.powi.v2f32", fn(t_v2f32, t_i32) -> t_v2f32);
547 ifn!("llvm.powi.v4f32", fn(t_v4f32, t_i32) -> t_v4f32);
548 ifn!("llvm.powi.v8f32", fn(t_v8f32, t_i32) -> t_v8f32);
549 ifn!("llvm.powi.v16f32", fn(t_v16f32, t_i32) -> t_v16f32);
550 ifn!("llvm.powi.f64", fn(t_f64, t_i32) -> t_f64);
551 ifn!("llvm.powi.v2f64", fn(t_v2f64, t_i32) -> t_v2f64);
552 ifn!("llvm.powi.v4f64", fn(t_v4f64, t_i32) -> t_v4f64);
553 ifn!("llvm.powi.v8f64", fn(t_v8f64, t_i32) -> t_v8f64);
555 ifn!("llvm.pow.f32", fn(t_f32, t_f32) -> t_f32);
556 ifn!("llvm.pow.v2f32", fn(t_v2f32, t_v2f32) -> t_v2f32);
557 ifn!("llvm.pow.v4f32", fn(t_v4f32, t_v4f32) -> t_v4f32);
558 ifn!("llvm.pow.v8f32", fn(t_v8f32, t_v8f32) -> t_v8f32);
559 ifn!("llvm.pow.v16f32", fn(t_v16f32, t_v16f32) -> t_v16f32);
560 ifn!("llvm.pow.f64", fn(t_f64, t_f64) -> t_f64);
561 ifn!("llvm.pow.v2f64", fn(t_v2f64, t_v2f64) -> t_v2f64);
562 ifn!("llvm.pow.v4f64", fn(t_v4f64, t_v4f64) -> t_v4f64);
563 ifn!("llvm.pow.v8f64", fn(t_v8f64, t_v8f64) -> t_v8f64);
565 ifn!("llvm.sqrt.f32", fn(t_f32) -> t_f32);
566 ifn!("llvm.sqrt.v2f32", fn(t_v2f32) -> t_v2f32);
567 ifn!("llvm.sqrt.v4f32", fn(t_v4f32) -> t_v4f32);
568 ifn!("llvm.sqrt.v8f32", fn(t_v8f32) -> t_v8f32);
569 ifn!("llvm.sqrt.v16f32", fn(t_v16f32) -> t_v16f32);
570 ifn!("llvm.sqrt.f64", fn(t_f64) -> t_f64);
571 ifn!("llvm.sqrt.v2f64", fn(t_v2f64) -> t_v2f64);
572 ifn!("llvm.sqrt.v4f64", fn(t_v4f64) -> t_v4f64);
573 ifn!("llvm.sqrt.v8f64", fn(t_v8f64) -> t_v8f64);
575 ifn!("llvm.sin.f32", fn(t_f32) -> t_f32);
576 ifn!("llvm.sin.v2f32", fn(t_v2f32) -> t_v2f32);
577 ifn!("llvm.sin.v4f32", fn(t_v4f32) -> t_v4f32);
578 ifn!("llvm.sin.v8f32", fn(t_v8f32) -> t_v8f32);
579 ifn!("llvm.sin.v16f32", fn(t_v16f32) -> t_v16f32);
580 ifn!("llvm.sin.f64", fn(t_f64) -> t_f64);
581 ifn!("llvm.sin.v2f64", fn(t_v2f64) -> t_v2f64);
582 ifn!("llvm.sin.v4f64", fn(t_v4f64) -> t_v4f64);
583 ifn!("llvm.sin.v8f64", fn(t_v8f64) -> t_v8f64);
585 ifn!("llvm.cos.f32", fn(t_f32) -> t_f32);
586 ifn!("llvm.cos.v2f32", fn(t_v2f32) -> t_v2f32);
587 ifn!("llvm.cos.v4f32", fn(t_v4f32) -> t_v4f32);
588 ifn!("llvm.cos.v8f32", fn(t_v8f32) -> t_v8f32);
589 ifn!("llvm.cos.v16f32", fn(t_v16f32) -> t_v16f32);
590 ifn!("llvm.cos.f64", fn(t_f64) -> t_f64);
591 ifn!("llvm.cos.v2f64", fn(t_v2f64) -> t_v2f64);
592 ifn!("llvm.cos.v4f64", fn(t_v4f64) -> t_v4f64);
593 ifn!("llvm.cos.v8f64", fn(t_v8f64) -> t_v8f64);
595 ifn!("llvm.exp.f32", fn(t_f32) -> t_f32);
596 ifn!("llvm.exp.v2f32", fn(t_v2f32) -> t_v2f32);
597 ifn!("llvm.exp.v4f32", fn(t_v4f32) -> t_v4f32);
598 ifn!("llvm.exp.v8f32", fn(t_v8f32) -> t_v8f32);
599 ifn!("llvm.exp.v16f32", fn(t_v16f32) -> t_v16f32);
600 ifn!("llvm.exp.f64", fn(t_f64) -> t_f64);
601 ifn!("llvm.exp.v2f64", fn(t_v2f64) -> t_v2f64);
602 ifn!("llvm.exp.v4f64", fn(t_v4f64) -> t_v4f64);
603 ifn!("llvm.exp.v8f64", fn(t_v8f64) -> t_v8f64);
605 ifn!("llvm.exp2.f32", fn(t_f32) -> t_f32);
606 ifn!("llvm.exp2.v2f32", fn(t_v2f32) -> t_v2f32);
607 ifn!("llvm.exp2.v4f32", fn(t_v4f32) -> t_v4f32);
608 ifn!("llvm.exp2.v8f32", fn(t_v8f32) -> t_v8f32);
609 ifn!("llvm.exp2.v16f32", fn(t_v16f32) -> t_v16f32);
610 ifn!("llvm.exp2.f64", fn(t_f64) -> t_f64);
611 ifn!("llvm.exp2.v2f64", fn(t_v2f64) -> t_v2f64);
612 ifn!("llvm.exp2.v4f64", fn(t_v4f64) -> t_v4f64);
613 ifn!("llvm.exp2.v8f64", fn(t_v8f64) -> t_v8f64);
615 ifn!("llvm.log.f32", fn(t_f32) -> t_f32);
616 ifn!("llvm.log.v2f32", fn(t_v2f32) -> t_v2f32);
617 ifn!("llvm.log.v4f32", fn(t_v4f32) -> t_v4f32);
618 ifn!("llvm.log.v8f32", fn(t_v8f32) -> t_v8f32);
619 ifn!("llvm.log.v16f32", fn(t_v16f32) -> t_v16f32);
620 ifn!("llvm.log.f64", fn(t_f64) -> t_f64);
621 ifn!("llvm.log.v2f64", fn(t_v2f64) -> t_v2f64);
622 ifn!("llvm.log.v4f64", fn(t_v4f64) -> t_v4f64);
623 ifn!("llvm.log.v8f64", fn(t_v8f64) -> t_v8f64);
625 ifn!("llvm.log10.f32", fn(t_f32) -> t_f32);
626 ifn!("llvm.log10.v2f32", fn(t_v2f32) -> t_v2f32);
627 ifn!("llvm.log10.v4f32", fn(t_v4f32) -> t_v4f32);
628 ifn!("llvm.log10.v8f32", fn(t_v8f32) -> t_v8f32);
629 ifn!("llvm.log10.v16f32", fn(t_v16f32) -> t_v16f32);
630 ifn!("llvm.log10.f64", fn(t_f64) -> t_f64);
631 ifn!("llvm.log10.v2f64", fn(t_v2f64) -> t_v2f64);
632 ifn!("llvm.log10.v4f64", fn(t_v4f64) -> t_v4f64);
633 ifn!("llvm.log10.v8f64", fn(t_v8f64) -> t_v8f64);
635 ifn!("llvm.log2.f32", fn(t_f32) -> t_f32);
636 ifn!("llvm.log2.v2f32", fn(t_v2f32) -> t_v2f32);
637 ifn!("llvm.log2.v4f32", fn(t_v4f32) -> t_v4f32);
638 ifn!("llvm.log2.v8f32", fn(t_v8f32) -> t_v8f32);
639 ifn!("llvm.log2.v16f32", fn(t_v16f32) -> t_v16f32);
640 ifn!("llvm.log2.f64", fn(t_f64) -> t_f64);
641 ifn!("llvm.log2.v2f64", fn(t_v2f64) -> t_v2f64);
642 ifn!("llvm.log2.v4f64", fn(t_v4f64) -> t_v4f64);
643 ifn!("llvm.log2.v8f64", fn(t_v8f64) -> t_v8f64);
645 ifn!("llvm.fma.f32", fn(t_f32, t_f32, t_f32) -> t_f32);
646 ifn!("llvm.fma.v2f32", fn(t_v2f32, t_v2f32, t_v2f32) -> t_v2f32);
647 ifn!("llvm.fma.v4f32", fn(t_v4f32, t_v4f32, t_v4f32) -> t_v4f32);
648 ifn!("llvm.fma.v8f32", fn(t_v8f32, t_v8f32, t_v8f32) -> t_v8f32);
649 ifn!("llvm.fma.v16f32", fn(t_v16f32, t_v16f32, t_v16f32) -> t_v16f32);
650 ifn!("llvm.fma.f64", fn(t_f64, t_f64, t_f64) -> t_f64);
651 ifn!("llvm.fma.v2f64", fn(t_v2f64, t_v2f64, t_v2f64) -> t_v2f64);
652 ifn!("llvm.fma.v4f64", fn(t_v4f64, t_v4f64, t_v4f64) -> t_v4f64);
653 ifn!("llvm.fma.v8f64", fn(t_v8f64, t_v8f64, t_v8f64) -> t_v8f64);
655 ifn!("llvm.fabs.f32", fn(t_f32) -> t_f32);
656 ifn!("llvm.fabs.v2f32", fn(t_v2f32) -> t_v2f32);
657 ifn!("llvm.fabs.v4f32", fn(t_v4f32) -> t_v4f32);
658 ifn!("llvm.fabs.v8f32", fn(t_v8f32) -> t_v8f32);
659 ifn!("llvm.fabs.v16f32", fn(t_v16f32) -> t_v16f32);
660 ifn!("llvm.fabs.f64", fn(t_f64) -> t_f64);
661 ifn!("llvm.fabs.v2f64", fn(t_v2f64) -> t_v2f64);
662 ifn!("llvm.fabs.v4f64", fn(t_v4f64) -> t_v4f64);
663 ifn!("llvm.fabs.v8f64", fn(t_v8f64) -> t_v8f64);
665 ifn!("llvm.floor.f32", fn(t_f32) -> t_f32);
666 ifn!("llvm.floor.v2f32", fn(t_v2f32) -> t_v2f32);
667 ifn!("llvm.floor.v4f32", fn(t_v4f32) -> t_v4f32);
668 ifn!("llvm.floor.v8f32", fn(t_v8f32) -> t_v8f32);
669 ifn!("llvm.floor.v16f32", fn(t_v16f32) -> t_v16f32);
670 ifn!("llvm.floor.f64", fn(t_f64) -> t_f64);
671 ifn!("llvm.floor.v2f64", fn(t_v2f64) -> t_v2f64);
672 ifn!("llvm.floor.v4f64", fn(t_v4f64) -> t_v4f64);
673 ifn!("llvm.floor.v8f64", fn(t_v8f64) -> t_v8f64);
675 ifn!("llvm.ceil.f32", fn(t_f32) -> t_f32);
676 ifn!("llvm.ceil.v2f32", fn(t_v2f32) -> t_v2f32);
677 ifn!("llvm.ceil.v4f32", fn(t_v4f32) -> t_v4f32);
678 ifn!("llvm.ceil.v8f32", fn(t_v8f32) -> t_v8f32);
679 ifn!("llvm.ceil.v16f32", fn(t_v16f32) -> t_v16f32);
680 ifn!("llvm.ceil.f64", fn(t_f64) -> t_f64);
681 ifn!("llvm.ceil.v2f64", fn(t_v2f64) -> t_v2f64);
682 ifn!("llvm.ceil.v4f64", fn(t_v4f64) -> t_v4f64);
683 ifn!("llvm.ceil.v8f64", fn(t_v8f64) -> t_v8f64);
685 ifn!("llvm.trunc.f32", fn(t_f32) -> t_f32);
686 ifn!("llvm.trunc.f64", fn(t_f64) -> t_f64);
688 ifn!("llvm.copysign.f32", fn(t_f32, t_f32) -> t_f32);
689 ifn!("llvm.copysign.f64", fn(t_f64, t_f64) -> t_f64);
690 ifn!("llvm.round.f32", fn(t_f32) -> t_f32);
691 ifn!("llvm.round.f64", fn(t_f64) -> t_f64);
693 ifn!("llvm.rint.f32", fn(t_f32) -> t_f32);
694 ifn!("llvm.rint.f64", fn(t_f64) -> t_f64);
695 ifn!("llvm.nearbyint.f32", fn(t_f32) -> t_f32);
696 ifn!("llvm.nearbyint.f64", fn(t_f64) -> t_f64);
698 ifn!("llvm.ctpop.i8", fn(t_i8) -> t_i8);
699 ifn!("llvm.ctpop.i16", fn(t_i16) -> t_i16);
700 ifn!("llvm.ctpop.i32", fn(t_i32) -> t_i32);
701 ifn!("llvm.ctpop.i64", fn(t_i64) -> t_i64);
702 ifn!("llvm.ctpop.i128", fn(t_i128) -> t_i128);
704 ifn!("llvm.ctlz.i8", fn(t_i8 , i1) -> t_i8);
705 ifn!("llvm.ctlz.i16", fn(t_i16, i1) -> t_i16);
706 ifn!("llvm.ctlz.i32", fn(t_i32, i1) -> t_i32);
707 ifn!("llvm.ctlz.i64", fn(t_i64, i1) -> t_i64);
708 ifn!("llvm.ctlz.i128", fn(t_i128, i1) -> t_i128);
710 ifn!("llvm.cttz.i8", fn(t_i8 , i1) -> t_i8);
711 ifn!("llvm.cttz.i16", fn(t_i16, i1) -> t_i16);
712 ifn!("llvm.cttz.i32", fn(t_i32, i1) -> t_i32);
713 ifn!("llvm.cttz.i64", fn(t_i64, i1) -> t_i64);
714 ifn!("llvm.cttz.i128", fn(t_i128, i1) -> t_i128);
716 ifn!("llvm.bswap.i16", fn(t_i16) -> t_i16);
717 ifn!("llvm.bswap.i32", fn(t_i32) -> t_i32);
718 ifn!("llvm.bswap.i64", fn(t_i64) -> t_i64);
719 ifn!("llvm.bswap.i128", fn(t_i128) -> t_i128);
721 ifn!("llvm.bitreverse.i8", fn(t_i8) -> t_i8);
722 ifn!("llvm.bitreverse.i16", fn(t_i16) -> t_i16);
723 ifn!("llvm.bitreverse.i32", fn(t_i32) -> t_i32);
724 ifn!("llvm.bitreverse.i64", fn(t_i64) -> t_i64);
725 ifn!("llvm.bitreverse.i128", fn(t_i128) -> t_i128);
727 ifn!("llvm.fshl.i8", fn(t_i8, t_i8, t_i8) -> t_i8);
728 ifn!("llvm.fshl.i16", fn(t_i16, t_i16, t_i16) -> t_i16);
729 ifn!("llvm.fshl.i32", fn(t_i32, t_i32, t_i32) -> t_i32);
730 ifn!("llvm.fshl.i64", fn(t_i64, t_i64, t_i64) -> t_i64);
731 ifn!("llvm.fshl.i128", fn(t_i128, t_i128, t_i128) -> t_i128);
733 ifn!("llvm.fshr.i8", fn(t_i8, t_i8, t_i8) -> t_i8);
734 ifn!("llvm.fshr.i16", fn(t_i16, t_i16, t_i16) -> t_i16);
735 ifn!("llvm.fshr.i32", fn(t_i32, t_i32, t_i32) -> t_i32);
736 ifn!("llvm.fshr.i64", fn(t_i64, t_i64, t_i64) -> t_i64);
737 ifn!("llvm.fshr.i128", fn(t_i128, t_i128, t_i128) -> t_i128);
739 ifn!("llvm.sadd.with.overflow.i8", fn(t_i8, t_i8) -> mk_struct!{t_i8, i1});
740 ifn!("llvm.sadd.with.overflow.i16", fn(t_i16, t_i16) -> mk_struct!{t_i16, i1});
741 ifn!("llvm.sadd.with.overflow.i32", fn(t_i32, t_i32) -> mk_struct!{t_i32, i1});
742 ifn!("llvm.sadd.with.overflow.i64", fn(t_i64, t_i64) -> mk_struct!{t_i64, i1});
743 ifn!("llvm.sadd.with.overflow.i128", fn(t_i128, t_i128) -> mk_struct!{t_i128, i1});
745 ifn!("llvm.uadd.with.overflow.i8", fn(t_i8, t_i8) -> mk_struct!{t_i8, i1});
746 ifn!("llvm.uadd.with.overflow.i16", fn(t_i16, t_i16) -> mk_struct!{t_i16, i1});
747 ifn!("llvm.uadd.with.overflow.i32", fn(t_i32, t_i32) -> mk_struct!{t_i32, i1});
748 ifn!("llvm.uadd.with.overflow.i64", fn(t_i64, t_i64) -> mk_struct!{t_i64, i1});
749 ifn!("llvm.uadd.with.overflow.i128", fn(t_i128, t_i128) -> mk_struct!{t_i128, i1});
751 ifn!("llvm.ssub.with.overflow.i8", fn(t_i8, t_i8) -> mk_struct!{t_i8, i1});
752 ifn!("llvm.ssub.with.overflow.i16", fn(t_i16, t_i16) -> mk_struct!{t_i16, i1});
753 ifn!("llvm.ssub.with.overflow.i32", fn(t_i32, t_i32) -> mk_struct!{t_i32, i1});
754 ifn!("llvm.ssub.with.overflow.i64", fn(t_i64, t_i64) -> mk_struct!{t_i64, i1});
755 ifn!("llvm.ssub.with.overflow.i128", fn(t_i128, t_i128) -> mk_struct!{t_i128, i1});
757 ifn!("llvm.usub.with.overflow.i8", fn(t_i8, t_i8) -> mk_struct!{t_i8, i1});
758 ifn!("llvm.usub.with.overflow.i16", fn(t_i16, t_i16) -> mk_struct!{t_i16, i1});
759 ifn!("llvm.usub.with.overflow.i32", fn(t_i32, t_i32) -> mk_struct!{t_i32, i1});
760 ifn!("llvm.usub.with.overflow.i64", fn(t_i64, t_i64) -> mk_struct!{t_i64, i1});
761 ifn!("llvm.usub.with.overflow.i128", fn(t_i128, t_i128) -> mk_struct!{t_i128, i1});
763 ifn!("llvm.smul.with.overflow.i8", fn(t_i8, t_i8) -> mk_struct!{t_i8, i1});
764 ifn!("llvm.smul.with.overflow.i16", fn(t_i16, t_i16) -> mk_struct!{t_i16, i1});
765 ifn!("llvm.smul.with.overflow.i32", fn(t_i32, t_i32) -> mk_struct!{t_i32, i1});
766 ifn!("llvm.smul.with.overflow.i64", fn(t_i64, t_i64) -> mk_struct!{t_i64, i1});
767 ifn!("llvm.smul.with.overflow.i128", fn(t_i128, t_i128) -> mk_struct!{t_i128, i1});
769 ifn!("llvm.umul.with.overflow.i8", fn(t_i8, t_i8) -> mk_struct!{t_i8, i1});
770 ifn!("llvm.umul.with.overflow.i16", fn(t_i16, t_i16) -> mk_struct!{t_i16, i1});
771 ifn!("llvm.umul.with.overflow.i32", fn(t_i32, t_i32) -> mk_struct!{t_i32, i1});
772 ifn!("llvm.umul.with.overflow.i64", fn(t_i64, t_i64) -> mk_struct!{t_i64, i1});
773 ifn!("llvm.umul.with.overflow.i128", fn(t_i128, t_i128) -> mk_struct!{t_i128, i1});
775 ifn!("llvm.lifetime.start", fn(t_i64,i8p) -> void);
776 ifn!("llvm.lifetime.end", fn(t_i64, i8p) -> void);
778 ifn!("llvm.expect.i1", fn(i1, i1) -> i1);
779 ifn!("llvm.eh.typeid.for", fn(i8p) -> t_i32);
780 ifn!("llvm.localescape", fn(...) -> void);
781 ifn!("llvm.localrecover", fn(i8p, i8p, t_i32) -> i8p);
782 ifn!("llvm.x86.seh.recoverfp", fn(i8p, i8p) -> i8p);
784 ifn!("llvm.assume", fn(i1) -> void);
785 ifn!("llvm.prefetch", fn(i8p, t_i32, t_i32, t_i32) -> void);
787 if cx.sess().opts.debuginfo != DebugInfo::None {
788 ifn!("llvm.dbg.declare", fn(Type::metadata(cx), Type::metadata(cx)) -> void);
789 ifn!("llvm.dbg.value", fn(Type::metadata(cx), t_i64, Type::metadata(cx)) -> void);