about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorMark-Simulacrum <mark.simulacrum@gmail.com>2016-12-16 16:45:52 -0700
committerMark Simulacrum <mark.simulacrum@gmail.com>2016-12-20 20:03:27 -0700
commitc4f6173af8cccda2154211a6de41c3eaa4bceaac (patch)
treed49cf6b16373139e7a6b055c1ca503dcc0f1009f /src
parentcbbdb73eb07fb9a29e20f4fb16b8f1c059e9763f (diff)
downloadrust-c4f6173af8cccda2154211a6de41c3eaa4bceaac.tar.gz
rust-c4f6173af8cccda2154211a6de41c3eaa4bceaac.zip
Replace init with get_entry_block.
Diffstat (limited to 'src')
-rw-r--r--src/librustc_trans/base.rs12
-rw-r--r--src/librustc_trans/callee.rs18
-rw-r--r--src/librustc_trans/common.rs46
-rw-r--r--src/librustc_trans/glue.rs5
-rw-r--r--src/librustc_trans/intrinsic.rs4
-rw-r--r--src/librustc_trans/meth.rs8
-rw-r--r--src/librustc_trans/mir/mod.rs2
7 files changed, 44 insertions, 51 deletions
diff --git a/src/librustc_trans/base.rs b/src/librustc_trans/base.rs
index e8a75d26534..30c1074b89c 100644
--- a/src/librustc_trans/base.rs
+++ b/src/librustc_trans/base.rs
@@ -657,11 +657,11 @@ impl<'blk, 'tcx> FunctionContext<'blk, 'tcx> {
 
     // Builds the return block for a function.
     pub fn build_return_block(&self, ret_cx: &BlockAndBuilder<'blk, 'tcx>) {
-        if self.llretslotptr.get().is_none() || self.fn_ty.ret.is_indirect() {
+        if self.llretslotptr.is_none() || self.fn_ty.ret.is_indirect() {
             return ret_cx.ret_void();
         }
 
-        let retslot = self.llretslotptr.get().unwrap();
+        let retslot = self.llretslotptr.unwrap();
         let retptr = Value(retslot);
         let llty = self.fn_ty.ret.original_ty;
         match (retptr.get_dominating_store(ret_cx), self.fn_ty.ret.cast) {
@@ -751,7 +751,7 @@ pub fn trans_instance<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, instance: Instance
 
     let fn_ty = FnType::new(ccx, abi, &sig, &[]);
 
-    let fcx = FunctionContext::new(ccx, lldecl, fn_ty, Some((instance, &sig, abi)));
+    let fcx = FunctionContext::new(ccx, lldecl, fn_ty, Some((instance, &sig, abi)), true);
 
     if fcx.mir.is_none() {
         bug!("attempted translation of `{}` w/o MIR", instance);
@@ -774,11 +774,11 @@ pub fn trans_ctor_shim<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
     let sig = ccx.tcx().erase_late_bound_regions_and_normalize(&ctor_ty.fn_sig());
     let fn_ty = FnType::new(ccx, Abi::Rust, &sig, &[]);
 
-    let fcx = FunctionContext::new(ccx, llfndecl, fn_ty, None);
-    let bcx = fcx.init(false);
+    let fcx = FunctionContext::new(ccx, llfndecl, fn_ty, None, false);
+    let bcx = fcx.get_entry_block();
 
     if !fcx.fn_ty.ret.is_ignore() {
-        let dest = fcx.llretslotptr.get().unwrap();
+        let dest = fcx.llretslotptr.unwrap();
         let dest_val = adt::MaybeSizedValue::sized(dest); // Can return unsized value
         let mut llarg_idx = fcx.fn_ty.ret.is_indirect() as usize;
         let mut arg_idx = 0;
diff --git a/src/librustc_trans/callee.rs b/src/librustc_trans/callee.rs
index 4f6165e1dbe..8c880210f62 100644
--- a/src/librustc_trans/callee.rs
+++ b/src/librustc_trans/callee.rs
@@ -347,8 +347,8 @@ fn trans_fn_once_adapter_shim<'a, 'tcx>(
     let lloncefn = declare::define_internal_fn(ccx, &function_name, llonce_fn_ty);
     attributes::set_frame_pointer_elimination(ccx, lloncefn);
 
-    let fcx = FunctionContext::new(ccx, lloncefn, fn_ty, None);
-    let mut bcx = fcx.init(false);
+    let fcx = FunctionContext::new(ccx, lloncefn, fn_ty, None, false);
+    let mut bcx = fcx.get_entry_block();
 
     // the first argument (`self`) will be the (by value) closure env.
 
@@ -378,8 +378,6 @@ fn trans_fn_once_adapter_shim<'a, 'tcx>(
         llargs[self_idx] = llenv;
     }
 
-    let dest = fcx.llretslotptr.get();
-
     let callee = Callee {
         data: Fn(llreffn),
         ty: llref_fn_ty
@@ -392,7 +390,7 @@ fn trans_fn_once_adapter_shim<'a, 'tcx>(
     let fn_ty = callee.direct_fn_type(bcx.ccx(), &[]);
 
     let first_llarg = if fn_ty.ret.is_indirect() {
-        dest
+        fcx.llretslotptr
     } else {
         None
     };
@@ -411,7 +409,7 @@ fn trans_fn_once_adapter_shim<'a, 'tcx>(
     fn_ty.apply_attrs_callsite(llret);
 
     if !fn_ty.ret.is_indirect() {
-        if let Some(llretslot) = dest {
+        if let Some(llretslot) = fcx.llretslotptr {
             fn_ty.ret.store(&bcx, llret, llretslot);
         }
     }
@@ -521,8 +519,8 @@ fn trans_fn_pointer_shim<'a, 'tcx>(
     let llfn = declare::define_internal_fn(ccx, &function_name, tuple_fn_ty);
     attributes::set_frame_pointer_elimination(ccx, llfn);
     //
-    let fcx = FunctionContext::new(ccx, llfn, fn_ty, None);
-    let bcx = fcx.init(false);
+    let fcx = FunctionContext::new(ccx, llfn, fn_ty, None, false);
+    let bcx = fcx.get_entry_block();
 
     let llargs = get_params(fcx.llfn);
 
@@ -536,13 +534,11 @@ fn trans_fn_pointer_shim<'a, 'tcx>(
         }
     });
 
-    let dest = fcx.llretslotptr.get();
-
     let callee = Callee {
         data: Fn(llfnpointer),
         ty: bare_fn_ty
     };
-    let bcx = callee.call(bcx, &llargs[(self_idx + 1)..], dest, None).0;
+    let bcx = callee.call(bcx, &llargs[(self_idx + 1)..], fcx.llretslotptr, None).0;
     fcx.finish(&bcx);
 
     ccx.fn_pointer_shims().borrow_mut().insert(bare_fn_ty_maybe_ref, llfn);
diff --git a/src/librustc_trans/common.rs b/src/librustc_trans/common.rs
index 11c995accc5..610c4cfd108 100644
--- a/src/librustc_trans/common.rs
+++ b/src/librustc_trans/common.rs
@@ -276,7 +276,7 @@ pub struct FunctionContext<'a, 'tcx: 'a> {
     // immediate, this points to an alloca in the function. Otherwise, it's a
     // pointer to the hidden first parameter of the function. After function
     // construction, this should always be Some.
-    pub llretslotptr: Cell<Option<ValueRef>>,
+    pub llretslotptr: Option<ValueRef>,
 
     // These pub elements: "hoisted basic blocks" containing
     // administrative activities that have to happen in only one place in
@@ -311,13 +311,14 @@ pub struct FunctionContext<'a, 'tcx: 'a> {
 
 impl<'a, 'tcx> FunctionContext<'a, 'tcx> {
     /// Create a function context for the given function.
-    /// Beware that you must call `fcx.init` before doing anything with the returned function
-    /// context.
-    pub fn new(ccx: &'a CrateContext<'a, 'tcx>,
-               llfndecl: ValueRef,
-               fn_ty: FnType,
-               definition: Option<(Instance<'tcx>, &ty::FnSig<'tcx>, Abi)>)
-               -> FunctionContext<'a, 'tcx> {
+    /// Call FunctionContext::get_entry_block for the first entry block.
+    pub fn new(
+        ccx: &'a CrateContext<'a, 'tcx>,
+        llfndecl: ValueRef,
+        fn_ty: FnType,
+        definition: Option<(Instance<'tcx>, &ty::FnSig<'tcx>, Abi)>,
+        skip_retptr: bool,
+    ) -> FunctionContext<'a, 'tcx> {
         let (param_substs, def_id) = match definition {
             Some((instance, ..)) => {
                 validate_substs(instance.substs);
@@ -350,7 +351,7 @@ impl<'a, 'tcx> FunctionContext<'a, 'tcx> {
         let mut fcx = FunctionContext {
             mir: mir,
             llfn: llfndecl,
-            llretslotptr: Cell::new(None),
+            llretslotptr: None,
             param_env: ccx.tcx().empty_parameter_environment(),
             alloca_insert_pt: None,
             landingpad_alloca: Cell::new(None),
@@ -372,31 +373,28 @@ impl<'a, 'tcx> FunctionContext<'a, 'tcx> {
         // This is later removed in the drop of FunctionContext.
         fcx.alloca_insert_pt = Some(val);
 
-        fcx
-    }
-
-    /// Performs setup on a newly created function, creating the entry
-    /// scope block and allocating space for the return pointer.
-    pub fn init(&'a self, skip_retptr: bool) -> BlockAndBuilder<'a, 'tcx> {
-        if !self.fn_ty.ret.is_ignore() && !skip_retptr {
-            // We normally allocate the llretslotptr, unless we
-            // have been instructed to skip it for immediate return
-            // values, or there is nothing to return at all.
-
+        // We normally allocate the llretslotptr, unless we
+        // have been instructed to skip it for immediate return
+        // values, or there is nothing to return at all.
+        if !fcx.fn_ty.ret.is_ignore() && !skip_retptr {
             // But if there are no nested returns, we skip the indirection
             // and have a single retslot
-            let slot = if self.fn_ty.ret.is_indirect() {
-                get_param(self.llfn, 0)
+            let slot = if fcx.fn_ty.ret.is_indirect() {
+                get_param(fcx.llfn, 0)
             } else {
                 // We create an alloca to hold a pointer of type `ret.original_ty`
                 // which will hold the pointer to the right alloca which has the
                 // final ret value
-                self.alloca(self.fn_ty.ret.memory_ty(self.ccx), "sret_slot")
+                fcx.alloca(fcx.fn_ty.ret.memory_ty(ccx), "sret_slot")
             };
 
-            self.llretslotptr.set(Some(slot));
+            fcx.llretslotptr = Some(slot);
         }
 
+        fcx
+    }
+
+    pub fn get_entry_block(&'a self) -> BlockAndBuilder<'a, 'tcx> {
         BlockAndBuilder::new(unsafe {
             llvm::LLVMGetFirstBasicBlock(self.llfn)
         }, self)
diff --git a/src/librustc_trans/glue.rs b/src/librustc_trans/glue.rs
index 8ad951c5ade..1f58327555e 100644
--- a/src/librustc_trans/glue.rs
+++ b/src/librustc_trans/glue.rs
@@ -202,9 +202,8 @@ pub fn implement_drop_glue<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
     assert_eq!(g.ty(), get_drop_glue_type(tcx, g.ty()));
     let (llfn, fn_ty) = ccx.drop_glues().borrow().get(&g).unwrap().clone();
 
-    let fcx = FunctionContext::new(ccx, llfn, fn_ty, None);
-
-    let bcx = fcx.init(false);
+    let fcx = FunctionContext::new(ccx, llfn, fn_ty, None, false);
+    let bcx = fcx.get_entry_block();
 
     ccx.stats().n_glues_created.set(ccx.stats().n_glues_created.get() + 1);
     // All glue functions take values passed *by alias*; this is a
diff --git a/src/librustc_trans/intrinsic.rs b/src/librustc_trans/intrinsic.rs
index 716cbec718e..ec6b908c264 100644
--- a/src/librustc_trans/intrinsic.rs
+++ b/src/librustc_trans/intrinsic.rs
@@ -965,8 +965,8 @@ fn gen_fn<'a, 'tcx>(fcx: &FunctionContext<'a, 'tcx>,
         sig: ty::Binder(sig)
     }));
     let llfn = declare::define_internal_fn(ccx, name, rust_fn_ty);
-    let fcx = FunctionContext::new(ccx, llfn, fn_ty, None);
-    trans(fcx.init(true));
+    let fcx = FunctionContext::new(ccx, llfn, fn_ty, None, true);
+    trans(fcx.get_entry_block());
     llfn
 }
 
diff --git a/src/librustc_trans/meth.rs b/src/librustc_trans/meth.rs
index 82c1fa94a4e..99330c12537 100644
--- a/src/librustc_trans/meth.rs
+++ b/src/librustc_trans/meth.rs
@@ -81,12 +81,12 @@ pub fn trans_object_shim<'a, 'tcx>(ccx: &'a CrateContext<'a, 'tcx>,
     let llfn = declare::define_internal_fn(ccx, &function_name, callee.ty);
     attributes::set_frame_pointer_elimination(ccx, llfn);
 
-    let fcx = FunctionContext::new(ccx, llfn, fn_ty, None);
-    let mut bcx = fcx.init(false);
+    let fcx = FunctionContext::new(ccx, llfn, fn_ty, None, false);
+    let mut bcx = fcx.get_entry_block();
 
-    let dest = fcx.llretslotptr.get();
     let llargs = get_params(fcx.llfn);
-    bcx = callee.call(bcx, &llargs[fcx.fn_ty.ret.is_indirect() as usize..], dest, None).0;
+    bcx = callee.call(bcx, &llargs[fcx.fn_ty.ret.is_indirect() as usize..], fcx.llretslotptr,
+        None).0;
 
     fcx.finish(&bcx);
 
diff --git a/src/librustc_trans/mir/mod.rs b/src/librustc_trans/mir/mod.rs
index 6c72791ec0f..f02a8f725f7 100644
--- a/src/librustc_trans/mir/mod.rs
+++ b/src/librustc_trans/mir/mod.rs
@@ -180,7 +180,7 @@ impl<'tcx> LocalRef<'tcx> {
 ///////////////////////////////////////////////////////////////////////////
 
 pub fn trans_mir<'blk, 'tcx: 'blk>(fcx: &'blk FunctionContext<'blk, 'tcx>) {
-    let bcx = fcx.init(true);
+    let bcx = fcx.get_entry_block();
     let mir = fcx.mir();
 
     // Analyze the temps to determine which must be lvalues