]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc/middle/trans/context.rs
auto merge of #15999 : Kimundi/rust/fix_folder, r=nikomatsakis
[rust.git] / src / librustc / middle / trans / context.rs
index a80ae9e2596da0c16a2f0c2ad488f2a215dfb43e..bb528790314da512fe2dae3a4234d58b3ad2a1a9 100644 (file)
@@ -8,12 +8,12 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-
 use driver::config::NoDebugInfo;
 use driver::session::Session;
-use lib::llvm::{ContextRef, ModuleRef, ValueRef};
-use lib::llvm::{llvm, TargetData, TypeNames};
-use lib::llvm::mk_target_data;
+use llvm;
+use llvm::{ContextRef, ModuleRef, ValueRef};
+use llvm::{TargetData};
+use llvm::mk_target_data;
 use metadata::common::LinkMeta;
 use middle::resolve;
 use middle::trans::adt;
@@ -22,7 +22,7 @@
 use middle::trans::common::{ExternMap,tydesc_info,BuilderRef_res};
 use middle::trans::debuginfo;
 use middle::trans::monomorphize::MonoId;
-use middle::trans::type_::Type;
+use middle::trans::type_::{Type, TypeNames};
 use middle::ty;
 use util::sha2::Sha256;
 use util::nodemap::{NodeMap, NodeSet, DefIdMap};
@@ -32,6 +32,7 @@
 use std::ptr;
 use std::rc::Rc;
 use std::collections::{HashMap, HashSet};
+use syntax::abi;
 use syntax::ast;
 use syntax::parse::token::InternedString;
 
@@ -116,10 +117,10 @@ pub struct CrateContext {
     pub int_type: Type,
     pub opaque_vec_type: Type,
     pub builder: BuilderRef_res,
-    /// Set when at least one function uses GC. Needed so that
-    /// decl_gc_metadata knows whether to link to the module metadata, which
-    /// is not emitted by LLVM's GC pass when no functions use GC.
-    pub uses_gc: bool,
+
+    /// Holds the LLVM values for closure IDs.
+    pub unboxed_closure_vals: RefCell<DefIdMap<ValueRef>>,
+
     pub dbg_cx: Option<debuginfo::CrateDebugContext>,
 
     pub eh_personality: RefCell<Option<ValueRef>>,
@@ -221,10 +222,10 @@ pub fn new(name: &str,
                     llvm_insns: RefCell::new(HashMap::new()),
                     fn_stats: RefCell::new(Vec::new()),
                 },
-                int_type: Type::from_ref(ptr::null()),
-                opaque_vec_type: Type::from_ref(ptr::null()),
+                int_type: Type::from_ref(ptr::mut_null()),
+                opaque_vec_type: Type::from_ref(ptr::mut_null()),
                 builder: BuilderRef_res(llvm::LLVMCreateBuilderInContext(llcx)),
-                uses_gc: false,
+                unboxed_closure_vals: RefCell::new(DefIdMap::new()),
                 dbg_cx: dbg_cx,
                 eh_personality: RefCell::new(None),
                 intrinsics: RefCell::new(HashMap::new()),
@@ -273,20 +274,32 @@ pub fn get_intrinsic(&self, key: & &'static str) -> ValueRef {
             None => fail!()
         }
     }
+
+    // Although there is an experimental implementation of LLVM which
+    // supports SS on armv7 it wasn't approved by Apple, see:
+    // http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20140505/216350.html
+    // It looks like it might be never accepted to upstream LLVM.
+    //
+    // So far the decision was to disable them in default builds
+    // but it could be enabled (with patched LLVM)
+    pub fn is_split_stack_supported(&self) -> bool {
+        let ref cfg = self.sess().targ_cfg;
+        cfg.os != abi::OsiOS || cfg.arch != abi::Arm
+    }
 }
 
 fn declare_intrinsic(ccx: &CrateContext, key: & &'static str) -> Option<ValueRef> {
     macro_rules! ifn (
         ($name:expr fn() -> $ret:expr) => (
             if *key == $name {
-                let f = base::decl_cdecl_fn(ccx.llmod, $name, Type::func([], &$ret), ty::mk_nil());
+                let f = base::decl_cdecl_fn(ccx, $name, Type::func([], &$ret), ty::mk_nil());
                 ccx.intrinsics.borrow_mut().insert($name, f.clone());
                 return Some(f);
             }
         );
         ($name:expr fn($($arg:expr),*) -> $ret:expr) => (
             if *key == $name {
-                let f = base::decl_cdecl_fn(ccx.llmod, $name,
+                let f = base::decl_cdecl_fn(ccx, $name,
                                   Type::func([$($arg),*], &$ret), ty::mk_nil());
                 ccx.intrinsics.borrow_mut().insert($name, f.clone());
                 return Some(f);
@@ -407,6 +420,9 @@ macro_rules! mk_struct (
     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});
 
+    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);
 
     // Some intrinsics were introduced in later versions of LLVM, but they have
@@ -418,7 +434,7 @@ macro_rules! compatible_ifn (
                 // The `if key == $name` is already in ifn!
                 ifn!($name fn($($arg),*) -> $ret);
             } else if *key == $name {
-                let f = base::decl_cdecl_fn(ccx.llmod, stringify!($cname),
+                let f = base::decl_cdecl_fn(ccx, stringify!($cname),
                                       Type::func([$($arg),*], &$ret),
                                       ty::mk_nil());
                 ccx.intrinsics.borrow_mut().insert($name, f.clone());