From 6c5b990c5f5e17f044d7c4673802a11d50bc709f Mon Sep 17 00:00:00 2001 From: Denis Merigoux Date: Thu, 30 Aug 2018 14:58:15 +0200 Subject: [PATCH] All CommonMethods now real methods (not static) --- src/librustc_codegen_llvm/base.rs | 2 +- src/librustc_codegen_llvm/common.rs | 20 +++++++++---------- src/librustc_codegen_llvm/glue.rs | 12 +++++------ .../interfaces/common.rs | 16 +++++++-------- src/librustc_codegen_llvm/intrinsic.rs | 8 ++++---- src/librustc_codegen_llvm/mir/block.rs | 2 +- src/librustc_codegen_llvm/mir/rvalue.rs | 3 +-- 7 files changed, 31 insertions(+), 32 deletions(-) diff --git a/src/librustc_codegen_llvm/base.rs b/src/librustc_codegen_llvm/base.rs index 6a2f437b1da..e13c488d2b7 100644 --- a/src/librustc_codegen_llvm/base.rs +++ b/src/librustc_codegen_llvm/base.rs @@ -1151,7 +1151,7 @@ fn module_codegen<'a, 'tcx>( if !cx.used_statics.borrow().is_empty() { let name = const_cstr!("llvm.used"); let section = const_cstr!("llvm.metadata"); - let array = CodegenCx::c_array(Type::i8(&cx).ptr_to(), &*cx.used_statics.borrow()); + let array = cx.c_array(Type::i8(&cx).ptr_to(), &*cx.used_statics.borrow()); unsafe { let g = llvm::LLVMAddGlobal(cx.llmod, diff --git a/src/librustc_codegen_llvm/common.rs b/src/librustc_codegen_llvm/common.rs index 80f8bbeabda..bd356047467 100644 --- a/src/librustc_codegen_llvm/common.rs +++ b/src/librustc_codegen_llvm/common.rs @@ -321,13 +321,13 @@ fn c_struct( &self.c_struct_in_context(&self.llcx, elts, packed) } - fn c_array(ty: &'ll Type, elts: &[&'ll Value]) -> &'ll Value { + fn c_array(&self, ty: &'ll Type, elts: &[&'ll Value]) -> &'ll Value { unsafe { return llvm::LLVMConstArray(ty, elts.as_ptr(), elts.len() as c_uint); } } - fn c_vector(elts: &[&'ll Value]) -> &'ll Value { + fn c_vector(&self, elts: &[&'ll Value]) -> &'ll Value { unsafe { return llvm::LLVMConstVector(elts.as_ptr(), elts.len() as c_uint); } @@ -337,7 +337,7 @@ fn c_bytes(&self, bytes: &[u8]) -> &'ll Value { &self.c_bytes_in_context(&self.llcx, bytes) } - fn const_get_elt(v: &'ll Value, idx: u64) -> &'ll Value { + fn const_get_elt(&self, v: &'ll Value, idx: u64) -> &'ll Value { unsafe { assert_eq!(idx as c_uint as u64, idx); let us = &[idx as c_uint]; @@ -350,9 +350,9 @@ fn const_get_elt(v: &'ll Value, idx: u64) -> &'ll Value { } } - fn const_get_real(v: &'ll Value) -> Option<(f64, bool)> { + fn const_get_real(&self, v: &'ll Value) -> Option<(f64, bool)> { unsafe { - if Self::is_const_real(v) { + if self.is_const_real(v) { let mut loses_info: llvm::Bool = ::std::mem::uninitialized(); let r = llvm::LLVMConstRealGetDouble(v, &mut loses_info); let loses_info = if loses_info == 1 { true } else { false }; @@ -363,27 +363,27 @@ fn const_get_real(v: &'ll Value) -> Option<(f64, bool)> { } } - fn const_to_uint(v: &'ll Value) -> u64 { + fn const_to_uint(&self, v: &'ll Value) -> u64 { unsafe { llvm::LLVMConstIntGetZExtValue(v) } } - fn is_const_integral(v: &'ll Value) -> bool { + fn is_const_integral(&self, v: &'ll Value) -> bool { unsafe { llvm::LLVMIsAConstantInt(v).is_some() } } - fn is_const_real(v: &'ll Value) -> bool { + fn is_const_real(&self, v: &'ll Value) -> bool { unsafe { llvm::LLVMIsAConstantFP(v).is_some() } } - fn const_to_opt_u128(v: &'ll Value, sign_ext: bool) -> Option { + fn const_to_opt_u128(&self, v: &'ll Value, sign_ext: bool) -> Option { unsafe { - if Self::is_const_integral(v) { + if self.is_const_integral(v) { let (mut lo, mut hi) = (0u64, 0u64); let success = llvm::LLVMRustConstInt128Get(v, sign_ext, &mut hi, &mut lo); diff --git a/src/librustc_codegen_llvm/glue.rs b/src/librustc_codegen_llvm/glue.rs index b2d2e379898..09bd3ae264b 100644 --- a/src/librustc_codegen_llvm/glue.rs +++ b/src/librustc_codegen_llvm/glue.rs @@ -34,8 +34,8 @@ pub fn size_and_align_of_dst( let (size, align) = bx.cx().size_and_align_of(t); debug!("size_and_align_of_dst t={} info={:?} size: {:?} align: {:?}", t, info, size, align); - let size = CodegenCx::c_usize(bx.cx(), size.bytes()); - let align = CodegenCx::c_usize(bx.cx(), align.abi()); + let size = bx.cx().c_usize(size.bytes()); + let align = bx.cx().c_usize(align.abi()); return (size, align); } match t.sty { @@ -49,8 +49,8 @@ pub fn size_and_align_of_dst( // The info in this case is the length of the str, so the size is that // times the unit size. let (size, align) = bx.cx().size_and_align_of(unit); - (bx.mul(info.unwrap(), CodegenCx::c_usize(bx.cx(), size.bytes())), - CodegenCx::c_usize(bx.cx(), align.abi())) + (bx.mul(info.unwrap(), bx.cx().c_usize(size.bytes())), + bx.cx().c_usize(align.abi())) } _ => { let cx = bx.cx(); @@ -93,8 +93,8 @@ pub fn size_and_align_of_dst( // Choose max of two known alignments (combined value must // be aligned according to more restrictive of the two). - let align = match (CodegenCx::const_to_opt_u128(sized_align, false), - CodegenCx::const_to_opt_u128(unsized_align, false)) { + let align = match (bx.cx().const_to_opt_u128(sized_align, false), + bx.cx().const_to_opt_u128(unsized_align, false)) { (Some(sized_align), Some(unsized_align)) => { // If both alignments are constant, (the sized_align should always be), then // pick the correct alignment statically. diff --git a/src/librustc_codegen_llvm/interfaces/common.rs b/src/librustc_codegen_llvm/interfaces/common.rs index 9eaf94cff66..79fed084588 100644 --- a/src/librustc_codegen_llvm/interfaces/common.rs +++ b/src/librustc_codegen_llvm/interfaces/common.rs @@ -40,16 +40,16 @@ fn c_struct( elts: &[Self::Value], packed: bool ) -> Self::Value; - fn c_array(ty: Self::Type, elts: &[Self::Value]) -> Self::Value; - fn c_vector(elts: &[Self::Value]) -> Self::Value; + fn c_array(&self, ty: Self::Type, elts: &[Self::Value]) -> Self::Value; + fn c_vector(&self, elts: &[Self::Value]) -> Self::Value; fn c_bytes(&self, bytes: &[u8]) -> Self::Value; - fn const_get_elt(v: Self::Value, idx: u64) -> Self::Value; - fn const_get_real(v: Self::Value) -> Option<(f64, bool)>; - fn const_to_uint(v: Self::Value) -> u64; - fn is_const_integral(v: Self::Value) -> bool; - fn is_const_real(v: Self::Value) -> bool; - fn const_to_opt_u128(v: Self::Value, sign_ext: bool) -> Option; + fn const_get_elt(&self, v: Self::Value, idx: u64) -> Self::Value; + fn const_get_real(&self, v: Self::Value) -> Option<(f64, bool)>; + fn const_to_uint(&self, v: Self::Value) -> u64; + fn is_const_integral(&self, v: Self::Value) -> bool; + fn is_const_real(&self, v: Self::Value) -> bool; + fn const_to_opt_u128(&self, v: Self::Value, sign_ext: bool) -> Option; } pub trait CommonWriteMethods : Backend { diff --git a/src/librustc_codegen_llvm/intrinsic.rs b/src/librustc_codegen_llvm/intrinsic.rs index 490d3c45aa8..90837a95c60 100644 --- a/src/librustc_codegen_llvm/intrinsic.rs +++ b/src/librustc_codegen_llvm/intrinsic.rs @@ -1114,8 +1114,8 @@ macro_rules! require_simd { let indices: Option> = (0..n) .map(|i| { let arg_idx = i; - let val = CodegenCx::const_get_elt(vector, i as u64); - match CodegenCx::const_to_opt_u128(val, true) { + let val = bx.cx().const_get_elt(vector, i as u64); + match bx.cx().const_to_opt_u128(val, true) { None => { emit_error!("shuffle index #{} is not a constant", arg_idx); None @@ -1136,7 +1136,7 @@ macro_rules! require_simd { return Ok(bx.shuffle_vector(args[0].immediate(), args[1].immediate(), - CodegenCx::c_vector(&indices))) + bx.cx().c_vector(&indices))) } if name == "simd_insert" { @@ -1549,7 +1549,7 @@ macro_rules! arith_red { // code is generated // * if the accumulator of the fmul isn't 1, incorrect // code is generated - match CodegenCx::const_get_real(acc) { + match bx.cx().const_get_real(acc) { None => return_error!("accumulator of {} is not a constant", $name), Some((v, loses_info)) => { if $name.contains("mul") && v != 1.0_f64 { diff --git a/src/librustc_codegen_llvm/mir/block.rs b/src/librustc_codegen_llvm/mir/block.rs index 737b25a1231..b9599d505d3 100644 --- a/src/librustc_codegen_llvm/mir/block.rs +++ b/src/librustc_codegen_llvm/mir/block.rs @@ -324,7 +324,7 @@ fn codegen_terminator(&mut self, mir::TerminatorKind::Assert { ref cond, expected, ref msg, target, cleanup } => { let cond = self.codegen_operand(&bx, cond).immediate(); - let mut const_cond = CodegenCx::const_to_opt_u128(cond, false).map(|c| c == 1); + let mut const_cond = bx.cx().const_to_opt_u128(cond, false).map(|c| c == 1); // This case can currently arise only from functions marked // with #[rustc_inherit_overflow_checks] and inlined from diff --git a/src/librustc_codegen_llvm/mir/rvalue.rs b/src/librustc_codegen_llvm/mir/rvalue.rs index 3c469cffaf3..2496e10b74b 100644 --- a/src/librustc_codegen_llvm/mir/rvalue.rs +++ b/src/librustc_codegen_llvm/mir/rvalue.rs @@ -20,7 +20,6 @@ use builder::Builder; use callee; use common::{self, IntPredicate, RealPredicate}; -use context::CodegenCx; use consts; use monomorphize; use type_::Type; @@ -110,7 +109,7 @@ pub fn codegen_rvalue(&mut self, let size = bx.cx().c_usize(dest.layout.size.bytes()); // Use llvm.memset.p0i8.* to initialize all zero arrays - if CodegenCx::is_const_integral(v) && CodegenCx::const_to_uint(v) == 0 { + if bx.cx().is_const_integral(v) && bx.cx().const_to_uint(v) == 0 { let fill = bx.cx().c_u8(0); base::call_memset(&bx, start, fill, size, align, false); return bx; -- 2.44.0