]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc_trans/trans/base.rs
Only retain external static symbols across LTO
[rust.git] / src / librustc_trans / trans / base.rs
index 76b1bad12146989c51b5681b0faa1d6ff7f95bd8..4748c62921de6f24e4376093d0460f11a97477ff 100644 (file)
@@ -48,7 +48,7 @@
 use rustc::dep_graph::DepNode;
 use rustc::front::map as hir_map;
 use rustc::util::common::time;
-use rustc_mir::mir_map::MirMap;
+use rustc::mir::mir_map::MirMap;
 use session::config::{self, NoDebugInfo, FullDebugInfo};
 use session::Session;
 use trans::_match;
 use std::collections::{HashMap, HashSet};
 use std::str;
 use std::{i8, i16, i32, i64};
-use syntax::abi::{Rust, RustCall, RustIntrinsic, PlatformIntrinsic, Abi};
+use syntax::abi::Abi;
 use syntax::codemap::{Span, DUMMY_SP};
 use syntax::parse::token::InternedString;
 use syntax::attr::AttrMetaMethods;
@@ -559,7 +559,7 @@ fn iter_variant<'blk, 'tcx, F>(cx: Block<'blk, 'tcx>,
             // NB: we must hit the discriminant first so that structural
             // comparison know not to proceed when the discriminants differ.
 
-            match adt::trans_switch(cx, &*repr, av) {
+            match adt::trans_switch(cx, &*repr, av, false) {
                 (_match::Single, None) => {
                     if n_variants != 0 {
                         assert!(n_variants == 1);
@@ -816,12 +816,12 @@ pub fn llty_and_min_for_signed_ty<'blk, 'tcx>(cx: Block<'blk, 'tcx>,
         ty::TyInt(t) => {
             let llty = Type::int_from_ty(cx.ccx(), t);
             let min = match t {
-                ast::TyIs if llty == Type::i32(cx.ccx()) => i32::MIN as u64,
-                ast::TyIs => i64::MIN as u64,
-                ast::TyI8 => i8::MIN as u64,
-                ast::TyI16 => i16::MIN as u64,
-                ast::TyI32 => i32::MIN as u64,
-                ast::TyI64 => i64::MIN as u64,
+                ast::IntTy::Is if llty == Type::i32(cx.ccx()) => i32::MIN as u64,
+                ast::IntTy::Is => i64::MIN as u64,
+                ast::IntTy::I8 => i8::MIN as u64,
+                ast::IntTy::I16 => i16::MIN as u64,
+                ast::IntTy::I32 => i32::MIN as u64,
+                ast::IntTy::I64 => i64::MIN as u64,
             };
             (llty, min)
         }
@@ -911,10 +911,10 @@ pub fn trans_external_path<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
     match t.sty {
         ty::TyBareFn(_, ref fn_ty) => {
             match ccx.sess().target.target.adjust_abi(fn_ty.abi) {
-                Rust | RustCall => {
+                Abi::Rust | Abi::RustCall => {
                     get_extern_rust_fn(ccx, t, &name[..], did)
                 }
-                RustIntrinsic | PlatformIntrinsic => {
+                Abi::RustIntrinsic | Abi::PlatformIntrinsic => {
                     ccx.sess().bug("unexpected intrinsic in trans_external_path")
                 }
                 _ => {
@@ -984,23 +984,11 @@ pub fn invoke<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
 /// currently uses SEH-ish unwinding with DWARF info tables to the side (same as
 /// 64-bit MinGW) instead of "full SEH".
 pub fn wants_msvc_seh(sess: &Session) -> bool {
-    sess.target.target.options.is_like_msvc && sess.target.target.arch == "x86"
+    sess.target.target.options.is_like_msvc
 }
 
 pub fn avoid_invoke(bcx: Block) -> bool {
-    // FIXME(#25869) currently SEH-based unwinding is pretty buggy in LLVM and
-    //               is being overhauled as this is being written. Until that
-    //               time such that upstream LLVM's implementation is more solid
-    //               and we start binding it we need to skip invokes for any
-    //               target which wants SEH-based unwinding.
-    if bcx.sess().no_landing_pads() || wants_msvc_seh(bcx.sess()) {
-        true
-    } else if bcx.is_lpad {
-        // Avoid using invoke if we are already inside a landing pad.
-        true
-    } else {
-        false
-    }
+    bcx.sess().no_landing_pads() || bcx.lpad().is_some()
 }
 
 pub fn need_invoke(bcx: Block) -> bool {
@@ -1148,10 +1136,9 @@ pub fn init_local<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, local: &hir::Local) -> Blo
 }
 
 pub fn raw_block<'blk, 'tcx>(fcx: &'blk FunctionContext<'blk, 'tcx>,
-                             is_lpad: bool,
                              llbb: BasicBlockRef)
                              -> Block<'blk, 'tcx> {
-    common::BlockS::new(llbb, is_lpad, None, fcx)
+    common::BlockS::new(llbb, None, fcx)
 }
 
 pub fn with_cond<'blk, 'tcx, F>(bcx: Block<'blk, 'tcx>, val: ValueRef, f: F) -> Block<'blk, 'tcx>
@@ -1324,7 +1311,7 @@ fn memfill<'a, 'tcx>(b: &Builder<'a, 'tcx>, llptr: ValueRef, ty: Ty<'tcx>, byte:
     let volatile = C_bool(ccx, false);
     b.call(llintrinsicfn,
            &[llptr, llzeroval, size, align, volatile],
-           None);
+           None, None);
 }
 
 /// In general, when we create an scratch value in an alloca, the
@@ -1398,7 +1385,7 @@ pub fn alloca_dropped<'blk, 'tcx>(cx: Block<'blk, 'tcx>, ty: Ty<'tcx>, name: &st
     // Block, which we do not have for `alloca_insert_pt`).
     core_lifetime_emit(cx.ccx(), p, Lifetime::Start, |ccx, size, lifetime_start| {
         let ptr = b.pointercast(p, Type::i8p(ccx));
-        b.call(lifetime_start, &[C_u64(ccx, size), ptr], None);
+        b.call(lifetime_start, &[C_u64(ccx, size), ptr], None, None);
     });
     memfill(&b, p, ty, adt::DTOR_DONE);
     p
@@ -1609,7 +1596,7 @@ pub fn new_fn_ctxt<'a, 'tcx>(ccx: &'a CrateContext<'a, 'tcx>,
         false
     };
 
-    let mir = ccx.mir_map().get(&id);
+    let mir = ccx.mir_map().map.get(&id);
 
     let mut fcx = FunctionContext {
         mir: mir,
@@ -1620,7 +1607,7 @@ pub fn new_fn_ctxt<'a, 'tcx>(ccx: &'a CrateContext<'a, 'tcx>,
         alloca_insert_pt: Cell::new(None),
         llreturn: Cell::new(None),
         needs_ret_allocas: nested_returns,
-        personality: Cell::new(None),
+        landingpad_alloca: Cell::new(None),
         caller_expects_out_pointer: uses_outptr,
         lllocals: RefCell::new(NodeMap()),
         llupvars: RefCell::new(NodeMap()),
@@ -1629,6 +1616,7 @@ pub fn new_fn_ctxt<'a, 'tcx>(ccx: &'a CrateContext<'a, 'tcx>,
         param_substs: param_substs,
         span: sp,
         block_arena: block_arena,
+        lpad_arena: TypedArena::new(),
         ccx: ccx,
         debug_context: debug_context,
         scopes: RefCell::new(Vec::new()),
@@ -1899,7 +1887,7 @@ pub fn finish_fn<'blk, 'tcx>(fcx: &'blk FunctionContext<'blk, 'tcx>,
             if !last_bcx.terminated.get() {
                 Br(last_bcx, llreturn, DebugLoc::None);
             }
-            raw_block(fcx, false, llreturn)
+            raw_block(fcx, llreturn)
         }
         None => last_bcx,
     };
@@ -2016,7 +2004,7 @@ pub fn trans_closure<'a, 'b, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
     let mut bcx = init_function(&fcx, false, output_type);
 
     if attributes.iter().any(|item| item.check_name("rustc_mir")) {
-        mir::trans_mir(bcx);
+        mir::trans_mir(bcx.build());
         fcx.cleanup();
         return;
     }
@@ -2043,7 +2031,7 @@ pub fn trans_closure<'a, 'b, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
            bcx.fcx.ccx.tn().val_to_string(bcx.fcx.llfn));
 
     let has_tupled_arg = match closure_env {
-        closure::ClosureEnv::NotClosure => abi == RustCall,
+        closure::ClosureEnv::NotClosure => abi == Abi::RustCall,
         _ => false,
     };
 
@@ -2515,7 +2503,7 @@ pub fn trans_item(ccx: &CrateContext, item: &hir::Item) {
                 for (ref ccx, is_origin) in ccx.maybe_iter(!from_external && trans_everywhere) {
                     let llfn = get_item_val(ccx, item.id);
                     let empty_substs = ccx.tcx().mk_substs(Substs::trans_empty());
-                    if abi != Rust {
+                    if abi != Abi::Rust {
                         foreign::trans_rust_fn_with_foreign_abi(ccx,
                                                                 &**decl,
                                                                 &**body,
@@ -2619,12 +2607,12 @@ fn register_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
                          node_type: Ty<'tcx>)
                          -> ValueRef {
     if let ty::TyBareFn(_, ref f) = node_type.sty {
-        if f.abi != Rust && f.abi != RustCall {
+        if f.abi != Abi::Rust && f.abi != Abi::RustCall {
             ccx.sess().span_bug(sp,
                                 &format!("only the `{}` or `{}` calling conventions are valid \
                                           for this function; `{}` was specified",
-                                         Rust.name(),
-                                         RustCall.name(),
+                                         Abi::Rust.name(),
+                                         Abi::RustCall.name(),
                                          f.abi.name()));
         }
     } else {
@@ -2713,11 +2701,12 @@ fn create_entry_fn(ccx: &CrateContext,
                 (rust_main, args)
             };
 
-            let result = llvm::LLVMBuildCall(bld,
-                                             start_fn,
-                                             args.as_ptr(),
-                                             args.len() as c_uint,
-                                             noname());
+            let result = llvm::LLVMRustBuildCall(bld,
+                                                 start_fn,
+                                                 args.as_ptr(),
+                                                 args.len() as c_uint,
+                                                 0 as *mut _,
+                                                 noname());
 
             llvm::LLVMBuildRet(bld, result);
         }
@@ -2801,7 +2790,7 @@ pub fn get_item_val(ccx: &CrateContext, id: ast::NodeId) -> ValueRef {
 
                 hir::ItemFn(_, _, _, abi, _, _) => {
                     let sym = sym();
-                    let llfn = if abi == Rust {
+                    let llfn = if abi == Abi::Rust {
                         register_fn(ccx, i.span, sym, i.id, ty)
                     } else {
                         foreign::register_rust_fn_with_foreign_abi(ccx, i.span, sym, i.id)
@@ -2924,7 +2913,7 @@ fn register_method(ccx: &CrateContext,
     let sym = exported_name(ccx, id, mty, &attrs);
 
     if let ty::TyBareFn(_, ref f) = mty.sty {
-        let llfn = if f.abi == Rust || f.abi == RustCall {
+        let llfn = if f.abi == Abi::Rust || f.abi == Abi::RustCall {
             register_fn(ccx, span, sym, id, mty)
         } else {
             foreign::register_rust_fn_with_foreign_abi(ccx, span, sym, id)
@@ -3292,8 +3281,7 @@ pub fn trans_crate<'tcx>(tcx: &ty::ctxt<'tcx>,
         for cnum in sess.cstore.crates() {
             let syms = sess.cstore.reachable_ids(cnum);
             reachable_symbols.extend(syms.into_iter().filter(|did| {
-                sess.cstore.is_extern_fn(shared_ccx.tcx(), *did) ||
-                sess.cstore.is_static(*did)
+                sess.cstore.is_extern_item(shared_ccx.tcx(), *did)
             }).map(|did| {
                 sess.cstore.item_symbol(did)
             }));