about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2021-01-28 15:19:16 +0000
committerbors <bors@rust-lang.org>2021-01-28 15:19:16 +0000
commitbf193d69fe48f4ec3cac57ab7abb4e9f2a291661 (patch)
tree00d12382e71d698743c2d1006823cd4cf03108cf
parent643a79af3d5a31fa87c8a4c9d7f8bc4ebe2add4b (diff)
parent20982b386fa9908f11d4c0b6db8c9ccf53700f8b (diff)
downloadrust-bf193d69fe48f4ec3cac57ab7abb4e9f2a291661.tar.gz
rust-bf193d69fe48f4ec3cac57ab7abb4e9f2a291661.zip
Auto merge of #81441 - tmiasko:ctfe-inline, r=oli-obk
Try inlining trivial functions used by CTFE

r? `@ghost`
-rw-r--r--compiler/rustc_mir/src/interpret/place.rs1
-rw-r--r--compiler/rustc_target/src/abi/mod.rs20
2 files changed, 19 insertions, 2 deletions
diff --git a/compiler/rustc_mir/src/interpret/place.rs b/compiler/rustc_mir/src/interpret/place.rs
index a003380dda7..efde7fe6948 100644
--- a/compiler/rustc_mir/src/interpret/place.rs
+++ b/compiler/rustc_mir/src/interpret/place.rs
@@ -153,6 +153,7 @@ impl<Tag> MemPlace<Tag> {
         }
     }
 
+    #[inline]
     pub fn offset(
         self,
         offset: Size,
diff --git a/compiler/rustc_target/src/abi/mod.rs b/compiler/rustc_target/src/abi/mod.rs
index 93868bed9b9..88b2923f6c4 100644
--- a/compiler/rustc_target/src/abi/mod.rs
+++ b/compiler/rustc_target/src/abi/mod.rs
@@ -441,16 +441,28 @@ pub struct Align {
 }
 
 impl Align {
+    #[inline]
     pub fn from_bits(bits: u64) -> Result<Align, String> {
         Align::from_bytes(Size::from_bits(bits).bytes())
     }
 
+    #[inline]
     pub fn from_bytes(align: u64) -> Result<Align, String> {
         // Treat an alignment of 0 bytes like 1-byte alignment.
         if align == 0 {
             return Ok(Align { pow2: 0 });
         }
 
+        #[cold]
+        fn not_power_of_2(align: u64) -> String {
+            format!("`{}` is not a power of 2", align)
+        }
+
+        #[cold]
+        fn too_large(align: u64) -> String {
+            format!("`{}` is too large", align)
+        }
+
         let mut bytes = align;
         let mut pow2: u8 = 0;
         while (bytes & 1) == 0 {
@@ -458,19 +470,21 @@ impl Align {
             bytes >>= 1;
         }
         if bytes != 1 {
-            return Err(format!("`{}` is not a power of 2", align));
+            return Err(not_power_of_2(align));
         }
         if pow2 > 29 {
-            return Err(format!("`{}` is too large", align));
+            return Err(too_large(align));
         }
 
         Ok(Align { pow2 })
     }
 
+    #[inline]
     pub fn bytes(self) -> u64 {
         1 << self.pow2
     }
 
+    #[inline]
     pub fn bits(self) -> u64 {
         self.bytes() * 8
     }
@@ -479,12 +493,14 @@ impl Align {
     /// (the largest power of two that the offset is a multiple of).
     ///
     /// N.B., for an offset of `0`, this happens to return `2^64`.
+    #[inline]
     pub fn max_for_offset(offset: Size) -> Align {
         Align { pow2: offset.bytes().trailing_zeros() as u8 }
     }
 
     /// Lower the alignment, if necessary, such that the given offset
     /// is aligned to it (the offset is a multiple of the alignment).
+    #[inline]
     pub fn restrict_for_offset(self, offset: Size) -> Align {
         self.min(Align::max_for_offset(offset))
     }