diff --git a/cranelift/codegen/meta/src/isa/x86/encodings.rs b/cranelift/codegen/meta/src/isa/x86/encodings.rs index ab929011b7..9c7ff89615 100644 --- a/cranelift/codegen/meta/src/isa/x86/encodings.rs +++ b/cranelift/codegen/meta/src/isa/x86/encodings.rs @@ -279,7 +279,8 @@ impl PerCpuModeEncodings { } } - /// Add the same encoding to both X86_32 and X86_64; assumes configuration (e.g. REX, operand binding) has already happened + /// Add the same encoding to both X86_32 and X86_64; assumes configuration (e.g. REX, operand + /// binding) has already happened. fn enc_32_64_maybe_isap( &mut self, inst: impl Clone + Into, diff --git a/cranelift/codegen/src/binemit/mod.rs b/cranelift/codegen/src/binemit/mod.rs index d6ca75d2d9..0123e4dbd3 100644 --- a/cranelift/codegen/src/binemit/mod.rs +++ b/cranelift/codegen/src/binemit/mod.rs @@ -185,7 +185,7 @@ where sink.begin_jumptables(); - // output jump tables + // Output jump tables. for (jt, jt_data) in func.jump_tables.iter() { let jt_offset = func.jt_offsets[jt]; for ebb in jt_data.iter() { @@ -196,7 +196,7 @@ where sink.begin_rodata(); - // output constants + // Output constants. for (_, constant_data) in func.dfg.constants.iter() { for byte in constant_data.iter() { sink.put1(*byte) diff --git a/cranelift/codegen/src/binemit/relaxation.rs b/cranelift/codegen/src/binemit/relaxation.rs index bd09d473d2..43f361885a 100644 --- a/cranelift/codegen/src/binemit/relaxation.rs +++ b/cranelift/codegen/src/binemit/relaxation.rs @@ -129,8 +129,7 @@ pub fn relax_branches( for (jt, jt_data) in func.jump_tables.iter() { func.jt_offsets[jt] = offset; - // TODO: this should be computed based on the min size needed to hold - // the furthest branch. + // TODO: this should be computed based on the min size needed to hold the furthest branch. offset += jt_data.len() as u32 * 4; } diff --git a/cranelift/codegen/src/ir/constant.rs b/cranelift/codegen/src/ir/constant.rs index 50e93df1ab..c22380db55 100644 --- a/cranelift/codegen/src/ir/constant.rs +++ b/cranelift/codegen/src/ir/constant.rs @@ -1,9 +1,12 @@ //! Constants //! -//! The constant pool defined here allows cranelift to avoid emitting the same constant multiple -//! times. As constants are inserted in the pool, a handle is returned; the handle is a cranelift -//! Entity. Inserting the same data multiple times will always return the same handle. Future work -//! could include: ensuring alignment of constants within the pool, bucketing constants by size. +//! The constant pool defined here allows Cranelift to avoid emitting the same constant multiple +//! times. As constants are inserted in the pool, a handle is returned; the handle is a Cranelift +//! Entity. Inserting the same data multiple times will always return the same handle. +//! +//! Future work could include: +//! - ensuring alignment of constants within the pool, +//! - bucketing constants by size. use crate::ir::Constant; use cranelift_entity::EntityRef; @@ -19,8 +22,8 @@ pub type ConstantOffset = u32; /// Inner type for storing data and offset together in the constant pool. The offset is optional /// because it must be set relative to the function code size (i.e. constants are emitted after the /// function body); because the function is not yet compiled when constants are inserted, -/// [`set_offset`](crate::ir::ConstantPool::set_offset) must be called once a constant's -/// offset from the beginning of the function is known (see +/// [`set_offset`](crate::ir::ConstantPool::set_offset) must be called once a constant's offset +/// from the beginning of the function is known (see /// [`relaxation.rs`](crate::binemit::relaxation)). #[derive(Clone)] pub struct ConstantPoolEntry { @@ -30,7 +33,7 @@ pub struct ConstantPoolEntry { impl ConstantPoolEntry { fn new(data: ConstantData) -> Self { - ConstantPoolEntry { data, offset: None } + Self { data, offset: None } } /// Return the size of the constant at this entry. @@ -44,21 +47,23 @@ impl ConstantPoolEntry { } } -/// Maintains the mapping between a constant handle (i.e. -/// [`Constant`](crate::ir::Constant)) and its constant data (i.e. -/// [`ConstantData`](crate::ir::ConstantData)). +/// Maintains the mapping between a constant handle (i.e. [`Constant`](crate::ir::Constant)) and +/// its constant data (i.e. [`ConstantData`](crate::ir::ConstantData)). #[derive(Clone)] pub struct ConstantPool { - /// This mapping maintains the insertion order as long as Constants are created with sequentially increasing integers. + /// This mapping maintains the insertion order as long as Constants are created with + /// sequentially increasing integers. handles_to_values: BTreeMap, - /// This mapping is unordered (no need for lexicographic ordering) but allows us to map constant data back to handles. + + /// This mapping is unordered (no need for lexicographic ordering) but allows us to map + /// constant data back to handles. values_to_handles: HashMap, } impl ConstantPool { /// Create a new constant pool instance. pub fn new() -> Self { - ConstantPool { + Self { handles_to_values: BTreeMap::new(), values_to_handles: HashMap::new(), } @@ -75,10 +80,7 @@ impl ConstantPool { /// returned. pub fn insert(&mut self, constant_value: ConstantData) -> Constant { if self.values_to_handles.contains_key(&constant_value) { - self.values_to_handles - .get(&constant_value) - .expect("A constant handle must have a corresponding constant value; this is an implementation error in ConstantPool") - .clone() + self.values_to_handles.get(&constant_value).unwrap().clone() } else { let constant_handle = Constant::new(self.len()); self.values_to_handles @@ -94,16 +96,17 @@ impl ConstantPool { /// Retrieve the constant data given a handle. pub fn get(&self, constant_handle: Constant) -> &ConstantData { assert!(self.handles_to_values.contains_key(&constant_handle)); - &self.handles_to_values - .get(&constant_handle) - .expect("A constant handle must have a corresponding constant value; was a constant handle created outside of the pool?") - .data + &self.handles_to_values.get(&constant_handle).unwrap().data } /// Assign an offset to a given constant, where the offset is the number of bytes from the /// beginning of the function to the beginning of the constant data inside the pool. pub fn set_offset(&mut self, constant_handle: Constant, constant_offset: ConstantOffset) { - assert!(self.handles_to_values.contains_key(&constant_handle), "A constant handle must have already been inserted into the pool; perhaps a constant pool was created outside of the pool?"); + assert!( + self.handles_to_values.contains_key(&constant_handle), + "A constant handle must have already been inserted into the pool; perhaps a \ + constant pool was created outside of the pool?" + ); self.handles_to_values .entry(constant_handle) .and_modify(|e| e.offset = Some(constant_offset)); @@ -112,10 +115,17 @@ impl ConstantPool { /// Retrieve the offset of a given constant, where the offset is the number of bytes from the /// beginning of the function to the beginning of the constant data inside the pool. pub fn get_offset(&self, constant_handle: Constant) -> ConstantOffset { - self.handles_to_values.get(&constant_handle) - .expect("A constant handle must have a corresponding constant value; was a constant handle created outside of the pool?") + self.handles_to_values + .get(&constant_handle) + .expect( + "A constant handle must have a corresponding constant value; was a constant \ + handle created outside of the pool?", + ) .offset - .expect("A constant offset has not yet been set; verify that `set_offset` has been called before this point") + .expect( + "A constant offset has not yet been set; verify that `set_offset` has been \ + called before this point", + ) } /// Iterate over the constants in insertion order. diff --git a/cranelift/codegen/src/ir/immediates.rs b/cranelift/codegen/src/ir/immediates.rs index d69aed4390..2c5ee27c47 100644 --- a/cranelift/codegen/src/ir/immediates.rs +++ b/cranelift/codegen/src/ir/immediates.rs @@ -292,7 +292,7 @@ impl FromStr for Uimm32 { /// A 128-bit unsigned integer immediate operand. /// -/// This is used as an immediate value in SIMD instructions +/// This is used as an immediate value in SIMD instructions. #[derive(Copy, Clone, PartialEq, Eq, Debug, Hash)] pub struct Uimm128(pub [u8; 16]); @@ -314,7 +314,7 @@ impl Uimm128 { } impl Display for Uimm128 { - // print a 128-bit vector in hexadecimal, e.g. 0x000102030405060708090a0b0c0d0e0f + // Print a 128-bit vector in hexadecimal, e.g. 0x000102030405060708090a0b0c0d0e0f. fn fmt(&self, f: &mut Formatter) -> fmt::Result { write!(f, "0x")?; let mut anything_written = false; diff --git a/cranelift/reader/src/parser.rs b/cranelift/reader/src/parser.rs index 6971ca663d..7965a4a31a 100644 --- a/cranelift/reader/src/parser.rs +++ b/cranelift/reader/src/parser.rs @@ -595,7 +595,8 @@ impl<'a> Parser<'a> { } } - // Match and consume a Uimm128 immediate; due to size restrictions on InstructionData, Uimm128 is boxed in cranelift-codegen/meta/src/shared/immediates.rs + // Match and consume a Uimm128 immediate; due to size restrictions on InstructionData, Uimm128 + // is boxed in cranelift-codegen/meta/src/shared/immediates.rs fn match_uimm128(&mut self, err_msg: &str) -> ParseResult { if let Some(Token::Integer(text)) = self.token() { self.consume();