]> git.lizzy.rs Git - rust.git/commitdiff
Remove is_const_integral method from ConstMethods
authorbjorn3 <bjorn3@users.noreply.github.com>
Tue, 27 Aug 2019 09:51:53 +0000 (11:51 +0200)
committerbjorn3 <bjorn3@users.noreply.github.com>
Sun, 13 Oct 2019 12:35:14 +0000 (14:35 +0200)
src/librustc_codegen_llvm/common.rs
src/librustc_codegen_ssa/mir/place.rs
src/librustc_codegen_ssa/mir/rvalue.rs
src/librustc_codegen_ssa/traits/consts.rs

index d1a7b4dd6bf75684522ebf733855ba9c8e8a933a..cc2f1b6776e457b002a489c0e9751206a0aa493d 100644 (file)
@@ -245,21 +245,19 @@ fn const_struct(
         struct_in_context(self.llcx, elts, packed)
     }
 
-    fn const_to_uint(&self, v: &'ll Value) -> u64 {
-        unsafe {
-            llvm::LLVMConstIntGetZExtValue(v)
-        }
-    }
-
-    fn is_const_integral(&self, v: &'ll Value) -> bool {
-        unsafe {
-            llvm::LLVMIsAConstantInt(v).is_some()
+    fn const_to_opt_uint(&self, v: &'ll Value) -> Option<u64> {
+        if is_const_integral(v) {
+            unsafe {
+                Some(llvm::LLVMConstIntGetZExtValue(v))
+            }
+        } else {
+            None
         }
     }
 
     fn const_to_opt_u128(&self, v: &'ll Value, sign_ext: bool) -> Option<u128> {
         unsafe {
-            if self.is_const_integral(v) {
+            if is_const_integral(v) {
                 let (mut lo, mut hi) = (0u64, 0u64);
                 let success = llvm::LLVMRustConstInt128Get(v, sign_ext,
                                                            &mut hi, &mut lo);
@@ -388,3 +386,9 @@ pub fn struct_in_context(
 fn hi_lo_to_u128(lo: u64, hi: u64) -> u128 {
     ((hi as u128) << 64) | (lo as u128)
 }
+
+fn is_const_integral(v: &'ll Value) -> bool {
+    unsafe {
+        llvm::LLVMIsAConstantInt(v).is_some()
+    }
+}
index 2d97f828f073de5ab50238f799b78c3916efc390..1d1bc2a81a2ca7459205a34391f665b92ec35a4e 100644 (file)
@@ -394,8 +394,8 @@ pub fn project_index<Bx: BuilderMethods<'a, 'tcx, Value = V>>(
         // Statically compute the offset if we can, otherwise just use the element size,
         // as this will yield the lowest alignment.
         let layout = self.layout.field(bx, 0);
-        let offset = if bx.is_const_integral(llindex) {
-            layout.size.checked_mul(bx.const_to_uint(llindex), bx).unwrap_or(layout.size)
+        let offset = if let Some(llindex) = bx.const_to_opt_uint(llindex) {
+            layout.size.checked_mul(llindex, bx).unwrap_or(layout.size)
         } else {
             layout.size
         };
index 978e7218aa745f1afb7f53e986b337c319c34148..3e88c7379daf8e57182efb64873c2a31fb539d48 100644 (file)
@@ -95,7 +95,7 @@ pub fn codegen_rvalue(
                     let size = bx.const_usize(dest.layout.size.bytes());
 
                     // 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);
                         bx.memset(start, fill, size, dest.align, MemFlags::empty());
                         return bx;
index e7ce03f1836198293376a553e1e5ee7027ae4f74..95ada60fae08dd74ffc6f926967232489a27e50d 100644 (file)
@@ -21,11 +21,9 @@ pub trait ConstMethods<'tcx>: BackendTypes {
 
     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 is_const_integral(&self, v: Self::Value) -> bool;
-
     fn scalar_to_backend(
         &self,
         cv: Scalar,