提交 6c5b990c 编写于 作者: D Denis Merigoux 提交者: Eduard-Mihai Burtescu

All CommonMethods now real methods (not static)

上级 33eee837
......@@ -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,
......
......@@ -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<u128> {
fn const_to_opt_u128(&self, v: &'ll Value, sign_ext: bool) -> Option<u128> {
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);
......
......@@ -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.
......
......@@ -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<u128>;
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<u128>;
}
pub trait CommonWriteMethods : Backend {
......
......@@ -1114,8 +1114,8 @@ fn generic_simd_intrinsic(
let indices: Option<Vec<_>> = (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 @@ fn generic_simd_intrinsic(
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 @@ fn non_ptr(t: ty::Ty) -> ty::Ty {
// 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 {
......
......@@ -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
......
......@@ -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;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册