about summary refs log tree commit diff
path: root/compiler/rustc_codegen_cranelift/src
diff options
context:
space:
mode:
authorbjorn3 <bjorn3@users.noreply.github.com>2020-11-03 11:00:04 +0100
committerbjorn3 <bjorn3@users.noreply.github.com>2020-11-03 11:00:04 +0100
commit216c4ae46352330bc7962f132fe226a7e73ab8fa (patch)
treec1d7af49fa1f27f325f090cff3f2d8861972fec9 /compiler/rustc_codegen_cranelift/src
parenta6403b0f04b58a35cb9f3e544b2847ee09bcf3a4 (diff)
parent03f01bbe901d60b71cf2c5ec766aef5e532ab79d (diff)
downloadrust-216c4ae46352330bc7962f132fe226a7e73ab8fa.tar.gz
rust-216c4ae46352330bc7962f132fe226a7e73ab8fa.zip
Merge commit '03f01bbe901d60b71cf2c5ec766aef5e532ab79d' into update_cg_clif-2020-11-01
Diffstat (limited to 'compiler/rustc_codegen_cranelift/src')
-rw-r--r--compiler/rustc_codegen_cranelift/src/abi/comments.rs12
-rw-r--r--compiler/rustc_codegen_cranelift/src/abi/mod.rs63
-rw-r--r--compiler/rustc_codegen_cranelift/src/allocator.rs4
-rw-r--r--compiler/rustc_codegen_cranelift/src/archive.rs2
-rw-r--r--compiler/rustc_codegen_cranelift/src/atomic_shim.rs2
-rw-r--r--compiler/rustc_codegen_cranelift/src/backend.rs12
-rw-r--r--compiler/rustc_codegen_cranelift/src/base.rs84
-rw-r--r--compiler/rustc_codegen_cranelift/src/bin/cg_clif.rs20
-rw-r--r--compiler/rustc_codegen_cranelift/src/bin/cg_clif_build_sysroot.rs3
-rw-r--r--compiler/rustc_codegen_cranelift/src/cast.rs8
-rw-r--r--compiler/rustc_codegen_cranelift/src/codegen_i128.rs8
-rw-r--r--compiler/rustc_codegen_cranelift/src/common.rs2
-rw-r--r--compiler/rustc_codegen_cranelift/src/constant.rs26
-rw-r--r--compiler/rustc_codegen_cranelift/src/debuginfo/emit.rs4
-rw-r--r--compiler/rustc_codegen_cranelift/src/debuginfo/line_info.rs4
-rw-r--r--compiler/rustc_codegen_cranelift/src/debuginfo/unwind.rs1
-rw-r--r--compiler/rustc_codegen_cranelift/src/driver/jit.rs4
-rw-r--r--compiler/rustc_codegen_cranelift/src/driver/mod.rs6
-rw-r--r--compiler/rustc_codegen_cranelift/src/inline_asm.rs8
-rw-r--r--compiler/rustc_codegen_cranelift/src/intrinsics/llvm.rs6
-rw-r--r--compiler/rustc_codegen_cranelift/src/intrinsics/mod.rs35
-rw-r--r--compiler/rustc_codegen_cranelift/src/intrinsics/simd.rs4
-rw-r--r--compiler/rustc_codegen_cranelift/src/lib.rs3
-rw-r--r--compiler/rustc_codegen_cranelift/src/linkage.rs8
-rw-r--r--compiler/rustc_codegen_cranelift/src/main_shim.rs2
-rw-r--r--compiler/rustc_codegen_cranelift/src/metadata.rs4
-rw-r--r--compiler/rustc_codegen_cranelift/src/num.rs18
-rw-r--r--compiler/rustc_codegen_cranelift/src/optimize/stack2reg.rs3
-rw-r--r--compiler/rustc_codegen_cranelift/src/pretty_clif.rs8
-rw-r--r--compiler/rustc_codegen_cranelift/src/trap.rs1
-rw-r--r--compiler/rustc_codegen_cranelift/src/value_and_place.rs39
-rw-r--r--compiler/rustc_codegen_cranelift/src/vtable.rs16
32 files changed, 205 insertions, 215 deletions
diff --git a/compiler/rustc_codegen_cranelift/src/abi/comments.rs b/compiler/rustc_codegen_cranelift/src/abi/comments.rs
index 7bb00c8d46a..01073d26e83 100644
--- a/compiler/rustc_codegen_cranelift/src/abi/comments.rs
+++ b/compiler/rustc_codegen_cranelift/src/abi/comments.rs
@@ -11,9 +11,9 @@ use crate::abi::pass_mode::*;
 use crate::prelude::*;
 
 pub(super) fn add_args_header_comment(fx: &mut FunctionCx<'_, '_, impl Module>) {
-    fx.add_global_comment(format!(
-        "kind  loc.idx   param    pass mode                            ty"
-    ));
+    fx.add_global_comment(
+        "kind  loc.idx   param    pass mode                            ty".to_string(),
+    );
 }
 
 pub(super) fn add_arg_comment<'tcx>(
@@ -56,9 +56,9 @@ pub(super) fn add_arg_comment<'tcx>(
 
 pub(super) fn add_locals_header_comment(fx: &mut FunctionCx<'_, '_, impl Module>) {
     fx.add_global_comment(String::new());
-    fx.add_global_comment(format!(
-        "kind  local ty                              size align (abi,pref)"
-    ));
+    fx.add_global_comment(
+        "kind  local ty                              size align (abi,pref)".to_string(),
+    );
 }
 
 pub(super) fn add_local_place_comments<'tcx>(
diff --git a/compiler/rustc_codegen_cranelift/src/abi/mod.rs b/compiler/rustc_codegen_cranelift/src/abi/mod.rs
index 80169122843..81091728692 100644
--- a/compiler/rustc_codegen_cranelift/src/abi/mod.rs
+++ b/compiler/rustc_codegen_cranelift/src/abi/mod.rs
@@ -300,7 +300,7 @@ impl<'tcx, M: Module> FunctionCx<'_, 'tcx, M> {
         return_ty: Ty<'tcx>,
     ) -> CValue<'tcx> {
         let (input_tys, args): (Vec<_>, Vec<_>) = args
-            .into_iter()
+            .iter()
             .map(|arg| {
                 (
                     self.clif_type(arg.layout().ty).unwrap(),
@@ -421,34 +421,31 @@ pub(crate) fn codegen_fn_prelude<'tcx>(
 
         // While this is normally an optimization to prevent an unnecessary copy when an argument is
         // not mutated by the current function, this is necessary to support unsized arguments.
-        match arg_kind {
-            ArgKind::Normal(Some(val)) => {
-                if let Some((addr, meta)) = val.try_to_ptr() {
-                    let local_decl = &fx.mir.local_decls[local];
-                    //                       v this ! is important
-                    let internally_mutable = !val.layout().ty.is_freeze(
-                        fx.tcx.at(local_decl.source_info.span),
-                        ParamEnv::reveal_all(),
-                    );
-                    if local_decl.mutability == mir::Mutability::Not && !internally_mutable {
-                        // We wont mutate this argument, so it is fine to borrow the backing storage
-                        // of this argument, to prevent a copy.
-
-                        let place = if let Some(meta) = meta {
-                            CPlace::for_ptr_with_extra(addr, meta, val.layout())
-                        } else {
-                            CPlace::for_ptr(addr, val.layout())
-                        };
-
-                        #[cfg(debug_assertions)]
-                        self::comments::add_local_place_comments(fx, place, local);
-
-                        assert_eq!(fx.local_map.push(place), local);
-                        continue;
-                    }
+        if let ArgKind::Normal(Some(val)) = arg_kind {
+            if let Some((addr, meta)) = val.try_to_ptr() {
+                let local_decl = &fx.mir.local_decls[local];
+                //                       v this ! is important
+                let internally_mutable = !val.layout().ty.is_freeze(
+                    fx.tcx.at(local_decl.source_info.span),
+                    ParamEnv::reveal_all(),
+                );
+                if local_decl.mutability == mir::Mutability::Not && !internally_mutable {
+                    // We wont mutate this argument, so it is fine to borrow the backing storage
+                    // of this argument, to prevent a copy.
+
+                    let place = if let Some(meta) = meta {
+                        CPlace::for_ptr_with_extra(addr, meta, val.layout())
+                    } else {
+                        CPlace::for_ptr(addr, val.layout())
+                    };
+
+                    #[cfg(debug_assertions)]
+                    self::comments::add_local_place_comments(fx, place, local);
+
+                    assert_eq!(fx.local_map.push(place), local);
+                    continue;
                 }
             }
-            _ => {}
         }
 
         let place = make_local_place(fx, local, layout, is_ssa);
@@ -500,7 +497,7 @@ pub(crate) fn codegen_terminator_call<'tcx>(
         .tcx
         .normalize_erasing_late_bound_regions(ParamEnv::reveal_all(), &fn_ty.fn_sig(fx.tcx));
 
-    let destination = destination.map(|(place, bb)| (trans_place(fx, place), bb));
+    let destination = destination.map(|(place, bb)| (codegen_place(fx, place), bb));
 
     // Handle special calls like instrinsics and empty drop glue.
     let instance = if let ty::FnDef(def_id, substs) = *fn_ty.kind() {
@@ -553,8 +550,8 @@ pub(crate) fn codegen_terminator_call<'tcx>(
     // Unpack arguments tuple for closures
     let args = if fn_sig.abi == Abi::RustCall {
         assert_eq!(args.len(), 2, "rust-call abi requires two arguments");
-        let self_arg = trans_operand(fx, &args[0]);
-        let pack_arg = trans_operand(fx, &args[1]);
+        let self_arg = codegen_operand(fx, &args[0]);
+        let pack_arg = codegen_operand(fx, &args[1]);
 
         let tupled_arguments = match pack_arg.layout().ty.kind() {
             ty::Tuple(ref tupled_arguments) => tupled_arguments,
@@ -568,8 +565,8 @@ pub(crate) fn codegen_terminator_call<'tcx>(
         }
         args
     } else {
-        args.into_iter()
-            .map(|arg| trans_operand(fx, arg))
+        args.iter()
+            .map(|arg| codegen_operand(fx, arg))
             .collect::<Vec<_>>()
     };
 
@@ -613,7 +610,7 @@ pub(crate) fn codegen_terminator_call<'tcx>(
                 let nop_inst = fx.bcx.ins().nop();
                 fx.add_comment(nop_inst, "indirect call");
             }
-            let func = trans_operand(fx, func).load_scalar(fx);
+            let func = codegen_operand(fx, func).load_scalar(fx);
             (
                 Some(func),
                 args.get(0)
diff --git a/compiler/rustc_codegen_cranelift/src/allocator.rs b/compiler/rustc_codegen_cranelift/src/allocator.rs
index 0735ad6f832..6c5916550ff 100644
--- a/compiler/rustc_codegen_cranelift/src/allocator.rs
+++ b/compiler/rustc_codegen_cranelift/src/allocator.rs
@@ -123,7 +123,7 @@ fn codegen_inner(
         .unwrap();
 
     let mut ctx = Context::new();
-    ctx.func = Function::with_name_signature(ExternalName::user(0, 0), sig.clone());
+    ctx.func = Function::with_name_signature(ExternalName::user(0, 0), sig);
     {
         let mut func_ctx = FunctionBuilderContext::new();
         let mut bcx = FunctionBuilder::new(&mut ctx.func, &mut func_ctx);
@@ -131,7 +131,7 @@ fn codegen_inner(
         let block = bcx.create_block();
         bcx.switch_to_block(block);
         let args = (&[usize_ty, usize_ty])
-            .into_iter()
+            .iter()
             .map(|&ty| bcx.append_block_param(block, ty))
             .collect::<Vec<Value>>();
 
diff --git a/compiler/rustc_codegen_cranelift/src/archive.rs b/compiler/rustc_codegen_cranelift/src/archive.rs
index 6382f8df344..9a970efbcfd 100644
--- a/compiler/rustc_codegen_cranelift/src/archive.rs
+++ b/compiler/rustc_codegen_cranelift/src/archive.rs
@@ -132,7 +132,7 @@ impl<'a> ArchiveBuilder<'a> for ArArchiveBuilder<'a> {
             }
 
             // ok, don't skip this
-            return false;
+            false
         })
     }
 
diff --git a/compiler/rustc_codegen_cranelift/src/atomic_shim.rs b/compiler/rustc_codegen_cranelift/src/atomic_shim.rs
index 92281fdacc9..2f0157c257b 100644
--- a/compiler/rustc_codegen_cranelift/src/atomic_shim.rs
+++ b/compiler/rustc_codegen_cranelift/src/atomic_shim.rs
@@ -7,7 +7,7 @@ use crate::prelude::*;
 
 #[cfg(all(feature = "jit", unix))]
 #[no_mangle]
-pub static mut __cg_clif_global_atomic_mutex: libc::pthread_mutex_t =
+static mut __cg_clif_global_atomic_mutex: libc::pthread_mutex_t =
     libc::PTHREAD_MUTEX_INITIALIZER;
 
 pub(crate) fn init_global_lock(
diff --git a/compiler/rustc_codegen_cranelift/src/backend.rs b/compiler/rustc_codegen_cranelift/src/backend.rs
index 8b900fd0dd0..9e32259716f 100644
--- a/compiler/rustc_codegen_cranelift/src/backend.rs
+++ b/compiler/rustc_codegen_cranelift/src/backend.rs
@@ -73,7 +73,7 @@ impl WriteDebugInfo for ObjectProduct {
         // FIXME use SHT_X86_64_UNWIND for .eh_frame
         let section_id = self.object.add_section(
             segment,
-            name.clone(),
+            name,
             if id == SectionId::EhFrame {
                 SectionKind::ReadOnlyData
             } else {
@@ -198,9 +198,9 @@ pub(crate) fn make_module(sess: &Session, name: String) -> ObjectModule {
         cranelift_module::default_libcall_names(),
     )
     .unwrap();
-    if std::env::var("CG_CLIF_FUNCTION_SECTIONS").is_ok() {
-        builder.per_function_section(true);
-    }
-    let module = ObjectModule::new(builder);
-    module
+    // Unlike cg_llvm, cg_clif defaults to disabling -Zfunction-sections. For cg_llvm binary size
+    // is important, while cg_clif cares more about compilation times. Enabling -Zfunction-sections
+    // can easily double the amount of time necessary to perform linking.
+    builder.per_function_section(sess.opts.debugging_opts.function_sections.unwrap_or(false));
+    ObjectModule::new(builder)
 }
diff --git a/compiler/rustc_codegen_cranelift/src/base.rs b/compiler/rustc_codegen_cranelift/src/base.rs
index fa9b8853d39..5474e5960f1 100644
--- a/compiler/rustc_codegen_cranelift/src/base.rs
+++ b/compiler/rustc_codegen_cranelift/src/base.rs
@@ -5,7 +5,7 @@ use rustc_middle::ty::adjustment::PointerCast;
 
 use crate::prelude::*;
 
-pub(crate) fn trans_fn<'tcx>(
+pub(crate) fn codegen_fn<'tcx>(
     cx: &mut crate::CodegenCx<'tcx, impl Module>,
     instance: Instance<'tcx>,
     linkage: Linkage,
@@ -202,7 +202,7 @@ fn codegen_fn_content(fx: &mut FunctionCx<'_, '_, impl Module>) {
         fx.bcx.ins().nop();
         for stmt in &bb_data.statements {
             fx.set_debug_loc(stmt.source_info);
-            trans_stmt(fx, block, stmt);
+            codegen_stmt(fx, block, stmt);
         }
 
         #[cfg(debug_assertions)]
@@ -258,7 +258,7 @@ fn codegen_fn_content(fx: &mut FunctionCx<'_, '_, impl Module>) {
                         continue;
                     }
                 }
-                let cond = trans_operand(fx, cond).load_scalar(fx);
+                let cond = codegen_operand(fx, cond).load_scalar(fx);
 
                 let target = fx.get_block(*target);
                 let failure = fx.bcx.create_block();
@@ -276,8 +276,8 @@ fn codegen_fn_content(fx: &mut FunctionCx<'_, '_, impl Module>) {
 
                 match msg {
                     AssertKind::BoundsCheck { ref len, ref index } => {
-                        let len = trans_operand(fx, len).load_scalar(fx);
-                        let index = trans_operand(fx, index).load_scalar(fx);
+                        let len = codegen_operand(fx, len).load_scalar(fx);
+                        let index = codegen_operand(fx, index).load_scalar(fx);
                         let location = fx
                             .get_caller_location(bb_data.terminator().source_info.span)
                             .load_scalar(fx);
@@ -301,7 +301,7 @@ fn codegen_fn_content(fx: &mut FunctionCx<'_, '_, impl Module>) {
                 switch_ty,
                 targets,
             } => {
-                let discr = trans_operand(fx, discr).load_scalar(fx);
+                let discr = codegen_operand(fx, discr).load_scalar(fx);
 
                 if switch_ty.kind() == fx.tcx.types.bool.kind() {
                     assert_eq!(targets.iter().count(), 1);
@@ -396,14 +396,14 @@ fn codegen_fn_content(fx: &mut FunctionCx<'_, '_, impl Module>) {
             | TerminatorKind::FalseUnwind { .. }
             | TerminatorKind::DropAndReplace { .. }
             | TerminatorKind::GeneratorDrop => {
-                bug!("shouldn't exist at trans {:?}", bb_data.terminator());
+                bug!("shouldn't exist at codegen {:?}", bb_data.terminator());
             }
             TerminatorKind::Drop {
                 place,
                 target,
                 unwind: _,
             } => {
-                let drop_place = trans_place(fx, *place);
+                let drop_place = codegen_place(fx, *place);
                 crate::abi::codegen_drop(fx, bb_data.terminator().source_info.span, drop_place);
 
                 let target_block = fx.get_block(*target);
@@ -416,7 +416,7 @@ fn codegen_fn_content(fx: &mut FunctionCx<'_, '_, impl Module>) {
     fx.bcx.finalize();
 }
 
-fn trans_stmt<'tcx>(
+fn codegen_stmt<'tcx>(
     fx: &mut FunctionCx<'_, 'tcx, impl Module>,
     #[allow(unused_variables)] cur_block: Block,
     stmt: &Statement<'tcx>,
@@ -439,19 +439,19 @@ fn trans_stmt<'tcx>(
             place,
             variant_index,
         } => {
-            let place = trans_place(fx, **place);
+            let place = codegen_place(fx, **place);
             crate::discriminant::codegen_set_discriminant(fx, place, *variant_index);
         }
         StatementKind::Assign(to_place_and_rval) => {
-            let lval = trans_place(fx, to_place_and_rval.0);
+            let lval = codegen_place(fx, to_place_and_rval.0);
             let dest_layout = lval.layout();
             match &to_place_and_rval.1 {
                 Rvalue::Use(operand) => {
-                    let val = trans_operand(fx, operand);
+                    let val = codegen_operand(fx, operand);
                     lval.write_cvalue(fx, val);
                 }
                 Rvalue::Ref(_, _, place) | Rvalue::AddressOf(_, place) => {
-                    let place = trans_place(fx, *place);
+                    let place = codegen_place(fx, *place);
                     let ref_ = place.place_ref(fx, lval.layout());
                     lval.write_cvalue(fx, ref_);
                 }
@@ -460,29 +460,29 @@ fn trans_stmt<'tcx>(
                     lval.write_cvalue(fx, val);
                 }
                 Rvalue::BinaryOp(bin_op, lhs, rhs) => {
-                    let lhs = trans_operand(fx, lhs);
-                    let rhs = trans_operand(fx, rhs);
+                    let lhs = codegen_operand(fx, lhs);
+                    let rhs = codegen_operand(fx, rhs);
 
                     let res = crate::num::codegen_binop(fx, *bin_op, lhs, rhs);
                     lval.write_cvalue(fx, res);
                 }
                 Rvalue::CheckedBinaryOp(bin_op, lhs, rhs) => {
-                    let lhs = trans_operand(fx, lhs);
-                    let rhs = trans_operand(fx, rhs);
+                    let lhs = codegen_operand(fx, lhs);
+                    let rhs = codegen_operand(fx, rhs);
 
                     let res = if !fx.tcx.sess.overflow_checks() {
                         let val =
-                            crate::num::trans_int_binop(fx, *bin_op, lhs, rhs).load_scalar(fx);
+                            crate::num::codegen_int_binop(fx, *bin_op, lhs, rhs).load_scalar(fx);
                         let is_overflow = fx.bcx.ins().iconst(types::I8, 0);
                         CValue::by_val_pair(val, is_overflow, lval.layout())
                     } else {
-                        crate::num::trans_checked_int_binop(fx, *bin_op, lhs, rhs)
+                        crate::num::codegen_checked_int_binop(fx, *bin_op, lhs, rhs)
                     };
 
                     lval.write_cvalue(fx, res);
                 }
                 Rvalue::UnaryOp(un_op, operand) => {
-                    let operand = trans_operand(fx, operand);
+                    let operand = codegen_operand(fx, operand);
                     let layout = operand.layout();
                     let val = operand.load_scalar(fx);
                     let res = match un_op {
@@ -500,7 +500,7 @@ fn trans_stmt<'tcx>(
                             ty::Int(IntTy::I128) => {
                                 // FIXME remove this case once ineg.i128 works
                                 let zero = CValue::const_val(fx, layout, 0);
-                                crate::num::trans_int_binop(fx, BinOp::Sub, zero, operand)
+                                crate::num::codegen_int_binop(fx, BinOp::Sub, zero, operand)
                             }
                             ty::Int(_) => CValue::by_val(fx.bcx.ins().ineg(val), layout),
                             ty::Float(_) => CValue::by_val(fx.bcx.ins().fneg(val), layout),
@@ -534,11 +534,11 @@ fn trans_stmt<'tcx>(
                 | Rvalue::Cast(CastKind::Pointer(PointerCast::MutToConstPointer), operand, to_ty)
                 | Rvalue::Cast(CastKind::Pointer(PointerCast::ArrayToPointer), operand, to_ty) => {
                     let to_layout = fx.layout_of(fx.monomorphize(to_ty));
-                    let operand = trans_operand(fx, operand);
+                    let operand = codegen_operand(fx, operand);
                     lval.write_cvalue(fx, operand.cast_pointer_to(to_layout));
                 }
                 Rvalue::Cast(CastKind::Misc, operand, to_ty) => {
-                    let operand = trans_operand(fx, operand);
+                    let operand = codegen_operand(fx, operand);
                     let from_ty = operand.layout().ty;
                     let to_ty = fx.monomorphize(to_ty);
 
@@ -639,7 +639,7 @@ fn trans_stmt<'tcx>(
                     operand,
                     _to_ty,
                 ) => {
-                    let operand = trans_operand(fx, operand);
+                    let operand = codegen_operand(fx, operand);
                     match *operand.layout().ty.kind() {
                         ty::Closure(def_id, substs) => {
                             let instance = Instance::resolve_closure(
@@ -657,18 +657,18 @@ fn trans_stmt<'tcx>(
                     }
                 }
                 Rvalue::Cast(CastKind::Pointer(PointerCast::Unsize), operand, _to_ty) => {
-                    let operand = trans_operand(fx, operand);
+                    let operand = codegen_operand(fx, operand);
                     operand.unsize_value(fx, lval);
                 }
                 Rvalue::Discriminant(place) => {
-                    let place = trans_place(fx, *place);
+                    let place = codegen_place(fx, *place);
                     let value = place.to_cvalue(fx);
                     let discr =
                         crate::discriminant::codegen_get_discriminant(fx, value, dest_layout);
                     lval.write_cvalue(fx, discr);
                 }
                 Rvalue::Repeat(operand, times) => {
-                    let operand = trans_operand(fx, operand);
+                    let operand = codegen_operand(fx, operand);
                     let times = fx
                         .monomorphize(times)
                         .eval(fx.tcx, ParamEnv::reveal_all())
@@ -706,7 +706,7 @@ fn trans_stmt<'tcx>(
                     }
                 }
                 Rvalue::Len(place) => {
-                    let place = trans_place(fx, *place);
+                    let place = codegen_place(fx, *place);
                     let usize_layout = fx.layout_of(fx.tcx.types.usize);
                     let len = codegen_array_len(fx, place);
                     lval.write_cvalue(fx, CValue::by_val(len, usize_layout));
@@ -753,14 +753,14 @@ fn trans_stmt<'tcx>(
                 }
                 Rvalue::Aggregate(kind, operands) => match **kind {
                     AggregateKind::Array(_ty) => {
-                        for (i, operand) in operands.into_iter().enumerate() {
-                            let operand = trans_operand(fx, operand);
+                        for (i, operand) in operands.iter().enumerate() {
+                            let operand = codegen_operand(fx, operand);
                             let index = fx.bcx.ins().iconst(fx.pointer_type, i as i64);
                             let to = lval.place_index(fx, index);
                             to.write_cvalue(fx, operand);
                         }
                     }
-                    _ => unreachable!("shouldn't exist at trans {:?}", to_place_and_rval.1),
+                    _ => unreachable!("shouldn't exist at codegen {:?}", to_place_and_rval.1),
                 },
             }
         }
@@ -813,20 +813,20 @@ fn trans_stmt<'tcx>(
                     assert!(!alignstack);
 
                     assert_eq!(inputs.len(), 2);
-                    let leaf = trans_operand(fx, &inputs[0].1).load_scalar(fx); // %eax
-                    let subleaf = trans_operand(fx, &inputs[1].1).load_scalar(fx); // %ecx
+                    let leaf = codegen_operand(fx, &inputs[0].1).load_scalar(fx); // %eax
+                    let subleaf = codegen_operand(fx, &inputs[1].1).load_scalar(fx); // %ecx
 
                     let (eax, ebx, ecx, edx) =
                         crate::intrinsics::codegen_cpuid_call(fx, leaf, subleaf);
 
                     assert_eq!(outputs.len(), 4);
-                    trans_place(fx, outputs[0])
+                    codegen_place(fx, outputs[0])
                         .write_cvalue(fx, CValue::by_val(eax, fx.layout_of(fx.tcx.types.u32)));
-                    trans_place(fx, outputs[1])
+                    codegen_place(fx, outputs[1])
                         .write_cvalue(fx, CValue::by_val(ebx, fx.layout_of(fx.tcx.types.u32)));
-                    trans_place(fx, outputs[2])
+                    codegen_place(fx, outputs[2])
                         .write_cvalue(fx, CValue::by_val(ecx, fx.layout_of(fx.tcx.types.u32)));
-                    trans_place(fx, outputs[3])
+                    codegen_place(fx, outputs[3])
                         .write_cvalue(fx, CValue::by_val(edx, fx.layout_of(fx.tcx.types.u32)));
                 }
                 "xgetbv" => {
@@ -892,7 +892,7 @@ fn codegen_array_len<'tcx>(
     }
 }
 
-pub(crate) fn trans_place<'tcx>(
+pub(crate) fn codegen_place<'tcx>(
     fx: &mut FunctionCx<'_, 'tcx, impl Module>,
     place: Place<'tcx>,
 ) -> CPlace<'tcx> {
@@ -938,7 +938,7 @@ pub(crate) fn trans_place<'tcx>(
                         let ptr = cplace.to_ptr();
                         cplace = CPlace::for_ptr(
                             ptr.offset_i64(fx, elem_layout.size.bytes() as i64 * (from as i64)),
-                            fx.layout_of(fx.tcx.mk_array(elem_ty, u64::from(to) - u64::from(from))),
+                            fx.layout_of(fx.tcx.mk_array(elem_ty, to - from)),
                         );
                     }
                     ty::Slice(elem_ty) => {
@@ -964,16 +964,16 @@ pub(crate) fn trans_place<'tcx>(
     cplace
 }
 
-pub(crate) fn trans_operand<'tcx>(
+pub(crate) fn codegen_operand<'tcx>(
     fx: &mut FunctionCx<'_, 'tcx, impl Module>,
     operand: &Operand<'tcx>,
 ) -> CValue<'tcx> {
     match operand {
         Operand::Move(place) | Operand::Copy(place) => {
-            let cplace = trans_place(fx, *place);
+            let cplace = codegen_place(fx, *place);
             cplace.to_cvalue(fx)
         }
-        Operand::Constant(const_) => crate::constant::trans_constant(fx, const_),
+        Operand::Constant(const_) => crate::constant::codegen_constant(fx, const_),
     }
 }
 
diff --git a/compiler/rustc_codegen_cranelift/src/bin/cg_clif.rs b/compiler/rustc_codegen_cranelift/src/bin/cg_clif.rs
index 590c9ef0ce1..71ef4d22673 100644
--- a/compiler/rustc_codegen_cranelift/src/bin/cg_clif.rs
+++ b/compiler/rustc_codegen_cranelift/src/bin/cg_clif.rs
@@ -24,22 +24,16 @@ impl rustc_driver::Callbacks for CraneliftPassesCallbacks {
         self.time_passes = config.opts.prints.is_empty()
             && (config.opts.debugging_opts.time_passes || config.opts.debugging_opts.time);
 
-        // FIXME workaround for an ICE
-        config.opts.debugging_opts.trim_diagnostic_paths = false;
-
         config.opts.cg.panic = Some(PanicStrategy::Abort);
         config.opts.debugging_opts.panic_abort_tests = true;
         config.opts.maybe_sysroot = Some(
-            std::env::current_exe()
-                .unwrap()
-                .parent()
-                .unwrap()
-                .parent()
-                .unwrap()
-                .parent()
-                .unwrap()
-                .join("build_sysroot")
-                .join("sysroot"),
+            config.opts.maybe_sysroot.clone().unwrap_or(
+                std::env::current_exe()
+                    .unwrap()
+                    .parent()
+                    .unwrap()
+                    .join("sysroot"),
+            ),
         );
     }
 }
diff --git a/compiler/rustc_codegen_cranelift/src/bin/cg_clif_build_sysroot.rs b/compiler/rustc_codegen_cranelift/src/bin/cg_clif_build_sysroot.rs
index c207d98d6c1..165d33dcfb5 100644
--- a/compiler/rustc_codegen_cranelift/src/bin/cg_clif_build_sysroot.rs
+++ b/compiler/rustc_codegen_cranelift/src/bin/cg_clif_build_sysroot.rs
@@ -44,9 +44,6 @@ impl rustc_driver::Callbacks for CraneliftPassesCallbacks {
             return;
         }
 
-        // FIXME workaround for an ICE
-        config.opts.debugging_opts.trim_diagnostic_paths = false;
-
         config.opts.cg.panic = Some(PanicStrategy::Abort);
         config.opts.debugging_opts.panic_abort_tests = true;
         config.opts.maybe_sysroot = Some(
diff --git a/compiler/rustc_codegen_cranelift/src/cast.rs b/compiler/rustc_codegen_cranelift/src/cast.rs
index 122a36b5bf7..57204de1135 100644
--- a/compiler/rustc_codegen_cranelift/src/cast.rs
+++ b/compiler/rustc_codegen_cranelift/src/cast.rs
@@ -181,12 +181,10 @@ pub(crate) fn clif_int_or_float_cast(
                 fx.bcx.ins().select(has_overflow, max_val, val)
             };
             fx.bcx.ins().ireduce(to_ty, val)
+        } else if to_signed {
+            fx.bcx.ins().fcvt_to_sint_sat(to_ty, from)
         } else {
-            if to_signed {
-                fx.bcx.ins().fcvt_to_sint_sat(to_ty, from)
-            } else {
-                fx.bcx.ins().fcvt_to_uint_sat(to_ty, from)
-            }
+            fx.bcx.ins().fcvt_to_uint_sat(to_ty, from)
         }
     } else if from_ty.is_float() && to_ty.is_float() {
         // float -> float
diff --git a/compiler/rustc_codegen_cranelift/src/codegen_i128.rs b/compiler/rustc_codegen_cranelift/src/codegen_i128.rs
index e998403dea6..d6a38bdafc9 100644
--- a/compiler/rustc_codegen_cranelift/src/codegen_i128.rs
+++ b/compiler/rustc_codegen_cranelift/src/codegen_i128.rs
@@ -21,9 +21,9 @@ pub(crate) fn maybe_codegen<'tcx>(
     match bin_op {
         BinOp::BitAnd | BinOp::BitOr | BinOp::BitXor => {
             assert!(!checked);
-            return None;
+            None
         }
-        BinOp::Add | BinOp::Sub if !checked => return None,
+        BinOp::Add | BinOp::Sub if !checked => None,
         BinOp::Add => {
             let out_ty = fx.tcx.mk_tup([lhs.layout().ty, fx.tcx.types.bool].iter());
             return Some(if is_signed {
@@ -57,7 +57,7 @@ pub(crate) fn maybe_codegen<'tcx>(
                 };
                 fx.easy_call("__multi3", &[lhs, rhs], val_ty)
             };
-            return Some(res);
+            Some(res)
         }
         BinOp::Div => {
             assert!(!checked);
@@ -77,7 +77,7 @@ pub(crate) fn maybe_codegen<'tcx>(
         }
         BinOp::Lt | BinOp::Le | BinOp::Eq | BinOp::Ge | BinOp::Gt | BinOp::Ne => {
             assert!(!checked);
-            return None;
+            None
         }
         BinOp::Shl | BinOp::Shr => {
             let is_overflow = if checked {
diff --git a/compiler/rustc_codegen_cranelift/src/common.rs b/compiler/rustc_codegen_cranelift/src/common.rs
index 13c62add41a..eda77bf19d3 100644
--- a/compiler/rustc_codegen_cranelift/src/common.rs
+++ b/compiler/rustc_codegen_cranelift/src/common.rs
@@ -406,7 +406,7 @@ impl<'tcx, M: Module> FunctionCx<'_, 'tcx, M> {
             caller.line as u32,
             caller.col_display as u32 + 1,
         ));
-        crate::constant::trans_const_value(self, const_loc, self.tcx.caller_location_ty())
+        crate::constant::codegen_const_value(self, const_loc, self.tcx.caller_location_ty())
     }
 
     pub(crate) fn triple(&self) -> &target_lexicon::Triple {
diff --git a/compiler/rustc_codegen_cranelift/src/constant.rs b/compiler/rustc_codegen_cranelift/src/constant.rs
index 1b514958a48..ce1d5ed2e61 100644
--- a/compiler/rustc_codegen_cranelift/src/constant.rs
+++ b/compiler/rustc_codegen_cranelift/src/constant.rs
@@ -106,7 +106,7 @@ fn codegen_static_ref<'tcx>(
     CPlace::for_ptr(crate::pointer::Pointer::new(global_ptr), layout)
 }
 
-pub(crate) fn trans_constant<'tcx>(
+pub(crate) fn codegen_constant<'tcx>(
     fx: &mut FunctionCx<'_, 'tcx, impl Module>,
     constant: &Constant<'tcx>,
 ) -> CValue<'tcx> {
@@ -151,10 +151,10 @@ pub(crate) fn trans_constant<'tcx>(
         | ConstKind::Error(_) => unreachable!("{:?}", const_),
     };
 
-    trans_const_value(fx, const_val, const_.ty)
+    codegen_const_value(fx, const_val, const_.ty)
 }
 
-pub(crate) fn trans_const_value<'tcx>(
+pub(crate) fn codegen_const_value<'tcx>(
     fx: &mut FunctionCx<'_, 'tcx, impl Module>,
     const_val: ConstValue<'tcx>,
     ty: Ty<'tcx>,
@@ -164,7 +164,7 @@ pub(crate) fn trans_const_value<'tcx>(
 
     if layout.is_zst() {
         return CValue::by_ref(
-            crate::Pointer::const_addr(fx, i64::try_from(layout.align.pref.bytes()).unwrap()),
+            crate::Pointer::dangling(layout.align.pref),
             layout,
         );
     }
@@ -188,7 +188,7 @@ pub(crate) fn trans_const_value<'tcx>(
             match x {
                 Scalar::Raw { data, size } => {
                     assert_eq!(u64::from(size), layout.size.bytes());
-                    return CValue::const_val(fx, layout, data);
+                    CValue::const_val(fx, layout, data)
                 }
                 Scalar::Ptr(ptr) => {
                     let alloc_kind = fx.tcx.get_global_alloc(ptr.alloc_id);
@@ -232,7 +232,7 @@ pub(crate) fn trans_const_value<'tcx>(
                     } else {
                         base_addr
                     };
-                    return CValue::by_val(val, layout);
+                    CValue::by_val(val, layout)
                 }
             }
         }
@@ -276,7 +276,7 @@ fn data_id_for_alloc_id(
 ) -> DataId {
     module
         .declare_data(
-            &format!("__alloc_{:x}", alloc_id.0),
+            &format!(".L__alloc_{:x}", alloc_id.0),
             Linkage::Local,
             mutability == rustc_hir::Mutability::Mut,
             false,
@@ -293,14 +293,12 @@ fn data_id_for_static(
     let rlinkage = tcx.codegen_fn_attrs(def_id).linkage;
     let linkage = if definition {
         crate::linkage::get_static_linkage(tcx, def_id)
+    } else if rlinkage == Some(rustc_middle::mir::mono::Linkage::ExternalWeak)
+        || rlinkage == Some(rustc_middle::mir::mono::Linkage::WeakAny)
+    {
+        Linkage::Preemptible
     } else {
-        if rlinkage == Some(rustc_middle::mir::mono::Linkage::ExternalWeak)
-            || rlinkage == Some(rustc_middle::mir::mono::Linkage::WeakAny)
-        {
-            Linkage::Preemptible
-        } else {
-            Linkage::Import
-        }
+        Linkage::Import
     };
 
     let instance = Instance::mono(tcx, def_id).polymorphize(tcx);
diff --git a/compiler/rustc_codegen_cranelift/src/debuginfo/emit.rs b/compiler/rustc_codegen_cranelift/src/debuginfo/emit.rs
index cf8fee2b1d1..f6f795e4561 100644
--- a/compiler/rustc_codegen_cranelift/src/debuginfo/emit.rs
+++ b/compiler/rustc_codegen_cranelift/src/debuginfo/emit.rs
@@ -195,9 +195,7 @@ impl Writer for WriterRelocate {
                     });
                     self.write_udata(0, size)
                 }
-                _ => {
-                    return Err(gimli::write::Error::UnsupportedPointerEncoding(eh_pe));
-                }
+                _ => Err(gimli::write::Error::UnsupportedPointerEncoding(eh_pe)),
             },
         }
     }
diff --git a/compiler/rustc_codegen_cranelift/src/debuginfo/line_info.rs b/compiler/rustc_codegen_cranelift/src/debuginfo/line_info.rs
index 4de84855328..d226755d85d 100644
--- a/compiler/rustc_codegen_cranelift/src/debuginfo/line_info.rs
+++ b/compiler/rustc_codegen_cranelift/src/debuginfo/line_info.rs
@@ -49,7 +49,7 @@ fn osstr_as_utf8_bytes(path: &OsStr) -> &[u8] {
 
 pub(crate) const MD5_LEN: usize = 16;
 
-pub fn make_file_info(hash: SourceFileHash) -> Option<FileInfo> {
+pub(crate) fn make_file_info(hash: SourceFileHash) -> Option<FileInfo> {
     if hash.kind == SourceFileHashAlgorithm::Md5 {
         let mut buf = [0u8; MD5_LEN];
         buf.copy_from_slice(hash.hash_bytes());
@@ -190,7 +190,7 @@ impl<'tcx> DebugContext<'tcx> {
             if current_file_changed {
                 let file_id = line_program_add_file(line_program, line_strings, &file);
                 line_program.row().file = file_id;
-                last_file = Some(file.clone());
+                last_file = Some(file);
             }
 
             line_program.row().line = line;
diff --git a/compiler/rustc_codegen_cranelift/src/debuginfo/unwind.rs b/compiler/rustc_codegen_cranelift/src/debuginfo/unwind.rs
index 61ebd931d2f..68138404c24 100644
--- a/compiler/rustc_codegen_cranelift/src/debuginfo/unwind.rs
+++ b/compiler/rustc_codegen_cranelift/src/debuginfo/unwind.rs
@@ -55,6 +55,7 @@ impl<'tcx> UnwindContext<'tcx> {
             UnwindInfo::WindowsX64(_) => {
                 // FIXME implement this
             }
+            unwind_info => unimplemented!("{:?}", unwind_info),
         }
     }
 
diff --git a/compiler/rustc_codegen_cranelift/src/driver/jit.rs b/compiler/rustc_codegen_cranelift/src/driver/jit.rs
index b5bab3d9e1e..3f47df7d844 100644
--- a/compiler/rustc_codegen_cranelift/src/driver/jit.rs
+++ b/compiler/rustc_codegen_cranelift/src/driver/jit.rs
@@ -94,7 +94,7 @@ pub(super) fn run_jit(tcx: TyCtxt<'_>) -> ! {
 
     let args = ::std::env::var("CG_CLIF_JIT_ARGS").unwrap_or_else(|_| String::new());
     let args = std::iter::once(&*tcx.crate_name(LOCAL_CRATE).as_str().to_string())
-        .chain(args.split(" "))
+        .chain(args.split(' '))
         .map(|arg| CString::new(arg).unwrap())
         .collect::<Vec<_>>();
     let mut argv = args.iter().map(|arg| arg.as_ptr()).collect::<Vec<_>>();
@@ -151,7 +151,7 @@ fn load_imported_symbols_for_jit(tcx: TyCtxt<'_>) -> Vec<(String, *const u8)> {
             }
             let dlsym_name = if cfg!(target_os = "macos") {
                 // On macOS `dlsym` expects the name without leading `_`.
-                assert!(name.starts_with("_"), "{:?}", name);
+                assert!(name.starts_with('_'), "{:?}", name);
                 &name[1..]
             } else {
                 &name
diff --git a/compiler/rustc_codegen_cranelift/src/driver/mod.rs b/compiler/rustc_codegen_cranelift/src/driver/mod.rs
index 2fb353ca162..a11dc57ee64 100644
--- a/compiler/rustc_codegen_cranelift/src/driver/mod.rs
+++ b/compiler/rustc_codegen_cranelift/src/driver/mod.rs
@@ -64,11 +64,11 @@ fn codegen_mono_items<'tcx>(
 
     for (mono_item, (linkage, visibility)) in mono_items {
         let linkage = crate::linkage::get_clif_linkage(mono_item, linkage, visibility);
-        trans_mono_item(cx, mono_item, linkage);
+        codegen_mono_item(cx, mono_item, linkage);
     }
 }
 
-fn trans_mono_item<'tcx, M: Module>(
+fn codegen_mono_item<'tcx, M: Module>(
     cx: &mut crate::CodegenCx<'tcx, M>,
     mono_item: MonoItem<'tcx>,
     linkage: Linkage,
@@ -80,7 +80,7 @@ fn trans_mono_item<'tcx, M: Module>(
                 crate::PrintOnPanic(|| format!("{:?} {}", inst, tcx.symbol_name(inst).name));
             debug_assert!(!inst.substs.needs_infer());
             tcx.sess
-                .time("codegen fn", || crate::base::trans_fn(cx, inst, linkage));
+                .time("codegen fn", || crate::base::codegen_fn(cx, inst, linkage));
         }
         MonoItem::Static(def_id) => {
             crate::constant::codegen_static(&mut cx.constants_cx, def_id);
diff --git a/compiler/rustc_codegen_cranelift/src/inline_asm.rs b/compiler/rustc_codegen_cranelift/src/inline_asm.rs
index aa2edb2dfd4..04aac780125 100644
--- a/compiler/rustc_codegen_cranelift/src/inline_asm.rs
+++ b/compiler/rustc_codegen_cranelift/src/inline_asm.rs
@@ -50,7 +50,7 @@ pub(crate) fn codegen_inline_asm<'tcx>(
                 inputs.push((
                     reg,
                     new_slot(reg.reg_class()),
-                    crate::base::trans_operand(fx, value).load_scalar(fx),
+                    crate::base::codegen_operand(fx, value).load_scalar(fx),
                 ));
             }
             InlineAsmOperand::Out {
@@ -64,7 +64,7 @@ pub(crate) fn codegen_inline_asm<'tcx>(
                     outputs.push((
                         reg,
                         new_slot(reg.reg_class()),
-                        crate::base::trans_place(fx, place),
+                        crate::base::codegen_place(fx, place),
                     ));
                 }
             }
@@ -79,13 +79,13 @@ pub(crate) fn codegen_inline_asm<'tcx>(
                 inputs.push((
                     reg,
                     new_slot(reg.reg_class()),
-                    crate::base::trans_operand(fx, in_value).load_scalar(fx),
+                    crate::base::codegen_operand(fx, in_value).load_scalar(fx),
                 ));
                 if let Some(out_place) = out_place {
                     outputs.push((
                         reg,
                         new_slot(reg.reg_class()),
-                        crate::base::trans_place(fx, out_place),
+                        crate::base::codegen_place(fx, out_place),
                     ));
                 }
             }
diff --git a/compiler/rustc_codegen_cranelift/src/intrinsics/llvm.rs b/compiler/rustc_codegen_cranelift/src/intrinsics/llvm.rs
index 18d86f0c5f9..171445f2d71 100644
--- a/compiler/rustc_codegen_cranelift/src/intrinsics/llvm.rs
+++ b/compiler/rustc_codegen_cranelift/src/intrinsics/llvm.rs
@@ -53,7 +53,7 @@ pub(crate) fn codegen_llvm_intrinsic_call<'tcx>(
         };
         llvm.x86.sse2.cmp.ps | llvm.x86.sse2.cmp.pd, (c x, c y, o kind) {
             let kind_const = crate::constant::mir_operand_get_const_val(fx, kind).expect("llvm.x86.sse2.cmp.* kind not const");
-            let flt_cc = match kind_const.val.try_to_bits(Size::from_bytes(1)).expect(&format!("kind not scalar: {:?}", kind_const)) {
+            let flt_cc = match kind_const.val.try_to_bits(Size::from_bytes(1)).unwrap_or_else(|| panic!("kind not scalar: {:?}", kind_const)) {
                 0 => FloatCC::Equal,
                 1 => FloatCC::LessThan,
                 2 => FloatCC::LessThanOrEqual,
@@ -84,7 +84,7 @@ pub(crate) fn codegen_llvm_intrinsic_call<'tcx>(
         llvm.x86.sse2.psrli.d, (c a, o imm8) {
             let imm8 = crate::constant::mir_operand_get_const_val(fx, imm8).expect("llvm.x86.sse2.psrli.d imm8 not const");
             simd_for_each_lane(fx, a, ret, |fx, _lane_layout, res_lane_layout, lane| {
-                let res_lane = match imm8.val.try_to_bits(Size::from_bytes(4)).expect(&format!("imm8 not scalar: {:?}", imm8)) {
+                let res_lane = match imm8.val.try_to_bits(Size::from_bytes(4)).unwrap_or_else(|| panic!("imm8 not scalar: {:?}", imm8)) {
                     imm8 if imm8 < 32 => fx.bcx.ins().ushr_imm(lane, i64::from(imm8 as u8)),
                     _ => fx.bcx.ins().iconst(types::I32, 0),
                 };
@@ -94,7 +94,7 @@ pub(crate) fn codegen_llvm_intrinsic_call<'tcx>(
         llvm.x86.sse2.pslli.d, (c a, o imm8) {
             let imm8 = crate::constant::mir_operand_get_const_val(fx, imm8).expect("llvm.x86.sse2.psrli.d imm8 not const");
             simd_for_each_lane(fx, a, ret, |fx, _lane_layout, res_lane_layout, lane| {
-                let res_lane = match imm8.val.try_to_bits(Size::from_bytes(4)).expect(&format!("imm8 not scalar: {:?}", imm8)) {
+                let res_lane = match imm8.val.try_to_bits(Size::from_bytes(4)).unwrap_or_else(|| panic!("imm8 not scalar: {:?}", imm8)) {
                     imm8 if imm8 < 32 => fx.bcx.ins().ishl_imm(lane, i64::from(imm8 as u8)),
                     _ => fx.bcx.ins().iconst(types::I32, 0),
                 };
diff --git a/compiler/rustc_codegen_cranelift/src/intrinsics/mod.rs b/compiler/rustc_codegen_cranelift/src/intrinsics/mod.rs
index 9a3e4c7b56e..a5f45b7abf4 100644
--- a/compiler/rustc_codegen_cranelift/src/intrinsics/mod.rs
+++ b/compiler/rustc_codegen_cranelift/src/intrinsics/mod.rs
@@ -9,6 +9,7 @@ pub(crate) use cpuid::codegen_cpuid_call;
 pub(crate) use llvm::codegen_llvm_intrinsic_call;
 
 use crate::prelude::*;
+use rustc_middle::ty::print::with_no_trimmed_paths;
 
 macro intrinsic_pat {
     (_) => {
@@ -30,10 +31,10 @@ macro intrinsic_arg {
         $arg
     },
     (c $fx:expr, $arg:ident) => {
-        trans_operand($fx, $arg)
+        codegen_operand($fx, $arg)
     },
     (v $fx:expr, $arg:ident) => {
-        trans_operand($fx, $arg).load_scalar($fx)
+        codegen_operand($fx, $arg).load_scalar($fx)
     }
 }
 
@@ -89,7 +90,7 @@ macro call_intrinsic_match {
                     assert!($substs.is_noop());
                     if let [$(ref $arg),*] = *$args {
                         let ($($arg,)*) = (
-                            $(trans_operand($fx, $arg),)*
+                            $(codegen_operand($fx, $arg),)*
                         );
                         let res = $fx.easy_call(stringify!($func), &[$($arg),*], $fx.tcx.types.$ty);
                         $ret.write_cvalue($fx, res);
@@ -576,7 +577,7 @@ pub(crate) fn codegen_intrinsic_call<'tcx>(
                 "unchecked_shr" => BinOp::Shr,
                 _ => unreachable!("intrinsic {}", intrinsic),
             };
-            let res = crate::num::trans_int_binop(fx, bin_op, x, y);
+            let res = crate::num::codegen_int_binop(fx, bin_op, x, y);
             ret.write_cvalue(fx, res);
         };
         _ if intrinsic.ends_with("_with_overflow"), (c x, c y) {
@@ -588,7 +589,7 @@ pub(crate) fn codegen_intrinsic_call<'tcx>(
                 _ => unreachable!("intrinsic {}", intrinsic),
             };
 
-            let res = crate::num::trans_checked_int_binop(
+            let res = crate::num::codegen_checked_int_binop(
                 fx,
                 bin_op,
                 x,
@@ -604,7 +605,7 @@ pub(crate) fn codegen_intrinsic_call<'tcx>(
                 "wrapping_mul" => BinOp::Mul,
                 _ => unreachable!("intrinsic {}", intrinsic),
             };
-            let res = crate::num::trans_int_binop(
+            let res = crate::num::codegen_int_binop(
                 fx,
                 bin_op,
                 x,
@@ -622,7 +623,7 @@ pub(crate) fn codegen_intrinsic_call<'tcx>(
 
             let signed = type_sign(T);
 
-            let checked_res = crate::num::trans_checked_int_binop(
+            let checked_res = crate::num::codegen_checked_int_binop(
                 fx,
                 bin_op,
                 lhs,
@@ -819,29 +820,29 @@ pub(crate) fn codegen_intrinsic_call<'tcx>(
         assert_inhabited | assert_zero_valid | assert_uninit_valid, <T> () {
             let layout = fx.layout_of(T);
             if layout.abi.is_uninhabited() {
-                crate::base::codegen_panic(
+                with_no_trimmed_paths(|| crate::base::codegen_panic(
                     fx,
                     &format!("attempted to instantiate uninhabited type `{}`", T),
                     span,
-                );
+                ));
                 return;
             }
 
             if intrinsic == "assert_zero_valid" && !layout.might_permit_raw_init(fx, /*zero:*/ true).unwrap() {
-                crate::base::codegen_panic(
+                with_no_trimmed_paths(|| crate::base::codegen_panic(
                     fx,
                     &format!("attempted to zero-initialize type `{}`, which is invalid", T),
                     span,
-                );
+                ));
                 return;
             }
 
             if intrinsic == "assert_uninit_valid" && !layout.might_permit_raw_init(fx, /*zero:*/ false).unwrap() {
-                crate::base::codegen_panic(
+                with_no_trimmed_paths(|| crate::base::codegen_panic(
                     fx,
                     &format!("attempted to leave type `{}` uninitialized, which is invalid", T),
                     span,
-                );
+                ));
                 return;
             }
         };
@@ -866,7 +867,7 @@ pub(crate) fn codegen_intrinsic_call<'tcx>(
         size_of | pref_align_of | min_align_of | needs_drop | type_id | type_name | variant_count, () {
             let const_val =
                 fx.tcx.const_eval_instance(ParamEnv::reveal_all(), instance, None).unwrap();
-            let val = crate::constant::trans_const_value(
+            let val = crate::constant::codegen_const_value(
                 fx,
                 const_val,
                 ret.layout().ty,
@@ -885,12 +886,12 @@ pub(crate) fn codegen_intrinsic_call<'tcx>(
         };
 
         ptr_guaranteed_eq, (c a, c b) {
-            let val = crate::num::trans_ptr_binop(fx, BinOp::Eq, a, b);
+            let val = crate::num::codegen_ptr_binop(fx, BinOp::Eq, a, b);
             ret.write_cvalue(fx, val);
         };
 
         ptr_guaranteed_ne, (c a, c b) {
-            let val = crate::num::trans_ptr_binop(fx, BinOp::Ne, a, b);
+            let val = crate::num::codegen_ptr_binop(fx, BinOp::Ne, a, b);
             ret.write_cvalue(fx, val);
         };
 
@@ -1068,7 +1069,7 @@ pub(crate) fn codegen_intrinsic_call<'tcx>(
         };
 
         fadd_fast | fsub_fast | fmul_fast | fdiv_fast | frem_fast, (c x, c y) {
-            let res = crate::num::trans_float_binop(fx, match intrinsic {
+            let res = crate::num::codegen_float_binop(fx, match intrinsic {
                 "fadd_fast" => BinOp::Add,
                 "fsub_fast" => BinOp::Sub,
                 "fmul_fast" => BinOp::Mul,
diff --git a/compiler/rustc_codegen_cranelift/src/intrinsics/simd.rs b/compiler/rustc_codegen_cranelift/src/intrinsics/simd.rs
index b4269f4fafa..2e31c4669e2 100644
--- a/compiler/rustc_codegen_cranelift/src/intrinsics/simd.rs
+++ b/compiler/rustc_codegen_cranelift/src/intrinsics/simd.rs
@@ -127,7 +127,7 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>(
                 );
             };
 
-            let idx = idx_const.val.try_to_bits(Size::from_bytes(4 /* u32*/)).expect(&format!("kind not scalar: {:?}", idx_const));
+            let idx = idx_const.val.try_to_bits(Size::from_bytes(4 /* u32*/)).unwrap_or_else(|| panic!("kind not scalar: {:?}", idx_const));
             let (_lane_type, lane_count) = lane_type_and_count(fx.tcx, base.layout());
             if idx >= lane_count.into() {
                 fx.tcx.sess.span_fatal(fx.mir.span, &format!("[simd_insert] idx {} >= lane_count {}", idx, lane_count));
@@ -149,7 +149,7 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>(
                 );
             };
 
-            let idx = idx_const.val.try_to_bits(Size::from_bytes(4 /* u32*/)).expect(&format!("kind not scalar: {:?}", idx_const));
+            let idx = idx_const.val.try_to_bits(Size::from_bytes(4 /* u32*/)).unwrap_or_else(|| panic!("kind not scalar: {:?}", idx_const));
             let (_lane_type, lane_count) = lane_type_and_count(fx.tcx, v.layout());
             if idx >= lane_count.into() {
                 fx.tcx.sess.span_fatal(fx.mir.span, &format!("[simd_extract] idx {} >= lane_count {}", idx, lane_count));
diff --git a/compiler/rustc_codegen_cranelift/src/lib.rs b/compiler/rustc_codegen_cranelift/src/lib.rs
index fd00a2e00a6..ba9ee0d450e 100644
--- a/compiler/rustc_codegen_cranelift/src/lib.rs
+++ b/compiler/rustc_codegen_cranelift/src/lib.rs
@@ -9,6 +9,7 @@
 )]
 #![warn(rust_2018_idioms)]
 #![warn(unused_lifetimes)]
+#![warn(unreachable_pub)]
 
 #[cfg(feature = "jit")]
 extern crate libc;
@@ -110,7 +111,7 @@ mod prelude {
     pub(crate) use cranelift_module::{self, DataContext, DataId, FuncId, Linkage, Module};
 
     pub(crate) use crate::abi::*;
-    pub(crate) use crate::base::{trans_operand, trans_place};
+    pub(crate) use crate::base::{codegen_operand, codegen_place};
     pub(crate) use crate::cast::*;
     pub(crate) use crate::common::*;
     pub(crate) use crate::debuginfo::{DebugContext, UnwindContext};
diff --git a/compiler/rustc_codegen_cranelift/src/linkage.rs b/compiler/rustc_codegen_cranelift/src/linkage.rs
index fe5d1d64443..dc1e2107ce7 100644
--- a/compiler/rustc_codegen_cranelift/src/linkage.rs
+++ b/compiler/rustc_codegen_cranelift/src/linkage.rs
@@ -25,11 +25,9 @@ pub(crate) fn get_static_linkage(tcx: TyCtxt<'_>, def_id: DefId) -> Linkage {
             RLinkage::ExternalWeak | RLinkage::WeakAny => Linkage::Preemptible,
             _ => panic!("{:?}", linkage),
         }
+    } else if tcx.is_reachable_non_generic(def_id) {
+        Linkage::Export
     } else {
-        if tcx.is_reachable_non_generic(def_id) {
-            Linkage::Export
-        } else {
-            Linkage::Hidden
-        }
+        Linkage::Hidden
     }
 }
diff --git a/compiler/rustc_codegen_cranelift/src/main_shim.rs b/compiler/rustc_codegen_cranelift/src/main_shim.rs
index db34d89fe2b..10f515e38ea 100644
--- a/compiler/rustc_codegen_cranelift/src/main_shim.rs
+++ b/compiler/rustc_codegen_cranelift/src/main_shim.rs
@@ -76,7 +76,7 @@ pub(crate) fn maybe_create_entry_wrapper(
             .unwrap();
 
         let mut ctx = Context::new();
-        ctx.func = Function::with_name_signature(ExternalName::user(0, 0), cmain_sig.clone());
+        ctx.func = Function::with_name_signature(ExternalName::user(0, 0), cmain_sig);
         {
             let mut func_ctx = FunctionBuilderContext::new();
             let mut bcx = FunctionBuilder::new(&mut ctx.func, &mut func_ctx);
diff --git a/compiler/rustc_codegen_cranelift/src/metadata.rs b/compiler/rustc_codegen_cranelift/src/metadata.rs
index 04369bf89fd..cda2a187ff9 100644
--- a/compiler/rustc_codegen_cranelift/src/metadata.rs
+++ b/compiler/rustc_codegen_cranelift/src/metadata.rs
@@ -29,7 +29,7 @@ impl MetadataLoader for CraneliftMetadataLoader {
                         .expect("Rlib metadata file too big to load into memory."),
                 );
                 ::std::io::copy(&mut entry, &mut buf).map_err(|e| format!("{:?}", e))?;
-                let buf: OwningRef<Vec<u8>, [u8]> = OwningRef::new(buf).into();
+                let buf: OwningRef<Vec<u8>, [u8]> = OwningRef::new(buf);
                 return Ok(rustc_erase_owner!(buf.map_owner_box()));
             }
         }
@@ -47,7 +47,7 @@ impl MetadataLoader for CraneliftMetadataLoader {
             .data()
             .map_err(|e| format!("failed to read .rustc section: {:?}", e))?
             .to_owned();
-        let buf: OwningRef<Vec<u8>, [u8]> = OwningRef::new(buf).into();
+        let buf: OwningRef<Vec<u8>, [u8]> = OwningRef::new(buf);
         Ok(rustc_erase_owner!(buf.map_owner_box()))
     }
 }
diff --git a/compiler/rustc_codegen_cranelift/src/num.rs b/compiler/rustc_codegen_cranelift/src/num.rs
index b37826d71f4..41f4a9b9662 100644
--- a/compiler/rustc_codegen_cranelift/src/num.rs
+++ b/compiler/rustc_codegen_cranelift/src/num.rs
@@ -89,10 +89,10 @@ pub(crate) fn codegen_binop<'tcx>(
     }
 
     match in_lhs.layout().ty.kind() {
-        ty::Bool => crate::num::trans_bool_binop(fx, bin_op, in_lhs, in_rhs),
-        ty::Uint(_) | ty::Int(_) => crate::num::trans_int_binop(fx, bin_op, in_lhs, in_rhs),
-        ty::Float(_) => crate::num::trans_float_binop(fx, bin_op, in_lhs, in_rhs),
-        ty::RawPtr(..) | ty::FnPtr(..) => crate::num::trans_ptr_binop(fx, bin_op, in_lhs, in_rhs),
+        ty::Bool => crate::num::codegen_bool_binop(fx, bin_op, in_lhs, in_rhs),
+        ty::Uint(_) | ty::Int(_) => crate::num::codegen_int_binop(fx, bin_op, in_lhs, in_rhs),
+        ty::Float(_) => crate::num::codegen_float_binop(fx, bin_op, in_lhs, in_rhs),
+        ty::RawPtr(..) | ty::FnPtr(..) => crate::num::codegen_ptr_binop(fx, bin_op, in_lhs, in_rhs),
         _ => unreachable!(
             "{:?}({:?}, {:?})",
             bin_op,
@@ -102,7 +102,7 @@ pub(crate) fn codegen_binop<'tcx>(
     }
 }
 
-pub(crate) fn trans_bool_binop<'tcx>(
+pub(crate) fn codegen_bool_binop<'tcx>(
     fx: &mut FunctionCx<'_, 'tcx, impl Module>,
     bin_op: BinOp,
     in_lhs: CValue<'tcx>,
@@ -123,7 +123,7 @@ pub(crate) fn trans_bool_binop<'tcx>(
     CValue::by_val(res, fx.layout_of(fx.tcx.types.bool))
 }
 
-pub(crate) fn trans_int_binop<'tcx>(
+pub(crate) fn codegen_int_binop<'tcx>(
     fx: &mut FunctionCx<'_, 'tcx, impl Module>,
     bin_op: BinOp,
     in_lhs: CValue<'tcx>,
@@ -196,7 +196,7 @@ pub(crate) fn trans_int_binop<'tcx>(
     CValue::by_val(val, in_lhs.layout())
 }
 
-pub(crate) fn trans_checked_int_binop<'tcx>(
+pub(crate) fn codegen_checked_int_binop<'tcx>(
     fx: &mut FunctionCx<'_, 'tcx, impl Module>,
     bin_op: BinOp,
     in_lhs: CValue<'tcx>,
@@ -357,7 +357,7 @@ pub(crate) fn trans_checked_int_binop<'tcx>(
     out_place.to_cvalue(fx)
 }
 
-pub(crate) fn trans_float_binop<'tcx>(
+pub(crate) fn codegen_float_binop<'tcx>(
     fx: &mut FunctionCx<'_, 'tcx, impl Module>,
     bin_op: BinOp,
     in_lhs: CValue<'tcx>,
@@ -402,7 +402,7 @@ pub(crate) fn trans_float_binop<'tcx>(
     CValue::by_val(res, in_lhs.layout())
 }
 
-pub(crate) fn trans_ptr_binop<'tcx>(
+pub(crate) fn codegen_ptr_binop<'tcx>(
     fx: &mut FunctionCx<'_, 'tcx, impl Module>,
     bin_op: BinOp,
     in_lhs: CValue<'tcx>,
diff --git a/compiler/rustc_codegen_cranelift/src/optimize/stack2reg.rs b/compiler/rustc_codegen_cranelift/src/optimize/stack2reg.rs
index f368d65f7f8..3c939d5a586 100644
--- a/compiler/rustc_codegen_cranelift/src/optimize/stack2reg.rs
+++ b/compiler/rustc_codegen_cranelift/src/optimize/stack2reg.rs
@@ -228,7 +228,8 @@ pub(super) fn optimize_function(
             match *potential_stores {
                 [] => {
                     #[cfg(debug_assertions)]
-                    clif_comments.add_comment(load, format!("[BUG?] Reading uninitialized memory"));
+                    clif_comments
+                        .add_comment(load, "[BUG?] Reading uninitialized memory".to_string());
                 }
                 [store]
                     if spatial_overlap(&opt_ctx.ctx.func, store, load) == SpatialOverlap::Full
diff --git a/compiler/rustc_codegen_cranelift/src/pretty_clif.rs b/compiler/rustc_codegen_cranelift/src/pretty_clif.rs
index 7f8ab953d71..ff878af7f5e 100644
--- a/compiler/rustc_codegen_cranelift/src/pretty_clif.rs
+++ b/compiler/rustc_codegen_cranelift/src/pretty_clif.rs
@@ -131,11 +131,11 @@ impl FuncWriter for &'_ CommentWriter {
             if !comment.is_empty() {
                 writeln!(w, "; {}", comment)?;
             } else {
-                writeln!(w, "")?;
+                writeln!(w)?;
             }
         }
         if !self.global_comments.is_empty() {
-            writeln!(w, "")?;
+            writeln!(w)?;
         }
 
         self.super_preamble(w, func, reg_info)
@@ -153,7 +153,7 @@ impl FuncWriter for &'_ CommentWriter {
         if let Some(comment) = self.entity_comments.get(&entity) {
             writeln!(w, " ; {}", comment.replace('\n', "\n; "))
         } else {
-            writeln!(w, "")
+            writeln!(w)
         }
     }
 
@@ -261,7 +261,7 @@ pub(crate) fn write_clif_file<'tcx>(
         writeln!(file, "set is_pic")?;
         writeln!(file, "set enable_simd")?;
         writeln!(file, "target {} haswell", target_triple)?;
-        writeln!(file, "")?;
+        writeln!(file)?;
         file.write_all(clif.as_bytes())?;
     };
     if let Err(err) = res {
diff --git a/compiler/rustc_codegen_cranelift/src/trap.rs b/compiler/rustc_codegen_cranelift/src/trap.rs
index 37dca77bdbd..690d96764a8 100644
--- a/compiler/rustc_codegen_cranelift/src/trap.rs
+++ b/compiler/rustc_codegen_cranelift/src/trap.rs
@@ -67,4 +67,3 @@ pub(crate) fn trap_unimplemented(fx: &mut FunctionCx<'_, '_, impl Module>, msg:
     let true_ = fx.bcx.ins().iconst(types::I32, 1);
     fx.bcx.ins().trapnz(true_, TrapCode::User(!0));
 }
-
diff --git a/compiler/rustc_codegen_cranelift/src/value_and_place.rs b/compiler/rustc_codegen_cranelift/src/value_and_place.rs
index 5d513cb3ea0..2b9ea5273b6 100644
--- a/compiler/rustc_codegen_cranelift/src/value_and_place.rs
+++ b/compiler/rustc_codegen_cranelift/src/value_and_place.rs
@@ -27,10 +27,10 @@ fn codegen_field<'tcx>(
             return simple(fx);
         }
         match field_layout.ty.kind() {
-            ty::Slice(..) | ty::Str | ty::Foreign(..) => return simple(fx),
+            ty::Slice(..) | ty::Str | ty::Foreign(..) => simple(fx),
             ty::Adt(def, _) if def.repr.packed() => {
                 assert_eq!(layout.align.abi.bytes(), 1);
-                return simple(fx);
+                simple(fx)
             }
             _ => {
                 // We have to align the offset for DST's
@@ -237,15 +237,12 @@ impl<'tcx> CValue<'tcx> {
 
         let clif_ty = fx.clif_type(layout.ty).unwrap();
 
-        match layout.ty.kind() {
-            ty::Bool => {
-                assert!(
-                    const_val == 0 || const_val == 1,
-                    "Invalid bool 0x{:032X}",
-                    const_val
-                );
-            }
-            _ => {}
+        if let ty::Bool = layout.ty.kind() {
+            assert!(
+                const_val == 0 || const_val == 1,
+                "Invalid bool 0x{:032X}",
+                const_val
+            );
         }
 
         let val = match layout.ty.kind() {
@@ -335,7 +332,7 @@ impl<'tcx> CPlace<'tcx> {
 
         let stack_slot = fx.bcx.create_stack_slot(StackSlotData {
             kind: StackSlotKind::ExplicitSlot,
-            size: layout.size.bytes() as u32,
+            size: u32::try_from(layout.size.bytes()).unwrap(),
             offset: None,
         });
         CPlace {
@@ -533,6 +530,13 @@ impl<'tcx> CPlace<'tcx> {
             dst_ty: Type,
         ) {
             let src_ty = fx.bcx.func.dfg.value_type(data);
+            assert_eq!(
+                src_ty.bytes(),
+                dst_ty.bytes(),
+                "write_cvalue_transmute: {:?} -> {:?}",
+                src_ty,
+                dst_ty,
+            );
             let data = match (src_ty, dst_ty) {
                 (_, _) if src_ty == dst_ty => data,
 
@@ -544,6 +548,17 @@ impl<'tcx> CPlace<'tcx> {
                 _ if src_ty.is_vector() && dst_ty.is_vector() => {
                     fx.bcx.ins().raw_bitcast(dst_ty, data)
                 }
+                _ if src_ty.is_vector() || dst_ty.is_vector() => {
+                    // FIXME do something more efficient for transmutes between vectors and integers.
+                    let stack_slot = fx.bcx.create_stack_slot(StackSlotData {
+                        kind: StackSlotKind::ExplicitSlot,
+                        size: src_ty.bytes(),
+                        offset: None,
+                    });
+                    let ptr = Pointer::stack_slot(stack_slot);
+                    ptr.store(fx, data, MemFlags::trusted());
+                    ptr.load(fx, dst_ty, MemFlags::trusted())
+                }
                 _ => unreachable!("write_cvalue_transmute: {:?} -> {:?}", src_ty, dst_ty),
             };
             fx.bcx
diff --git a/compiler/rustc_codegen_cranelift/src/vtable.rs b/compiler/rustc_codegen_cranelift/src/vtable.rs
index bb3cf8b3f3a..238abc0d8bd 100644
--- a/compiler/rustc_codegen_cranelift/src/vtable.rs
+++ b/compiler/rustc_codegen_cranelift/src/vtable.rs
@@ -108,14 +108,14 @@ fn build_vtable<'tcx>(
         (&[]).iter()
     };
     let methods = methods.cloned().map(|opt_mth| {
-        opt_mth.map_or(None, |(def_id, substs)| {
-            Some(import_function(
+        opt_mth.map(|(def_id, substs)| {
+            import_function(
                 tcx,
                 &mut fx.cx.module,
                 Instance::resolve_for_vtable(tcx, ParamEnv::reveal_all(), def_id, substs)
                     .unwrap()
                     .polymorphize(fx.tcx),
-            ))
+            )
         })
     });
     components.extend(methods);
@@ -137,15 +137,7 @@ fn build_vtable<'tcx>(
         }
     }
 
-    data_ctx.set_align(
-        fx.tcx
-            .data_layout
-            .pointer_align
-            .pref
-            .bytes()
-            .try_into()
-            .unwrap(),
-    );
+    data_ctx.set_align(fx.tcx.data_layout.pointer_align.pref.bytes());
 
     let data_id = fx
         .cx