2013-06-13 19:19:50 +12:00
|
|
|
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
2014-07-07 17:58:01 -07:00
|
|
|
use llvm;
|
2016-12-16 18:48:25 -07:00
|
|
|
use llvm::{ContextRef, ModuleRef, ValueRef};
|
2017-04-17 12:35:53 -04:00
|
|
|
use rustc::dep_graph::{DepGraph, DepGraphSafe};
|
2016-12-19 21:26:49 -07:00
|
|
|
use rustc::hir;
|
2017-04-13 18:08:36 -04:00
|
|
|
use rustc::hir::def_id::DefId;
|
2016-03-22 17:30:57 +02:00
|
|
|
use rustc::traits;
|
2016-03-22 19:23:36 +02:00
|
|
|
use debuginfo;
|
2017-03-08 18:33:21 +02:00
|
|
|
use callee;
|
2016-12-19 19:32:50 -07:00
|
|
|
use base;
|
2016-03-22 19:23:36 +02:00
|
|
|
use declare;
|
|
|
|
use monomorphize::Instance;
|
2016-02-14 13:01:44 -05:00
|
|
|
|
2016-05-06 14:27:34 -04:00
|
|
|
use partitioning::CodegenUnit;
|
2016-10-11 23:46:22 -04:00
|
|
|
use type_::Type;
|
2016-11-04 17:37:42 -04:00
|
|
|
use rustc_data_structures::base_n;
|
2016-08-08 23:39:49 +03:00
|
|
|
use rustc::ty::subst::Substs;
|
2016-03-22 17:30:57 +02:00
|
|
|
use rustc::ty::{self, Ty, TyCtxt};
|
2017-03-10 06:25:51 +02:00
|
|
|
use rustc::ty::layout::{LayoutTyper, TyLayout};
|
2014-11-15 20:30:33 -05:00
|
|
|
use session::config::NoDebugInfo;
|
|
|
|
use session::Session;
|
2016-07-14 23:40:14 +02:00
|
|
|
use session::config;
|
2017-04-14 15:10:53 -04:00
|
|
|
use symbol_cache::SymbolCache;
|
2017-04-14 13:27:39 -04:00
|
|
|
use util::nodemap::{NodeSet, DefIdMap, FxHashMap};
|
2013-12-09 14:56:53 -07:00
|
|
|
|
2016-04-18 15:38:45 +03:00
|
|
|
use std::ffi::{CStr, CString};
|
2013-12-18 18:35:33 -08:00
|
|
|
use std::cell::{Cell, RefCell};
|
2014-03-15 22:29:34 +02:00
|
|
|
use std::ptr;
|
2016-12-19 21:26:49 -07:00
|
|
|
use std::iter;
|
2016-04-18 15:38:45 +03:00
|
|
|
use std::str;
|
2013-06-13 14:49:01 +12:00
|
|
|
use syntax::ast;
|
2016-11-16 08:21:52 +00:00
|
|
|
use syntax::symbol::InternedString;
|
2016-12-18 11:50:07 -07:00
|
|
|
use syntax_pos::DUMMY_SP;
|
2017-03-14 01:08:21 +02:00
|
|
|
use abi::Abi;
|
2013-06-13 14:49:01 +12:00
|
|
|
|
2017-04-13 17:11:54 -04:00
|
|
|
#[derive(Clone, Default)]
|
2014-04-22 03:25:56 +03:00
|
|
|
pub struct Stats {
|
2015-03-25 17:06:52 -07:00
|
|
|
pub n_glues_created: Cell<usize>,
|
|
|
|
pub n_null_glues: Cell<usize>,
|
|
|
|
pub n_real_glues: Cell<usize>,
|
|
|
|
pub n_fns: Cell<usize>,
|
|
|
|
pub n_inlines: Cell<usize>,
|
|
|
|
pub n_closures: Cell<usize>,
|
|
|
|
pub n_llvm_insns: Cell<usize>,
|
2016-11-08 14:02:55 +11:00
|
|
|
pub llvm_insns: RefCell<FxHashMap<String, usize>>,
|
2014-11-10 12:27:56 -08:00
|
|
|
// (ident, llvm-instructions)
|
2015-03-25 17:06:52 -07:00
|
|
|
pub fn_stats: RefCell<Vec<(String, usize)> >,
|
2014-04-22 03:25:56 +03:00
|
|
|
}
|
|
|
|
|
2017-04-13 17:11:54 -04:00
|
|
|
impl Stats {
|
|
|
|
pub fn extend(&mut self, stats: Stats) {
|
|
|
|
self.n_glues_created.set(self.n_glues_created.get() + stats.n_glues_created.get());
|
|
|
|
self.n_null_glues.set(self.n_null_glues.get() + stats.n_null_glues.get());
|
|
|
|
self.n_real_glues.set(self.n_real_glues.get() + stats.n_real_glues.get());
|
|
|
|
self.n_fns.set(self.n_fns.get() + stats.n_fns.get());
|
|
|
|
self.n_inlines.set(self.n_inlines.get() + stats.n_inlines.get());
|
|
|
|
self.n_closures.set(self.n_closures.get() + stats.n_closures.get());
|
|
|
|
self.n_llvm_insns.set(self.n_llvm_insns.get() + stats.n_llvm_insns.get());
|
|
|
|
self.llvm_insns.borrow_mut().extend(
|
|
|
|
stats.llvm_insns.borrow().iter()
|
|
|
|
.map(|(key, value)| (key.clone(), value.clone())));
|
|
|
|
self.fn_stats.borrow_mut().append(&mut *stats.fn_stats.borrow_mut());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-16 11:27:57 -07:00
|
|
|
/// The shared portion of a `CrateContext`. There is one `SharedCrateContext`
|
|
|
|
/// per crate. The data here is shared between all compilation units of the
|
|
|
|
/// crate, so it must not contain references to any LLVM data structures
|
|
|
|
/// (aside from metadata-related ones).
|
2015-06-14 01:49:28 +03:00
|
|
|
pub struct SharedCrateContext<'a, 'tcx: 'a> {
|
2016-11-28 18:05:53 -05:00
|
|
|
exported_symbols: NodeSet,
|
2016-05-03 05:23:22 +03:00
|
|
|
tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
2016-12-19 08:09:03 -07:00
|
|
|
empty_param_env: ty::ParameterEnvironment<'tcx>,
|
2015-01-06 00:56:30 -05:00
|
|
|
check_overflow: bool,
|
2014-07-31 16:45:29 -07:00
|
|
|
|
2015-05-12 14:46:19 -07:00
|
|
|
use_dll_storage_attrs: bool,
|
2014-07-16 11:27:57 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/// The local portion of a `CrateContext`. There is one `LocalCrateContext`
|
|
|
|
/// per compilation unit. Each one has its own LLVM `ContextRef` so that
|
|
|
|
/// several compilation units may be optimized in parallel. All other LLVM
|
|
|
|
/// data structures in the `LocalCrateContext` are tied to that `ContextRef`.
|
2017-04-14 15:10:53 -04:00
|
|
|
pub struct LocalCrateContext<'a, 'tcx: 'a> {
|
2014-09-05 09:18:53 -07:00
|
|
|
llmod: ModuleRef,
|
|
|
|
llcx: ContextRef,
|
2017-04-13 17:11:54 -04:00
|
|
|
stats: Stats,
|
2016-05-06 15:21:17 -04:00
|
|
|
codegen_unit: CodegenUnit<'tcx>,
|
2016-11-08 14:02:55 +11:00
|
|
|
needs_unwind_cleanup_cache: RefCell<FxHashMap<Ty<'tcx>, bool>>,
|
2016-02-23 22:04:27 +02:00
|
|
|
/// Cache instances of monomorphic and polymorphic items
|
2016-11-08 14:02:55 +11:00
|
|
|
instances: RefCell<FxHashMap<Instance<'tcx>, ValueRef>>,
|
2014-04-01 07:11:23 -04:00
|
|
|
/// Cache generated vtables
|
2016-11-16 09:21:49 -07:00
|
|
|
vtables: RefCell<FxHashMap<(ty::Ty<'tcx>,
|
|
|
|
Option<ty::PolyExistentialTraitRef<'tcx>>), ValueRef>>,
|
2014-04-01 07:11:23 -04:00
|
|
|
/// Cache of constant strings,
|
2016-11-08 14:02:55 +11:00
|
|
|
const_cstr_cache: RefCell<FxHashMap<InternedString, ValueRef>>,
|
2013-06-13 14:02:33 +12:00
|
|
|
|
2014-04-01 07:11:23 -04:00
|
|
|
/// Reverse-direction for const ptrs cast from globals.
|
2015-01-29 14:03:34 +02:00
|
|
|
/// Key is a ValueRef holding a *T,
|
2014-04-01 07:11:23 -04:00
|
|
|
/// Val is a ValueRef holding a *[T].
|
|
|
|
///
|
|
|
|
/// Needed because LLVM loses pointer->pointee association
|
|
|
|
/// when we ptrcast, and we have to ptrcast during translation
|
2015-01-29 14:03:34 +02:00
|
|
|
/// of a [T] const because we form a slice, a (*T,usize) pair, not
|
|
|
|
/// a pointer to an LLVM array type. Similar for trait objects.
|
2016-11-08 14:02:55 +11:00
|
|
|
const_unsized: RefCell<FxHashMap<ValueRef, ValueRef>>,
|
2015-01-29 14:03:34 +02:00
|
|
|
|
|
|
|
/// Cache of emitted const globals (value -> global)
|
2016-11-08 14:02:55 +11:00
|
|
|
const_globals: RefCell<FxHashMap<ValueRef, ValueRef>>,
|
2013-06-13 14:02:33 +12:00
|
|
|
|
2014-04-01 07:11:23 -04:00
|
|
|
/// Cache of emitted const values
|
2016-11-08 14:02:55 +11:00
|
|
|
const_values: RefCell<FxHashMap<(ast::NodeId, &'tcx Substs<'tcx>), ValueRef>>,
|
2013-06-13 14:02:33 +12:00
|
|
|
|
2014-04-01 07:11:23 -04:00
|
|
|
/// Cache of external const values
|
2014-09-05 09:18:53 -07:00
|
|
|
extern_const_values: RefCell<DefIdMap<ValueRef>>,
|
2013-06-13 14:02:33 +12:00
|
|
|
|
2016-04-21 16:15:56 +03:00
|
|
|
/// Mapping from static definitions to their DefId's.
|
2016-11-08 14:02:55 +11:00
|
|
|
statics: RefCell<FxHashMap<ValueRef, DefId>>,
|
2016-04-21 16:15:56 +03:00
|
|
|
|
2016-11-08 14:02:55 +11:00
|
|
|
impl_method_cache: RefCell<FxHashMap<(DefId, ast::Name), DefId>>,
|
2013-06-14 17:38:17 +12:00
|
|
|
|
2014-04-01 07:11:23 -04:00
|
|
|
/// Cache of closure wrappers for bare fn's.
|
2016-11-08 14:02:55 +11:00
|
|
|
closure_bare_wrapper_cache: RefCell<FxHashMap<ValueRef, ValueRef>>,
|
2014-09-05 09:18:53 -07:00
|
|
|
|
2015-06-28 10:36:46 -07:00
|
|
|
/// List of globals for static variables which need to be passed to the
|
|
|
|
/// LLVM function ReplaceAllUsesWith (RAUW) when translation is complete.
|
|
|
|
/// (We have to make sure we don't invalidate any ValueRefs referring
|
|
|
|
/// to constants.)
|
|
|
|
statics_to_rauw: RefCell<Vec<(ValueRef, ValueRef)>>,
|
|
|
|
|
2017-04-05 21:11:22 -05:00
|
|
|
/// Statics that will be placed in the llvm.used variable
|
|
|
|
/// See http://llvm.org/docs/LangRef.html#the-llvm-used-global-variable for details
|
2017-02-20 14:42:47 -05:00
|
|
|
used_statics: RefCell<Vec<ValueRef>>,
|
|
|
|
|
2016-11-08 14:02:55 +11:00
|
|
|
lltypes: RefCell<FxHashMap<Ty<'tcx>, Type>>,
|
|
|
|
llsizingtypes: RefCell<FxHashMap<Ty<'tcx>, Type>>,
|
|
|
|
type_hashcodes: RefCell<FxHashMap<Ty<'tcx>, String>>,
|
2014-09-05 09:18:53 -07:00
|
|
|
int_type: Type,
|
|
|
|
opaque_vec_type: Type,
|
2016-10-11 23:46:22 -04:00
|
|
|
str_slice_type: Type,
|
2014-05-28 22:26:56 -07:00
|
|
|
|
|
|
|
/// Holds the LLVM values for closure IDs.
|
2016-11-08 14:02:55 +11:00
|
|
|
closure_vals: RefCell<FxHashMap<Instance<'tcx>, ValueRef>>,
|
2014-05-28 22:26:56 -07:00
|
|
|
|
2014-09-29 22:11:30 +03:00
|
|
|
dbg_cx: Option<debuginfo::CrateDebugContext<'tcx>>,
|
2014-04-09 19:56:31 -04:00
|
|
|
|
2016-02-23 21:59:23 +02:00
|
|
|
eh_personality: Cell<Option<ValueRef>>,
|
|
|
|
eh_unwind_resume: Cell<Option<ValueRef>>,
|
|
|
|
rust_try_fn: Cell<Option<ValueRef>>,
|
2014-05-19 09:30:09 -07:00
|
|
|
|
2016-11-08 14:02:55 +11:00
|
|
|
intrinsics: RefCell<FxHashMap<&'static str, ValueRef>>,
|
2014-07-21 16:42:34 -07:00
|
|
|
|
2015-10-25 23:02:15 +02:00
|
|
|
/// Depth of the current type-of computation - used to bail out
|
|
|
|
type_of_depth: Cell<usize>,
|
2016-05-26 08:59:58 -04:00
|
|
|
|
2016-10-21 12:41:20 -04:00
|
|
|
/// A counter that is used for generating local symbol names
|
|
|
|
local_gen_sym_counter: Cell<usize>,
|
2017-04-14 15:10:53 -04:00
|
|
|
|
|
|
|
symbol_cache: &'a SymbolCache<'a, 'tcx>,
|
2016-01-21 08:33:58 -05:00
|
|
|
}
|
|
|
|
|
2016-05-06 16:53:59 -04:00
|
|
|
/// A CrateContext value binds together one LocalCrateContext with the
|
|
|
|
/// SharedCrateContext. It exists as a convenience wrapper, so we don't have to
|
|
|
|
/// pass around (SharedCrateContext, LocalCrateContext) tuples all over trans.
|
2014-04-22 15:56:37 +03:00
|
|
|
pub struct CrateContext<'a, 'tcx: 'a> {
|
2015-06-14 01:49:28 +03:00
|
|
|
shared: &'a SharedCrateContext<'a, 'tcx>,
|
2017-04-14 15:10:53 -04:00
|
|
|
local_ccx: &'a LocalCrateContext<'a, 'tcx>,
|
2014-07-16 11:27:57 -07:00
|
|
|
}
|
|
|
|
|
2017-04-13 13:57:45 -04:00
|
|
|
impl<'a, 'tcx> CrateContext<'a, 'tcx> {
|
|
|
|
pub fn new(shared: &'a SharedCrateContext<'a, 'tcx>,
|
2017-04-14 15:10:53 -04:00
|
|
|
local_ccx: &'a LocalCrateContext<'a, 'tcx>)
|
2017-04-13 13:57:45 -04:00
|
|
|
-> Self {
|
|
|
|
CrateContext { shared, local_ccx }
|
|
|
|
}
|
run optimization and codegen on worker threads
Refactor the code in `llvm::back` that invokes LLVM optimization and codegen
passes so that it can be called from worker threads. (Previously, it used
`&Session` extensively, and `Session` is not `Share`.) The new code can handle
multiple compilation units, by compiling each unit to `crate.0.o`, `crate.1.o`,
etc., and linking together all the `crate.N.o` files into a single `crate.o`
using `ld -r`. The later linking steps can then be run unchanged.
The new code preserves the behavior of `--emit`/`-o` when building a single
compilation unit. With multiple compilation units, the `--emit=asm/ir/bc`
options produce multiple files, so combinations like `--emit=ir -o foo.ll` will
not actually produce `foo.ll` (they instead produce several `foo.N.ll` files).
The new code supports `-Z lto` only when using a single compilation unit.
Compiling with multiple compilation units and `-Z lto` will produce an error.
(I can't think of any good reason to do such a thing.) Linking with `-Z lto`
against a library that was built as multiple compilation units will also fail,
because the rlib does not contain a `crate.bytecode.deflate` file. This could
be supported in the future by linking together the `crate.N.bc` files produced
when compiling the library into a single `crate.bc`, or by making the LTO code
support multiple `crate.N.bytecode.deflate` files.
2014-07-17 10:52:52 -07:00
|
|
|
}
|
|
|
|
|
2017-04-13 13:57:45 -04:00
|
|
|
impl<'a, 'tcx> DepGraphSafe for CrateContext<'a, 'tcx> {
|
run optimization and codegen on worker threads
Refactor the code in `llvm::back` that invokes LLVM optimization and codegen
passes so that it can be called from worker threads. (Previously, it used
`&Session` extensively, and `Session` is not `Share`.) The new code can handle
multiple compilation units, by compiling each unit to `crate.0.o`, `crate.1.o`,
etc., and linking together all the `crate.N.o` files into a single `crate.o`
using `ld -r`. The later linking steps can then be run unchanged.
The new code preserves the behavior of `--emit`/`-o` when building a single
compilation unit. With multiple compilation units, the `--emit=asm/ir/bc`
options produce multiple files, so combinations like `--emit=ir -o foo.ll` will
not actually produce `foo.ll` (they instead produce several `foo.N.ll` files).
The new code supports `-Z lto` only when using a single compilation unit.
Compiling with multiple compilation units and `-Z lto` will produce an error.
(I can't think of any good reason to do such a thing.) Linking with `-Z lto`
against a library that was built as multiple compilation units will also fail,
because the rlib does not contain a `crate.bytecode.deflate` file. This could
be supported in the future by linking together the `crate.N.bc` files produced
when compiling the library into a single `crate.bc`, or by making the LTO code
support multiple `crate.N.bytecode.deflate` files.
2014-07-17 10:52:52 -07:00
|
|
|
}
|
|
|
|
|
2016-07-14 23:40:14 +02:00
|
|
|
pub fn get_reloc_model(sess: &Session) -> llvm::RelocMode {
|
|
|
|
let reloc_model_arg = match sess.opts.cg.relocation_model {
|
|
|
|
Some(ref s) => &s[..],
|
|
|
|
None => &sess.target.target.options.relocation_model[..],
|
|
|
|
};
|
|
|
|
|
2016-08-06 15:50:48 +10:00
|
|
|
match ::back::write::RELOC_MODEL_ARGS.iter().find(
|
|
|
|
|&&arg| arg.0 == reloc_model_arg) {
|
|
|
|
Some(x) => x.1,
|
2016-07-14 23:40:14 +02:00
|
|
|
_ => {
|
|
|
|
sess.err(&format!("{:?} is not a valid relocation mode",
|
|
|
|
sess.opts
|
|
|
|
.cg
|
2016-08-06 15:50:48 +10:00
|
|
|
.code_model));
|
2016-07-14 23:40:14 +02:00
|
|
|
sess.abort_if_errors();
|
|
|
|
bug!();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn is_any_library(sess: &Session) -> bool {
|
|
|
|
sess.crate_types.borrow().iter().any(|ty| {
|
|
|
|
*ty != config::CrateTypeExecutable
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn is_pie_binary(sess: &Session) -> bool {
|
2016-08-02 00:16:16 +03:00
|
|
|
!is_any_library(sess) && get_reloc_model(sess) == llvm::RelocMode::PIC
|
2016-07-14 23:40:14 +02:00
|
|
|
}
|
|
|
|
|
2017-04-13 11:48:19 -04:00
|
|
|
pub unsafe fn create_context_and_module(sess: &Session, mod_name: &str) -> (ContextRef, ModuleRef) {
|
2014-07-16 11:27:57 -07:00
|
|
|
let llcx = llvm::LLVMContextCreate();
|
2015-02-17 22:47:40 -08:00
|
|
|
let mod_name = CString::new(mod_name).unwrap();
|
2014-11-25 13:28:35 -08:00
|
|
|
let llmod = llvm::LLVMModuleCreateWithNameInContext(mod_name.as_ptr(), llcx);
|
|
|
|
|
2016-04-18 15:38:45 +03:00
|
|
|
// Ensure the data-layout values hardcoded remain the defaults.
|
|
|
|
if sess.target.target.options.is_builtin {
|
2015-07-16 15:48:16 -07:00
|
|
|
let tm = ::back::write::create_target_machine(sess);
|
|
|
|
llvm::LLVMRustSetDataLayoutFromTargetMachine(llmod, tm);
|
|
|
|
llvm::LLVMRustDisposeTargetMachine(tm);
|
2016-04-18 15:38:45 +03:00
|
|
|
|
|
|
|
let data_layout = llvm::LLVMGetDataLayout(llmod);
|
|
|
|
let data_layout = str::from_utf8(CStr::from_ptr(data_layout).to_bytes())
|
|
|
|
.ok().expect("got a non-UTF8 data-layout from LLVM");
|
|
|
|
|
2016-07-25 10:21:31 -07:00
|
|
|
// Unfortunately LLVM target specs change over time, and right now we
|
|
|
|
// don't have proper support to work with any more than one
|
|
|
|
// `data_layout` than the one that is in the rust-lang/rust repo. If
|
|
|
|
// this compiler is configured against a custom LLVM, we may have a
|
|
|
|
// differing data layout, even though we should update our own to use
|
|
|
|
// that one.
|
|
|
|
//
|
|
|
|
// As an interim hack, if CFG_LLVM_ROOT is not an empty string then we
|
|
|
|
// disable this check entirely as we may be configured with something
|
|
|
|
// that has a different target layout.
|
|
|
|
//
|
|
|
|
// Unsure if this will actually cause breakage when rustc is configured
|
|
|
|
// as such.
|
|
|
|
//
|
|
|
|
// FIXME(#34960)
|
|
|
|
let cfg_llvm_root = option_env!("CFG_LLVM_ROOT").unwrap_or("");
|
|
|
|
let custom_llvm_used = cfg_llvm_root.trim() != "";
|
|
|
|
|
|
|
|
if !custom_llvm_used && sess.target.target.data_layout != data_layout {
|
2016-04-18 15:38:45 +03:00
|
|
|
bug!("data-layout for builtin `{}` target, `{}`, \
|
|
|
|
differs from LLVM default, `{}`",
|
|
|
|
sess.target.target.llvm_target,
|
|
|
|
sess.target.target.data_layout,
|
|
|
|
data_layout);
|
|
|
|
}
|
2015-07-16 15:48:16 -07:00
|
|
|
}
|
2014-11-25 13:28:35 -08:00
|
|
|
|
2016-04-18 15:38:45 +03:00
|
|
|
let data_layout = CString::new(&sess.target.target.data_layout[..]).unwrap();
|
|
|
|
llvm::LLVMSetDataLayout(llmod, data_layout.as_ptr());
|
|
|
|
|
2015-02-17 22:47:40 -08:00
|
|
|
let llvm_target = sess.target.target.llvm_target.as_bytes();
|
|
|
|
let llvm_target = CString::new(llvm_target).unwrap();
|
2014-11-25 13:28:35 -08:00
|
|
|
llvm::LLVMRustSetNormalizedTarget(llmod, llvm_target.as_ptr());
|
2016-07-14 23:40:14 +02:00
|
|
|
|
|
|
|
if is_pie_binary(sess) {
|
|
|
|
llvm::LLVMRustSetModulePIELevel(llmod);
|
|
|
|
}
|
|
|
|
|
2014-07-16 11:27:57 -07:00
|
|
|
(llcx, llmod)
|
|
|
|
}
|
|
|
|
|
2015-06-14 01:49:28 +03:00
|
|
|
impl<'b, 'tcx> SharedCrateContext<'b, 'tcx> {
|
2016-05-03 05:23:22 +03:00
|
|
|
pub fn new(tcx: TyCtxt<'b, 'tcx, 'tcx>,
|
2016-11-28 18:05:53 -05:00
|
|
|
exported_symbols: NodeSet,
|
2016-08-16 17:41:38 +03:00
|
|
|
check_overflow: bool)
|
2015-06-14 01:49:28 +03:00
|
|
|
-> SharedCrateContext<'b, 'tcx> {
|
2015-05-12 14:46:19 -07:00
|
|
|
// An interesting part of Windows which MSVC forces our hand on (and
|
|
|
|
// apparently MinGW didn't) is the usage of `dllimport` and `dllexport`
|
|
|
|
// attributes in LLVM IR as well as native dependencies (in C these
|
|
|
|
// correspond to `__declspec(dllimport)`).
|
|
|
|
//
|
|
|
|
// Whenever a dynamic library is built by MSVC it must have its public
|
|
|
|
// interface specified by functions tagged with `dllexport` or otherwise
|
|
|
|
// they're not available to be linked against. This poses a few problems
|
|
|
|
// for the compiler, some of which are somewhat fundamental, but we use
|
|
|
|
// the `use_dll_storage_attrs` variable below to attach the `dllexport`
|
2016-11-28 18:05:53 -05:00
|
|
|
// attribute to all LLVM functions that are exported e.g. they're
|
2015-05-12 14:46:19 -07:00
|
|
|
// already tagged with external linkage). This is suboptimal for a few
|
|
|
|
// reasons:
|
|
|
|
//
|
|
|
|
// * If an object file will never be included in a dynamic library,
|
|
|
|
// there's no need to attach the dllexport attribute. Most object
|
|
|
|
// files in Rust are not destined to become part of a dll as binaries
|
|
|
|
// are statically linked by default.
|
|
|
|
// * If the compiler is emitting both an rlib and a dylib, the same
|
|
|
|
// source object file is currently used but with MSVC this may be less
|
|
|
|
// feasible. The compiler may be able to get around this, but it may
|
|
|
|
// involve some invasive changes to deal with this.
|
|
|
|
//
|
|
|
|
// The flipside of this situation is that whenever you link to a dll and
|
|
|
|
// you import a function from it, the import should be tagged with
|
|
|
|
// `dllimport`. At this time, however, the compiler does not emit
|
|
|
|
// `dllimport` for any declarations other than constants (where it is
|
|
|
|
// required), which is again suboptimal for even more reasons!
|
|
|
|
//
|
|
|
|
// * Calling a function imported from another dll without using
|
|
|
|
// `dllimport` causes the linker/compiler to have extra overhead (one
|
|
|
|
// `jmp` instruction on x86) when calling the function.
|
|
|
|
// * The same object file may be used in different circumstances, so a
|
|
|
|
// function may be imported from a dll if the object is linked into a
|
|
|
|
// dll, but it may be just linked against if linked into an rlib.
|
|
|
|
// * The compiler has no knowledge about whether native functions should
|
|
|
|
// be tagged dllimport or not.
|
|
|
|
//
|
|
|
|
// For now the compiler takes the perf hit (I do not have any numbers to
|
|
|
|
// this effect) by marking very little as `dllimport` and praying the
|
|
|
|
// linker will take care of everything. Fixing this problem will likely
|
|
|
|
// require adding a few attributes to Rust itself (feature gated at the
|
|
|
|
// start) and then strongly recommending static linkage on MSVC!
|
|
|
|
let use_dll_storage_attrs = tcx.sess.target.target.options.is_like_msvc;
|
|
|
|
|
2016-05-05 14:14:41 -04:00
|
|
|
SharedCrateContext {
|
2016-11-28 18:05:53 -05:00
|
|
|
exported_symbols: exported_symbols,
|
2016-12-19 08:09:03 -07:00
|
|
|
empty_param_env: tcx.empty_parameter_environment(),
|
2014-07-16 11:27:57 -07:00
|
|
|
tcx: tcx,
|
2015-01-06 00:56:30 -05:00
|
|
|
check_overflow: check_overflow,
|
2015-05-12 14:46:19 -07:00
|
|
|
use_dll_storage_attrs: use_dll_storage_attrs,
|
2014-07-16 11:27:57 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-18 11:50:07 -07:00
|
|
|
pub fn type_needs_drop(&self, ty: Ty<'tcx>) -> bool {
|
2017-04-18 00:22:55 +03:00
|
|
|
ty.needs_drop(self.tcx, &self.empty_param_env)
|
2016-12-18 11:50:07 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn type_is_sized(&self, ty: Ty<'tcx>) -> bool {
|
2016-12-19 08:09:03 -07:00
|
|
|
ty.is_sized(self.tcx, &self.empty_param_env, DUMMY_SP)
|
2017-04-17 21:18:56 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn type_is_freeze(&self, ty: Ty<'tcx>) -> bool {
|
|
|
|
ty.is_freeze(self.tcx, &self.empty_param_env, DUMMY_SP)
|
2016-12-18 11:50:07 -07:00
|
|
|
}
|
|
|
|
|
2016-11-28 18:05:53 -05:00
|
|
|
pub fn exported_symbols<'a>(&'a self) -> &'a NodeSet {
|
|
|
|
&self.exported_symbols
|
2014-07-16 11:27:57 -07:00
|
|
|
}
|
|
|
|
|
2016-05-03 05:23:22 +03:00
|
|
|
pub fn tcx<'a>(&'a self) -> TyCtxt<'a, 'tcx, 'tcx> {
|
2014-07-16 11:27:57 -07:00
|
|
|
self.tcx
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn sess<'a>(&'a self) -> &'a Session {
|
|
|
|
&self.tcx.sess
|
|
|
|
}
|
|
|
|
|
2016-12-09 17:13:13 -05:00
|
|
|
pub fn dep_graph<'a>(&'a self) -> &'a DepGraph {
|
|
|
|
&self.tcx.dep_graph
|
|
|
|
}
|
|
|
|
|
2015-05-12 14:46:19 -07:00
|
|
|
pub fn use_dll_storage_attrs(&self) -> bool {
|
|
|
|
self.use_dll_storage_attrs
|
|
|
|
}
|
2014-07-16 11:27:57 -07:00
|
|
|
}
|
|
|
|
|
2017-04-14 15:10:53 -04:00
|
|
|
impl<'a, 'tcx> LocalCrateContext<'a, 'tcx> {
|
|
|
|
pub fn new(shared: &SharedCrateContext<'a, 'tcx>,
|
|
|
|
codegen_unit: CodegenUnit<'tcx>,
|
|
|
|
symbol_cache: &'a SymbolCache<'a, 'tcx>)
|
|
|
|
-> LocalCrateContext<'a, 'tcx> {
|
2013-06-13 14:49:01 +12:00
|
|
|
unsafe {
|
2016-05-06 15:21:17 -04:00
|
|
|
// Append ".rs" to LLVM module identifier.
|
|
|
|
//
|
|
|
|
// LLVM code generator emits a ".file filename" directive
|
|
|
|
// for ELF backends. Value of the "filename" is set as the
|
|
|
|
// LLVM module identifier. Due to a LLVM MC bug[1], LLVM
|
|
|
|
// crashes if the module identifier is same as other symbols
|
|
|
|
// such as a function name in the module.
|
|
|
|
// 1. http://llvm.org/bugs/show_bug.cgi?id=11479
|
2016-07-21 12:49:59 -04:00
|
|
|
let llmod_id = format!("{}.rs", codegen_unit.name());
|
2016-05-06 15:21:17 -04:00
|
|
|
|
|
|
|
let (llcx, llmod) = create_context_and_module(&shared.tcx.sess,
|
|
|
|
&llmod_id[..]);
|
2014-07-16 11:27:57 -07:00
|
|
|
|
|
|
|
let dbg_cx = if shared.tcx.sess.opts.debuginfo != NoDebugInfo {
|
2016-07-13 00:40:38 +02:00
|
|
|
let dctx = debuginfo::CrateDebugContext::new(llmod);
|
|
|
|
debuginfo::metadata::compile_unit_metadata(shared, &dctx, shared.tcx.sess);
|
|
|
|
Some(dctx)
|
2013-06-13 14:49:01 +12:00
|
|
|
} else {
|
|
|
|
None
|
|
|
|
};
|
|
|
|
|
2016-05-05 14:14:41 -04:00
|
|
|
let local_ccx = LocalCrateContext {
|
2014-03-15 22:29:34 +02:00
|
|
|
llmod: llmod,
|
|
|
|
llcx: llcx,
|
2017-04-13 17:11:54 -04:00
|
|
|
stats: Stats::default(),
|
2016-05-06 15:21:17 -04:00
|
|
|
codegen_unit: codegen_unit,
|
2016-11-08 14:02:55 +11:00
|
|
|
needs_unwind_cleanup_cache: RefCell::new(FxHashMap()),
|
|
|
|
instances: RefCell::new(FxHashMap()),
|
|
|
|
vtables: RefCell::new(FxHashMap()),
|
|
|
|
const_cstr_cache: RefCell::new(FxHashMap()),
|
|
|
|
const_unsized: RefCell::new(FxHashMap()),
|
|
|
|
const_globals: RefCell::new(FxHashMap()),
|
|
|
|
const_values: RefCell::new(FxHashMap()),
|
2015-01-16 14:27:43 -08:00
|
|
|
extern_const_values: RefCell::new(DefIdMap()),
|
2016-11-08 14:02:55 +11:00
|
|
|
statics: RefCell::new(FxHashMap()),
|
|
|
|
impl_method_cache: RefCell::new(FxHashMap()),
|
|
|
|
closure_bare_wrapper_cache: RefCell::new(FxHashMap()),
|
2015-06-28 10:36:46 -07:00
|
|
|
statics_to_rauw: RefCell::new(Vec::new()),
|
2017-02-20 14:42:47 -05:00
|
|
|
used_statics: RefCell::new(Vec::new()),
|
2016-11-08 14:02:55 +11:00
|
|
|
lltypes: RefCell::new(FxHashMap()),
|
|
|
|
llsizingtypes: RefCell::new(FxHashMap()),
|
|
|
|
type_hashcodes: RefCell::new(FxHashMap()),
|
2014-09-14 20:27:36 -07:00
|
|
|
int_type: Type::from_ref(ptr::null_mut()),
|
|
|
|
opaque_vec_type: Type::from_ref(ptr::null_mut()),
|
2016-10-11 23:46:22 -04:00
|
|
|
str_slice_type: Type::from_ref(ptr::null_mut()),
|
2016-11-08 14:02:55 +11:00
|
|
|
closure_vals: RefCell::new(FxHashMap()),
|
2014-03-15 22:29:34 +02:00
|
|
|
dbg_cx: dbg_cx,
|
2016-02-23 21:59:23 +02:00
|
|
|
eh_personality: Cell::new(None),
|
|
|
|
eh_unwind_resume: Cell::new(None),
|
|
|
|
rust_try_fn: Cell::new(None),
|
2016-11-08 14:02:55 +11:00
|
|
|
intrinsics: RefCell::new(FxHashMap()),
|
2015-10-25 23:02:15 +02:00
|
|
|
type_of_depth: Cell::new(0),
|
2016-10-21 12:41:20 -04:00
|
|
|
local_gen_sym_counter: Cell::new(0),
|
2017-04-14 15:10:53 -04:00
|
|
|
symbol_cache: symbol_cache,
|
2014-03-15 22:29:34 +02:00
|
|
|
};
|
|
|
|
|
2016-05-05 14:14:41 -04:00
|
|
|
let (int_type, opaque_vec_type, str_slice_ty, mut local_ccx) = {
|
|
|
|
// Do a little dance to create a dummy CrateContext, so we can
|
|
|
|
// create some things in the LLVM module of this codegen unit
|
|
|
|
let mut local_ccxs = vec![local_ccx];
|
|
|
|
let (int_type, opaque_vec_type, str_slice_ty) = {
|
|
|
|
let dummy_ccx = LocalCrateContext::dummy_ccx(shared,
|
|
|
|
local_ccxs.as_mut_slice());
|
|
|
|
let mut str_slice_ty = Type::named_struct(&dummy_ccx, "str_slice");
|
|
|
|
str_slice_ty.set_struct_body(&[Type::i8p(&dummy_ccx),
|
|
|
|
Type::int(&dummy_ccx)],
|
|
|
|
false);
|
|
|
|
(Type::int(&dummy_ccx), Type::opaque_vec(&dummy_ccx), str_slice_ty)
|
|
|
|
};
|
|
|
|
(int_type, opaque_vec_type, str_slice_ty, local_ccxs.pop().unwrap())
|
|
|
|
};
|
2014-03-15 22:29:34 +02:00
|
|
|
|
2016-05-05 14:14:41 -04:00
|
|
|
local_ccx.int_type = int_type;
|
|
|
|
local_ccx.opaque_vec_type = opaque_vec_type;
|
2016-10-11 23:46:22 -04:00
|
|
|
local_ccx.str_slice_type = str_slice_ty;
|
2014-03-15 22:29:34 +02:00
|
|
|
|
2014-07-16 11:27:57 -07:00
|
|
|
local_ccx
|
2013-06-13 14:49:01 +12:00
|
|
|
}
|
|
|
|
}
|
2013-07-21 15:33:40 +02:00
|
|
|
|
2014-07-16 11:27:57 -07:00
|
|
|
/// Create a dummy `CrateContext` from `self` and the provided
|
|
|
|
/// `SharedCrateContext`. This is somewhat dangerous because `self` may
|
2016-05-05 14:14:41 -04:00
|
|
|
/// not be fully initialized.
|
2014-07-16 11:27:57 -07:00
|
|
|
///
|
|
|
|
/// This is used in the `LocalCrateContext` constructor to allow calling
|
|
|
|
/// functions that expect a complete `CrateContext`, even before the local
|
|
|
|
/// portion is fully initialized and attached to the `SharedCrateContext`.
|
2017-04-14 15:10:53 -04:00
|
|
|
fn dummy_ccx(shared: &'a SharedCrateContext<'a, 'tcx>,
|
|
|
|
local_ccxs: &'a [LocalCrateContext<'a, 'tcx>])
|
|
|
|
-> CrateContext<'a, 'tcx> {
|
2016-05-05 14:14:41 -04:00
|
|
|
assert!(local_ccxs.len() == 1);
|
2014-07-16 11:27:57 -07:00
|
|
|
CrateContext {
|
|
|
|
shared: shared,
|
2017-04-13 12:07:25 -04:00
|
|
|
local_ccx: &local_ccxs[0]
|
2014-07-16 11:27:57 -07:00
|
|
|
}
|
2014-03-15 22:29:34 +02:00
|
|
|
}
|
2017-04-13 17:11:54 -04:00
|
|
|
|
|
|
|
pub fn into_stats(self) -> Stats {
|
|
|
|
self.stats
|
|
|
|
}
|
2014-07-16 11:27:57 -07:00
|
|
|
}
|
2014-03-15 22:29:34 +02:00
|
|
|
|
2014-04-22 15:56:37 +03:00
|
|
|
impl<'b, 'tcx> CrateContext<'b, 'tcx> {
|
2015-06-14 01:49:28 +03:00
|
|
|
pub fn shared(&self) -> &'b SharedCrateContext<'b, 'tcx> {
|
2014-07-16 11:27:57 -07:00
|
|
|
self.shared
|
|
|
|
}
|
|
|
|
|
2017-04-14 15:10:53 -04:00
|
|
|
fn local(&self) -> &'b LocalCrateContext<'b, 'tcx> {
|
2017-04-13 12:07:25 -04:00
|
|
|
self.local_ccx
|
2014-07-16 11:27:57 -07:00
|
|
|
}
|
|
|
|
|
2016-05-03 05:23:22 +03:00
|
|
|
pub fn tcx<'a>(&'a self) -> TyCtxt<'a, 'tcx, 'tcx> {
|
2015-06-14 01:49:28 +03:00
|
|
|
self.shared.tcx
|
2014-09-05 09:18:53 -07:00
|
|
|
}
|
|
|
|
|
2014-03-05 16:36:01 +02:00
|
|
|
pub fn sess<'a>(&'a self) -> &'a Session {
|
2014-07-16 11:27:57 -07:00
|
|
|
&self.shared.tcx.sess
|
2014-03-05 16:36:01 +02:00
|
|
|
}
|
|
|
|
|
2015-08-15 18:43:39 +12:00
|
|
|
pub fn get_intrinsic(&self, key: &str) -> ValueRef {
|
2014-11-29 16:41:21 -05:00
|
|
|
if let Some(v) = self.intrinsics().borrow().get(key).cloned() {
|
|
|
|
return v;
|
2014-04-09 19:56:31 -04:00
|
|
|
}
|
|
|
|
match declare_intrinsic(self, key) {
|
|
|
|
Some(v) => return v,
|
2016-03-29 01:46:02 +02:00
|
|
|
None => bug!("unknown intrinsic '{}'", key)
|
2014-04-09 19:56:31 -04:00
|
|
|
}
|
|
|
|
}
|
2014-05-12 20:03:34 +03:00
|
|
|
|
2014-09-05 09:18:53 -07:00
|
|
|
pub fn llmod(&self) -> ModuleRef {
|
2016-05-05 14:14:41 -04:00
|
|
|
self.local().llmod
|
2014-09-05 09:18:53 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn llcx(&self) -> ContextRef {
|
2016-05-05 14:14:41 -04:00
|
|
|
self.local().llcx
|
2014-09-05 09:18:53 -07:00
|
|
|
}
|
|
|
|
|
2016-05-06 15:21:17 -04:00
|
|
|
pub fn codegen_unit(&self) -> &CodegenUnit<'tcx> {
|
|
|
|
&self.local().codegen_unit
|
|
|
|
}
|
|
|
|
|
2015-07-16 15:48:16 -07:00
|
|
|
pub fn td(&self) -> llvm::TargetDataRef {
|
|
|
|
unsafe { llvm::LLVMRustGetModuleDataLayout(self.llmod()) }
|
2014-09-05 09:18:53 -07:00
|
|
|
}
|
|
|
|
|
2016-11-08 14:02:55 +11:00
|
|
|
pub fn needs_unwind_cleanup_cache(&self) -> &RefCell<FxHashMap<Ty<'tcx>, bool>> {
|
2016-05-05 14:14:41 -04:00
|
|
|
&self.local().needs_unwind_cleanup_cache
|
2014-12-16 15:00:05 -05:00
|
|
|
}
|
|
|
|
|
2016-11-08 14:02:55 +11:00
|
|
|
pub fn instances<'a>(&'a self) -> &'a RefCell<FxHashMap<Instance<'tcx>, ValueRef>> {
|
2016-05-05 14:14:41 -04:00
|
|
|
&self.local().instances
|
2014-09-05 09:18:53 -07:00
|
|
|
}
|
|
|
|
|
2016-11-16 09:21:49 -07:00
|
|
|
pub fn vtables<'a>(&'a self)
|
|
|
|
-> &'a RefCell<FxHashMap<(ty::Ty<'tcx>,
|
|
|
|
Option<ty::PolyExistentialTraitRef<'tcx>>), ValueRef>> {
|
2016-05-05 14:14:41 -04:00
|
|
|
&self.local().vtables
|
2014-09-05 09:18:53 -07:00
|
|
|
}
|
|
|
|
|
2016-11-08 14:02:55 +11:00
|
|
|
pub fn const_cstr_cache<'a>(&'a self) -> &'a RefCell<FxHashMap<InternedString, ValueRef>> {
|
2016-05-05 14:14:41 -04:00
|
|
|
&self.local().const_cstr_cache
|
2014-09-05 09:18:53 -07:00
|
|
|
}
|
|
|
|
|
2016-11-08 14:02:55 +11:00
|
|
|
pub fn const_unsized<'a>(&'a self) -> &'a RefCell<FxHashMap<ValueRef, ValueRef>> {
|
2016-05-05 14:14:41 -04:00
|
|
|
&self.local().const_unsized
|
2015-01-29 14:03:34 +02:00
|
|
|
}
|
|
|
|
|
2016-11-08 14:02:55 +11:00
|
|
|
pub fn const_globals<'a>(&'a self) -> &'a RefCell<FxHashMap<ValueRef, ValueRef>> {
|
2016-05-05 14:14:41 -04:00
|
|
|
&self.local().const_globals
|
2014-09-05 09:18:53 -07:00
|
|
|
}
|
|
|
|
|
2016-11-08 14:02:55 +11:00
|
|
|
pub fn const_values<'a>(&'a self) -> &'a RefCell<FxHashMap<(ast::NodeId, &'tcx Substs<'tcx>),
|
|
|
|
ValueRef>> {
|
2016-05-05 14:14:41 -04:00
|
|
|
&self.local().const_values
|
2014-09-05 09:18:53 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn extern_const_values<'a>(&'a self) -> &'a RefCell<DefIdMap<ValueRef>> {
|
2016-05-05 14:14:41 -04:00
|
|
|
&self.local().extern_const_values
|
2014-09-05 09:18:53 -07:00
|
|
|
}
|
|
|
|
|
2016-11-08 14:02:55 +11:00
|
|
|
pub fn statics<'a>(&'a self) -> &'a RefCell<FxHashMap<ValueRef, DefId>> {
|
2016-05-09 16:15:04 -04:00
|
|
|
&self.local().statics
|
2016-04-21 16:15:56 +03:00
|
|
|
}
|
|
|
|
|
2014-09-05 09:18:53 -07:00
|
|
|
pub fn impl_method_cache<'a>(&'a self)
|
2016-11-08 14:02:55 +11:00
|
|
|
-> &'a RefCell<FxHashMap<(DefId, ast::Name), DefId>> {
|
2016-05-05 14:14:41 -04:00
|
|
|
&self.local().impl_method_cache
|
2014-09-05 09:18:53 -07:00
|
|
|
}
|
|
|
|
|
2016-11-08 14:02:55 +11:00
|
|
|
pub fn closure_bare_wrapper_cache<'a>(&'a self) -> &'a RefCell<FxHashMap<ValueRef, ValueRef>> {
|
2016-05-05 14:14:41 -04:00
|
|
|
&self.local().closure_bare_wrapper_cache
|
2014-09-05 09:18:53 -07:00
|
|
|
}
|
|
|
|
|
2015-06-28 10:36:46 -07:00
|
|
|
pub fn statics_to_rauw<'a>(&'a self) -> &'a RefCell<Vec<(ValueRef, ValueRef)>> {
|
2016-05-05 14:14:41 -04:00
|
|
|
&self.local().statics_to_rauw
|
2015-06-28 10:36:46 -07:00
|
|
|
}
|
|
|
|
|
2017-02-20 14:42:47 -05:00
|
|
|
pub fn used_statics<'a>(&'a self) -> &'a RefCell<Vec<ValueRef>> {
|
|
|
|
&self.local().used_statics
|
|
|
|
}
|
|
|
|
|
2016-11-08 14:02:55 +11:00
|
|
|
pub fn lltypes<'a>(&'a self) -> &'a RefCell<FxHashMap<Ty<'tcx>, Type>> {
|
2016-05-05 14:14:41 -04:00
|
|
|
&self.local().lltypes
|
2014-09-05 09:18:53 -07:00
|
|
|
}
|
|
|
|
|
2016-11-08 14:02:55 +11:00
|
|
|
pub fn llsizingtypes<'a>(&'a self) -> &'a RefCell<FxHashMap<Ty<'tcx>, Type>> {
|
2016-05-05 14:14:41 -04:00
|
|
|
&self.local().llsizingtypes
|
2014-09-05 09:18:53 -07:00
|
|
|
}
|
|
|
|
|
2016-11-08 14:02:55 +11:00
|
|
|
pub fn type_hashcodes<'a>(&'a self) -> &'a RefCell<FxHashMap<Ty<'tcx>, String>> {
|
2016-05-05 14:14:41 -04:00
|
|
|
&self.local().type_hashcodes
|
2014-09-05 09:18:53 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn stats<'a>(&'a self) -> &'a Stats {
|
2017-04-13 17:11:54 -04:00
|
|
|
&self.local().stats
|
2014-09-05 09:18:53 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn int_type(&self) -> Type {
|
2016-05-05 14:14:41 -04:00
|
|
|
self.local().int_type
|
2014-09-05 09:18:53 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn opaque_vec_type(&self) -> Type {
|
2016-05-05 14:14:41 -04:00
|
|
|
self.local().opaque_vec_type
|
2014-09-05 09:18:53 -07:00
|
|
|
}
|
|
|
|
|
2016-10-11 23:46:22 -04:00
|
|
|
pub fn str_slice_type(&self) -> Type {
|
|
|
|
self.local().str_slice_type
|
|
|
|
}
|
|
|
|
|
2016-11-08 14:02:55 +11:00
|
|
|
pub fn closure_vals<'a>(&'a self) -> &'a RefCell<FxHashMap<Instance<'tcx>, ValueRef>> {
|
2016-05-05 14:14:41 -04:00
|
|
|
&self.local().closure_vals
|
2014-09-05 09:18:53 -07:00
|
|
|
}
|
|
|
|
|
2014-09-29 22:11:30 +03:00
|
|
|
pub fn dbg_cx<'a>(&'a self) -> &'a Option<debuginfo::CrateDebugContext<'tcx>> {
|
2016-05-05 14:14:41 -04:00
|
|
|
&self.local().dbg_cx
|
2014-09-05 09:18:53 -07:00
|
|
|
}
|
|
|
|
|
2016-02-23 21:59:23 +02:00
|
|
|
pub fn rust_try_fn<'a>(&'a self) -> &'a Cell<Option<ValueRef>> {
|
2016-05-05 14:14:41 -04:00
|
|
|
&self.local().rust_try_fn
|
2015-07-13 18:11:44 -07:00
|
|
|
}
|
|
|
|
|
2016-11-08 14:02:55 +11:00
|
|
|
fn intrinsics<'a>(&'a self) -> &'a RefCell<FxHashMap<&'static str, ValueRef>> {
|
2016-05-05 14:14:41 -04:00
|
|
|
&self.local().intrinsics
|
2014-09-05 09:18:53 -07:00
|
|
|
}
|
2014-07-21 16:42:34 -07:00
|
|
|
|
2014-11-06 21:30:49 -05:00
|
|
|
pub fn obj_size_bound(&self) -> u64 {
|
2016-04-19 09:11:46 +03:00
|
|
|
self.tcx().data_layout.obj_size_bound()
|
2014-10-14 23:40:21 +03:00
|
|
|
}
|
|
|
|
|
2014-09-29 22:11:30 +03:00
|
|
|
pub fn report_overbig_object(&self, obj: Ty<'tcx>) -> ! {
|
2014-10-14 23:40:21 +03:00
|
|
|
self.sess().fatal(
|
2015-06-18 20:25:05 +03:00
|
|
|
&format!("the type `{:?}` is too big for the current architecture",
|
|
|
|
obj))
|
2014-10-14 23:40:21 +03:00
|
|
|
}
|
2015-01-06 00:56:30 -05:00
|
|
|
|
2015-10-25 23:02:15 +02:00
|
|
|
pub fn enter_type_of(&self, ty: Ty<'tcx>) -> TypeOfDepthLock<'b, 'tcx> {
|
2016-05-05 14:14:41 -04:00
|
|
|
let current_depth = self.local().type_of_depth.get();
|
2015-10-25 23:02:15 +02:00
|
|
|
debug!("enter_type_of({:?}) at depth {:?}", ty, current_depth);
|
|
|
|
if current_depth > self.sess().recursion_limit.get() {
|
|
|
|
self.sess().fatal(
|
|
|
|
&format!("overflow representing the type `{}`", ty))
|
|
|
|
}
|
2016-05-05 14:14:41 -04:00
|
|
|
self.local().type_of_depth.set(current_depth + 1);
|
|
|
|
TypeOfDepthLock(self.local())
|
2015-10-25 23:02:15 +02:00
|
|
|
}
|
|
|
|
|
2015-01-06 00:56:30 -05:00
|
|
|
pub fn check_overflow(&self) -> bool {
|
|
|
|
self.shared.check_overflow
|
|
|
|
}
|
2015-03-25 11:57:55 +01:00
|
|
|
|
2015-05-12 14:46:19 -07:00
|
|
|
pub fn use_dll_storage_attrs(&self) -> bool {
|
|
|
|
self.shared.use_dll_storage_attrs()
|
|
|
|
}
|
2015-10-21 17:20:00 -04:00
|
|
|
|
2017-04-14 15:10:53 -04:00
|
|
|
pub fn symbol_cache(&self) -> &'b SymbolCache<'b, 'tcx> {
|
|
|
|
self.local().symbol_cache
|
2016-05-26 08:59:58 -04:00
|
|
|
}
|
|
|
|
|
2016-03-09 18:22:05 -05:00
|
|
|
/// Given the def-id of some item that has no type parameters, make
|
|
|
|
/// a suitable "empty substs" for it.
|
|
|
|
pub fn empty_substs_for_def_id(&self, item_def_id: DefId) -> &'tcx Substs<'tcx> {
|
2017-02-08 18:31:03 +01:00
|
|
|
self.tcx().empty_substs_for_def_id(item_def_id)
|
2016-03-09 18:22:05 -05:00
|
|
|
}
|
2016-10-21 12:41:20 -04:00
|
|
|
|
|
|
|
/// Generate a new symbol name with the given prefix. This symbol name must
|
|
|
|
/// only be used for definitions with `internal` or `private` linkage.
|
|
|
|
pub fn generate_local_symbol_name(&self, prefix: &str) -> String {
|
|
|
|
let idx = self.local().local_gen_sym_counter.get();
|
|
|
|
self.local().local_gen_sym_counter.set(idx + 1);
|
|
|
|
// Include a '.' character, so there can be no accidental conflicts with
|
|
|
|
// user defined names
|
2016-11-04 17:37:42 -04:00
|
|
|
let mut name = String::with_capacity(prefix.len() + 6);
|
|
|
|
name.push_str(prefix);
|
|
|
|
name.push_str(".");
|
2016-12-12 21:56:52 +03:00
|
|
|
base_n::push_str(idx as u64, base_n::ALPHANUMERIC_ONLY, &mut name);
|
2016-11-04 17:37:42 -04:00
|
|
|
name
|
2016-10-21 12:41:20 -04:00
|
|
|
}
|
2016-12-19 19:32:50 -07:00
|
|
|
|
|
|
|
pub fn eh_personality(&self) -> ValueRef {
|
|
|
|
// The exception handling personality function.
|
|
|
|
//
|
|
|
|
// If our compilation unit has the `eh_personality` lang item somewhere
|
|
|
|
// within it, then we just need to translate that. Otherwise, we're
|
|
|
|
// building an rlib which will depend on some upstream implementation of
|
|
|
|
// this function, so we just codegen a generic reference to it. We don't
|
|
|
|
// specify any of the types for the function, we just make it a symbol
|
|
|
|
// that LLVM can later use.
|
|
|
|
//
|
|
|
|
// Note that MSVC is a little special here in that we don't use the
|
|
|
|
// `eh_personality` lang item at all. Currently LLVM has support for
|
|
|
|
// both Dwarf and SEH unwind mechanisms for MSVC targets and uses the
|
|
|
|
// *name of the personality function* to decide what kind of unwind side
|
|
|
|
// tables/landing pads to emit. It looks like Dwarf is used by default,
|
|
|
|
// injecting a dependency on the `_Unwind_Resume` symbol for resuming
|
|
|
|
// an "exception", but for MSVC we want to force SEH. This means that we
|
|
|
|
// can't actually have the personality function be our standard
|
|
|
|
// `rust_eh_personality` function, but rather we wired it up to the
|
|
|
|
// CRT's custom personality function, which forces LLVM to consider
|
|
|
|
// landing pads as "landing pads for SEH".
|
2016-12-19 21:41:03 -07:00
|
|
|
if let Some(llpersonality) = self.local().eh_personality.get() {
|
|
|
|
return llpersonality
|
|
|
|
}
|
2016-12-19 19:32:50 -07:00
|
|
|
let tcx = self.tcx();
|
2016-12-19 21:41:03 -07:00
|
|
|
let llfn = match tcx.lang_items.eh_personality() {
|
2016-12-19 19:32:50 -07:00
|
|
|
Some(def_id) if !base::wants_msvc_seh(self.sess()) => {
|
2017-03-08 18:33:21 +02:00
|
|
|
callee::resolve_and_get_fn(self, def_id, tcx.intern_substs(&[]))
|
2016-12-19 19:32:50 -07:00
|
|
|
}
|
|
|
|
_ => {
|
|
|
|
let name = if base::wants_msvc_seh(self.sess()) {
|
|
|
|
"__CxxFrameHandler3"
|
|
|
|
} else {
|
|
|
|
"rust_eh_personality"
|
|
|
|
};
|
|
|
|
let fty = Type::variadic_func(&[], &Type::i32(self));
|
2016-12-19 21:41:03 -07:00
|
|
|
declare::declare_cfn(self, name, fty)
|
2016-12-19 19:32:50 -07:00
|
|
|
}
|
2016-12-19 21:41:03 -07:00
|
|
|
};
|
|
|
|
self.local().eh_personality.set(Some(llfn));
|
|
|
|
llfn
|
2016-12-19 19:32:50 -07:00
|
|
|
}
|
|
|
|
|
2016-12-19 21:26:49 -07:00
|
|
|
// Returns a ValueRef of the "eh_unwind_resume" lang item if one is defined,
|
|
|
|
// otherwise declares it as an external function.
|
|
|
|
pub fn eh_unwind_resume(&self) -> ValueRef {
|
|
|
|
use attributes;
|
|
|
|
let unwresume = &self.local().eh_unwind_resume;
|
|
|
|
if let Some(llfn) = unwresume.get() {
|
|
|
|
return llfn;
|
|
|
|
}
|
|
|
|
|
|
|
|
let tcx = self.tcx();
|
|
|
|
assert!(self.sess().target.target.options.custom_unwind_resume);
|
|
|
|
if let Some(def_id) = tcx.lang_items.eh_unwind_resume() {
|
2017-03-08 18:33:21 +02:00
|
|
|
let llfn = callee::resolve_and_get_fn(self, def_id, tcx.intern_substs(&[]));
|
2016-12-19 21:26:49 -07:00
|
|
|
unwresume.set(Some(llfn));
|
|
|
|
return llfn;
|
|
|
|
}
|
|
|
|
|
2017-02-13 10:51:06 +02:00
|
|
|
let ty = tcx.mk_fn_ptr(ty::Binder(tcx.mk_fn_sig(
|
|
|
|
iter::once(tcx.mk_mut_ptr(tcx.types.u8)),
|
|
|
|
tcx.types.never,
|
|
|
|
false,
|
|
|
|
hir::Unsafety::Unsafe,
|
|
|
|
Abi::C
|
|
|
|
)));
|
2016-12-19 21:26:49 -07:00
|
|
|
|
|
|
|
let llfn = declare::declare_fn(self, "rust_eh_unwind_resume", ty);
|
|
|
|
attributes::unwind(llfn, true);
|
|
|
|
unwresume.set(Some(llfn));
|
|
|
|
llfn
|
|
|
|
}
|
2014-04-09 19:56:31 -04:00
|
|
|
}
|
|
|
|
|
2017-03-10 06:25:51 +02:00
|
|
|
impl<'a, 'tcx> ty::layout::HasDataLayout for &'a SharedCrateContext<'a, 'tcx> {
|
|
|
|
fn data_layout(&self) -> &ty::layout::TargetDataLayout {
|
|
|
|
&self.tcx.data_layout
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a, 'tcx> ty::layout::HasTyCtxt<'tcx> for &'a SharedCrateContext<'a, 'tcx> {
|
|
|
|
fn tcx<'b>(&'b self) -> TyCtxt<'b, 'tcx, 'tcx> {
|
|
|
|
self.tcx
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a, 'tcx> ty::layout::HasDataLayout for &'a CrateContext<'a, 'tcx> {
|
|
|
|
fn data_layout(&self) -> &ty::layout::TargetDataLayout {
|
|
|
|
&self.shared.tcx.data_layout
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a, 'tcx> ty::layout::HasTyCtxt<'tcx> for &'a CrateContext<'a, 'tcx> {
|
|
|
|
fn tcx<'b>(&'b self) -> TyCtxt<'b, 'tcx, 'tcx> {
|
|
|
|
self.shared.tcx
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a, 'tcx> LayoutTyper<'tcx> for &'a SharedCrateContext<'a, 'tcx> {
|
|
|
|
type TyLayout = TyLayout<'tcx>;
|
|
|
|
|
|
|
|
fn layout_of(self, ty: Ty<'tcx>) -> Self::TyLayout {
|
|
|
|
self.tcx().infer_ctxt((), traits::Reveal::All).enter(|infcx| {
|
|
|
|
infcx.layout_of(ty).unwrap_or_else(|e| {
|
|
|
|
match e {
|
|
|
|
ty::layout::LayoutError::SizeOverflow(_) =>
|
|
|
|
self.sess().fatal(&e.to_string()),
|
|
|
|
_ => bug!("failed to get layout for `{}`: {}", ty, e)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a, 'tcx> LayoutTyper<'tcx> for &'a CrateContext<'a, 'tcx> {
|
|
|
|
type TyLayout = TyLayout<'tcx>;
|
|
|
|
|
|
|
|
fn layout_of(self, ty: Ty<'tcx>) -> Self::TyLayout {
|
|
|
|
self.shared.layout_of(ty)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-14 15:10:53 -04:00
|
|
|
pub struct TypeOfDepthLock<'a, 'tcx: 'a>(&'a LocalCrateContext<'a, 'tcx>);
|
2015-10-25 23:02:15 +02:00
|
|
|
|
|
|
|
impl<'a, 'tcx> Drop for TypeOfDepthLock<'a, 'tcx> {
|
|
|
|
fn drop(&mut self) {
|
|
|
|
self.0.type_of_depth.set(self.0.type_of_depth.get() - 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-28 18:20:30 -07:00
|
|
|
/// Declare any llvm intrinsics that you might need
|
2015-08-15 18:43:39 +12:00
|
|
|
fn declare_intrinsic(ccx: &CrateContext, key: &str) -> Option<ValueRef> {
|
2015-01-02 14:44:21 -08:00
|
|
|
macro_rules! ifn {
|
2015-01-05 01:51:03 -05:00
|
|
|
($name:expr, fn() -> $ret:expr) => (
|
2015-08-15 18:43:39 +12:00
|
|
|
if key == $name {
|
2016-02-23 21:46:08 +02:00
|
|
|
let f = declare::declare_cfn(ccx, $name, Type::func(&[], &$ret));
|
2015-09-06 19:26:41 -05:00
|
|
|
llvm::SetUnnamedAddr(f, false);
|
2014-09-05 09:18:53 -07:00
|
|
|
ccx.intrinsics().borrow_mut().insert($name, f.clone());
|
2014-04-09 19:56:31 -04:00
|
|
|
return Some(f);
|
|
|
|
}
|
|
|
|
);
|
2015-10-23 18:18:44 -07:00
|
|
|
($name:expr, fn(...) -> $ret:expr) => (
|
|
|
|
if key == $name {
|
2016-02-23 21:46:08 +02:00
|
|
|
let f = declare::declare_cfn(ccx, $name, Type::variadic_func(&[], &$ret));
|
2015-10-23 18:18:44 -07:00
|
|
|
llvm::SetUnnamedAddr(f, false);
|
|
|
|
ccx.intrinsics().borrow_mut().insert($name, f.clone());
|
|
|
|
return Some(f);
|
|
|
|
}
|
|
|
|
);
|
2015-01-05 01:51:03 -05:00
|
|
|
($name:expr, fn($($arg:expr),*) -> $ret:expr) => (
|
2015-08-15 18:43:39 +12:00
|
|
|
if key == $name {
|
2016-02-23 21:46:08 +02:00
|
|
|
let f = declare::declare_cfn(ccx, $name, Type::func(&[$($arg),*], &$ret));
|
2015-09-06 19:26:41 -05:00
|
|
|
llvm::SetUnnamedAddr(f, false);
|
2014-09-05 09:18:53 -07:00
|
|
|
ccx.intrinsics().borrow_mut().insert($name, f.clone());
|
2014-04-09 19:56:31 -04:00
|
|
|
return Some(f);
|
|
|
|
}
|
2015-10-23 18:18:44 -07:00
|
|
|
);
|
2015-01-02 14:44:21 -08:00
|
|
|
}
|
|
|
|
macro_rules! mk_struct {
|
2014-11-17 21:39:01 +13:00
|
|
|
($($field_ty:expr),*) => (Type::struct_(ccx, &[$($field_ty),*], false))
|
2015-01-02 14:44:21 -08:00
|
|
|
}
|
2014-04-09 19:56:31 -04:00
|
|
|
|
|
|
|
let i8p = Type::i8p(ccx);
|
|
|
|
let void = Type::void(ccx);
|
|
|
|
let i1 = Type::i1(ccx);
|
|
|
|
let t_i8 = Type::i8(ccx);
|
|
|
|
let t_i16 = Type::i16(ccx);
|
|
|
|
let t_i32 = Type::i32(ccx);
|
|
|
|
let t_i64 = Type::i64(ccx);
|
2016-08-23 03:56:52 +03:00
|
|
|
let t_i128 = Type::i128(ccx);
|
2014-04-09 19:56:31 -04:00
|
|
|
let t_f32 = Type::f32(ccx);
|
|
|
|
let t_f64 = Type::f64(ccx);
|
|
|
|
|
2015-08-15 18:43:39 +12:00
|
|
|
ifn!("llvm.memcpy.p0i8.p0i8.i16", fn(i8p, i8p, t_i16, t_i32, i1) -> void);
|
2015-01-05 01:51:03 -05:00
|
|
|
ifn!("llvm.memcpy.p0i8.p0i8.i32", fn(i8p, i8p, t_i32, t_i32, i1) -> void);
|
|
|
|
ifn!("llvm.memcpy.p0i8.p0i8.i64", fn(i8p, i8p, t_i64, t_i32, i1) -> void);
|
2015-08-15 18:43:39 +12:00
|
|
|
ifn!("llvm.memmove.p0i8.p0i8.i16", fn(i8p, i8p, t_i16, t_i32, i1) -> void);
|
2015-01-05 01:51:03 -05:00
|
|
|
ifn!("llvm.memmove.p0i8.p0i8.i32", fn(i8p, i8p, t_i32, t_i32, i1) -> void);
|
|
|
|
ifn!("llvm.memmove.p0i8.p0i8.i64", fn(i8p, i8p, t_i64, t_i32, i1) -> void);
|
2015-08-15 18:43:39 +12:00
|
|
|
ifn!("llvm.memset.p0i8.i16", fn(i8p, t_i8, t_i16, t_i32, i1) -> void);
|
2015-01-05 01:51:03 -05:00
|
|
|
ifn!("llvm.memset.p0i8.i32", fn(i8p, t_i8, t_i32, t_i32, i1) -> void);
|
|
|
|
ifn!("llvm.memset.p0i8.i64", fn(i8p, t_i8, t_i64, t_i32, i1) -> void);
|
|
|
|
|
|
|
|
ifn!("llvm.trap", fn() -> void);
|
|
|
|
ifn!("llvm.debugtrap", fn() -> void);
|
2015-10-23 18:18:44 -07:00
|
|
|
ifn!("llvm.frameaddress", fn(t_i32) -> i8p);
|
2015-01-05 01:51:03 -05:00
|
|
|
|
|
|
|
ifn!("llvm.powi.f32", fn(t_f32, t_i32) -> t_f32);
|
|
|
|
ifn!("llvm.powi.f64", fn(t_f64, t_i32) -> t_f64);
|
|
|
|
ifn!("llvm.pow.f32", fn(t_f32, t_f32) -> t_f32);
|
|
|
|
ifn!("llvm.pow.f64", fn(t_f64, t_f64) -> t_f64);
|
|
|
|
|
|
|
|
ifn!("llvm.sqrt.f32", fn(t_f32) -> t_f32);
|
|
|
|
ifn!("llvm.sqrt.f64", fn(t_f64) -> t_f64);
|
|
|
|
ifn!("llvm.sin.f32", fn(t_f32) -> t_f32);
|
|
|
|
ifn!("llvm.sin.f64", fn(t_f64) -> t_f64);
|
|
|
|
ifn!("llvm.cos.f32", fn(t_f32) -> t_f32);
|
|
|
|
ifn!("llvm.cos.f64", fn(t_f64) -> t_f64);
|
|
|
|
ifn!("llvm.exp.f32", fn(t_f32) -> t_f32);
|
|
|
|
ifn!("llvm.exp.f64", fn(t_f64) -> t_f64);
|
|
|
|
ifn!("llvm.exp2.f32", fn(t_f32) -> t_f32);
|
|
|
|
ifn!("llvm.exp2.f64", fn(t_f64) -> t_f64);
|
|
|
|
ifn!("llvm.log.f32", fn(t_f32) -> t_f32);
|
|
|
|
ifn!("llvm.log.f64", fn(t_f64) -> t_f64);
|
|
|
|
ifn!("llvm.log10.f32", fn(t_f32) -> t_f32);
|
|
|
|
ifn!("llvm.log10.f64", fn(t_f64) -> t_f64);
|
|
|
|
ifn!("llvm.log2.f32", fn(t_f32) -> t_f32);
|
|
|
|
ifn!("llvm.log2.f64", fn(t_f64) -> t_f64);
|
|
|
|
|
|
|
|
ifn!("llvm.fma.f32", fn(t_f32, t_f32, t_f32) -> t_f32);
|
|
|
|
ifn!("llvm.fma.f64", fn(t_f64, t_f64, t_f64) -> t_f64);
|
|
|
|
|
|
|
|
ifn!("llvm.fabs.f32", fn(t_f32) -> t_f32);
|
|
|
|
ifn!("llvm.fabs.f64", fn(t_f64) -> t_f64);
|
|
|
|
|
|
|
|
ifn!("llvm.floor.f32", fn(t_f32) -> t_f32);
|
|
|
|
ifn!("llvm.floor.f64", fn(t_f64) -> t_f64);
|
|
|
|
ifn!("llvm.ceil.f32", fn(t_f32) -> t_f32);
|
|
|
|
ifn!("llvm.ceil.f64", fn(t_f64) -> t_f64);
|
|
|
|
ifn!("llvm.trunc.f32", fn(t_f32) -> t_f32);
|
|
|
|
ifn!("llvm.trunc.f64", fn(t_f64) -> t_f64);
|
|
|
|
|
2015-01-24 12:00:35 +01:00
|
|
|
ifn!("llvm.copysign.f32", fn(t_f32, t_f32) -> t_f32);
|
|
|
|
ifn!("llvm.copysign.f64", fn(t_f64, t_f64) -> t_f64);
|
|
|
|
ifn!("llvm.round.f32", fn(t_f32) -> t_f32);
|
|
|
|
ifn!("llvm.round.f64", fn(t_f64) -> t_f64);
|
|
|
|
|
2015-01-05 01:51:03 -05:00
|
|
|
ifn!("llvm.rint.f32", fn(t_f32) -> t_f32);
|
|
|
|
ifn!("llvm.rint.f64", fn(t_f64) -> t_f64);
|
|
|
|
ifn!("llvm.nearbyint.f32", fn(t_f32) -> t_f32);
|
|
|
|
ifn!("llvm.nearbyint.f64", fn(t_f64) -> t_f64);
|
|
|
|
|
|
|
|
ifn!("llvm.ctpop.i8", fn(t_i8) -> t_i8);
|
|
|
|
ifn!("llvm.ctpop.i16", fn(t_i16) -> t_i16);
|
|
|
|
ifn!("llvm.ctpop.i32", fn(t_i32) -> t_i32);
|
|
|
|
ifn!("llvm.ctpop.i64", fn(t_i64) -> t_i64);
|
2016-08-23 03:56:52 +03:00
|
|
|
ifn!("llvm.ctpop.i128", fn(t_i128) -> t_i128);
|
2015-01-05 01:51:03 -05:00
|
|
|
|
|
|
|
ifn!("llvm.ctlz.i8", fn(t_i8 , i1) -> t_i8);
|
|
|
|
ifn!("llvm.ctlz.i16", fn(t_i16, i1) -> t_i16);
|
|
|
|
ifn!("llvm.ctlz.i32", fn(t_i32, i1) -> t_i32);
|
|
|
|
ifn!("llvm.ctlz.i64", fn(t_i64, i1) -> t_i64);
|
2016-08-23 03:56:52 +03:00
|
|
|
ifn!("llvm.ctlz.i128", fn(t_i128, i1) -> t_i128);
|
2015-01-05 01:51:03 -05:00
|
|
|
|
|
|
|
ifn!("llvm.cttz.i8", fn(t_i8 , i1) -> t_i8);
|
|
|
|
ifn!("llvm.cttz.i16", fn(t_i16, i1) -> t_i16);
|
|
|
|
ifn!("llvm.cttz.i32", fn(t_i32, i1) -> t_i32);
|
|
|
|
ifn!("llvm.cttz.i64", fn(t_i64, i1) -> t_i64);
|
2016-08-23 03:56:52 +03:00
|
|
|
ifn!("llvm.cttz.i128", fn(t_i128, i1) -> t_i128);
|
2015-01-05 01:51:03 -05:00
|
|
|
|
|
|
|
ifn!("llvm.bswap.i16", fn(t_i16) -> t_i16);
|
|
|
|
ifn!("llvm.bswap.i32", fn(t_i32) -> t_i32);
|
|
|
|
ifn!("llvm.bswap.i64", fn(t_i64) -> t_i64);
|
2016-08-23 03:56:52 +03:00
|
|
|
ifn!("llvm.bswap.i128", fn(t_i128) -> t_i128);
|
2015-01-05 01:51:03 -05:00
|
|
|
|
|
|
|
ifn!("llvm.sadd.with.overflow.i8", fn(t_i8, t_i8) -> mk_struct!{t_i8, i1});
|
|
|
|
ifn!("llvm.sadd.with.overflow.i16", fn(t_i16, t_i16) -> mk_struct!{t_i16, i1});
|
|
|
|
ifn!("llvm.sadd.with.overflow.i32", fn(t_i32, t_i32) -> mk_struct!{t_i32, i1});
|
|
|
|
ifn!("llvm.sadd.with.overflow.i64", fn(t_i64, t_i64) -> mk_struct!{t_i64, i1});
|
2016-08-23 03:56:52 +03:00
|
|
|
ifn!("llvm.sadd.with.overflow.i128", fn(t_i128, t_i128) -> mk_struct!{t_i128, i1});
|
2015-01-05 01:51:03 -05:00
|
|
|
|
|
|
|
ifn!("llvm.uadd.with.overflow.i8", fn(t_i8, t_i8) -> mk_struct!{t_i8, i1});
|
|
|
|
ifn!("llvm.uadd.with.overflow.i16", fn(t_i16, t_i16) -> mk_struct!{t_i16, i1});
|
|
|
|
ifn!("llvm.uadd.with.overflow.i32", fn(t_i32, t_i32) -> mk_struct!{t_i32, i1});
|
|
|
|
ifn!("llvm.uadd.with.overflow.i64", fn(t_i64, t_i64) -> mk_struct!{t_i64, i1});
|
2016-08-23 03:56:52 +03:00
|
|
|
ifn!("llvm.uadd.with.overflow.i128", fn(t_i128, t_i128) -> mk_struct!{t_i128, i1});
|
2015-01-05 01:51:03 -05:00
|
|
|
|
|
|
|
ifn!("llvm.ssub.with.overflow.i8", fn(t_i8, t_i8) -> mk_struct!{t_i8, i1});
|
|
|
|
ifn!("llvm.ssub.with.overflow.i16", fn(t_i16, t_i16) -> mk_struct!{t_i16, i1});
|
|
|
|
ifn!("llvm.ssub.with.overflow.i32", fn(t_i32, t_i32) -> mk_struct!{t_i32, i1});
|
|
|
|
ifn!("llvm.ssub.with.overflow.i64", fn(t_i64, t_i64) -> mk_struct!{t_i64, i1});
|
2016-08-23 03:56:52 +03:00
|
|
|
ifn!("llvm.ssub.with.overflow.i128", fn(t_i128, t_i128) -> mk_struct!{t_i128, i1});
|
2015-01-05 01:51:03 -05:00
|
|
|
|
|
|
|
ifn!("llvm.usub.with.overflow.i8", fn(t_i8, t_i8) -> mk_struct!{t_i8, i1});
|
|
|
|
ifn!("llvm.usub.with.overflow.i16", fn(t_i16, t_i16) -> mk_struct!{t_i16, i1});
|
|
|
|
ifn!("llvm.usub.with.overflow.i32", fn(t_i32, t_i32) -> mk_struct!{t_i32, i1});
|
|
|
|
ifn!("llvm.usub.with.overflow.i64", fn(t_i64, t_i64) -> mk_struct!{t_i64, i1});
|
2016-08-23 03:56:52 +03:00
|
|
|
ifn!("llvm.usub.with.overflow.i128", fn(t_i128, t_i128) -> mk_struct!{t_i128, i1});
|
2015-01-05 01:51:03 -05:00
|
|
|
|
|
|
|
ifn!("llvm.smul.with.overflow.i8", fn(t_i8, t_i8) -> mk_struct!{t_i8, i1});
|
|
|
|
ifn!("llvm.smul.with.overflow.i16", fn(t_i16, t_i16) -> mk_struct!{t_i16, i1});
|
|
|
|
ifn!("llvm.smul.with.overflow.i32", fn(t_i32, t_i32) -> mk_struct!{t_i32, i1});
|
|
|
|
ifn!("llvm.smul.with.overflow.i64", fn(t_i64, t_i64) -> mk_struct!{t_i64, i1});
|
2016-08-23 03:56:52 +03:00
|
|
|
ifn!("llvm.smul.with.overflow.i128", fn(t_i128, t_i128) -> mk_struct!{t_i128, i1});
|
2015-01-05 01:51:03 -05:00
|
|
|
|
|
|
|
ifn!("llvm.umul.with.overflow.i8", fn(t_i8, t_i8) -> mk_struct!{t_i8, i1});
|
|
|
|
ifn!("llvm.umul.with.overflow.i16", fn(t_i16, t_i16) -> mk_struct!{t_i16, i1});
|
|
|
|
ifn!("llvm.umul.with.overflow.i32", fn(t_i32, t_i32) -> mk_struct!{t_i32, i1});
|
|
|
|
ifn!("llvm.umul.with.overflow.i64", fn(t_i64, t_i64) -> mk_struct!{t_i64, i1});
|
2016-08-23 03:56:52 +03:00
|
|
|
ifn!("llvm.umul.with.overflow.i128", fn(t_i128, t_i128) -> mk_struct!{t_i128, i1});
|
2015-01-05 01:51:03 -05:00
|
|
|
|
|
|
|
ifn!("llvm.lifetime.start", fn(t_i64,i8p) -> void);
|
|
|
|
ifn!("llvm.lifetime.end", fn(t_i64, i8p) -> void);
|
|
|
|
|
|
|
|
ifn!("llvm.expect.i1", fn(i1, i1) -> i1);
|
2015-07-20 13:27:38 -07:00
|
|
|
ifn!("llvm.eh.typeid.for", fn(i8p) -> t_i32);
|
2015-10-23 18:18:44 -07:00
|
|
|
ifn!("llvm.localescape", fn(...) -> void);
|
|
|
|
ifn!("llvm.localrecover", fn(i8p, i8p, t_i32) -> i8p);
|
|
|
|
ifn!("llvm.x86.seh.recoverfp", fn(i8p, i8p) -> i8p);
|
2014-04-09 19:56:31 -04:00
|
|
|
|
2016-06-10 17:37:46 -04:00
|
|
|
ifn!("llvm.assume", fn(i1) -> void);
|
2014-04-09 19:56:31 -04:00
|
|
|
|
|
|
|
if ccx.sess().opts.debuginfo != NoDebugInfo {
|
2015-01-05 01:51:03 -05:00
|
|
|
ifn!("llvm.dbg.declare", fn(Type::metadata(ccx), Type::metadata(ccx)) -> void);
|
|
|
|
ifn!("llvm.dbg.value", fn(Type::metadata(ccx), t_i64, Type::metadata(ccx)) -> void);
|
2014-04-09 19:56:31 -04:00
|
|
|
}
|
|
|
|
return None;
|
2013-06-13 14:49:01 +12:00
|
|
|
}
|