about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorbjorn3 <bjorn3@users.noreply.github.com>2019-09-11 11:01:04 +0200
committerGitHub <noreply@github.com>2019-09-11 11:01:04 +0200
commit71482b5ca6913a13bd017bb08f3ffb89f4c3ed9c (patch)
treeb7ece1432d4a40de18151ba0e547e389a09f82b9 /src
parentb0e5c78ad2c4e0b7fba996e77972268c5a33a011 (diff)
parent3a8dd34831904825ffaba50c1cbbf6343cb2059b (diff)
downloadrust-71482b5ca6913a13bd017bb08f3ffb89f4c3ed9c.tar.gz
rust-71482b5ca6913a13bd017bb08f3ffb89f4c3ed9c.zip
Merge pull request #700 from bjorn3/upstream_cranelift
Use upstream cranelift
Diffstat (limited to 'src')
-rw-r--r--src/allocator.rs11
-rw-r--r--src/base.rs12
-rw-r--r--src/codegen_i128.rs2
-rw-r--r--src/common.rs2
-rw-r--r--src/main_shim.rs13
-rw-r--r--src/trap.rs2
6 files changed, 20 insertions, 22 deletions
diff --git a/src/allocator.rs b/src/allocator.rs
index b3b2b53444d..d4a1f1a49fa 100644
--- a/src/allocator.rs
+++ b/src/allocator.rs
@@ -73,10 +73,8 @@ pub fn codegen_inner(module: &mut Module<impl Backend + 'static>, kind: Allocato
             .unwrap();
 
         let mut ctx = Context::new();
-        ctx.func = Function::with_name_signature(ExternalName::user(0, 0), sig.clone());
-        {
-            let mut func_ctx = FunctionBuilderContext::new();
-            let mut bcx = FunctionBuilder::new(&mut ctx.func, &mut func_ctx);
+        ctx.func = {
+            let mut bcx = FunctionBuilder::new(Function::with_name_signature(ExternalName::user(0, 0), sig.clone()));
 
             let ebb = bcx.create_ebb();
             bcx.switch_to_block(ebb);
@@ -92,8 +90,9 @@ pub fn codegen_inner(module: &mut Module<impl Backend + 'static>, kind: Allocato
             let results = bcx.inst_results(call_inst).to_vec(); // Clone to prevent borrow error
             bcx.ins().return_(&results);
             bcx.seal_all_blocks();
-            bcx.finalize();
-        }
+            bcx.finalize()
+        };
+
         module.define_function(func_id, &mut ctx).unwrap();
     }
 }
diff --git a/src/base.rs b/src/base.rs
index 68ca6cffbef..81735ef7a62 100644
--- a/src/base.rs
+++ b/src/base.rs
@@ -19,10 +19,8 @@ pub fn trans_fn<'clif, 'tcx, B: Backend + 'static>(
         .as_mut()
         .map(|debug_context| FunctionDebugContext::new(tcx, debug_context, mir, &name, &sig));
 
-    // Make FunctionBuilder
-    let mut func = Function::with_name_signature(ExternalName::user(0, 0), sig);
-    let mut func_ctx = FunctionBuilderContext::new();
-    let mut bcx = FunctionBuilder::new(&mut func, &mut func_ctx);
+    // FIXME reuse Function and FunctionBuilder between multiple trans_fn calls
+    let mut bcx = FunctionBuilder::new(Function::with_name_signature(ExternalName::user(0, 0), sig));
 
     // Predefine ebb's
     let start_ebb = bcx.create_ebb();
@@ -58,6 +56,9 @@ pub fn trans_fn<'clif, 'tcx, B: Backend + 'static>(
         codegen_fn_content(&mut fx);
     });
 
+    fx.bcx.seal_all_blocks();
+    let func = fx.bcx.finalize();
+
     // Recover all necessary data from fx, before accessing func will prevent future access to it.
     let instance = fx.instance;
     let clif_comments = fx.clif_comments;
@@ -238,9 +239,6 @@ fn codegen_fn_content(fx: &mut FunctionCx<'_, '_, impl Backend>) {
             }
         };
     }
-
-    fx.bcx.seal_all_blocks();
-    fx.bcx.finalize();
 }
 
 fn trans_stmt<'tcx>(
diff --git a/src/codegen_i128.rs b/src/codegen_i128.rs
index 6653b4e2d91..2d2aa7e1a1d 100644
--- a/src/codegen_i128.rs
+++ b/src/codegen_i128.rs
@@ -98,7 +98,7 @@ pub fn maybe_codegen<'tcx>(
             // Optimize `val >> 64`, because compiler_builtins uses it to deconstruct an 128bit
             // integer into its lsb and msb.
             // https://github.com/rust-lang-nursery/compiler-builtins/blob/79a6a1603d5672cbb9187ff41ff4d9b5048ac1cb/src/int/mod.rs#L217
-            if let Some(64) = resolve_value_imm(fx.bcx.func, rhs_val) {
+            if let Some(64) = resolve_value_imm(&fx.bcx.func, rhs_val) {
                 let (lhs_lsb, lhs_msb) = fx.bcx.ins().isplit(lhs_val);
                 let all_zeros = fx.bcx.ins().iconst(types::I64, 0);
                 let val = match (bin_op, is_signed) {
diff --git a/src/common.rs b/src/common.rs
index 67af9506b79..fbb60713bd0 100644
--- a/src/common.rs
+++ b/src/common.rs
@@ -269,7 +269,7 @@ pub struct FunctionCx<'clif, 'tcx, B: Backend + 'static> {
     pub instance: Instance<'tcx>,
     pub mir: &'tcx Body<'tcx>,
 
-    pub bcx: FunctionBuilder<'clif>,
+    pub bcx: FunctionBuilder,
     pub ebb_map: HashMap<BasicBlock, Ebb>,
     pub local_map: HashMap<Local, CPlace<'tcx>>,
 
diff --git a/src/main_shim.rs b/src/main_shim.rs
index b619cb9b0ad..ae2e16690b7 100644
--- a/src/main_shim.rs
+++ b/src/main_shim.rs
@@ -56,10 +56,10 @@ pub fn maybe_create_entry_wrapper(tcx: TyCtxt<'_>, module: &mut Module<impl Back
             .unwrap();
 
         let mut ctx = Context::new();
-        ctx.func = Function::with_name_signature(ExternalName::user(0, 0), cmain_sig.clone());
-        {
-            let mut func_ctx = FunctionBuilderContext::new();
-            let mut bcx: FunctionBuilder = FunctionBuilder::new(&mut ctx.func, &mut func_ctx);
+        ctx.func = {
+            let mut bcx: FunctionBuilder = FunctionBuilder::new(
+                Function::with_name_signature(ExternalName::user(0, 0), cmain_sig.clone())
+            );
 
             let ebb = bcx.create_ebb();
             bcx.switch_to_block(ebb);
@@ -93,8 +93,9 @@ pub fn maybe_create_entry_wrapper(tcx: TyCtxt<'_>, module: &mut Module<impl Back
             let result = bcx.inst_results(call_inst)[0];
             bcx.ins().return_(&[result]);
             bcx.seal_all_blocks();
-            bcx.finalize();
-        }
+            bcx.finalize()
+        };
+
         m.define_function(cmain_func_id, &mut ctx).unwrap();
     }
 }
diff --git a/src/trap.rs b/src/trap.rs
index 7309332a157..849c5325109 100644
--- a/src/trap.rs
+++ b/src/trap.rs
@@ -36,7 +36,7 @@ fn codegen_print(fx: &mut FunctionCx<'_, '_, impl cranelift_module::Backend>, ms
     // Ignore DuplicateDefinition error, as the data will be the same
     let _ = fx.module.define_data(msg_id, &data_ctx);
 
-    let local_msg_id = fx.module.declare_data_in_func(msg_id, fx.bcx.func);
+    let local_msg_id = fx.module.declare_data_in_func(msg_id, &mut fx.bcx.func);
     #[cfg(debug_assertions)]
     {
         fx.add_entity_comment(local_msg_id, msg);