Skip to content

Commit cf858a8

Browse files
committed
Remove is_const_integral method from ConstMethods
1 parent 4d1a5ad commit cf858a8

File tree

4 files changed

+18
-16
lines changed

4 files changed

+18
-16
lines changed

src/librustc_codegen_llvm/common.rs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -245,21 +245,19 @@ impl ConstMethods<'tcx> for CodegenCx<'ll, 'tcx> {
245245
struct_in_context(self.llcx, elts, packed)
246246
}
247247

248-
fn const_to_uint(&self, v: &'ll Value) -> u64 {
249-
unsafe {
250-
llvm::LLVMConstIntGetZExtValue(v)
251-
}
252-
}
253-
254-
fn is_const_integral(&self, v: &'ll Value) -> bool {
255-
unsafe {
256-
llvm::LLVMIsAConstantInt(v).is_some()
248+
fn const_to_opt_uint(&self, v: &'ll Value) -> Option<u64> {
249+
if is_const_integral(v) {
250+
unsafe {
251+
Some(llvm::LLVMConstIntGetZExtValue(v))
252+
}
253+
} else {
254+
None
257255
}
258256
}
259257

260258
fn const_to_opt_u128(&self, v: &'ll Value, sign_ext: bool) -> Option<u128> {
261259
unsafe {
262-
if self.is_const_integral(v) {
260+
if is_const_integral(v) {
263261
let (mut lo, mut hi) = (0u64, 0u64);
264262
let success = llvm::LLVMRustConstInt128Get(v, sign_ext,
265263
&mut hi, &mut lo);
@@ -388,3 +386,9 @@ pub fn struct_in_context(
388386
fn hi_lo_to_u128(lo: u64, hi: u64) -> u128 {
389387
((hi as u128) << 64) | (lo as u128)
390388
}
389+
390+
fn is_const_integral(v: &'ll Value) -> bool {
391+
unsafe {
392+
llvm::LLVMIsAConstantInt(v).is_some()
393+
}
394+
}

src/librustc_codegen_ssa/mir/place.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -394,8 +394,8 @@ impl<'a, 'tcx, V: CodegenObject> PlaceRef<'tcx, V> {
394394
// Statically compute the offset if we can, otherwise just use the element size,
395395
// as this will yield the lowest alignment.
396396
let layout = self.layout.field(bx, 0);
397-
let offset = if bx.is_const_integral(llindex) {
398-
layout.size.checked_mul(bx.const_to_uint(llindex), bx).unwrap_or(layout.size)
397+
let offset = if let Some(llindex) = bx.const_to_opt_uint(llindex) {
398+
layout.size.checked_mul(llindex, bx).unwrap_or(layout.size)
399399
} else {
400400
layout.size
401401
};

src/librustc_codegen_ssa/mir/rvalue.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
9595
let size = bx.const_usize(dest.layout.size.bytes());
9696

9797
// Use llvm.memset.p0i8.* to initialize all zero arrays
98-
if bx.cx().is_const_integral(v) && bx.cx().const_to_uint(v) == 0 {
98+
if bx.cx().const_to_opt_uint(v) == Some(0) {
9999
let fill = bx.cx().const_u8(0);
100100
bx.memset(start, fill, size, dest.align, MemFlags::empty());
101101
return bx;

src/librustc_codegen_ssa/traits/consts.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,9 @@ pub trait ConstMethods<'tcx>: BackendTypes {
2121

2222
fn const_struct(&self, elts: &[Self::Value], packed: bool) -> Self::Value;
2323

24-
fn const_to_uint(&self, v: Self::Value) -> u64;
24+
fn const_to_opt_uint(&self, v: Self::Value) -> Option<u64>;
2525
fn const_to_opt_u128(&self, v: Self::Value, sign_ext: bool) -> Option<u128>;
2626

27-
fn is_const_integral(&self, v: Self::Value) -> bool;
28-
2927
fn scalar_to_backend(
3028
&self,
3129
cv: Scalar,

0 commit comments

Comments
 (0)