]> git.lizzy.rs Git - rust.git/blob - src/librustc_trans/context.rs
refactor `ParamEnv::empty(Reveal)` into two distinct methods
[rust.git] / src / librustc_trans / 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 llvm::{ContextRef, ModuleRef, ValueRef};
14 use rustc::dep_graph::DepGraphSafe;
15 use rustc::hir;
16 use rustc::hir::def_id::DefId;
17 use debuginfo;
18 use callee;
19 use base;
20 use declare;
21 use monomorphize::Instance;
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, NoDebugInfo};
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
35 use std::ffi::{CStr, CString};
36 use std::cell::{Cell, RefCell};
37 use std::ptr;
38 use std::iter;
39 use std::str;
40 use std::sync::Arc;
41 use syntax::symbol::InternedString;
42 use abi::Abi;
43
44 /// There is one `CodegenCx` per compilation unit. Each one has its own LLVM
45 /// `ContextRef` so that several compilation units may be optimized in parallel.
46 /// All other LLVM data structures in the `CodegenCx` are tied to that `ContextRef`.
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: ModuleRef,
54     pub llcx: ContextRef,
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>, ValueRef>>,
60     /// Cache generated vtables
61     pub vtables: RefCell<FxHashMap<(Ty<'tcx>,
62                                 Option<ty::PolyExistentialTraitRef<'tcx>>), ValueRef>>,
63     /// Cache of constant strings,
64     pub const_cstr_cache: RefCell<FxHashMap<InternedString, ValueRef>>,
65
66     /// Reverse-direction for const ptrs cast from globals.
67     /// Key is a ValueRef holding a *T,
68     /// Val is a ValueRef holding a *[T].
69     ///
70     /// Needed because LLVM loses pointer->pointee association
71     /// when we ptrcast, and we have to ptrcast during translation
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<ValueRef, ValueRef>>,
75
76     /// Cache of emitted const globals (value -> global)
77     pub const_globals: RefCell<FxHashMap<ValueRef, ValueRef>>,
78
79     /// Mapping from static definitions to their DefId's.
80     pub statics: RefCell<FxHashMap<ValueRef, DefId>>,
81
82     /// List of globals for static variables which need to be passed to the
83     /// LLVM function ReplaceAllUsesWith (RAUW) when translation is complete.
84     /// (We have to make sure we don't invalidate any ValueRefs referring
85     /// to constants.)
86     pub statics_to_rauw: RefCell<Vec<(ValueRef, ValueRef)>>,
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<ValueRef>>,
91
92     pub lltypes: RefCell<FxHashMap<(Ty<'tcx>, Option<usize>), Type>>,
93     pub scalar_lltypes: RefCell<FxHashMap<Ty<'tcx>, Type>>,
94     pub pointee_infos: RefCell<FxHashMap<(Ty<'tcx>, Size), Option<PointeeInfo>>>,
95     pub isize_ty: Type,
96
97     pub dbg_cx: Option<debuginfo::CrateDebugContext<'tcx>>,
98
99     eh_personality: Cell<Option<ValueRef>>,
100     eh_unwind_resume: Cell<Option<ValueRef>>,
101     pub rust_try_fn: Cell<Option<ValueRef>>,
102
103     intrinsics: RefCell<FxHashMap<&'static str, ValueRef>>,
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::CrateTypeExecutable
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_context_and_module(sess: &Session, mod_name: &str) -> (ContextRef, ModuleRef) {
159     let llcx = llvm::LLVMRustContextCreate(sess.fewer_names());
160     let mod_name = CString::new(mod_name).unwrap();
161     let llmod = llvm::LLVMModuleCreateWithNameInContext(mod_name.as_ptr(), llcx);
162
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);
166         llvm::LLVMRustSetDataLayoutFromTargetMachine(llmod, tm);
167         llvm::LLVMRustDisposeTargetMachine(tm);
168
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");
172
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
178         // that one.
179         //
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.
183         //
184         // Unsure if this will actually cause breakage when rustc is configured
185         // as such.
186         //
187         // FIXME(#34960)
188         let cfg_llvm_root = option_env!("CFG_LLVM_ROOT").unwrap_or("");
189         let custom_llvm_used = cfg_llvm_root.trim() != "";
190
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,
196                  data_layout);
197         }
198     }
199
200     let data_layout = CString::new(&sess.target.target.data_layout[..]).unwrap();
201     llvm::LLVMSetDataLayout(llmod, data_layout.as_ptr());
202
203     let llvm_target = sess.target.target.llvm_target.as_bytes();
204     let llvm_target = CString::new(llvm_target).unwrap();
205     llvm::LLVMRustSetNormalizedTarget(llmod, llvm_target.as_ptr());
206
207     if is_pie_binary(sess) {
208         llvm::LLVMRustSetModulePIELevel(llmod);
209     }
210
211     (llcx, llmod)
212 }
213
214 impl<'a, 'tcx> CodegenCx<'a, 'tcx> {
215     pub fn new(tcx: TyCtxt<'a, 'tcx, 'tcx>,
216                codegen_unit: Arc<CodegenUnit<'tcx>>,
217                llmod_id: &str)
218                -> CodegenCx<'a, 'tcx> {
219         // An interesting part of Windows which MSVC forces our hand on (and
220         // apparently MinGW didn't) is the usage of `dllimport` and `dllexport`
221         // attributes in LLVM IR as well as native dependencies (in C these
222         // correspond to `__declspec(dllimport)`).
223         //
224         // Whenever a dynamic library is built by MSVC it must have its public
225         // interface specified by functions tagged with `dllexport` or otherwise
226         // they're not available to be linked against. This poses a few problems
227         // for the compiler, some of which are somewhat fundamental, but we use
228         // the `use_dll_storage_attrs` variable below to attach the `dllexport`
229         // attribute to all LLVM functions that are exported e.g. they're
230         // already tagged with external linkage). This is suboptimal for a few
231         // reasons:
232         //
233         // * If an object file will never be included in a dynamic library,
234         //   there's no need to attach the dllexport attribute. Most object
235         //   files in Rust are not destined to become part of a dll as binaries
236         //   are statically linked by default.
237         // * If the compiler is emitting both an rlib and a dylib, the same
238         //   source object file is currently used but with MSVC this may be less
239         //   feasible. The compiler may be able to get around this, but it may
240         //   involve some invasive changes to deal with this.
241         //
242         // The flipside of this situation is that whenever you link to a dll and
243         // you import a function from it, the import should be tagged with
244         // `dllimport`. At this time, however, the compiler does not emit
245         // `dllimport` for any declarations other than constants (where it is
246         // required), which is again suboptimal for even more reasons!
247         //
248         // * Calling a function imported from another dll without using
249         //   `dllimport` causes the linker/compiler to have extra overhead (one
250         //   `jmp` instruction on x86) when calling the function.
251         // * The same object file may be used in different circumstances, so a
252         //   function may be imported from a dll if the object is linked into a
253         //   dll, but it may be just linked against if linked into an rlib.
254         // * The compiler has no knowledge about whether native functions should
255         //   be tagged dllimport or not.
256         //
257         // For now the compiler takes the perf hit (I do not have any numbers to
258         // this effect) by marking very little as `dllimport` and praying the
259         // linker will take care of everything. Fixing this problem will likely
260         // require adding a few attributes to Rust itself (feature gated at the
261         // start) and then strongly recommending static linkage on MSVC!
262         let use_dll_storage_attrs = tcx.sess.target.target.options.is_like_msvc;
263
264         let check_overflow = tcx.sess.overflow_checks();
265
266         let tls_model = get_tls_model(&tcx.sess);
267
268         unsafe {
269             let (llcx, llmod) = create_context_and_module(&tcx.sess,
270                                                           &llmod_id[..]);
271
272             let dbg_cx = if tcx.sess.opts.debuginfo != NoDebugInfo {
273                 let dctx = debuginfo::CrateDebugContext::new(llmod);
274                 debuginfo::metadata::compile_unit_metadata(tcx,
275                                                            codegen_unit.name(),
276                                                            &dctx);
277                 Some(dctx)
278             } else {
279                 None
280             };
281
282             let mut cx = CodegenCx {
283                 tcx,
284                 check_overflow,
285                 use_dll_storage_attrs,
286                 tls_model,
287                 llmod,
288                 llcx,
289                 stats: RefCell::new(Stats::default()),
290                 codegen_unit,
291                 instances: RefCell::new(FxHashMap()),
292                 vtables: RefCell::new(FxHashMap()),
293                 const_cstr_cache: RefCell::new(FxHashMap()),
294                 const_unsized: RefCell::new(FxHashMap()),
295                 const_globals: RefCell::new(FxHashMap()),
296                 statics: RefCell::new(FxHashMap()),
297                 statics_to_rauw: RefCell::new(Vec::new()),
298                 used_statics: RefCell::new(Vec::new()),
299                 lltypes: RefCell::new(FxHashMap()),
300                 scalar_lltypes: RefCell::new(FxHashMap()),
301                 pointee_infos: RefCell::new(FxHashMap()),
302                 isize_ty: Type::from_ref(ptr::null_mut()),
303                 dbg_cx,
304                 eh_personality: Cell::new(None),
305                 eh_unwind_resume: Cell::new(None),
306                 rust_try_fn: Cell::new(None),
307                 intrinsics: RefCell::new(FxHashMap()),
308                 local_gen_sym_counter: Cell::new(0),
309             };
310             cx.isize_ty = Type::isize(&cx);
311             cx
312         }
313     }
314
315     pub fn into_stats(self) -> Stats {
316         self.stats.into_inner()
317     }
318 }
319
320 impl<'b, 'tcx> CodegenCx<'b, 'tcx> {
321     pub fn sess<'a>(&'a self) -> &'a Session {
322         &self.tcx.sess
323     }
324
325     pub fn get_intrinsic(&self, key: &str) -> ValueRef {
326         if let Some(v) = self.intrinsics.borrow().get(key).cloned() {
327             return v;
328         }
329         match declare_intrinsic(self, key) {
330             Some(v) => return v,
331             None => bug!("unknown intrinsic '{}'", key)
332         }
333     }
334
335     /// Generate a new symbol name with the given prefix. This symbol name must
336     /// only be used for definitions with `internal` or `private` linkage.
337     pub fn generate_local_symbol_name(&self, prefix: &str) -> String {
338         let idx = self.local_gen_sym_counter.get();
339         self.local_gen_sym_counter.set(idx + 1);
340         // Include a '.' character, so there can be no accidental conflicts with
341         // user defined names
342         let mut name = String::with_capacity(prefix.len() + 6);
343         name.push_str(prefix);
344         name.push_str(".");
345         base_n::push_str(idx as u128, base_n::ALPHANUMERIC_ONLY, &mut name);
346         name
347     }
348
349     pub fn eh_personality(&self) -> ValueRef {
350         // The exception handling personality function.
351         //
352         // If our compilation unit has the `eh_personality` lang item somewhere
353         // within it, then we just need to translate that. Otherwise, we're
354         // building an rlib which will depend on some upstream implementation of
355         // this function, so we just codegen a generic reference to it. We don't
356         // specify any of the types for the function, we just make it a symbol
357         // that LLVM can later use.
358         //
359         // Note that MSVC is a little special here in that we don't use the
360         // `eh_personality` lang item at all. Currently LLVM has support for
361         // both Dwarf and SEH unwind mechanisms for MSVC targets and uses the
362         // *name of the personality function* to decide what kind of unwind side
363         // tables/landing pads to emit. It looks like Dwarf is used by default,
364         // injecting a dependency on the `_Unwind_Resume` symbol for resuming
365         // an "exception", but for MSVC we want to force SEH. This means that we
366         // can't actually have the personality function be our standard
367         // `rust_eh_personality` function, but rather we wired it up to the
368         // CRT's custom personality function, which forces LLVM to consider
369         // landing pads as "landing pads for SEH".
370         if let Some(llpersonality) = self.eh_personality.get() {
371             return llpersonality
372         }
373         let tcx = self.tcx;
374         let llfn = match tcx.lang_items().eh_personality() {
375             Some(def_id) if !base::wants_msvc_seh(self.sess()) => {
376                 callee::resolve_and_get_fn(self, def_id, tcx.intern_substs(&[]))
377             }
378             _ => {
379                 let name = if base::wants_msvc_seh(self.sess()) {
380                     "__CxxFrameHandler3"
381                 } else {
382                     "rust_eh_personality"
383                 };
384                 let fty = Type::variadic_func(&[], &Type::i32(self));
385                 declare::declare_cfn(self, name, fty)
386             }
387         };
388         self.eh_personality.set(Some(llfn));
389         llfn
390     }
391
392     // Returns a ValueRef of the "eh_unwind_resume" lang item if one is defined,
393     // otherwise declares it as an external function.
394     pub fn eh_unwind_resume(&self) -> ValueRef {
395         use attributes;
396         let unwresume = &self.eh_unwind_resume;
397         if let Some(llfn) = unwresume.get() {
398             return llfn;
399         }
400
401         let tcx = self.tcx;
402         assert!(self.sess().target.target.options.custom_unwind_resume);
403         if let Some(def_id) = tcx.lang_items().eh_unwind_resume() {
404             let llfn = callee::resolve_and_get_fn(self, def_id, tcx.intern_substs(&[]));
405             unwresume.set(Some(llfn));
406             return llfn;
407         }
408
409         let ty = tcx.mk_fn_ptr(ty::Binder(tcx.mk_fn_sig(
410             iter::once(tcx.mk_mut_ptr(tcx.types.u8)),
411             tcx.types.never,
412             false,
413             hir::Unsafety::Unsafe,
414             Abi::C
415         )));
416
417         let llfn = declare::declare_fn(self, "rust_eh_unwind_resume", ty);
418         attributes::unwind(llfn, true);
419         unwresume.set(Some(llfn));
420         llfn
421     }
422
423     pub fn type_needs_drop(&self, ty: Ty<'tcx>) -> bool {
424         common::type_needs_drop(self.tcx, ty)
425     }
426
427     pub fn type_is_sized(&self, ty: Ty<'tcx>) -> bool {
428         common::type_is_sized(self.tcx, ty)
429     }
430
431     pub fn type_is_freeze(&self, ty: Ty<'tcx>) -> bool {
432         common::type_is_freeze(self.tcx, ty)
433     }
434
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()) {
438             return false;
439         }
440
441         let tail = self.tcx.struct_tail(ty);
442         match tail.sty {
443             ty::TyForeign(..) => false,
444             ty::TyStr | ty::TySlice(..) | ty::TyDynamic(..) => true,
445             _ => bug!("unexpected unsized tail: {:?}", tail.sty),
446         }
447     }
448 }
449
450 impl<'a, 'tcx> ty::layout::HasDataLayout for &'a CodegenCx<'a, 'tcx> {
451     fn data_layout(&self) -> &ty::layout::TargetDataLayout {
452         &self.tcx.data_layout
453     }
454 }
455
456 impl<'a, 'tcx> ty::layout::HasTyCtxt<'tcx> for &'a CodegenCx<'a, 'tcx> {
457     fn tcx<'b>(&'b self) -> TyCtxt<'b, 'tcx, 'tcx> {
458         self.tcx
459     }
460 }
461
462 impl<'a, 'tcx> LayoutOf<Ty<'tcx>> for &'a CodegenCx<'a, 'tcx> {
463     type TyLayout = TyLayout<'tcx>;
464
465     fn layout_of(self, ty: Ty<'tcx>) -> Self::TyLayout {
466         self.tcx.layout_of(ty::ParamEnv::reveal_all().and(ty))
467             .unwrap_or_else(|e| match e {
468                 LayoutError::SizeOverflow(_) => self.sess().fatal(&e.to_string()),
469                 _ => bug!("failed to get layout for `{}`: {}", ty, e)
470             })
471     }
472 }
473
474 /// Declare any llvm intrinsics that you might need
475 fn declare_intrinsic(cx: &CodegenCx, key: &str) -> Option<ValueRef> {
476     macro_rules! ifn {
477         ($name:expr, fn() -> $ret:expr) => (
478             if key == $name {
479                 let f = declare::declare_cfn(cx, $name, Type::func(&[], &$ret));
480                 llvm::SetUnnamedAddr(f, false);
481                 cx.intrinsics.borrow_mut().insert($name, f.clone());
482                 return Some(f);
483             }
484         );
485         ($name:expr, fn(...) -> $ret:expr) => (
486             if key == $name {
487                 let f = declare::declare_cfn(cx, $name, Type::variadic_func(&[], &$ret));
488                 llvm::SetUnnamedAddr(f, false);
489                 cx.intrinsics.borrow_mut().insert($name, f.clone());
490                 return Some(f);
491             }
492         );
493         ($name:expr, fn($($arg:expr),*) -> $ret:expr) => (
494             if key == $name {
495                 let f = declare::declare_cfn(cx, $name, Type::func(&[$($arg),*], &$ret));
496                 llvm::SetUnnamedAddr(f, false);
497                 cx.intrinsics.borrow_mut().insert($name, f.clone());
498                 return Some(f);
499             }
500         );
501     }
502     macro_rules! mk_struct {
503         ($($field_ty:expr),*) => (Type::struct_(cx, &[$($field_ty),*], false))
504     }
505
506     let i8p = Type::i8p(cx);
507     let void = Type::void(cx);
508     let i1 = Type::i1(cx);
509     let t_i8 = Type::i8(cx);
510     let t_i16 = Type::i16(cx);
511     let t_i32 = Type::i32(cx);
512     let t_i64 = Type::i64(cx);
513     let t_i128 = Type::i128(cx);
514     let t_f32 = Type::f32(cx);
515     let t_f64 = Type::f64(cx);
516
517     ifn!("llvm.memcpy.p0i8.p0i8.i16", fn(i8p, i8p, t_i16, t_i32, i1) -> void);
518     ifn!("llvm.memcpy.p0i8.p0i8.i32", fn(i8p, i8p, t_i32, t_i32, i1) -> void);
519     ifn!("llvm.memcpy.p0i8.p0i8.i64", fn(i8p, i8p, t_i64, t_i32, i1) -> void);
520     ifn!("llvm.memmove.p0i8.p0i8.i16", fn(i8p, i8p, t_i16, t_i32, i1) -> void);
521     ifn!("llvm.memmove.p0i8.p0i8.i32", fn(i8p, i8p, t_i32, t_i32, i1) -> void);
522     ifn!("llvm.memmove.p0i8.p0i8.i64", fn(i8p, i8p, t_i64, t_i32, i1) -> void);
523     ifn!("llvm.memset.p0i8.i16", fn(i8p, t_i8, t_i16, t_i32, i1) -> void);
524     ifn!("llvm.memset.p0i8.i32", fn(i8p, t_i8, t_i32, t_i32, i1) -> void);
525     ifn!("llvm.memset.p0i8.i64", fn(i8p, t_i8, t_i64, t_i32, i1) -> void);
526
527     ifn!("llvm.trap", fn() -> void);
528     ifn!("llvm.debugtrap", fn() -> void);
529     ifn!("llvm.frameaddress", fn(t_i32) -> i8p);
530
531     ifn!("llvm.powi.f32", fn(t_f32, t_i32) -> t_f32);
532     ifn!("llvm.powi.f64", fn(t_f64, t_i32) -> t_f64);
533     ifn!("llvm.pow.f32", fn(t_f32, t_f32) -> t_f32);
534     ifn!("llvm.pow.f64", fn(t_f64, t_f64) -> t_f64);
535
536     ifn!("llvm.sqrt.f32", fn(t_f32) -> t_f32);
537     ifn!("llvm.sqrt.f64", fn(t_f64) -> t_f64);
538     ifn!("llvm.sin.f32", fn(t_f32) -> t_f32);
539     ifn!("llvm.sin.f64", fn(t_f64) -> t_f64);
540     ifn!("llvm.cos.f32", fn(t_f32) -> t_f32);
541     ifn!("llvm.cos.f64", fn(t_f64) -> t_f64);
542     ifn!("llvm.exp.f32", fn(t_f32) -> t_f32);
543     ifn!("llvm.exp.f64", fn(t_f64) -> t_f64);
544     ifn!("llvm.exp2.f32", fn(t_f32) -> t_f32);
545     ifn!("llvm.exp2.f64", fn(t_f64) -> t_f64);
546     ifn!("llvm.log.f32", fn(t_f32) -> t_f32);
547     ifn!("llvm.log.f64", fn(t_f64) -> t_f64);
548     ifn!("llvm.log10.f32", fn(t_f32) -> t_f32);
549     ifn!("llvm.log10.f64", fn(t_f64) -> t_f64);
550     ifn!("llvm.log2.f32", fn(t_f32) -> t_f32);
551     ifn!("llvm.log2.f64", fn(t_f64) -> t_f64);
552
553     ifn!("llvm.fma.f32", fn(t_f32, t_f32, t_f32) -> t_f32);
554     ifn!("llvm.fma.f64", fn(t_f64, t_f64, t_f64) -> t_f64);
555
556     ifn!("llvm.fabs.f32", fn(t_f32) -> t_f32);
557     ifn!("llvm.fabs.f64", fn(t_f64) -> t_f64);
558
559     ifn!("llvm.floor.f32", fn(t_f32) -> t_f32);
560     ifn!("llvm.floor.f64", fn(t_f64) -> t_f64);
561     ifn!("llvm.ceil.f32", fn(t_f32) -> t_f32);
562     ifn!("llvm.ceil.f64", fn(t_f64) -> t_f64);
563     ifn!("llvm.trunc.f32", fn(t_f32) -> t_f32);
564     ifn!("llvm.trunc.f64", fn(t_f64) -> t_f64);
565
566     ifn!("llvm.copysign.f32", fn(t_f32, t_f32) -> t_f32);
567     ifn!("llvm.copysign.f64", fn(t_f64, t_f64) -> t_f64);
568     ifn!("llvm.round.f32", fn(t_f32) -> t_f32);
569     ifn!("llvm.round.f64", fn(t_f64) -> t_f64);
570
571     ifn!("llvm.rint.f32", fn(t_f32) -> t_f32);
572     ifn!("llvm.rint.f64", fn(t_f64) -> t_f64);
573     ifn!("llvm.nearbyint.f32", fn(t_f32) -> t_f32);
574     ifn!("llvm.nearbyint.f64", fn(t_f64) -> t_f64);
575
576     ifn!("llvm.ctpop.i8", fn(t_i8) -> t_i8);
577     ifn!("llvm.ctpop.i16", fn(t_i16) -> t_i16);
578     ifn!("llvm.ctpop.i32", fn(t_i32) -> t_i32);
579     ifn!("llvm.ctpop.i64", fn(t_i64) -> t_i64);
580     ifn!("llvm.ctpop.i128", fn(t_i128) -> t_i128);
581
582     ifn!("llvm.ctlz.i8", fn(t_i8 , i1) -> t_i8);
583     ifn!("llvm.ctlz.i16", fn(t_i16, i1) -> t_i16);
584     ifn!("llvm.ctlz.i32", fn(t_i32, i1) -> t_i32);
585     ifn!("llvm.ctlz.i64", fn(t_i64, i1) -> t_i64);
586     ifn!("llvm.ctlz.i128", fn(t_i128, i1) -> t_i128);
587
588     ifn!("llvm.cttz.i8", fn(t_i8 , i1) -> t_i8);
589     ifn!("llvm.cttz.i16", fn(t_i16, i1) -> t_i16);
590     ifn!("llvm.cttz.i32", fn(t_i32, i1) -> t_i32);
591     ifn!("llvm.cttz.i64", fn(t_i64, i1) -> t_i64);
592     ifn!("llvm.cttz.i128", fn(t_i128, i1) -> t_i128);
593
594     ifn!("llvm.bswap.i16", fn(t_i16) -> t_i16);
595     ifn!("llvm.bswap.i32", fn(t_i32) -> t_i32);
596     ifn!("llvm.bswap.i64", fn(t_i64) -> t_i64);
597     ifn!("llvm.bswap.i128", fn(t_i128) -> t_i128);
598
599     ifn!("llvm.bitreverse.i8", fn(t_i8) -> t_i8);
600     ifn!("llvm.bitreverse.i16", fn(t_i16) -> t_i16);
601     ifn!("llvm.bitreverse.i32", fn(t_i32) -> t_i32);
602     ifn!("llvm.bitreverse.i64", fn(t_i64) -> t_i64);
603     ifn!("llvm.bitreverse.i128", fn(t_i128) -> t_i128);
604
605     ifn!("llvm.sadd.with.overflow.i8", fn(t_i8, t_i8) -> mk_struct!{t_i8, i1});
606     ifn!("llvm.sadd.with.overflow.i16", fn(t_i16, t_i16) -> mk_struct!{t_i16, i1});
607     ifn!("llvm.sadd.with.overflow.i32", fn(t_i32, t_i32) -> mk_struct!{t_i32, i1});
608     ifn!("llvm.sadd.with.overflow.i64", fn(t_i64, t_i64) -> mk_struct!{t_i64, i1});
609     ifn!("llvm.sadd.with.overflow.i128", fn(t_i128, t_i128) -> mk_struct!{t_i128, i1});
610
611     ifn!("llvm.uadd.with.overflow.i8", fn(t_i8, t_i8) -> mk_struct!{t_i8, i1});
612     ifn!("llvm.uadd.with.overflow.i16", fn(t_i16, t_i16) -> mk_struct!{t_i16, i1});
613     ifn!("llvm.uadd.with.overflow.i32", fn(t_i32, t_i32) -> mk_struct!{t_i32, i1});
614     ifn!("llvm.uadd.with.overflow.i64", fn(t_i64, t_i64) -> mk_struct!{t_i64, i1});
615     ifn!("llvm.uadd.with.overflow.i128", fn(t_i128, t_i128) -> mk_struct!{t_i128, i1});
616
617     ifn!("llvm.ssub.with.overflow.i8", fn(t_i8, t_i8) -> mk_struct!{t_i8, i1});
618     ifn!("llvm.ssub.with.overflow.i16", fn(t_i16, t_i16) -> mk_struct!{t_i16, i1});
619     ifn!("llvm.ssub.with.overflow.i32", fn(t_i32, t_i32) -> mk_struct!{t_i32, i1});
620     ifn!("llvm.ssub.with.overflow.i64", fn(t_i64, t_i64) -> mk_struct!{t_i64, i1});
621     ifn!("llvm.ssub.with.overflow.i128", fn(t_i128, t_i128) -> mk_struct!{t_i128, i1});
622
623     ifn!("llvm.usub.with.overflow.i8", fn(t_i8, t_i8) -> mk_struct!{t_i8, i1});
624     ifn!("llvm.usub.with.overflow.i16", fn(t_i16, t_i16) -> mk_struct!{t_i16, i1});
625     ifn!("llvm.usub.with.overflow.i32", fn(t_i32, t_i32) -> mk_struct!{t_i32, i1});
626     ifn!("llvm.usub.with.overflow.i64", fn(t_i64, t_i64) -> mk_struct!{t_i64, i1});
627     ifn!("llvm.usub.with.overflow.i128", fn(t_i128, t_i128) -> mk_struct!{t_i128, i1});
628
629     ifn!("llvm.smul.with.overflow.i8", fn(t_i8, t_i8) -> mk_struct!{t_i8, i1});
630     ifn!("llvm.smul.with.overflow.i16", fn(t_i16, t_i16) -> mk_struct!{t_i16, i1});
631     ifn!("llvm.smul.with.overflow.i32", fn(t_i32, t_i32) -> mk_struct!{t_i32, i1});
632     ifn!("llvm.smul.with.overflow.i64", fn(t_i64, t_i64) -> mk_struct!{t_i64, i1});
633     ifn!("llvm.smul.with.overflow.i128", fn(t_i128, t_i128) -> mk_struct!{t_i128, i1});
634
635     ifn!("llvm.umul.with.overflow.i8", fn(t_i8, t_i8) -> mk_struct!{t_i8, i1});
636     ifn!("llvm.umul.with.overflow.i16", fn(t_i16, t_i16) -> mk_struct!{t_i16, i1});
637     ifn!("llvm.umul.with.overflow.i32", fn(t_i32, t_i32) -> mk_struct!{t_i32, i1});
638     ifn!("llvm.umul.with.overflow.i64", fn(t_i64, t_i64) -> mk_struct!{t_i64, i1});
639     ifn!("llvm.umul.with.overflow.i128", fn(t_i128, t_i128) -> mk_struct!{t_i128, i1});
640
641     ifn!("llvm.lifetime.start", fn(t_i64,i8p) -> void);
642     ifn!("llvm.lifetime.end", fn(t_i64, i8p) -> void);
643
644     ifn!("llvm.expect.i1", fn(i1, i1) -> i1);
645     ifn!("llvm.eh.typeid.for", fn(i8p) -> t_i32);
646     ifn!("llvm.localescape", fn(...) -> void);
647     ifn!("llvm.localrecover", fn(i8p, i8p, t_i32) -> i8p);
648     ifn!("llvm.x86.seh.recoverfp", fn(i8p, i8p) -> i8p);
649
650     ifn!("llvm.assume", fn(i1) -> void);
651     ifn!("llvm.prefetch", fn(i8p, t_i32, t_i32, t_i32) -> void);
652
653     if cx.sess().opts.debuginfo != NoDebugInfo {
654         ifn!("llvm.dbg.declare", fn(Type::metadata(cx), Type::metadata(cx)) -> void);
655         ifn!("llvm.dbg.value", fn(Type::metadata(cx), t_i64, Type::metadata(cx)) -> void);
656     }
657     return None;
658 }