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;
16 use rustc::hir::def_id::DefId;
21 use monomorphize::Instance;
23 use monomorphize::partitioning::CodegenUnit;
25 use type_of::PointeeInfo;
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 use rustc_target::spec::{HasTargetSpec, Target};
36 use std::ffi::{CStr, CString};
37 use std::cell::{Cell, RefCell};
41 use syntax::symbol::LocalInternedString;
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,
53 pub llmod: &'a llvm::Module,
54 pub llcx: &'a llvm::Context,
55 pub stats: RefCell<Stats>,
56 pub codegen_unit: Arc<CodegenUnit<'tcx>>,
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<LocalInternedString, ValueRef>>,
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].
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<ValueRef, ValueRef>>,
76 /// Cache of emitted const globals (value -> global)
77 pub const_globals: RefCell<FxHashMap<ValueRef, ValueRef>>,
79 /// Mapping from static definitions to their DefId's.
80 pub statics: RefCell<FxHashMap<ValueRef, DefId>>,
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 ValueRefs referring
86 pub statics_to_rauw: RefCell<Vec<(ValueRef, ValueRef)>>,
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>>,
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>>>,
97 pub dbg_cx: Option<debuginfo::CrateDebugContext<'a, 'tcx>>,
99 eh_personality: Cell<Option<ValueRef>>,
100 eh_unwind_resume: Cell<Option<ValueRef>>,
101 pub rust_try_fn: Cell<Option<ValueRef>>,
103 intrinsics: RefCell<FxHashMap<&'static str, ValueRef>>,
105 /// A counter that is used for generating local symbol names
106 local_gen_sym_counter: Cell<usize>,
109 impl<'a, 'tcx> DepGraphSafe for CodegenCx<'a, 'tcx> {
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[..],
118 match ::back::write::RELOC_MODEL_ARGS.iter().find(
119 |&&arg| arg.0 == reloc_model_arg) {
122 sess.err(&format!("{:?} is not a valid relocation mode",
124 sess.abort_if_errors();
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[..],
136 match ::back::write::TLS_MODEL_ARGS.iter().find(
137 |&&arg| arg.0 == tls_model_arg) {
140 sess.err(&format!("{:?} is not a valid TLS model",
142 sess.abort_if_errors();
148 fn is_any_library(sess: &Session) -> bool {
149 sess.crate_types.borrow().iter().any(|ty| {
150 *ty != config::CrateTypeExecutable
154 pub fn is_pie_binary(sess: &Session) -> bool {
155 !is_any_library(sess) && get_reloc_model(sess) == llvm::RelocMode::PIC
158 pub unsafe fn create_module(sess: &Session, llcx: &'ll llvm::Context, mod_name: &str) -> &'ll llvm::Module {
159 let mod_name = CString::new(mod_name).unwrap();
160 let llmod = llvm::LLVMModuleCreateWithNameInContext(mod_name.as_ptr(), llcx);
162 // Ensure the data-layout values hardcoded remain the defaults.
163 if sess.target.target.options.is_builtin {
164 let tm = ::back::write::create_target_machine(sess, false);
165 llvm::LLVMRustSetDataLayoutFromTargetMachine(llmod, tm);
166 llvm::LLVMRustDisposeTargetMachine(tm);
168 let data_layout = llvm::LLVMGetDataLayout(llmod);
169 let data_layout = str::from_utf8(CStr::from_ptr(data_layout).to_bytes())
170 .ok().expect("got a non-UTF8 data-layout from LLVM");
172 // Unfortunately LLVM target specs change over time, and right now we
173 // don't have proper support to work with any more than one
174 // `data_layout` than the one that is in the rust-lang/rust repo. If
175 // this compiler is configured against a custom LLVM, we may have a
176 // differing data layout, even though we should update our own to use
179 // As an interim hack, if CFG_LLVM_ROOT is not an empty string then we
180 // disable this check entirely as we may be configured with something
181 // that has a different target layout.
183 // Unsure if this will actually cause breakage when rustc is configured
187 let cfg_llvm_root = option_env!("CFG_LLVM_ROOT").unwrap_or("");
188 let custom_llvm_used = cfg_llvm_root.trim() != "";
190 if !custom_llvm_used && sess.target.target.data_layout != data_layout {
191 bug!("data-layout for builtin `{}` target, `{}`, \
192 differs from LLVM default, `{}`",
193 sess.target.target.llvm_target,
194 sess.target.target.data_layout,
199 let data_layout = CString::new(&sess.target.target.data_layout[..]).unwrap();
200 llvm::LLVMSetDataLayout(llmod, data_layout.as_ptr());
202 let llvm_target = sess.target.target.llvm_target.as_bytes();
203 let llvm_target = CString::new(llvm_target).unwrap();
204 llvm::LLVMRustSetNormalizedTarget(llmod, llvm_target.as_ptr());
206 if is_pie_binary(sess) {
207 llvm::LLVMRustSetModulePIELevel(llmod);
213 impl<'a, 'tcx> CodegenCx<'a, 'tcx> {
214 crate fn new(tcx: TyCtxt<'a, 'tcx, 'tcx>,
215 codegen_unit: Arc<CodegenUnit<'tcx>>,
216 llvm_module: &'a ::ModuleLlvm)
217 -> CodegenCx<'a, 'tcx> {
218 // An interesting part of Windows which MSVC forces our hand on (and
219 // apparently MinGW didn't) is the usage of `dllimport` and `dllexport`
220 // attributes in LLVM IR as well as native dependencies (in C these
221 // correspond to `__declspec(dllimport)`).
223 // Whenever a dynamic library is built by MSVC it must have its public
224 // interface specified by functions tagged with `dllexport` or otherwise
225 // they're not available to be linked against. This poses a few problems
226 // for the compiler, some of which are somewhat fundamental, but we use
227 // the `use_dll_storage_attrs` variable below to attach the `dllexport`
228 // attribute to all LLVM functions that are exported e.g. they're
229 // already tagged with external linkage). This is suboptimal for a few
232 // * If an object file will never be included in a dynamic library,
233 // there's no need to attach the dllexport attribute. Most object
234 // files in Rust are not destined to become part of a dll as binaries
235 // are statically linked by default.
236 // * If the compiler is emitting both an rlib and a dylib, the same
237 // source object file is currently used but with MSVC this may be less
238 // feasible. The compiler may be able to get around this, but it may
239 // involve some invasive changes to deal with this.
241 // The flipside of this situation is that whenever you link to a dll and
242 // you import a function from it, the import should be tagged with
243 // `dllimport`. At this time, however, the compiler does not emit
244 // `dllimport` for any declarations other than constants (where it is
245 // required), which is again suboptimal for even more reasons!
247 // * Calling a function imported from another dll without using
248 // `dllimport` causes the linker/compiler to have extra overhead (one
249 // `jmp` instruction on x86) when calling the function.
250 // * The same object file may be used in different circumstances, so a
251 // function may be imported from a dll if the object is linked into a
252 // dll, but it may be just linked against if linked into an rlib.
253 // * The compiler has no knowledge about whether native functions should
254 // be tagged dllimport or not.
256 // For now the compiler takes the perf hit (I do not have any numbers to
257 // this effect) by marking very little as `dllimport` and praying the
258 // linker will take care of everything. Fixing this problem will likely
259 // require adding a few attributes to Rust itself (feature gated at the
260 // start) and then strongly recommending static linkage on MSVC!
261 let use_dll_storage_attrs = tcx.sess.target.target.options.is_like_msvc;
263 let check_overflow = tcx.sess.overflow_checks();
265 let tls_model = get_tls_model(&tcx.sess);
267 let (llcx, llmod) = (&*llvm_module.llcx, llvm_module.llmod());
269 let dbg_cx = if tcx.sess.opts.debuginfo != NoDebugInfo {
270 let dctx = debuginfo::CrateDebugContext::new(llmod);
271 debuginfo::metadata::compile_unit_metadata(tcx,
272 &codegen_unit.name().as_str(),
279 let isize_ty = Type::ix_llcx(llcx, tcx.data_layout.pointer_size.bits());
284 use_dll_storage_attrs,
288 stats: RefCell::new(Stats::default()),
290 instances: RefCell::new(FxHashMap()),
291 vtables: RefCell::new(FxHashMap()),
292 const_cstr_cache: RefCell::new(FxHashMap()),
293 const_unsized: RefCell::new(FxHashMap()),
294 const_globals: RefCell::new(FxHashMap()),
295 statics: RefCell::new(FxHashMap()),
296 statics_to_rauw: RefCell::new(Vec::new()),
297 used_statics: RefCell::new(Vec::new()),
298 lltypes: RefCell::new(FxHashMap()),
299 scalar_lltypes: RefCell::new(FxHashMap()),
300 pointee_infos: RefCell::new(FxHashMap()),
303 eh_personality: Cell::new(None),
304 eh_unwind_resume: Cell::new(None),
305 rust_try_fn: Cell::new(None),
306 intrinsics: RefCell::new(FxHashMap()),
307 local_gen_sym_counter: Cell::new(0),
312 impl<'b, 'tcx> CodegenCx<'b, 'tcx> {
313 pub fn sess<'a>(&'a self) -> &'a Session {
317 pub fn get_intrinsic(&self, key: &str) -> ValueRef {
318 if let Some(v) = self.intrinsics.borrow().get(key).cloned() {
321 match declare_intrinsic(self, key) {
323 None => bug!("unknown intrinsic '{}'", key)
327 /// Generate a new symbol name with the given prefix. This symbol name must
328 /// only be used for definitions with `internal` or `private` linkage.
329 pub fn generate_local_symbol_name(&self, prefix: &str) -> String {
330 let idx = self.local_gen_sym_counter.get();
331 self.local_gen_sym_counter.set(idx + 1);
332 // Include a '.' character, so there can be no accidental conflicts with
333 // user defined names
334 let mut name = String::with_capacity(prefix.len() + 6);
335 name.push_str(prefix);
337 base_n::push_str(idx as u128, base_n::ALPHANUMERIC_ONLY, &mut name);
341 pub fn eh_personality(&self) -> ValueRef {
342 // The exception handling personality function.
344 // If our compilation unit has the `eh_personality` lang item somewhere
345 // within it, then we just need to codegen that. Otherwise, we're
346 // building an rlib which will depend on some upstream implementation of
347 // this function, so we just codegen a generic reference to it. We don't
348 // specify any of the types for the function, we just make it a symbol
349 // that LLVM can later use.
351 // Note that MSVC is a little special here in that we don't use the
352 // `eh_personality` lang item at all. Currently LLVM has support for
353 // both Dwarf and SEH unwind mechanisms for MSVC targets and uses the
354 // *name of the personality function* to decide what kind of unwind side
355 // tables/landing pads to emit. It looks like Dwarf is used by default,
356 // injecting a dependency on the `_Unwind_Resume` symbol for resuming
357 // an "exception", but for MSVC we want to force SEH. This means that we
358 // can't actually have the personality function be our standard
359 // `rust_eh_personality` function, but rather we wired it up to the
360 // CRT's custom personality function, which forces LLVM to consider
361 // landing pads as "landing pads for SEH".
362 if let Some(llpersonality) = self.eh_personality.get() {
366 let llfn = match tcx.lang_items().eh_personality() {
367 Some(def_id) if !base::wants_msvc_seh(self.sess()) => {
368 callee::resolve_and_get_fn(self, def_id, tcx.intern_substs(&[]))
371 let name = if base::wants_msvc_seh(self.sess()) {
374 "rust_eh_personality"
376 let fty = Type::variadic_func(&[], &Type::i32(self));
377 declare::declare_cfn(self, name, fty)
380 self.eh_personality.set(Some(llfn));
384 // Returns a ValueRef of the "eh_unwind_resume" lang item if one is defined,
385 // otherwise declares it as an external function.
386 pub fn eh_unwind_resume(&self) -> ValueRef {
388 let unwresume = &self.eh_unwind_resume;
389 if let Some(llfn) = unwresume.get() {
394 assert!(self.sess().target.target.options.custom_unwind_resume);
395 if let Some(def_id) = tcx.lang_items().eh_unwind_resume() {
396 let llfn = callee::resolve_and_get_fn(self, def_id, tcx.intern_substs(&[]));
397 unwresume.set(Some(llfn));
401 let ty = tcx.mk_fn_ptr(ty::Binder::bind(tcx.mk_fn_sig(
402 iter::once(tcx.mk_mut_ptr(tcx.types.u8)),
405 hir::Unsafety::Unsafe,
409 let llfn = declare::declare_fn(self, "rust_eh_unwind_resume", ty);
410 attributes::unwind(llfn, true);
411 unwresume.set(Some(llfn));
415 pub fn type_needs_drop(&self, ty: Ty<'tcx>) -> bool {
416 common::type_needs_drop(self.tcx, ty)
419 pub fn type_is_sized(&self, ty: Ty<'tcx>) -> bool {
420 common::type_is_sized(self.tcx, ty)
423 pub fn type_is_freeze(&self, ty: Ty<'tcx>) -> bool {
424 common::type_is_freeze(self.tcx, ty)
427 pub fn type_has_metadata(&self, ty: Ty<'tcx>) -> bool {
428 use syntax_pos::DUMMY_SP;
429 if ty.is_sized(self.tcx.at(DUMMY_SP), ty::ParamEnv::reveal_all()) {
433 let tail = self.tcx.struct_tail(ty);
435 ty::TyForeign(..) => false,
436 ty::TyStr | ty::TySlice(..) | ty::TyDynamic(..) => true,
437 _ => bug!("unexpected unsized tail: {:?}", tail.sty),
442 impl<'a, 'tcx> ty::layout::HasDataLayout for &'a CodegenCx<'a, 'tcx> {
443 fn data_layout(&self) -> &ty::layout::TargetDataLayout {
444 &self.tcx.data_layout
448 impl<'a, 'tcx> HasTargetSpec for &'a CodegenCx<'a, 'tcx> {
449 fn target_spec(&self) -> &Target {
450 &self.tcx.sess.target.target
454 impl<'a, 'tcx> ty::layout::HasTyCtxt<'tcx> for &'a CodegenCx<'a, 'tcx> {
455 fn tcx<'b>(&'b self) -> TyCtxt<'b, 'tcx, 'tcx> {
460 impl<'a, 'tcx> LayoutOf for &'a CodegenCx<'a, 'tcx> {
462 type TyLayout = TyLayout<'tcx>;
464 fn layout_of(self, ty: Ty<'tcx>) -> Self::TyLayout {
465 self.tcx.layout_of(ty::ParamEnv::reveal_all().and(ty))
466 .unwrap_or_else(|e| match e {
467 LayoutError::SizeOverflow(_) => self.sess().fatal(&e.to_string()),
468 _ => bug!("failed to get layout for `{}`: {}", ty, e)
473 /// Declare any llvm intrinsics that you might need
474 fn declare_intrinsic(cx: &CodegenCx, key: &str) -> Option<ValueRef> {
476 ($name:expr, fn() -> $ret:expr) => (
478 let f = declare::declare_cfn(cx, $name, Type::func(&[], &$ret));
479 llvm::SetUnnamedAddr(f, false);
480 cx.intrinsics.borrow_mut().insert($name, f.clone());
484 ($name:expr, fn(...) -> $ret:expr) => (
486 let f = declare::declare_cfn(cx, $name, Type::variadic_func(&[], &$ret));
487 llvm::SetUnnamedAddr(f, false);
488 cx.intrinsics.borrow_mut().insert($name, f.clone());
492 ($name:expr, fn($($arg:expr),*) -> $ret:expr) => (
494 let f = declare::declare_cfn(cx, $name, Type::func(&[$($arg),*], &$ret));
495 llvm::SetUnnamedAddr(f, false);
496 cx.intrinsics.borrow_mut().insert($name, f.clone());
501 macro_rules! mk_struct {
502 ($($field_ty:expr),*) => (Type::struct_(cx, &[$($field_ty),*], false))
505 let i8p = Type::i8p(cx);
506 let void = Type::void(cx);
507 let i1 = Type::i1(cx);
508 let t_i8 = Type::i8(cx);
509 let t_i16 = Type::i16(cx);
510 let t_i32 = Type::i32(cx);
511 let t_i64 = Type::i64(cx);
512 let t_i128 = Type::i128(cx);
513 let t_f32 = Type::f32(cx);
514 let t_f64 = Type::f64(cx);
516 let t_v2f32 = Type::vector(&t_f32, 2);
517 let t_v4f32 = Type::vector(&t_f32, 4);
518 let t_v8f32 = Type::vector(&t_f32, 8);
519 let t_v16f32 = Type::vector(&t_f32, 16);
521 let t_v2f64 = Type::vector(&t_f64, 2);
522 let t_v4f64 = Type::vector(&t_f64, 4);
523 let t_v8f64 = Type::vector(&t_f64, 8);
525 ifn!("llvm.memcpy.p0i8.p0i8.i16", fn(i8p, i8p, t_i16, t_i32, i1) -> void);
526 ifn!("llvm.memcpy.p0i8.p0i8.i32", fn(i8p, i8p, t_i32, t_i32, i1) -> void);
527 ifn!("llvm.memcpy.p0i8.p0i8.i64", fn(i8p, i8p, t_i64, t_i32, i1) -> void);
528 ifn!("llvm.memmove.p0i8.p0i8.i16", fn(i8p, i8p, t_i16, t_i32, i1) -> void);
529 ifn!("llvm.memmove.p0i8.p0i8.i32", fn(i8p, i8p, t_i32, t_i32, i1) -> void);
530 ifn!("llvm.memmove.p0i8.p0i8.i64", fn(i8p, i8p, t_i64, t_i32, i1) -> void);
531 ifn!("llvm.memset.p0i8.i16", fn(i8p, t_i8, t_i16, t_i32, i1) -> void);
532 ifn!("llvm.memset.p0i8.i32", fn(i8p, t_i8, t_i32, t_i32, i1) -> void);
533 ifn!("llvm.memset.p0i8.i64", fn(i8p, t_i8, t_i64, t_i32, i1) -> void);
535 ifn!("llvm.trap", fn() -> void);
536 ifn!("llvm.debugtrap", fn() -> void);
537 ifn!("llvm.frameaddress", fn(t_i32) -> i8p);
539 ifn!("llvm.powi.f32", fn(t_f32, t_i32) -> t_f32);
540 ifn!("llvm.powi.v2f32", fn(t_v2f32, t_i32) -> t_v2f32);
541 ifn!("llvm.powi.v4f32", fn(t_v4f32, t_i32) -> t_v4f32);
542 ifn!("llvm.powi.v8f32", fn(t_v8f32, t_i32) -> t_v8f32);
543 ifn!("llvm.powi.v16f32", fn(t_v16f32, t_i32) -> t_v16f32);
544 ifn!("llvm.powi.f64", fn(t_f64, t_i32) -> t_f64);
545 ifn!("llvm.powi.v2f64", fn(t_v2f64, t_i32) -> t_v2f64);
546 ifn!("llvm.powi.v4f64", fn(t_v4f64, t_i32) -> t_v4f64);
547 ifn!("llvm.powi.v8f64", fn(t_v8f64, t_i32) -> t_v8f64);
549 ifn!("llvm.pow.f32", fn(t_f32, t_f32) -> t_f32);
550 ifn!("llvm.pow.v2f32", fn(t_v2f32, t_v2f32) -> t_v2f32);
551 ifn!("llvm.pow.v4f32", fn(t_v4f32, t_v4f32) -> t_v4f32);
552 ifn!("llvm.pow.v8f32", fn(t_v8f32, t_v8f32) -> t_v8f32);
553 ifn!("llvm.pow.v16f32", fn(t_v16f32, t_v16f32) -> t_v16f32);
554 ifn!("llvm.pow.f64", fn(t_f64, t_f64) -> t_f64);
555 ifn!("llvm.pow.v2f64", fn(t_v2f64, t_v2f64) -> t_v2f64);
556 ifn!("llvm.pow.v4f64", fn(t_v4f64, t_v4f64) -> t_v4f64);
557 ifn!("llvm.pow.v8f64", fn(t_v8f64, t_v8f64) -> t_v8f64);
559 ifn!("llvm.sqrt.f32", fn(t_f32) -> t_f32);
560 ifn!("llvm.sqrt.v2f32", fn(t_v2f32) -> t_v2f32);
561 ifn!("llvm.sqrt.v4f32", fn(t_v4f32) -> t_v4f32);
562 ifn!("llvm.sqrt.v8f32", fn(t_v8f32) -> t_v8f32);
563 ifn!("llvm.sqrt.v16f32", fn(t_v16f32) -> t_v16f32);
564 ifn!("llvm.sqrt.f64", fn(t_f64) -> t_f64);
565 ifn!("llvm.sqrt.v2f64", fn(t_v2f64) -> t_v2f64);
566 ifn!("llvm.sqrt.v4f64", fn(t_v4f64) -> t_v4f64);
567 ifn!("llvm.sqrt.v8f64", fn(t_v8f64) -> t_v8f64);
569 ifn!("llvm.sin.f32", fn(t_f32) -> t_f32);
570 ifn!("llvm.sin.v2f32", fn(t_v2f32) -> t_v2f32);
571 ifn!("llvm.sin.v4f32", fn(t_v4f32) -> t_v4f32);
572 ifn!("llvm.sin.v8f32", fn(t_v8f32) -> t_v8f32);
573 ifn!("llvm.sin.v16f32", fn(t_v16f32) -> t_v16f32);
574 ifn!("llvm.sin.f64", fn(t_f64) -> t_f64);
575 ifn!("llvm.sin.v2f64", fn(t_v2f64) -> t_v2f64);
576 ifn!("llvm.sin.v4f64", fn(t_v4f64) -> t_v4f64);
577 ifn!("llvm.sin.v8f64", fn(t_v8f64) -> t_v8f64);
579 ifn!("llvm.cos.f32", fn(t_f32) -> t_f32);
580 ifn!("llvm.cos.v2f32", fn(t_v2f32) -> t_v2f32);
581 ifn!("llvm.cos.v4f32", fn(t_v4f32) -> t_v4f32);
582 ifn!("llvm.cos.v8f32", fn(t_v8f32) -> t_v8f32);
583 ifn!("llvm.cos.v16f32", fn(t_v16f32) -> t_v16f32);
584 ifn!("llvm.cos.f64", fn(t_f64) -> t_f64);
585 ifn!("llvm.cos.v2f64", fn(t_v2f64) -> t_v2f64);
586 ifn!("llvm.cos.v4f64", fn(t_v4f64) -> t_v4f64);
587 ifn!("llvm.cos.v8f64", fn(t_v8f64) -> t_v8f64);
589 ifn!("llvm.exp.f32", fn(t_f32) -> t_f32);
590 ifn!("llvm.exp.v2f32", fn(t_v2f32) -> t_v2f32);
591 ifn!("llvm.exp.v4f32", fn(t_v4f32) -> t_v4f32);
592 ifn!("llvm.exp.v8f32", fn(t_v8f32) -> t_v8f32);
593 ifn!("llvm.exp.v16f32", fn(t_v16f32) -> t_v16f32);
594 ifn!("llvm.exp.f64", fn(t_f64) -> t_f64);
595 ifn!("llvm.exp.v2f64", fn(t_v2f64) -> t_v2f64);
596 ifn!("llvm.exp.v4f64", fn(t_v4f64) -> t_v4f64);
597 ifn!("llvm.exp.v8f64", fn(t_v8f64) -> t_v8f64);
599 ifn!("llvm.exp2.f32", fn(t_f32) -> t_f32);
600 ifn!("llvm.exp2.v2f32", fn(t_v2f32) -> t_v2f32);
601 ifn!("llvm.exp2.v4f32", fn(t_v4f32) -> t_v4f32);
602 ifn!("llvm.exp2.v8f32", fn(t_v8f32) -> t_v8f32);
603 ifn!("llvm.exp2.v16f32", fn(t_v16f32) -> t_v16f32);
604 ifn!("llvm.exp2.f64", fn(t_f64) -> t_f64);
605 ifn!("llvm.exp2.v2f64", fn(t_v2f64) -> t_v2f64);
606 ifn!("llvm.exp2.v4f64", fn(t_v4f64) -> t_v4f64);
607 ifn!("llvm.exp2.v8f64", fn(t_v8f64) -> t_v8f64);
609 ifn!("llvm.log.f32", fn(t_f32) -> t_f32);
610 ifn!("llvm.log.v2f32", fn(t_v2f32) -> t_v2f32);
611 ifn!("llvm.log.v4f32", fn(t_v4f32) -> t_v4f32);
612 ifn!("llvm.log.v8f32", fn(t_v8f32) -> t_v8f32);
613 ifn!("llvm.log.v16f32", fn(t_v16f32) -> t_v16f32);
614 ifn!("llvm.log.f64", fn(t_f64) -> t_f64);
615 ifn!("llvm.log.v2f64", fn(t_v2f64) -> t_v2f64);
616 ifn!("llvm.log.v4f64", fn(t_v4f64) -> t_v4f64);
617 ifn!("llvm.log.v8f64", fn(t_v8f64) -> t_v8f64);
619 ifn!("llvm.log10.f32", fn(t_f32) -> t_f32);
620 ifn!("llvm.log10.v2f32", fn(t_v2f32) -> t_v2f32);
621 ifn!("llvm.log10.v4f32", fn(t_v4f32) -> t_v4f32);
622 ifn!("llvm.log10.v8f32", fn(t_v8f32) -> t_v8f32);
623 ifn!("llvm.log10.v16f32", fn(t_v16f32) -> t_v16f32);
624 ifn!("llvm.log10.f64", fn(t_f64) -> t_f64);
625 ifn!("llvm.log10.v2f64", fn(t_v2f64) -> t_v2f64);
626 ifn!("llvm.log10.v4f64", fn(t_v4f64) -> t_v4f64);
627 ifn!("llvm.log10.v8f64", fn(t_v8f64) -> t_v8f64);
629 ifn!("llvm.log2.f32", fn(t_f32) -> t_f32);
630 ifn!("llvm.log2.v2f32", fn(t_v2f32) -> t_v2f32);
631 ifn!("llvm.log2.v4f32", fn(t_v4f32) -> t_v4f32);
632 ifn!("llvm.log2.v8f32", fn(t_v8f32) -> t_v8f32);
633 ifn!("llvm.log2.v16f32", fn(t_v16f32) -> t_v16f32);
634 ifn!("llvm.log2.f64", fn(t_f64) -> t_f64);
635 ifn!("llvm.log2.v2f64", fn(t_v2f64) -> t_v2f64);
636 ifn!("llvm.log2.v4f64", fn(t_v4f64) -> t_v4f64);
637 ifn!("llvm.log2.v8f64", fn(t_v8f64) -> t_v8f64);
639 ifn!("llvm.fma.f32", fn(t_f32, t_f32, t_f32) -> t_f32);
640 ifn!("llvm.fma.v2f32", fn(t_v2f32, t_v2f32, t_v2f32) -> t_v2f32);
641 ifn!("llvm.fma.v4f32", fn(t_v4f32, t_v4f32, t_v4f32) -> t_v4f32);
642 ifn!("llvm.fma.v8f32", fn(t_v8f32, t_v8f32, t_v8f32) -> t_v8f32);
643 ifn!("llvm.fma.v16f32", fn(t_v16f32, t_v16f32, t_v16f32) -> t_v16f32);
644 ifn!("llvm.fma.f64", fn(t_f64, t_f64, t_f64) -> t_f64);
645 ifn!("llvm.fma.v2f64", fn(t_v2f64, t_v2f64, t_v2f64) -> t_v2f64);
646 ifn!("llvm.fma.v4f64", fn(t_v4f64, t_v4f64, t_v4f64) -> t_v4f64);
647 ifn!("llvm.fma.v8f64", fn(t_v8f64, t_v8f64, t_v8f64) -> t_v8f64);
649 ifn!("llvm.fabs.f32", fn(t_f32) -> t_f32);
650 ifn!("llvm.fabs.v2f32", fn(t_v2f32) -> t_v2f32);
651 ifn!("llvm.fabs.v4f32", fn(t_v4f32) -> t_v4f32);
652 ifn!("llvm.fabs.v8f32", fn(t_v8f32) -> t_v8f32);
653 ifn!("llvm.fabs.v16f32", fn(t_v16f32) -> t_v16f32);
654 ifn!("llvm.fabs.f64", fn(t_f64) -> t_f64);
655 ifn!("llvm.fabs.v2f64", fn(t_v2f64) -> t_v2f64);
656 ifn!("llvm.fabs.v4f64", fn(t_v4f64) -> t_v4f64);
657 ifn!("llvm.fabs.v8f64", fn(t_v8f64) -> t_v8f64);
659 ifn!("llvm.floor.f32", fn(t_f32) -> t_f32);
660 ifn!("llvm.floor.v2f32", fn(t_v2f32) -> t_v2f32);
661 ifn!("llvm.floor.v4f32", fn(t_v4f32) -> t_v4f32);
662 ifn!("llvm.floor.v8f32", fn(t_v8f32) -> t_v8f32);
663 ifn!("llvm.floor.v16f32", fn(t_v16f32) -> t_v16f32);
664 ifn!("llvm.floor.f64", fn(t_f64) -> t_f64);
665 ifn!("llvm.floor.v2f64", fn(t_v2f64) -> t_v2f64);
666 ifn!("llvm.floor.v4f64", fn(t_v4f64) -> t_v4f64);
667 ifn!("llvm.floor.v8f64", fn(t_v8f64) -> t_v8f64);
669 ifn!("llvm.ceil.f32", fn(t_f32) -> t_f32);
670 ifn!("llvm.ceil.v2f32", fn(t_v2f32) -> t_v2f32);
671 ifn!("llvm.ceil.v4f32", fn(t_v4f32) -> t_v4f32);
672 ifn!("llvm.ceil.v8f32", fn(t_v8f32) -> t_v8f32);
673 ifn!("llvm.ceil.v16f32", fn(t_v16f32) -> t_v16f32);
674 ifn!("llvm.ceil.f64", fn(t_f64) -> t_f64);
675 ifn!("llvm.ceil.v2f64", fn(t_v2f64) -> t_v2f64);
676 ifn!("llvm.ceil.v4f64", fn(t_v4f64) -> t_v4f64);
677 ifn!("llvm.ceil.v8f64", fn(t_v8f64) -> t_v8f64);
679 ifn!("llvm.trunc.f32", fn(t_f32) -> t_f32);
680 ifn!("llvm.trunc.f64", fn(t_f64) -> t_f64);
682 ifn!("llvm.copysign.f32", fn(t_f32, t_f32) -> t_f32);
683 ifn!("llvm.copysign.f64", fn(t_f64, t_f64) -> t_f64);
684 ifn!("llvm.round.f32", fn(t_f32) -> t_f32);
685 ifn!("llvm.round.f64", fn(t_f64) -> t_f64);
687 ifn!("llvm.rint.f32", fn(t_f32) -> t_f32);
688 ifn!("llvm.rint.f64", fn(t_f64) -> t_f64);
689 ifn!("llvm.nearbyint.f32", fn(t_f32) -> t_f32);
690 ifn!("llvm.nearbyint.f64", fn(t_f64) -> t_f64);
692 ifn!("llvm.ctpop.i8", fn(t_i8) -> t_i8);
693 ifn!("llvm.ctpop.i16", fn(t_i16) -> t_i16);
694 ifn!("llvm.ctpop.i32", fn(t_i32) -> t_i32);
695 ifn!("llvm.ctpop.i64", fn(t_i64) -> t_i64);
696 ifn!("llvm.ctpop.i128", fn(t_i128) -> t_i128);
698 ifn!("llvm.ctlz.i8", fn(t_i8 , i1) -> t_i8);
699 ifn!("llvm.ctlz.i16", fn(t_i16, i1) -> t_i16);
700 ifn!("llvm.ctlz.i32", fn(t_i32, i1) -> t_i32);
701 ifn!("llvm.ctlz.i64", fn(t_i64, i1) -> t_i64);
702 ifn!("llvm.ctlz.i128", fn(t_i128, i1) -> t_i128);
704 ifn!("llvm.cttz.i8", fn(t_i8 , i1) -> t_i8);
705 ifn!("llvm.cttz.i16", fn(t_i16, i1) -> t_i16);
706 ifn!("llvm.cttz.i32", fn(t_i32, i1) -> t_i32);
707 ifn!("llvm.cttz.i64", fn(t_i64, i1) -> t_i64);
708 ifn!("llvm.cttz.i128", fn(t_i128, i1) -> t_i128);
710 ifn!("llvm.bswap.i16", fn(t_i16) -> t_i16);
711 ifn!("llvm.bswap.i32", fn(t_i32) -> t_i32);
712 ifn!("llvm.bswap.i64", fn(t_i64) -> t_i64);
713 ifn!("llvm.bswap.i128", fn(t_i128) -> t_i128);
715 ifn!("llvm.bitreverse.i8", fn(t_i8) -> t_i8);
716 ifn!("llvm.bitreverse.i16", fn(t_i16) -> t_i16);
717 ifn!("llvm.bitreverse.i32", fn(t_i32) -> t_i32);
718 ifn!("llvm.bitreverse.i64", fn(t_i64) -> t_i64);
719 ifn!("llvm.bitreverse.i128", fn(t_i128) -> t_i128);
721 ifn!("llvm.sadd.with.overflow.i8", fn(t_i8, t_i8) -> mk_struct!{t_i8, i1});
722 ifn!("llvm.sadd.with.overflow.i16", fn(t_i16, t_i16) -> mk_struct!{t_i16, i1});
723 ifn!("llvm.sadd.with.overflow.i32", fn(t_i32, t_i32) -> mk_struct!{t_i32, i1});
724 ifn!("llvm.sadd.with.overflow.i64", fn(t_i64, t_i64) -> mk_struct!{t_i64, i1});
725 ifn!("llvm.sadd.with.overflow.i128", fn(t_i128, t_i128) -> mk_struct!{t_i128, i1});
727 ifn!("llvm.uadd.with.overflow.i8", fn(t_i8, t_i8) -> mk_struct!{t_i8, i1});
728 ifn!("llvm.uadd.with.overflow.i16", fn(t_i16, t_i16) -> mk_struct!{t_i16, i1});
729 ifn!("llvm.uadd.with.overflow.i32", fn(t_i32, t_i32) -> mk_struct!{t_i32, i1});
730 ifn!("llvm.uadd.with.overflow.i64", fn(t_i64, t_i64) -> mk_struct!{t_i64, i1});
731 ifn!("llvm.uadd.with.overflow.i128", fn(t_i128, t_i128) -> mk_struct!{t_i128, i1});
733 ifn!("llvm.ssub.with.overflow.i8", fn(t_i8, t_i8) -> mk_struct!{t_i8, i1});
734 ifn!("llvm.ssub.with.overflow.i16", fn(t_i16, t_i16) -> mk_struct!{t_i16, i1});
735 ifn!("llvm.ssub.with.overflow.i32", fn(t_i32, t_i32) -> mk_struct!{t_i32, i1});
736 ifn!("llvm.ssub.with.overflow.i64", fn(t_i64, t_i64) -> mk_struct!{t_i64, i1});
737 ifn!("llvm.ssub.with.overflow.i128", fn(t_i128, t_i128) -> mk_struct!{t_i128, i1});
739 ifn!("llvm.usub.with.overflow.i8", fn(t_i8, t_i8) -> mk_struct!{t_i8, i1});
740 ifn!("llvm.usub.with.overflow.i16", fn(t_i16, t_i16) -> mk_struct!{t_i16, i1});
741 ifn!("llvm.usub.with.overflow.i32", fn(t_i32, t_i32) -> mk_struct!{t_i32, i1});
742 ifn!("llvm.usub.with.overflow.i64", fn(t_i64, t_i64) -> mk_struct!{t_i64, i1});
743 ifn!("llvm.usub.with.overflow.i128", fn(t_i128, t_i128) -> mk_struct!{t_i128, i1});
745 ifn!("llvm.smul.with.overflow.i8", fn(t_i8, t_i8) -> mk_struct!{t_i8, i1});
746 ifn!("llvm.smul.with.overflow.i16", fn(t_i16, t_i16) -> mk_struct!{t_i16, i1});
747 ifn!("llvm.smul.with.overflow.i32", fn(t_i32, t_i32) -> mk_struct!{t_i32, i1});
748 ifn!("llvm.smul.with.overflow.i64", fn(t_i64, t_i64) -> mk_struct!{t_i64, i1});
749 ifn!("llvm.smul.with.overflow.i128", fn(t_i128, t_i128) -> mk_struct!{t_i128, i1});
751 ifn!("llvm.umul.with.overflow.i8", fn(t_i8, t_i8) -> mk_struct!{t_i8, i1});
752 ifn!("llvm.umul.with.overflow.i16", fn(t_i16, t_i16) -> mk_struct!{t_i16, i1});
753 ifn!("llvm.umul.with.overflow.i32", fn(t_i32, t_i32) -> mk_struct!{t_i32, i1});
754 ifn!("llvm.umul.with.overflow.i64", fn(t_i64, t_i64) -> mk_struct!{t_i64, i1});
755 ifn!("llvm.umul.with.overflow.i128", fn(t_i128, t_i128) -> mk_struct!{t_i128, i1});
757 ifn!("llvm.lifetime.start", fn(t_i64,i8p) -> void);
758 ifn!("llvm.lifetime.end", fn(t_i64, i8p) -> void);
760 ifn!("llvm.expect.i1", fn(i1, i1) -> i1);
761 ifn!("llvm.eh.typeid.for", fn(i8p) -> t_i32);
762 ifn!("llvm.localescape", fn(...) -> void);
763 ifn!("llvm.localrecover", fn(i8p, i8p, t_i32) -> i8p);
764 ifn!("llvm.x86.seh.recoverfp", fn(i8p, i8p) -> i8p);
766 ifn!("llvm.assume", fn(i1) -> void);
767 ifn!("llvm.prefetch", fn(i8p, t_i32, t_i32, t_i32) -> void);
769 if cx.sess().opts.debuginfo != NoDebugInfo {
770 ifn!("llvm.dbg.declare", fn(Type::metadata(cx), Type::metadata(cx)) -> void);
771 ifn!("llvm.dbg.value", fn(Type::metadata(cx), t_i64, Type::metadata(cx)) -> void);