Remove is_const_integral method from ConstMethods
This commit is contained in:
parent
4d1a5ade9b
commit
cf858a8ac0
4 changed files with 18 additions and 16 deletions
|
@ -245,21 +245,19 @@ impl ConstMethods<'tcx> for CodegenCx<'ll, 'tcx> {
|
||||||
struct_in_context(self.llcx, elts, packed)
|
struct_in_context(self.llcx, elts, packed)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn const_to_uint(&self, v: &'ll Value) -> u64 {
|
fn const_to_opt_uint(&self, v: &'ll Value) -> Option<u64> {
|
||||||
|
if is_const_integral(v) {
|
||||||
unsafe {
|
unsafe {
|
||||||
llvm::LLVMConstIntGetZExtValue(v)
|
Some(llvm::LLVMConstIntGetZExtValue(v))
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
|
None
|
||||||
fn is_const_integral(&self, v: &'ll Value) -> bool {
|
|
||||||
unsafe {
|
|
||||||
llvm::LLVMIsAConstantInt(v).is_some()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn const_to_opt_u128(&self, v: &'ll Value, sign_ext: bool) -> Option<u128> {
|
fn const_to_opt_u128(&self, v: &'ll Value, sign_ext: bool) -> Option<u128> {
|
||||||
unsafe {
|
unsafe {
|
||||||
if self.is_const_integral(v) {
|
if is_const_integral(v) {
|
||||||
let (mut lo, mut hi) = (0u64, 0u64);
|
let (mut lo, mut hi) = (0u64, 0u64);
|
||||||
let success = llvm::LLVMRustConstInt128Get(v, sign_ext,
|
let success = llvm::LLVMRustConstInt128Get(v, sign_ext,
|
||||||
&mut hi, &mut lo);
|
&mut hi, &mut lo);
|
||||||
|
@ -388,3 +386,9 @@ pub fn struct_in_context(
|
||||||
fn hi_lo_to_u128(lo: u64, hi: u64) -> u128 {
|
fn hi_lo_to_u128(lo: u64, hi: u64) -> u128 {
|
||||||
((hi as u128) << 64) | (lo as u128)
|
((hi as u128) << 64) | (lo as u128)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn is_const_integral(v: &'ll Value) -> bool {
|
||||||
|
unsafe {
|
||||||
|
llvm::LLVMIsAConstantInt(v).is_some()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -394,8 +394,8 @@ impl<'a, 'tcx, V: CodegenObject> PlaceRef<'tcx, V> {
|
||||||
// Statically compute the offset if we can, otherwise just use the element size,
|
// Statically compute the offset if we can, otherwise just use the element size,
|
||||||
// as this will yield the lowest alignment.
|
// as this will yield the lowest alignment.
|
||||||
let layout = self.layout.field(bx, 0);
|
let layout = self.layout.field(bx, 0);
|
||||||
let offset = if bx.is_const_integral(llindex) {
|
let offset = if let Some(llindex) = bx.const_to_opt_uint(llindex) {
|
||||||
layout.size.checked_mul(bx.const_to_uint(llindex), bx).unwrap_or(layout.size)
|
layout.size.checked_mul(llindex, bx).unwrap_or(layout.size)
|
||||||
} else {
|
} else {
|
||||||
layout.size
|
layout.size
|
||||||
};
|
};
|
||||||
|
|
|
@ -95,7 +95,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
|
||||||
let size = bx.const_usize(dest.layout.size.bytes());
|
let size = bx.const_usize(dest.layout.size.bytes());
|
||||||
|
|
||||||
// Use llvm.memset.p0i8.* to initialize all zero arrays
|
// Use llvm.memset.p0i8.* to initialize all zero arrays
|
||||||
if bx.cx().is_const_integral(v) && bx.cx().const_to_uint(v) == 0 {
|
if bx.cx().const_to_opt_uint(v) == Some(0) {
|
||||||
let fill = bx.cx().const_u8(0);
|
let fill = bx.cx().const_u8(0);
|
||||||
bx.memset(start, fill, size, dest.align, MemFlags::empty());
|
bx.memset(start, fill, size, dest.align, MemFlags::empty());
|
||||||
return bx;
|
return bx;
|
||||||
|
|
|
@ -21,11 +21,9 @@ pub trait ConstMethods<'tcx>: BackendTypes {
|
||||||
|
|
||||||
fn const_struct(&self, elts: &[Self::Value], packed: bool) -> Self::Value;
|
fn const_struct(&self, elts: &[Self::Value], packed: bool) -> Self::Value;
|
||||||
|
|
||||||
fn const_to_uint(&self, v: Self::Value) -> u64;
|
fn const_to_opt_uint(&self, v: Self::Value) -> Option<u64>;
|
||||||
fn const_to_opt_u128(&self, v: Self::Value, sign_ext: bool) -> Option<u128>;
|
fn const_to_opt_u128(&self, v: Self::Value, sign_ext: bool) -> Option<u128>;
|
||||||
|
|
||||||
fn is_const_integral(&self, v: Self::Value) -> bool;
|
|
||||||
|
|
||||||
fn scalar_to_backend(
|
fn scalar_to_backend(
|
||||||
&self,
|
&self,
|
||||||
cv: Scalar,
|
cv: Scalar,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue