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.
13 use llvm::{ContextRef, ModuleRef, ValueRef};
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};
42 use syntax::symbol::LocalInternedString;
45 /// There is one `CodegenCx` per compilation unit. Each one has its own LLVM
46 /// `ContextRef` so that several compilation units may be optimized in parallel.
47 /// All other LLVM data structures in the `CodegenCx` are tied to that `ContextRef`.
48 pub struct CodegenCx<'a, 'tcx: 'a> {
49 pub tcx: TyCtxt<'a, 'tcx, 'tcx>,
50 pub check_overflow: bool,
51 pub use_dll_storage_attrs: bool,
52 pub tls_model: llvm::ThreadLocalMode,
56 pub stats: RefCell<Stats>,
57 pub codegen_unit: Arc<CodegenUnit<'tcx>>,
59 /// Cache instances of monomorphic and polymorphic items
60 pub instances: RefCell<FxHashMap<Instance<'tcx>, ValueRef>>,
61 /// Cache generated vtables
62 pub vtables: RefCell<FxHashMap<(Ty<'tcx>,
63 Option<ty::PolyExistentialTraitRef<'tcx>>), ValueRef>>,
64 /// Cache of constant strings,
65 pub const_cstr_cache: RefCell<FxHashMap<LocalInternedString, ValueRef>>,
67 /// Reverse-direction for const ptrs cast from globals.
68 /// Key is a ValueRef holding a *T,
69 /// Val is a ValueRef holding a *[T].
71 /// Needed because LLVM loses pointer->pointee association
72 /// when we ptrcast, and we have to ptrcast during translation
73 /// of a [T] const because we form a slice, a (*T,usize) pair, not
74 /// a pointer to an LLVM array type. Similar for trait objects.
75 pub const_unsized: RefCell<FxHashMap<ValueRef, ValueRef>>,
77 /// Cache of emitted const globals (value -> global)
78 pub const_globals: RefCell<FxHashMap<ValueRef, ValueRef>>,
80 /// Mapping from static definitions to their DefId's.
81 pub statics: RefCell<FxHashMap<ValueRef, DefId>>,
83 /// List of globals for static variables which need to be passed to the
84 /// LLVM function ReplaceAllUsesWith (RAUW) when translation is complete.
85 /// (We have to make sure we don't invalidate any ValueRefs referring
87 pub statics_to_rauw: RefCell<Vec<(ValueRef, ValueRef)>>,
89 /// Statics that will be placed in the llvm.used variable
90 /// See http://llvm.org/docs/LangRef.html#the-llvm-used-global-variable for details
91 pub used_statics: RefCell<Vec<ValueRef>>,
93 pub lltypes: RefCell<FxHashMap<(Ty<'tcx>, Option<usize>), Type>>,
94 pub scalar_lltypes: RefCell<FxHashMap<Ty<'tcx>, Type>>,
95 pub pointee_infos: RefCell<FxHashMap<(Ty<'tcx>, Size), Option<PointeeInfo>>>,
98 pub dbg_cx: Option<debuginfo::CrateDebugContext<'tcx>>,
100 eh_personality: Cell<Option<ValueRef>>,
101 eh_unwind_resume: Cell<Option<ValueRef>>,
102 pub rust_try_fn: Cell<Option<ValueRef>>,
104 intrinsics: RefCell<FxHashMap<&'static str, ValueRef>>,
106 /// A counter that is used for generating local symbol names
107 local_gen_sym_counter: Cell<usize>,
110 impl<'a, 'tcx> DepGraphSafe for CodegenCx<'a, 'tcx> {
113 pub fn get_reloc_model(sess: &Session) -> llvm::RelocMode {
114 let reloc_model_arg = match sess.opts.cg.relocation_model {
115 Some(ref s) => &s[..],
116 None => &sess.target.target.options.relocation_model[..],
119 match ::back::write::RELOC_MODEL_ARGS.iter().find(
120 |&&arg| arg.0 == reloc_model_arg) {
123 sess.err(&format!("{:?} is not a valid relocation mode",
125 sess.abort_if_errors();
131 fn get_tls_model(sess: &Session) -> llvm::ThreadLocalMode {
132 let tls_model_arg = match sess.opts.debugging_opts.tls_model {
133 Some(ref s) => &s[..],
134 None => &sess.target.target.options.tls_model[..],
137 match ::back::write::TLS_MODEL_ARGS.iter().find(
138 |&&arg| arg.0 == tls_model_arg) {
141 sess.err(&format!("{:?} is not a valid TLS model",
143 sess.abort_if_errors();
149 fn is_any_library(sess: &Session) -> bool {
150 sess.crate_types.borrow().iter().any(|ty| {
151 *ty != config::CrateTypeExecutable
155 pub fn is_pie_binary(sess: &Session) -> bool {
156 !is_any_library(sess) && get_reloc_model(sess) == llvm::RelocMode::PIC
159 pub unsafe fn create_context_and_module(sess: &Session, mod_name: &str) -> (ContextRef, ModuleRef) {
160 let llcx = llvm::LLVMRustContextCreate(sess.fewer_names());
161 let mod_name = CString::new(mod_name).unwrap();
162 let llmod = llvm::LLVMModuleCreateWithNameInContext(mod_name.as_ptr(), llcx);
164 // Ensure the data-layout values hardcoded remain the defaults.
165 if sess.target.target.options.is_builtin {
166 let tm = ::back::write::create_target_machine(sess, false);
167 llvm::LLVMRustSetDataLayoutFromTargetMachine(llmod, tm);
168 llvm::LLVMRustDisposeTargetMachine(tm);
170 let data_layout = llvm::LLVMGetDataLayout(llmod);
171 let data_layout = str::from_utf8(CStr::from_ptr(data_layout).to_bytes())
172 .ok().expect("got a non-UTF8 data-layout from LLVM");
174 // Unfortunately LLVM target specs change over time, and right now we
175 // don't have proper support to work with any more than one
176 // `data_layout` than the one that is in the rust-lang/rust repo. If
177 // this compiler is configured against a custom LLVM, we may have a
178 // differing data layout, even though we should update our own to use
181 // As an interim hack, if CFG_LLVM_ROOT is not an empty string then we
182 // disable this check entirely as we may be configured with something
183 // that has a different target layout.
185 // Unsure if this will actually cause breakage when rustc is configured
189 let cfg_llvm_root = option_env!("CFG_LLVM_ROOT").unwrap_or("");
190 let custom_llvm_used = cfg_llvm_root.trim() != "";
192 if !custom_llvm_used && sess.target.target.data_layout != data_layout {
193 bug!("data-layout for builtin `{}` target, `{}`, \
194 differs from LLVM default, `{}`",
195 sess.target.target.llvm_target,
196 sess.target.target.data_layout,
201 let data_layout = CString::new(&sess.target.target.data_layout[..]).unwrap();
202 llvm::LLVMSetDataLayout(llmod, data_layout.as_ptr());
204 let llvm_target = sess.target.target.llvm_target.as_bytes();
205 let llvm_target = CString::new(llvm_target).unwrap();
206 llvm::LLVMRustSetNormalizedTarget(llmod, llvm_target.as_ptr());
208 if is_pie_binary(sess) {
209 llvm::LLVMRustSetModulePIELevel(llmod);
215 impl<'a, 'tcx> CodegenCx<'a, 'tcx> {
216 pub fn new(tcx: TyCtxt<'a, 'tcx, 'tcx>,
217 codegen_unit: Arc<CodegenUnit<'tcx>>,
219 -> CodegenCx<'a, 'tcx> {
220 // An interesting part of Windows which MSVC forces our hand on (and
221 // apparently MinGW didn't) is the usage of `dllimport` and `dllexport`
222 // attributes in LLVM IR as well as native dependencies (in C these
223 // correspond to `__declspec(dllimport)`).
225 // Whenever a dynamic library is built by MSVC it must have its public
226 // interface specified by functions tagged with `dllexport` or otherwise
227 // they're not available to be linked against. This poses a few problems
228 // for the compiler, some of which are somewhat fundamental, but we use
229 // the `use_dll_storage_attrs` variable below to attach the `dllexport`
230 // attribute to all LLVM functions that are exported e.g. they're
231 // already tagged with external linkage). This is suboptimal for a few
234 // * If an object file will never be included in a dynamic library,
235 // there's no need to attach the dllexport attribute. Most object
236 // files in Rust are not destined to become part of a dll as binaries
237 // are statically linked by default.
238 // * If the compiler is emitting both an rlib and a dylib, the same
239 // source object file is currently used but with MSVC this may be less
240 // feasible. The compiler may be able to get around this, but it may
241 // involve some invasive changes to deal with this.
243 // The flipside of this situation is that whenever you link to a dll and
244 // you import a function from it, the import should be tagged with
245 // `dllimport`. At this time, however, the compiler does not emit
246 // `dllimport` for any declarations other than constants (where it is
247 // required), which is again suboptimal for even more reasons!
249 // * Calling a function imported from another dll without using
250 // `dllimport` causes the linker/compiler to have extra overhead (one
251 // `jmp` instruction on x86) when calling the function.
252 // * The same object file may be used in different circumstances, so a
253 // function may be imported from a dll if the object is linked into a
254 // dll, but it may be just linked against if linked into an rlib.
255 // * The compiler has no knowledge about whether native functions should
256 // be tagged dllimport or not.
258 // For now the compiler takes the perf hit (I do not have any numbers to
259 // this effect) by marking very little as `dllimport` and praying the
260 // linker will take care of everything. Fixing this problem will likely
261 // require adding a few attributes to Rust itself (feature gated at the
262 // start) and then strongly recommending static linkage on MSVC!
263 let use_dll_storage_attrs = tcx.sess.target.target.options.is_like_msvc;
265 let check_overflow = tcx.sess.overflow_checks();
267 let tls_model = get_tls_model(&tcx.sess);
270 let (llcx, llmod) = create_context_and_module(&tcx.sess,
273 let dbg_cx = if tcx.sess.opts.debuginfo != NoDebugInfo {
274 let dctx = debuginfo::CrateDebugContext::new(llmod);
275 debuginfo::metadata::compile_unit_metadata(tcx,
276 &codegen_unit.name().as_str(),
283 let mut cx = CodegenCx {
286 use_dll_storage_attrs,
290 stats: RefCell::new(Stats::default()),
292 instances: RefCell::new(FxHashMap()),
293 vtables: RefCell::new(FxHashMap()),
294 const_cstr_cache: RefCell::new(FxHashMap()),
295 const_unsized: RefCell::new(FxHashMap()),
296 const_globals: RefCell::new(FxHashMap()),
297 statics: RefCell::new(FxHashMap()),
298 statics_to_rauw: RefCell::new(Vec::new()),
299 used_statics: RefCell::new(Vec::new()),
300 lltypes: RefCell::new(FxHashMap()),
301 scalar_lltypes: RefCell::new(FxHashMap()),
302 pointee_infos: RefCell::new(FxHashMap()),
303 isize_ty: Type::from_ref(ptr::null_mut()),
305 eh_personality: Cell::new(None),
306 eh_unwind_resume: Cell::new(None),
307 rust_try_fn: Cell::new(None),
308 intrinsics: RefCell::new(FxHashMap()),
309 local_gen_sym_counter: Cell::new(0),
311 cx.isize_ty = Type::isize(&cx);
316 pub fn into_stats(self) -> Stats {
317 self.stats.into_inner()
321 impl<'b, 'tcx> CodegenCx<'b, 'tcx> {
322 pub fn sess<'a>(&'a self) -> &'a Session {
326 pub fn get_intrinsic(&self, key: &str) -> ValueRef {
327 if let Some(v) = self.intrinsics.borrow().get(key).cloned() {
330 match declare_intrinsic(self, key) {
332 None => bug!("unknown intrinsic '{}'", key)
336 /// Generate a new symbol name with the given prefix. This symbol name must
337 /// only be used for definitions with `internal` or `private` linkage.
338 pub fn generate_local_symbol_name(&self, prefix: &str) -> String {
339 let idx = self.local_gen_sym_counter.get();
340 self.local_gen_sym_counter.set(idx + 1);
341 // Include a '.' character, so there can be no accidental conflicts with
342 // user defined names
343 let mut name = String::with_capacity(prefix.len() + 6);
344 name.push_str(prefix);
346 base_n::push_str(idx as u128, base_n::ALPHANUMERIC_ONLY, &mut name);
350 pub fn eh_personality(&self) -> ValueRef {
351 // The exception handling personality function.
353 // If our compilation unit has the `eh_personality` lang item somewhere
354 // within it, then we just need to translate that. Otherwise, we're
355 // building an rlib which will depend on some upstream implementation of
356 // this function, so we just codegen a generic reference to it. We don't
357 // specify any of the types for the function, we just make it a symbol
358 // that LLVM can later use.
360 // Note that MSVC is a little special here in that we don't use the
361 // `eh_personality` lang item at all. Currently LLVM has support for
362 // both Dwarf and SEH unwind mechanisms for MSVC targets and uses the
363 // *name of the personality function* to decide what kind of unwind side
364 // tables/landing pads to emit. It looks like Dwarf is used by default,
365 // injecting a dependency on the `_Unwind_Resume` symbol for resuming
366 // an "exception", but for MSVC we want to force SEH. This means that we
367 // can't actually have the personality function be our standard
368 // `rust_eh_personality` function, but rather we wired it up to the
369 // CRT's custom personality function, which forces LLVM to consider
370 // landing pads as "landing pads for SEH".
371 if let Some(llpersonality) = self.eh_personality.get() {
375 let llfn = match tcx.lang_items().eh_personality() {
376 Some(def_id) if !base::wants_msvc_seh(self.sess()) => {
377 callee::resolve_and_get_fn(self, def_id, tcx.intern_substs(&[]))
380 let name = if base::wants_msvc_seh(self.sess()) {
383 "rust_eh_personality"
385 let fty = Type::variadic_func(&[], &Type::i32(self));
386 declare::declare_cfn(self, name, fty)
389 self.eh_personality.set(Some(llfn));
393 // Returns a ValueRef of the "eh_unwind_resume" lang item if one is defined,
394 // otherwise declares it as an external function.
395 pub fn eh_unwind_resume(&self) -> ValueRef {
397 let unwresume = &self.eh_unwind_resume;
398 if let Some(llfn) = unwresume.get() {
403 assert!(self.sess().target.target.options.custom_unwind_resume);
404 if let Some(def_id) = tcx.lang_items().eh_unwind_resume() {
405 let llfn = callee::resolve_and_get_fn(self, def_id, tcx.intern_substs(&[]));
406 unwresume.set(Some(llfn));
410 let ty = tcx.mk_fn_ptr(ty::Binder::bind(tcx.mk_fn_sig(
411 iter::once(tcx.mk_mut_ptr(tcx.types.u8)),
414 hir::Unsafety::Unsafe,
418 let llfn = declare::declare_fn(self, "rust_eh_unwind_resume", ty);
419 attributes::unwind(llfn, true);
420 unwresume.set(Some(llfn));
424 pub fn type_needs_drop(&self, ty: Ty<'tcx>) -> bool {
425 common::type_needs_drop(self.tcx, ty)
428 pub fn type_is_sized(&self, ty: Ty<'tcx>) -> bool {
429 common::type_is_sized(self.tcx, ty)
432 pub fn type_is_freeze(&self, ty: Ty<'tcx>) -> bool {
433 common::type_is_freeze(self.tcx, ty)
436 pub fn type_has_metadata(&self, ty: Ty<'tcx>) -> bool {
437 use syntax_pos::DUMMY_SP;
438 if ty.is_sized(self.tcx.at(DUMMY_SP), ty::ParamEnv::reveal_all()) {
442 let tail = self.tcx.struct_tail(ty);
444 ty::TyForeign(..) => false,
445 ty::TyStr | ty::TySlice(..) | ty::TyDynamic(..) => true,
446 _ => bug!("unexpected unsized tail: {:?}", tail.sty),
451 impl<'a, 'tcx> ty::layout::HasDataLayout for &'a CodegenCx<'a, 'tcx> {
452 fn data_layout(&self) -> &ty::layout::TargetDataLayout {
453 &self.tcx.data_layout
457 impl<'a, 'tcx> HasTargetSpec for &'a CodegenCx<'a, 'tcx> {
458 fn target_spec(&self) -> &Target {
459 &self.tcx.sess.target.target
463 impl<'a, 'tcx> ty::layout::HasTyCtxt<'tcx> for &'a CodegenCx<'a, 'tcx> {
464 fn tcx<'b>(&'b self) -> TyCtxt<'b, 'tcx, 'tcx> {
469 impl<'a, 'tcx> LayoutOf for &'a CodegenCx<'a, 'tcx> {
471 type TyLayout = TyLayout<'tcx>;
473 fn layout_of(self, ty: Ty<'tcx>) -> Self::TyLayout {
474 self.tcx.layout_of(ty::ParamEnv::reveal_all().and(ty))
475 .unwrap_or_else(|e| match e {
476 LayoutError::SizeOverflow(_) => self.sess().fatal(&e.to_string()),
477 _ => bug!("failed to get layout for `{}`: {}", ty, e)
482 /// Declare any llvm intrinsics that you might need
483 fn declare_intrinsic(cx: &CodegenCx, key: &str) -> Option<ValueRef> {
485 ($name:expr, fn() -> $ret:expr) => (
487 let f = declare::declare_cfn(cx, $name, Type::func(&[], &$ret));
488 llvm::SetUnnamedAddr(f, false);
489 cx.intrinsics.borrow_mut().insert($name, f.clone());
493 ($name:expr, fn(...) -> $ret:expr) => (
495 let f = declare::declare_cfn(cx, $name, Type::variadic_func(&[], &$ret));
496 llvm::SetUnnamedAddr(f, false);
497 cx.intrinsics.borrow_mut().insert($name, f.clone());
501 ($name:expr, fn($($arg:expr),*) -> $ret:expr) => (
503 let f = declare::declare_cfn(cx, $name, Type::func(&[$($arg),*], &$ret));
504 llvm::SetUnnamedAddr(f, false);
505 cx.intrinsics.borrow_mut().insert($name, f.clone());
510 macro_rules! mk_struct {
511 ($($field_ty:expr),*) => (Type::struct_(cx, &[$($field_ty),*], false))
514 let i8p = Type::i8p(cx);
515 let void = Type::void(cx);
516 let i1 = Type::i1(cx);
517 let t_i8 = Type::i8(cx);
518 let t_i16 = Type::i16(cx);
519 let t_i32 = Type::i32(cx);
520 let t_i64 = Type::i64(cx);
521 let t_i128 = Type::i128(cx);
522 let t_f32 = Type::f32(cx);
523 let t_f64 = Type::f64(cx);
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.f64", fn(t_f64, t_i32) -> t_f64);
541 ifn!("llvm.pow.f32", fn(t_f32, t_f32) -> t_f32);
542 ifn!("llvm.pow.f64", fn(t_f64, t_f64) -> t_f64);
544 ifn!("llvm.sqrt.f32", fn(t_f32) -> t_f32);
545 ifn!("llvm.sqrt.f64", fn(t_f64) -> t_f64);
546 ifn!("llvm.sin.f32", fn(t_f32) -> t_f32);
547 ifn!("llvm.sin.f64", fn(t_f64) -> t_f64);
548 ifn!("llvm.cos.f32", fn(t_f32) -> t_f32);
549 ifn!("llvm.cos.f64", fn(t_f64) -> t_f64);
550 ifn!("llvm.exp.f32", fn(t_f32) -> t_f32);
551 ifn!("llvm.exp.f64", fn(t_f64) -> t_f64);
552 ifn!("llvm.exp2.f32", fn(t_f32) -> t_f32);
553 ifn!("llvm.exp2.f64", fn(t_f64) -> t_f64);
554 ifn!("llvm.log.f32", fn(t_f32) -> t_f32);
555 ifn!("llvm.log.f64", fn(t_f64) -> t_f64);
556 ifn!("llvm.log10.f32", fn(t_f32) -> t_f32);
557 ifn!("llvm.log10.f64", fn(t_f64) -> t_f64);
558 ifn!("llvm.log2.f32", fn(t_f32) -> t_f32);
559 ifn!("llvm.log2.f64", fn(t_f64) -> t_f64);
561 ifn!("llvm.fma.f32", fn(t_f32, t_f32, t_f32) -> t_f32);
562 ifn!("llvm.fma.f64", fn(t_f64, t_f64, t_f64) -> t_f64);
564 ifn!("llvm.fabs.f32", fn(t_f32) -> t_f32);
565 ifn!("llvm.fabs.f64", fn(t_f64) -> t_f64);
567 ifn!("llvm.floor.f32", fn(t_f32) -> t_f32);
568 ifn!("llvm.floor.f64", fn(t_f64) -> t_f64);
569 ifn!("llvm.ceil.f32", fn(t_f32) -> t_f32);
570 ifn!("llvm.ceil.f64", fn(t_f64) -> t_f64);
571 ifn!("llvm.trunc.f32", fn(t_f32) -> t_f32);
572 ifn!("llvm.trunc.f64", fn(t_f64) -> t_f64);
574 ifn!("llvm.copysign.f32", fn(t_f32, t_f32) -> t_f32);
575 ifn!("llvm.copysign.f64", fn(t_f64, t_f64) -> t_f64);
576 ifn!("llvm.round.f32", fn(t_f32) -> t_f32);
577 ifn!("llvm.round.f64", fn(t_f64) -> t_f64);
579 ifn!("llvm.rint.f32", fn(t_f32) -> t_f32);
580 ifn!("llvm.rint.f64", fn(t_f64) -> t_f64);
581 ifn!("llvm.nearbyint.f32", fn(t_f32) -> t_f32);
582 ifn!("llvm.nearbyint.f64", fn(t_f64) -> t_f64);
584 ifn!("llvm.ctpop.i8", fn(t_i8) -> t_i8);
585 ifn!("llvm.ctpop.i16", fn(t_i16) -> t_i16);
586 ifn!("llvm.ctpop.i32", fn(t_i32) -> t_i32);
587 ifn!("llvm.ctpop.i64", fn(t_i64) -> t_i64);
588 ifn!("llvm.ctpop.i128", fn(t_i128) -> t_i128);
590 ifn!("llvm.ctlz.i8", fn(t_i8 , i1) -> t_i8);
591 ifn!("llvm.ctlz.i16", fn(t_i16, i1) -> t_i16);
592 ifn!("llvm.ctlz.i32", fn(t_i32, i1) -> t_i32);
593 ifn!("llvm.ctlz.i64", fn(t_i64, i1) -> t_i64);
594 ifn!("llvm.ctlz.i128", fn(t_i128, i1) -> t_i128);
596 ifn!("llvm.cttz.i8", fn(t_i8 , i1) -> t_i8);
597 ifn!("llvm.cttz.i16", fn(t_i16, i1) -> t_i16);
598 ifn!("llvm.cttz.i32", fn(t_i32, i1) -> t_i32);
599 ifn!("llvm.cttz.i64", fn(t_i64, i1) -> t_i64);
600 ifn!("llvm.cttz.i128", fn(t_i128, i1) -> t_i128);
602 ifn!("llvm.bswap.i16", fn(t_i16) -> t_i16);
603 ifn!("llvm.bswap.i32", fn(t_i32) -> t_i32);
604 ifn!("llvm.bswap.i64", fn(t_i64) -> t_i64);
605 ifn!("llvm.bswap.i128", fn(t_i128) -> t_i128);
607 ifn!("llvm.bitreverse.i8", fn(t_i8) -> t_i8);
608 ifn!("llvm.bitreverse.i16", fn(t_i16) -> t_i16);
609 ifn!("llvm.bitreverse.i32", fn(t_i32) -> t_i32);
610 ifn!("llvm.bitreverse.i64", fn(t_i64) -> t_i64);
611 ifn!("llvm.bitreverse.i128", fn(t_i128) -> t_i128);
613 ifn!("llvm.sadd.with.overflow.i8", fn(t_i8, t_i8) -> mk_struct!{t_i8, i1});
614 ifn!("llvm.sadd.with.overflow.i16", fn(t_i16, t_i16) -> mk_struct!{t_i16, i1});
615 ifn!("llvm.sadd.with.overflow.i32", fn(t_i32, t_i32) -> mk_struct!{t_i32, i1});
616 ifn!("llvm.sadd.with.overflow.i64", fn(t_i64, t_i64) -> mk_struct!{t_i64, i1});
617 ifn!("llvm.sadd.with.overflow.i128", fn(t_i128, t_i128) -> mk_struct!{t_i128, i1});
619 ifn!("llvm.uadd.with.overflow.i8", fn(t_i8, t_i8) -> mk_struct!{t_i8, i1});
620 ifn!("llvm.uadd.with.overflow.i16", fn(t_i16, t_i16) -> mk_struct!{t_i16, i1});
621 ifn!("llvm.uadd.with.overflow.i32", fn(t_i32, t_i32) -> mk_struct!{t_i32, i1});
622 ifn!("llvm.uadd.with.overflow.i64", fn(t_i64, t_i64) -> mk_struct!{t_i64, i1});
623 ifn!("llvm.uadd.with.overflow.i128", fn(t_i128, t_i128) -> mk_struct!{t_i128, i1});
625 ifn!("llvm.ssub.with.overflow.i8", fn(t_i8, t_i8) -> mk_struct!{t_i8, i1});
626 ifn!("llvm.ssub.with.overflow.i16", fn(t_i16, t_i16) -> mk_struct!{t_i16, i1});
627 ifn!("llvm.ssub.with.overflow.i32", fn(t_i32, t_i32) -> mk_struct!{t_i32, i1});
628 ifn!("llvm.ssub.with.overflow.i64", fn(t_i64, t_i64) -> mk_struct!{t_i64, i1});
629 ifn!("llvm.ssub.with.overflow.i128", fn(t_i128, t_i128) -> mk_struct!{t_i128, i1});
631 ifn!("llvm.usub.with.overflow.i8", fn(t_i8, t_i8) -> mk_struct!{t_i8, i1});
632 ifn!("llvm.usub.with.overflow.i16", fn(t_i16, t_i16) -> mk_struct!{t_i16, i1});
633 ifn!("llvm.usub.with.overflow.i32", fn(t_i32, t_i32) -> mk_struct!{t_i32, i1});
634 ifn!("llvm.usub.with.overflow.i64", fn(t_i64, t_i64) -> mk_struct!{t_i64, i1});
635 ifn!("llvm.usub.with.overflow.i128", fn(t_i128, t_i128) -> mk_struct!{t_i128, i1});
637 ifn!("llvm.smul.with.overflow.i8", fn(t_i8, t_i8) -> mk_struct!{t_i8, i1});
638 ifn!("llvm.smul.with.overflow.i16", fn(t_i16, t_i16) -> mk_struct!{t_i16, i1});
639 ifn!("llvm.smul.with.overflow.i32", fn(t_i32, t_i32) -> mk_struct!{t_i32, i1});
640 ifn!("llvm.smul.with.overflow.i64", fn(t_i64, t_i64) -> mk_struct!{t_i64, i1});
641 ifn!("llvm.smul.with.overflow.i128", fn(t_i128, t_i128) -> mk_struct!{t_i128, i1});
643 ifn!("llvm.umul.with.overflow.i8", fn(t_i8, t_i8) -> mk_struct!{t_i8, i1});
644 ifn!("llvm.umul.with.overflow.i16", fn(t_i16, t_i16) -> mk_struct!{t_i16, i1});
645 ifn!("llvm.umul.with.overflow.i32", fn(t_i32, t_i32) -> mk_struct!{t_i32, i1});
646 ifn!("llvm.umul.with.overflow.i64", fn(t_i64, t_i64) -> mk_struct!{t_i64, i1});
647 ifn!("llvm.umul.with.overflow.i128", fn(t_i128, t_i128) -> mk_struct!{t_i128, i1});
649 ifn!("llvm.lifetime.start", fn(t_i64,i8p) -> void);
650 ifn!("llvm.lifetime.end", fn(t_i64, i8p) -> void);
652 ifn!("llvm.expect.i1", fn(i1, i1) -> i1);
653 ifn!("llvm.eh.typeid.for", fn(i8p) -> t_i32);
654 ifn!("llvm.localescape", fn(...) -> void);
655 ifn!("llvm.localrecover", fn(i8p, i8p, t_i32) -> i8p);
656 ifn!("llvm.x86.seh.recoverfp", fn(i8p, i8p) -> i8p);
658 ifn!("llvm.assume", fn(i1) -> void);
659 ifn!("llvm.prefetch", fn(i8p, t_i32, t_i32, t_i32) -> void);
661 if cx.sess().opts.debuginfo != NoDebugInfo {
662 ifn!("llvm.dbg.declare", fn(Type::metadata(cx), Type::metadata(cx)) -> void);
663 ifn!("llvm.dbg.value", fn(Type::metadata(cx), t_i64, Type::metadata(cx)) -> void);