]> git.lizzy.rs Git - rust.git/blob - src/librustc_codegen_llvm/context.rs
Normalize DebugInfoLevel to standard style
[rust.git] / src / librustc_codegen_llvm / context.rs
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.
4 //
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.
10
11 use common;
12 use llvm;
13 use rustc::dep_graph::DepGraphSafe;
14 use rustc::hir;
15 use rustc::hir::def_id::DefId;
16 use debuginfo;
17 use callee;
18 use base;
19 use declare;
20 use monomorphize::Instance;
21 use value::Value;
22
23 use monomorphize::partitioning::CodegenUnit;
24 use type_::Type;
25 use type_of::PointeeInfo;
26
27 use rustc_data_structures::base_n;
28 use rustc::mir::mono::Stats;
29 use rustc::session::config::{self, DebugInfo};
30 use rustc::session::Session;
31 use rustc::ty::layout::{LayoutError, LayoutOf, Size, TyLayout};
32 use rustc::ty::{self, Ty, TyCtxt};
33 use rustc::util::nodemap::FxHashMap;
34 use rustc_target::spec::{HasTargetSpec, Target};
35
36 use std::ffi::{CStr, CString};
37 use std::cell::{Cell, RefCell};
38 use std::iter;
39 use std::str;
40 use std::sync::Arc;
41 use syntax::symbol::LocalInternedString;
42 use abi::Abi;
43
44 /// There is one `CodegenCx` per compilation unit. Each one has its own LLVM
45 /// `llvm::Context` so that several compilation units may be optimized in parallel.
46 /// All other LLVM data structures in the `CodegenCx` are tied to that `llvm::Context`.
47 pub struct CodegenCx<'a, 'tcx: 'a> {
48     pub tcx: TyCtxt<'a, 'tcx, 'tcx>,
49     pub check_overflow: bool,
50     pub use_dll_storage_attrs: bool,
51     pub tls_model: llvm::ThreadLocalMode,
52
53     pub llmod: &'a llvm::Module,
54     pub llcx: &'a llvm::Context,
55     pub stats: RefCell<Stats>,
56     pub codegen_unit: Arc<CodegenUnit<'tcx>>,
57
58     /// Cache instances of monomorphic and polymorphic items
59     pub instances: RefCell<FxHashMap<Instance<'tcx>, &'a Value>>,
60     /// Cache generated vtables
61     pub vtables: RefCell<FxHashMap<(Ty<'tcx>,
62                                 Option<ty::PolyExistentialTraitRef<'tcx>>), &'a Value>>,
63     /// Cache of constant strings,
64     pub const_cstr_cache: RefCell<FxHashMap<LocalInternedString, &'a Value>>,
65
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].
69     ///
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<&'a Value, &'a Value>>,
75
76     /// Cache of emitted const globals (value -> global)
77     pub const_globals: RefCell<FxHashMap<&'a Value, &'a Value>>,
78
79     /// Mapping from static definitions to their DefId's.
80     pub statics: RefCell<FxHashMap<&'a Value, DefId>>,
81
82     /// List of globals for static variables which need to be passed to the
83     /// LLVM function ReplaceAllUsesWith (RAUW) when codegen is complete.
84     /// (We have to make sure we don't invalidate any Values referring
85     /// to constants.)
86     pub statics_to_rauw: RefCell<Vec<(&'a Value, &'a Value)>>,
87
88     /// Statics that will be placed in the llvm.used variable
89     /// See http://llvm.org/docs/LangRef.html#the-llvm-used-global-variable for details
90     pub used_statics: RefCell<Vec<&'a Value>>,
91
92     pub lltypes: RefCell<FxHashMap<(Ty<'tcx>, Option<usize>), &'a Type>>,
93     pub scalar_lltypes: RefCell<FxHashMap<Ty<'tcx>, &'a Type>>,
94     pub pointee_infos: RefCell<FxHashMap<(Ty<'tcx>, Size), Option<PointeeInfo>>>,
95     pub isize_ty: &'a Type,
96
97     pub dbg_cx: Option<debuginfo::CrateDebugContext<'a, 'tcx>>,
98
99     eh_personality: Cell<Option<&'a Value>>,
100     eh_unwind_resume: Cell<Option<&'a Value>>,
101     pub rust_try_fn: Cell<Option<&'a Value>>,
102
103     intrinsics: RefCell<FxHashMap<&'static str, &'a Value>>,
104
105     /// A counter that is used for generating local symbol names
106     local_gen_sym_counter: Cell<usize>,
107 }
108
109 impl<'a, 'tcx> DepGraphSafe for CodegenCx<'a, 'tcx> {
110 }
111
112 pub fn get_reloc_model(sess: &Session) -> llvm::RelocMode {
113     let reloc_model_arg = match sess.opts.cg.relocation_model {
114         Some(ref s) => &s[..],
115         None => &sess.target.target.options.relocation_model[..],
116     };
117
118     match ::back::write::RELOC_MODEL_ARGS.iter().find(
119         |&&arg| arg.0 == reloc_model_arg) {
120         Some(x) => x.1,
121         _ => {
122             sess.err(&format!("{:?} is not a valid relocation mode",
123                               reloc_model_arg));
124             sess.abort_if_errors();
125             bug!();
126         }
127     }
128 }
129
130 fn get_tls_model(sess: &Session) -> llvm::ThreadLocalMode {
131     let tls_model_arg = match sess.opts.debugging_opts.tls_model {
132         Some(ref s) => &s[..],
133         None => &sess.target.target.options.tls_model[..],
134     };
135
136     match ::back::write::TLS_MODEL_ARGS.iter().find(
137         |&&arg| arg.0 == tls_model_arg) {
138         Some(x) => x.1,
139         _ => {
140             sess.err(&format!("{:?} is not a valid TLS model",
141                               tls_model_arg));
142             sess.abort_if_errors();
143             bug!();
144         }
145     }
146 }
147
148 fn is_any_library(sess: &Session) -> bool {
149     sess.crate_types.borrow().iter().any(|ty| {
150         *ty != config::CrateType::Executable
151     })
152 }
153
154 pub fn is_pie_binary(sess: &Session) -> bool {
155     !is_any_library(sess) && get_reloc_model(sess) == llvm::RelocMode::PIC
156 }
157
158 pub unsafe fn create_module(
159     sess: &Session,
160     llcx: &'ll llvm::Context,
161     mod_name: &str,
162 ) -> &'ll llvm::Module {
163     let mod_name = CString::new(mod_name).unwrap();
164     let llmod = llvm::LLVMModuleCreateWithNameInContext(mod_name.as_ptr(), llcx);
165
166     // Ensure the data-layout values hardcoded remain the defaults.
167     if sess.target.target.options.is_builtin {
168         let tm = ::back::write::create_target_machine(sess, false);
169         llvm::LLVMRustSetDataLayoutFromTargetMachine(llmod, tm);
170         llvm::LLVMRustDisposeTargetMachine(tm);
171
172         let data_layout = llvm::LLVMGetDataLayout(llmod);
173         let data_layout = str::from_utf8(CStr::from_ptr(data_layout).to_bytes())
174             .ok().expect("got a non-UTF8 data-layout from LLVM");
175
176         // Unfortunately LLVM target specs change over time, and right now we
177         // don't have proper support to work with any more than one
178         // `data_layout` than the one that is in the rust-lang/rust repo. If
179         // this compiler is configured against a custom LLVM, we may have a
180         // differing data layout, even though we should update our own to use
181         // that one.
182         //
183         // As an interim hack, if CFG_LLVM_ROOT is not an empty string then we
184         // disable this check entirely as we may be configured with something
185         // that has a different target layout.
186         //
187         // Unsure if this will actually cause breakage when rustc is configured
188         // as such.
189         //
190         // FIXME(#34960)
191         let cfg_llvm_root = option_env!("CFG_LLVM_ROOT").unwrap_or("");
192         let custom_llvm_used = cfg_llvm_root.trim() != "";
193
194         if !custom_llvm_used && sess.target.target.data_layout != data_layout {
195             bug!("data-layout for builtin `{}` target, `{}`, \
196                   differs from LLVM default, `{}`",
197                  sess.target.target.llvm_target,
198                  sess.target.target.data_layout,
199                  data_layout);
200         }
201     }
202
203     let data_layout = CString::new(&sess.target.target.data_layout[..]).unwrap();
204     llvm::LLVMSetDataLayout(llmod, data_layout.as_ptr());
205
206     let llvm_target = sess.target.target.llvm_target.as_bytes();
207     let llvm_target = CString::new(llvm_target).unwrap();
208     llvm::LLVMRustSetNormalizedTarget(llmod, llvm_target.as_ptr());
209
210     if is_pie_binary(sess) {
211         llvm::LLVMRustSetModulePIELevel(llmod);
212     }
213
214     llmod
215 }
216
217 impl<'a, 'tcx> CodegenCx<'a, 'tcx> {
218     crate fn new(tcx: TyCtxt<'a, 'tcx, 'tcx>,
219                codegen_unit: Arc<CodegenUnit<'tcx>>,
220                llvm_module: &'a ::ModuleLlvm)
221                -> CodegenCx<'a, 'tcx> {
222         // An interesting part of Windows which MSVC forces our hand on (and
223         // apparently MinGW didn't) is the usage of `dllimport` and `dllexport`
224         // attributes in LLVM IR as well as native dependencies (in C these
225         // correspond to `__declspec(dllimport)`).
226         //
227         // Whenever a dynamic library is built by MSVC it must have its public
228         // interface specified by functions tagged with `dllexport` or otherwise
229         // they're not available to be linked against. This poses a few problems
230         // for the compiler, some of which are somewhat fundamental, but we use
231         // the `use_dll_storage_attrs` variable below to attach the `dllexport`
232         // attribute to all LLVM functions that are exported e.g. they're
233         // already tagged with external linkage). This is suboptimal for a few
234         // reasons:
235         //
236         // * If an object file will never be included in a dynamic library,
237         //   there's no need to attach the dllexport attribute. Most object
238         //   files in Rust are not destined to become part of a dll as binaries
239         //   are statically linked by default.
240         // * If the compiler is emitting both an rlib and a dylib, the same
241         //   source object file is currently used but with MSVC this may be less
242         //   feasible. The compiler may be able to get around this, but it may
243         //   involve some invasive changes to deal with this.
244         //
245         // The flipside of this situation is that whenever you link to a dll and
246         // you import a function from it, the import should be tagged with
247         // `dllimport`. At this time, however, the compiler does not emit
248         // `dllimport` for any declarations other than constants (where it is
249         // required), which is again suboptimal for even more reasons!
250         //
251         // * Calling a function imported from another dll without using
252         //   `dllimport` causes the linker/compiler to have extra overhead (one
253         //   `jmp` instruction on x86) when calling the function.
254         // * The same object file may be used in different circumstances, so a
255         //   function may be imported from a dll if the object is linked into a
256         //   dll, but it may be just linked against if linked into an rlib.
257         // * The compiler has no knowledge about whether native functions should
258         //   be tagged dllimport or not.
259         //
260         // For now the compiler takes the perf hit (I do not have any numbers to
261         // this effect) by marking very little as `dllimport` and praying the
262         // linker will take care of everything. Fixing this problem will likely
263         // require adding a few attributes to Rust itself (feature gated at the
264         // start) and then strongly recommending static linkage on MSVC!
265         let use_dll_storage_attrs = tcx.sess.target.target.options.is_like_msvc;
266
267         let check_overflow = tcx.sess.overflow_checks();
268
269         let tls_model = get_tls_model(&tcx.sess);
270
271         let (llcx, llmod) = (&*llvm_module.llcx, llvm_module.llmod());
272
273         let dbg_cx = if tcx.sess.opts.debuginfo != DebugInfo::None {
274             let dctx = debuginfo::CrateDebugContext::new(llmod);
275             debuginfo::metadata::compile_unit_metadata(tcx,
276                                                         &codegen_unit.name().as_str(),
277                                                         &dctx);
278             Some(dctx)
279         } else {
280             None
281         };
282
283         let isize_ty = Type::ix_llcx(llcx, tcx.data_layout.pointer_size.bits());
284
285         CodegenCx {
286             tcx,
287             check_overflow,
288             use_dll_storage_attrs,
289             tls_model,
290             llmod,
291             llcx,
292             stats: RefCell::new(Stats::default()),
293             codegen_unit,
294             instances: RefCell::new(FxHashMap()),
295             vtables: RefCell::new(FxHashMap()),
296             const_cstr_cache: RefCell::new(FxHashMap()),
297             const_unsized: RefCell::new(FxHashMap()),
298             const_globals: RefCell::new(FxHashMap()),
299             statics: RefCell::new(FxHashMap()),
300             statics_to_rauw: RefCell::new(Vec::new()),
301             used_statics: RefCell::new(Vec::new()),
302             lltypes: RefCell::new(FxHashMap()),
303             scalar_lltypes: RefCell::new(FxHashMap()),
304             pointee_infos: RefCell::new(FxHashMap()),
305             isize_ty,
306             dbg_cx,
307             eh_personality: Cell::new(None),
308             eh_unwind_resume: Cell::new(None),
309             rust_try_fn: Cell::new(None),
310             intrinsics: RefCell::new(FxHashMap()),
311             local_gen_sym_counter: Cell::new(0),
312         }
313     }
314 }
315
316 impl<'b, 'tcx> CodegenCx<'b, 'tcx> {
317     pub fn sess<'a>(&'a self) -> &'a Session {
318         &self.tcx.sess
319     }
320
321     pub fn get_intrinsic(&self, key: &str) -> &'b Value {
322         if let Some(v) = self.intrinsics.borrow().get(key).cloned() {
323             return v;
324         }
325         match declare_intrinsic(self, key) {
326             Some(v) => return v,
327             None => bug!("unknown intrinsic '{}'", key)
328         }
329     }
330
331     /// Generate a new symbol name with the given prefix. This symbol name must
332     /// only be used for definitions with `internal` or `private` linkage.
333     pub fn generate_local_symbol_name(&self, prefix: &str) -> String {
334         let idx = self.local_gen_sym_counter.get();
335         self.local_gen_sym_counter.set(idx + 1);
336         // Include a '.' character, so there can be no accidental conflicts with
337         // user defined names
338         let mut name = String::with_capacity(prefix.len() + 6);
339         name.push_str(prefix);
340         name.push_str(".");
341         base_n::push_str(idx as u128, base_n::ALPHANUMERIC_ONLY, &mut name);
342         name
343     }
344
345     pub fn eh_personality(&self) -> &'b Value {
346         // The exception handling personality function.
347         //
348         // If our compilation unit has the `eh_personality` lang item somewhere
349         // within it, then we just need to codegen that. Otherwise, we're
350         // building an rlib which will depend on some upstream implementation of
351         // this function, so we just codegen a generic reference to it. We don't
352         // specify any of the types for the function, we just make it a symbol
353         // that LLVM can later use.
354         //
355         // Note that MSVC is a little special here in that we don't use the
356         // `eh_personality` lang item at all. Currently LLVM has support for
357         // both Dwarf and SEH unwind mechanisms for MSVC targets and uses the
358         // *name of the personality function* to decide what kind of unwind side
359         // tables/landing pads to emit. It looks like Dwarf is used by default,
360         // injecting a dependency on the `_Unwind_Resume` symbol for resuming
361         // an "exception", but for MSVC we want to force SEH. This means that we
362         // can't actually have the personality function be our standard
363         // `rust_eh_personality` function, but rather we wired it up to the
364         // CRT's custom personality function, which forces LLVM to consider
365         // landing pads as "landing pads for SEH".
366         if let Some(llpersonality) = self.eh_personality.get() {
367             return llpersonality
368         }
369         let tcx = self.tcx;
370         let llfn = match tcx.lang_items().eh_personality() {
371             Some(def_id) if !base::wants_msvc_seh(self.sess()) => {
372                 callee::resolve_and_get_fn(self, def_id, tcx.intern_substs(&[]))
373             }
374             _ => {
375                 let name = if base::wants_msvc_seh(self.sess()) {
376                     "__CxxFrameHandler3"
377                 } else {
378                     "rust_eh_personality"
379                 };
380                 let fty = Type::variadic_func(&[], Type::i32(self));
381                 declare::declare_cfn(self, name, fty)
382             }
383         };
384         self.eh_personality.set(Some(llfn));
385         llfn
386     }
387
388     // Returns a Value of the "eh_unwind_resume" lang item if one is defined,
389     // otherwise declares it as an external function.
390     pub fn eh_unwind_resume(&self) -> &'b Value {
391         use attributes;
392         let unwresume = &self.eh_unwind_resume;
393         if let Some(llfn) = unwresume.get() {
394             return llfn;
395         }
396
397         let tcx = self.tcx;
398         assert!(self.sess().target.target.options.custom_unwind_resume);
399         if let Some(def_id) = tcx.lang_items().eh_unwind_resume() {
400             let llfn = callee::resolve_and_get_fn(self, def_id, tcx.intern_substs(&[]));
401             unwresume.set(Some(llfn));
402             return llfn;
403         }
404
405         let ty = tcx.mk_fn_ptr(ty::Binder::bind(tcx.mk_fn_sig(
406             iter::once(tcx.mk_mut_ptr(tcx.types.u8)),
407             tcx.types.never,
408             false,
409             hir::Unsafety::Unsafe,
410             Abi::C
411         )));
412
413         let llfn = declare::declare_fn(self, "rust_eh_unwind_resume", ty);
414         attributes::unwind(llfn, true);
415         unwresume.set(Some(llfn));
416         llfn
417     }
418
419     pub fn type_needs_drop(&self, ty: Ty<'tcx>) -> bool {
420         common::type_needs_drop(self.tcx, ty)
421     }
422
423     pub fn type_is_sized(&self, ty: Ty<'tcx>) -> bool {
424         common::type_is_sized(self.tcx, ty)
425     }
426
427     pub fn type_is_freeze(&self, ty: Ty<'tcx>) -> bool {
428         common::type_is_freeze(self.tcx, ty)
429     }
430
431     pub fn type_has_metadata(&self, ty: Ty<'tcx>) -> bool {
432         use syntax_pos::DUMMY_SP;
433         if ty.is_sized(self.tcx.at(DUMMY_SP), ty::ParamEnv::reveal_all()) {
434             return false;
435         }
436
437         let tail = self.tcx.struct_tail(ty);
438         match tail.sty {
439             ty::TyForeign(..) => false,
440             ty::TyStr | ty::TySlice(..) | ty::TyDynamic(..) => true,
441             _ => bug!("unexpected unsized tail: {:?}", tail.sty),
442         }
443     }
444 }
445
446 impl ty::layout::HasDataLayout for &'a CodegenCx<'ll, 'tcx> {
447     fn data_layout(&self) -> &ty::layout::TargetDataLayout {
448         &self.tcx.data_layout
449     }
450 }
451
452 impl HasTargetSpec for &'a CodegenCx<'ll, 'tcx> {
453     fn target_spec(&self) -> &Target {
454         &self.tcx.sess.target.target
455     }
456 }
457
458 impl ty::layout::HasTyCtxt<'tcx> for &'a CodegenCx<'ll, 'tcx> {
459     fn tcx<'b>(&'b self) -> TyCtxt<'b, 'tcx, 'tcx> {
460         self.tcx
461     }
462 }
463
464 impl LayoutOf for &'a CodegenCx<'ll, 'tcx> {
465     type Ty = Ty<'tcx>;
466     type TyLayout = TyLayout<'tcx>;
467
468     fn layout_of(self, ty: Ty<'tcx>) -> Self::TyLayout {
469         self.tcx.layout_of(ty::ParamEnv::reveal_all().and(ty))
470             .unwrap_or_else(|e| match e {
471                 LayoutError::SizeOverflow(_) => self.sess().fatal(&e.to_string()),
472                 _ => bug!("failed to get layout for `{}`: {}", ty, e)
473             })
474     }
475 }
476
477 /// Declare any llvm intrinsics that you might need
478 fn declare_intrinsic(cx: &CodegenCx<'ll, '_>, key: &str) -> Option<&'ll Value> {
479     macro_rules! ifn {
480         ($name:expr, fn() -> $ret:expr) => (
481             if key == $name {
482                 let f = declare::declare_cfn(cx, $name, Type::func(&[], $ret));
483                 llvm::SetUnnamedAddr(f, false);
484                 cx.intrinsics.borrow_mut().insert($name, f.clone());
485                 return Some(f);
486             }
487         );
488         ($name:expr, fn(...) -> $ret:expr) => (
489             if key == $name {
490                 let f = declare::declare_cfn(cx, $name, Type::variadic_func(&[], $ret));
491                 llvm::SetUnnamedAddr(f, false);
492                 cx.intrinsics.borrow_mut().insert($name, f.clone());
493                 return Some(f);
494             }
495         );
496         ($name:expr, fn($($arg:expr),*) -> $ret:expr) => (
497             if key == $name {
498                 let f = declare::declare_cfn(cx, $name, Type::func(&[$($arg),*], $ret));
499                 llvm::SetUnnamedAddr(f, false);
500                 cx.intrinsics.borrow_mut().insert($name, f.clone());
501                 return Some(f);
502             }
503         );
504     }
505     macro_rules! mk_struct {
506         ($($field_ty:expr),*) => (Type::struct_(cx, &[$($field_ty),*], false))
507     }
508
509     let i8p = Type::i8p(cx);
510     let void = Type::void(cx);
511     let i1 = Type::i1(cx);
512     let t_i8 = Type::i8(cx);
513     let t_i16 = Type::i16(cx);
514     let t_i32 = Type::i32(cx);
515     let t_i64 = Type::i64(cx);
516     let t_i128 = Type::i128(cx);
517     let t_f32 = Type::f32(cx);
518     let t_f64 = Type::f64(cx);
519
520     let t_v2f32 = Type::vector(t_f32, 2);
521     let t_v4f32 = Type::vector(t_f32, 4);
522     let t_v8f32 = Type::vector(t_f32, 8);
523     let t_v16f32 = Type::vector(t_f32, 16);
524
525     let t_v2f64 = Type::vector(t_f64, 2);
526     let t_v4f64 = Type::vector(t_f64, 4);
527     let t_v8f64 = Type::vector(t_f64, 8);
528
529     ifn!("llvm.memcpy.p0i8.p0i8.i16", fn(i8p, i8p, t_i16, t_i32, i1) -> void);
530     ifn!("llvm.memcpy.p0i8.p0i8.i32", fn(i8p, i8p, t_i32, t_i32, i1) -> void);
531     ifn!("llvm.memcpy.p0i8.p0i8.i64", fn(i8p, i8p, t_i64, t_i32, i1) -> void);
532     ifn!("llvm.memmove.p0i8.p0i8.i16", fn(i8p, i8p, t_i16, t_i32, i1) -> void);
533     ifn!("llvm.memmove.p0i8.p0i8.i32", fn(i8p, i8p, t_i32, t_i32, i1) -> void);
534     ifn!("llvm.memmove.p0i8.p0i8.i64", fn(i8p, i8p, t_i64, t_i32, i1) -> void);
535     ifn!("llvm.memset.p0i8.i16", fn(i8p, t_i8, t_i16, t_i32, i1) -> void);
536     ifn!("llvm.memset.p0i8.i32", fn(i8p, t_i8, t_i32, t_i32, i1) -> void);
537     ifn!("llvm.memset.p0i8.i64", fn(i8p, t_i8, t_i64, t_i32, i1) -> void);
538
539     ifn!("llvm.trap", fn() -> void);
540     ifn!("llvm.debugtrap", fn() -> void);
541     ifn!("llvm.frameaddress", fn(t_i32) -> i8p);
542
543     ifn!("llvm.powi.f32", fn(t_f32, t_i32) -> t_f32);
544     ifn!("llvm.powi.v2f32", fn(t_v2f32, t_i32) -> t_v2f32);
545     ifn!("llvm.powi.v4f32", fn(t_v4f32, t_i32) -> t_v4f32);
546     ifn!("llvm.powi.v8f32", fn(t_v8f32, t_i32) -> t_v8f32);
547     ifn!("llvm.powi.v16f32", fn(t_v16f32, t_i32) -> t_v16f32);
548     ifn!("llvm.powi.f64", fn(t_f64, t_i32) -> t_f64);
549     ifn!("llvm.powi.v2f64", fn(t_v2f64, t_i32) -> t_v2f64);
550     ifn!("llvm.powi.v4f64", fn(t_v4f64, t_i32) -> t_v4f64);
551     ifn!("llvm.powi.v8f64", fn(t_v8f64, t_i32) -> t_v8f64);
552
553     ifn!("llvm.pow.f32", fn(t_f32, t_f32) -> t_f32);
554     ifn!("llvm.pow.v2f32", fn(t_v2f32, t_v2f32) -> t_v2f32);
555     ifn!("llvm.pow.v4f32", fn(t_v4f32, t_v4f32) -> t_v4f32);
556     ifn!("llvm.pow.v8f32", fn(t_v8f32, t_v8f32) -> t_v8f32);
557     ifn!("llvm.pow.v16f32", fn(t_v16f32, t_v16f32) -> t_v16f32);
558     ifn!("llvm.pow.f64", fn(t_f64, t_f64) -> t_f64);
559     ifn!("llvm.pow.v2f64", fn(t_v2f64, t_v2f64) -> t_v2f64);
560     ifn!("llvm.pow.v4f64", fn(t_v4f64, t_v4f64) -> t_v4f64);
561     ifn!("llvm.pow.v8f64", fn(t_v8f64, t_v8f64) -> t_v8f64);
562
563     ifn!("llvm.sqrt.f32", fn(t_f32) -> t_f32);
564     ifn!("llvm.sqrt.v2f32", fn(t_v2f32) -> t_v2f32);
565     ifn!("llvm.sqrt.v4f32", fn(t_v4f32) -> t_v4f32);
566     ifn!("llvm.sqrt.v8f32", fn(t_v8f32) -> t_v8f32);
567     ifn!("llvm.sqrt.v16f32", fn(t_v16f32) -> t_v16f32);
568     ifn!("llvm.sqrt.f64", fn(t_f64) -> t_f64);
569     ifn!("llvm.sqrt.v2f64", fn(t_v2f64) -> t_v2f64);
570     ifn!("llvm.sqrt.v4f64", fn(t_v4f64) -> t_v4f64);
571     ifn!("llvm.sqrt.v8f64", fn(t_v8f64) -> t_v8f64);
572
573     ifn!("llvm.sin.f32", fn(t_f32) -> t_f32);
574     ifn!("llvm.sin.v2f32", fn(t_v2f32) -> t_v2f32);
575     ifn!("llvm.sin.v4f32", fn(t_v4f32) -> t_v4f32);
576     ifn!("llvm.sin.v8f32", fn(t_v8f32) -> t_v8f32);
577     ifn!("llvm.sin.v16f32", fn(t_v16f32) -> t_v16f32);
578     ifn!("llvm.sin.f64", fn(t_f64) -> t_f64);
579     ifn!("llvm.sin.v2f64", fn(t_v2f64) -> t_v2f64);
580     ifn!("llvm.sin.v4f64", fn(t_v4f64) -> t_v4f64);
581     ifn!("llvm.sin.v8f64", fn(t_v8f64) -> t_v8f64);
582
583     ifn!("llvm.cos.f32", fn(t_f32) -> t_f32);
584     ifn!("llvm.cos.v2f32", fn(t_v2f32) -> t_v2f32);
585     ifn!("llvm.cos.v4f32", fn(t_v4f32) -> t_v4f32);
586     ifn!("llvm.cos.v8f32", fn(t_v8f32) -> t_v8f32);
587     ifn!("llvm.cos.v16f32", fn(t_v16f32) -> t_v16f32);
588     ifn!("llvm.cos.f64", fn(t_f64) -> t_f64);
589     ifn!("llvm.cos.v2f64", fn(t_v2f64) -> t_v2f64);
590     ifn!("llvm.cos.v4f64", fn(t_v4f64) -> t_v4f64);
591     ifn!("llvm.cos.v8f64", fn(t_v8f64) -> t_v8f64);
592
593     ifn!("llvm.exp.f32", fn(t_f32) -> t_f32);
594     ifn!("llvm.exp.v2f32", fn(t_v2f32) -> t_v2f32);
595     ifn!("llvm.exp.v4f32", fn(t_v4f32) -> t_v4f32);
596     ifn!("llvm.exp.v8f32", fn(t_v8f32) -> t_v8f32);
597     ifn!("llvm.exp.v16f32", fn(t_v16f32) -> t_v16f32);
598     ifn!("llvm.exp.f64", fn(t_f64) -> t_f64);
599     ifn!("llvm.exp.v2f64", fn(t_v2f64) -> t_v2f64);
600     ifn!("llvm.exp.v4f64", fn(t_v4f64) -> t_v4f64);
601     ifn!("llvm.exp.v8f64", fn(t_v8f64) -> t_v8f64);
602
603     ifn!("llvm.exp2.f32", fn(t_f32) -> t_f32);
604     ifn!("llvm.exp2.v2f32", fn(t_v2f32) -> t_v2f32);
605     ifn!("llvm.exp2.v4f32", fn(t_v4f32) -> t_v4f32);
606     ifn!("llvm.exp2.v8f32", fn(t_v8f32) -> t_v8f32);
607     ifn!("llvm.exp2.v16f32", fn(t_v16f32) -> t_v16f32);
608     ifn!("llvm.exp2.f64", fn(t_f64) -> t_f64);
609     ifn!("llvm.exp2.v2f64", fn(t_v2f64) -> t_v2f64);
610     ifn!("llvm.exp2.v4f64", fn(t_v4f64) -> t_v4f64);
611     ifn!("llvm.exp2.v8f64", fn(t_v8f64) -> t_v8f64);
612
613     ifn!("llvm.log.f32", fn(t_f32) -> t_f32);
614     ifn!("llvm.log.v2f32", fn(t_v2f32) -> t_v2f32);
615     ifn!("llvm.log.v4f32", fn(t_v4f32) -> t_v4f32);
616     ifn!("llvm.log.v8f32", fn(t_v8f32) -> t_v8f32);
617     ifn!("llvm.log.v16f32", fn(t_v16f32) -> t_v16f32);
618     ifn!("llvm.log.f64", fn(t_f64) -> t_f64);
619     ifn!("llvm.log.v2f64", fn(t_v2f64) -> t_v2f64);
620     ifn!("llvm.log.v4f64", fn(t_v4f64) -> t_v4f64);
621     ifn!("llvm.log.v8f64", fn(t_v8f64) -> t_v8f64);
622
623     ifn!("llvm.log10.f32", fn(t_f32) -> t_f32);
624     ifn!("llvm.log10.v2f32", fn(t_v2f32) -> t_v2f32);
625     ifn!("llvm.log10.v4f32", fn(t_v4f32) -> t_v4f32);
626     ifn!("llvm.log10.v8f32", fn(t_v8f32) -> t_v8f32);
627     ifn!("llvm.log10.v16f32", fn(t_v16f32) -> t_v16f32);
628     ifn!("llvm.log10.f64", fn(t_f64) -> t_f64);
629     ifn!("llvm.log10.v2f64", fn(t_v2f64) -> t_v2f64);
630     ifn!("llvm.log10.v4f64", fn(t_v4f64) -> t_v4f64);
631     ifn!("llvm.log10.v8f64", fn(t_v8f64) -> t_v8f64);
632
633     ifn!("llvm.log2.f32", fn(t_f32) -> t_f32);
634     ifn!("llvm.log2.v2f32", fn(t_v2f32) -> t_v2f32);
635     ifn!("llvm.log2.v4f32", fn(t_v4f32) -> t_v4f32);
636     ifn!("llvm.log2.v8f32", fn(t_v8f32) -> t_v8f32);
637     ifn!("llvm.log2.v16f32", fn(t_v16f32) -> t_v16f32);
638     ifn!("llvm.log2.f64", fn(t_f64) -> t_f64);
639     ifn!("llvm.log2.v2f64", fn(t_v2f64) -> t_v2f64);
640     ifn!("llvm.log2.v4f64", fn(t_v4f64) -> t_v4f64);
641     ifn!("llvm.log2.v8f64", fn(t_v8f64) -> t_v8f64);
642
643     ifn!("llvm.fma.f32", fn(t_f32, t_f32, t_f32) -> t_f32);
644     ifn!("llvm.fma.v2f32", fn(t_v2f32, t_v2f32, t_v2f32) -> t_v2f32);
645     ifn!("llvm.fma.v4f32", fn(t_v4f32, t_v4f32, t_v4f32) -> t_v4f32);
646     ifn!("llvm.fma.v8f32", fn(t_v8f32, t_v8f32, t_v8f32) -> t_v8f32);
647     ifn!("llvm.fma.v16f32", fn(t_v16f32, t_v16f32, t_v16f32) -> t_v16f32);
648     ifn!("llvm.fma.f64", fn(t_f64, t_f64, t_f64) -> t_f64);
649     ifn!("llvm.fma.v2f64", fn(t_v2f64, t_v2f64, t_v2f64) -> t_v2f64);
650     ifn!("llvm.fma.v4f64", fn(t_v4f64, t_v4f64, t_v4f64) -> t_v4f64);
651     ifn!("llvm.fma.v8f64", fn(t_v8f64, t_v8f64, t_v8f64) -> t_v8f64);
652
653     ifn!("llvm.fabs.f32", fn(t_f32) -> t_f32);
654     ifn!("llvm.fabs.v2f32", fn(t_v2f32) -> t_v2f32);
655     ifn!("llvm.fabs.v4f32", fn(t_v4f32) -> t_v4f32);
656     ifn!("llvm.fabs.v8f32", fn(t_v8f32) -> t_v8f32);
657     ifn!("llvm.fabs.v16f32", fn(t_v16f32) -> t_v16f32);
658     ifn!("llvm.fabs.f64", fn(t_f64) -> t_f64);
659     ifn!("llvm.fabs.v2f64", fn(t_v2f64) -> t_v2f64);
660     ifn!("llvm.fabs.v4f64", fn(t_v4f64) -> t_v4f64);
661     ifn!("llvm.fabs.v8f64", fn(t_v8f64) -> t_v8f64);
662
663     ifn!("llvm.floor.f32", fn(t_f32) -> t_f32);
664     ifn!("llvm.floor.v2f32", fn(t_v2f32) -> t_v2f32);
665     ifn!("llvm.floor.v4f32", fn(t_v4f32) -> t_v4f32);
666     ifn!("llvm.floor.v8f32", fn(t_v8f32) -> t_v8f32);
667     ifn!("llvm.floor.v16f32", fn(t_v16f32) -> t_v16f32);
668     ifn!("llvm.floor.f64", fn(t_f64) -> t_f64);
669     ifn!("llvm.floor.v2f64", fn(t_v2f64) -> t_v2f64);
670     ifn!("llvm.floor.v4f64", fn(t_v4f64) -> t_v4f64);
671     ifn!("llvm.floor.v8f64", fn(t_v8f64) -> t_v8f64);
672
673     ifn!("llvm.ceil.f32", fn(t_f32) -> t_f32);
674     ifn!("llvm.ceil.v2f32", fn(t_v2f32) -> t_v2f32);
675     ifn!("llvm.ceil.v4f32", fn(t_v4f32) -> t_v4f32);
676     ifn!("llvm.ceil.v8f32", fn(t_v8f32) -> t_v8f32);
677     ifn!("llvm.ceil.v16f32", fn(t_v16f32) -> t_v16f32);
678     ifn!("llvm.ceil.f64", fn(t_f64) -> t_f64);
679     ifn!("llvm.ceil.v2f64", fn(t_v2f64) -> t_v2f64);
680     ifn!("llvm.ceil.v4f64", fn(t_v4f64) -> t_v4f64);
681     ifn!("llvm.ceil.v8f64", fn(t_v8f64) -> t_v8f64);
682
683     ifn!("llvm.trunc.f32", fn(t_f32) -> t_f32);
684     ifn!("llvm.trunc.f64", fn(t_f64) -> t_f64);
685
686     ifn!("llvm.copysign.f32", fn(t_f32, t_f32) -> t_f32);
687     ifn!("llvm.copysign.f64", fn(t_f64, t_f64) -> t_f64);
688     ifn!("llvm.round.f32", fn(t_f32) -> t_f32);
689     ifn!("llvm.round.f64", fn(t_f64) -> t_f64);
690
691     ifn!("llvm.rint.f32", fn(t_f32) -> t_f32);
692     ifn!("llvm.rint.f64", fn(t_f64) -> t_f64);
693     ifn!("llvm.nearbyint.f32", fn(t_f32) -> t_f32);
694     ifn!("llvm.nearbyint.f64", fn(t_f64) -> t_f64);
695
696     ifn!("llvm.ctpop.i8", fn(t_i8) -> t_i8);
697     ifn!("llvm.ctpop.i16", fn(t_i16) -> t_i16);
698     ifn!("llvm.ctpop.i32", fn(t_i32) -> t_i32);
699     ifn!("llvm.ctpop.i64", fn(t_i64) -> t_i64);
700     ifn!("llvm.ctpop.i128", fn(t_i128) -> t_i128);
701
702     ifn!("llvm.ctlz.i8", fn(t_i8 , i1) -> t_i8);
703     ifn!("llvm.ctlz.i16", fn(t_i16, i1) -> t_i16);
704     ifn!("llvm.ctlz.i32", fn(t_i32, i1) -> t_i32);
705     ifn!("llvm.ctlz.i64", fn(t_i64, i1) -> t_i64);
706     ifn!("llvm.ctlz.i128", fn(t_i128, i1) -> t_i128);
707
708     ifn!("llvm.cttz.i8", fn(t_i8 , i1) -> t_i8);
709     ifn!("llvm.cttz.i16", fn(t_i16, i1) -> t_i16);
710     ifn!("llvm.cttz.i32", fn(t_i32, i1) -> t_i32);
711     ifn!("llvm.cttz.i64", fn(t_i64, i1) -> t_i64);
712     ifn!("llvm.cttz.i128", fn(t_i128, i1) -> t_i128);
713
714     ifn!("llvm.bswap.i16", fn(t_i16) -> t_i16);
715     ifn!("llvm.bswap.i32", fn(t_i32) -> t_i32);
716     ifn!("llvm.bswap.i64", fn(t_i64) -> t_i64);
717     ifn!("llvm.bswap.i128", fn(t_i128) -> t_i128);
718
719     ifn!("llvm.bitreverse.i8", fn(t_i8) -> t_i8);
720     ifn!("llvm.bitreverse.i16", fn(t_i16) -> t_i16);
721     ifn!("llvm.bitreverse.i32", fn(t_i32) -> t_i32);
722     ifn!("llvm.bitreverse.i64", fn(t_i64) -> t_i64);
723     ifn!("llvm.bitreverse.i128", fn(t_i128) -> t_i128);
724
725     ifn!("llvm.sadd.with.overflow.i8", fn(t_i8, t_i8) -> mk_struct!{t_i8, i1});
726     ifn!("llvm.sadd.with.overflow.i16", fn(t_i16, t_i16) -> mk_struct!{t_i16, i1});
727     ifn!("llvm.sadd.with.overflow.i32", fn(t_i32, t_i32) -> mk_struct!{t_i32, i1});
728     ifn!("llvm.sadd.with.overflow.i64", fn(t_i64, t_i64) -> mk_struct!{t_i64, i1});
729     ifn!("llvm.sadd.with.overflow.i128", fn(t_i128, t_i128) -> mk_struct!{t_i128, i1});
730
731     ifn!("llvm.uadd.with.overflow.i8", fn(t_i8, t_i8) -> mk_struct!{t_i8, i1});
732     ifn!("llvm.uadd.with.overflow.i16", fn(t_i16, t_i16) -> mk_struct!{t_i16, i1});
733     ifn!("llvm.uadd.with.overflow.i32", fn(t_i32, t_i32) -> mk_struct!{t_i32, i1});
734     ifn!("llvm.uadd.with.overflow.i64", fn(t_i64, t_i64) -> mk_struct!{t_i64, i1});
735     ifn!("llvm.uadd.with.overflow.i128", fn(t_i128, t_i128) -> mk_struct!{t_i128, i1});
736
737     ifn!("llvm.ssub.with.overflow.i8", fn(t_i8, t_i8) -> mk_struct!{t_i8, i1});
738     ifn!("llvm.ssub.with.overflow.i16", fn(t_i16, t_i16) -> mk_struct!{t_i16, i1});
739     ifn!("llvm.ssub.with.overflow.i32", fn(t_i32, t_i32) -> mk_struct!{t_i32, i1});
740     ifn!("llvm.ssub.with.overflow.i64", fn(t_i64, t_i64) -> mk_struct!{t_i64, i1});
741     ifn!("llvm.ssub.with.overflow.i128", fn(t_i128, t_i128) -> mk_struct!{t_i128, i1});
742
743     ifn!("llvm.usub.with.overflow.i8", fn(t_i8, t_i8) -> mk_struct!{t_i8, i1});
744     ifn!("llvm.usub.with.overflow.i16", fn(t_i16, t_i16) -> mk_struct!{t_i16, i1});
745     ifn!("llvm.usub.with.overflow.i32", fn(t_i32, t_i32) -> mk_struct!{t_i32, i1});
746     ifn!("llvm.usub.with.overflow.i64", fn(t_i64, t_i64) -> mk_struct!{t_i64, i1});
747     ifn!("llvm.usub.with.overflow.i128", fn(t_i128, t_i128) -> mk_struct!{t_i128, i1});
748
749     ifn!("llvm.smul.with.overflow.i8", fn(t_i8, t_i8) -> mk_struct!{t_i8, i1});
750     ifn!("llvm.smul.with.overflow.i16", fn(t_i16, t_i16) -> mk_struct!{t_i16, i1});
751     ifn!("llvm.smul.with.overflow.i32", fn(t_i32, t_i32) -> mk_struct!{t_i32, i1});
752     ifn!("llvm.smul.with.overflow.i64", fn(t_i64, t_i64) -> mk_struct!{t_i64, i1});
753     ifn!("llvm.smul.with.overflow.i128", fn(t_i128, t_i128) -> mk_struct!{t_i128, i1});
754
755     ifn!("llvm.umul.with.overflow.i8", fn(t_i8, t_i8) -> mk_struct!{t_i8, i1});
756     ifn!("llvm.umul.with.overflow.i16", fn(t_i16, t_i16) -> mk_struct!{t_i16, i1});
757     ifn!("llvm.umul.with.overflow.i32", fn(t_i32, t_i32) -> mk_struct!{t_i32, i1});
758     ifn!("llvm.umul.with.overflow.i64", fn(t_i64, t_i64) -> mk_struct!{t_i64, i1});
759     ifn!("llvm.umul.with.overflow.i128", fn(t_i128, t_i128) -> mk_struct!{t_i128, i1});
760
761     ifn!("llvm.lifetime.start", fn(t_i64,i8p) -> void);
762     ifn!("llvm.lifetime.end", fn(t_i64, i8p) -> void);
763
764     ifn!("llvm.expect.i1", fn(i1, i1) -> i1);
765     ifn!("llvm.eh.typeid.for", fn(i8p) -> t_i32);
766     ifn!("llvm.localescape", fn(...) -> void);
767     ifn!("llvm.localrecover", fn(i8p, i8p, t_i32) -> i8p);
768     ifn!("llvm.x86.seh.recoverfp", fn(i8p, i8p) -> i8p);
769
770     ifn!("llvm.assume", fn(i1) -> void);
771     ifn!("llvm.prefetch", fn(i8p, t_i32, t_i32, t_i32) -> void);
772
773     if cx.sess().opts.debuginfo != DebugInfo::None {
774         ifn!("llvm.dbg.declare", fn(Type::metadata(cx), Type::metadata(cx)) -> void);
775         ifn!("llvm.dbg.value", fn(Type::metadata(cx), t_i64, Type::metadata(cx)) -> void);
776     }
777     return None;
778 }