From 73566fea0d89c3e942ac6bb9fb195fc13765cdba Mon Sep 17 00:00:00 2001 From: Lukas Diekmann Date: Tue, 13 Feb 2024 11:17:50 +0000 Subject: [PATCH] Fix tests and make ptradd instruction packed. --- tests/ir_lowering/empty.ll | 1 + ykrt/src/compile/jitc_yk/aot_ir.rs | 14 +++++++++++++- ykrt/src/compile/jitc_yk/jit_ir.rs | 18 +++++++++++++++++- 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/tests/ir_lowering/empty.ll b/tests/ir_lowering/empty.ll index 44ac2da14..af3dead63 100644 --- a/tests/ir_lowering/empty.ll +++ b/tests/ir_lowering/empty.ll @@ -3,6 +3,7 @@ ; # IR format version: 0 ; # Num funcs: 1 ; # Num consts: 0 +; # Num globals: 0 ; # Num types: 2 ; ; func main() { diff --git a/ykrt/src/compile/jitc_yk/aot_ir.rs b/ykrt/src/compile/jitc_yk/aot_ir.rs index 8fa3fe765..991d199a2 100644 --- a/ykrt/src/compile/jitc_yk/aot_ir.rs +++ b/ykrt/src/compile/jitc_yk/aot_ir.rs @@ -909,6 +909,7 @@ impl Module { ret.push_str(&format!("# IR format version: {}\n", self.version)); ret.push_str(&format!("# Num funcs: {}\n", self.funcs.len())); ret.push_str(&format!("# Num consts: {}\n", self.consts.len())); + ret.push_str(&format!("# Num globals: {}\n", self.globals.len())); ret.push_str(&format!("# Num types: {}\n", self.types.len())); for func in &self.funcs { @@ -1177,6 +1178,16 @@ mod tests { // bytes: data.write_u32::(50).unwrap(); + // GLOBALS + // num_globals: + write_native_usize(&mut data, 1); + + // GLOBAL 1 + // is_threadlocal: + let _ = data.write_u8(0); + // name: + write_str(&mut data, "aaa"); + // TYPES // num_types: write_native_usize(&mut data, 7); @@ -1246,6 +1257,7 @@ mod tests { # IR format version: 0 # Num funcs: 2 # Num consts: 3 +# Num globals: 1 # Num types: 7 func foo($arg0: ptr, $arg1: i32) -> i32 { @@ -1255,7 +1267,7 @@ func foo($arg0: ptr, $arg1: i32) -> i32 { condbr $0_0, bb0, bb1 bb1: ?inst<%3 = some_llvm_instruction ...> - $1_1: ptr = getelementptr -1i32 + $1_1: ptr = ptradd -1i32 $1_2: ptr = alloca i32, 50i32 $1_3: ptr = call bar(50i32, 50i32) br diff --git a/ykrt/src/compile/jitc_yk/jit_ir.rs b/ykrt/src/compile/jitc_yk/jit_ir.rs index 1efe6ba1d..8c935cb5e 100644 --- a/ykrt/src/compile/jitc_yk/jit_ir.rs +++ b/ykrt/src/compile/jitc_yk/jit_ir.rs @@ -507,6 +507,7 @@ impl fmt::Display for StoreGlobalInstruction { /// Returns a pointer value that is the result of adding the specified (byte) offset to the input /// pointer operand. #[derive(Debug)] +#[repr(packed)] pub struct PtrAddInstruction { /// The pointer to offset ptr: PackedOperand, @@ -514,9 +515,19 @@ pub struct PtrAddInstruction { off: u32, } +impl PtrAddInstruction { + fn ptr(&self) -> Operand { + let ptr = self.ptr; + ptr.get() + } + fn offset(&self) -> u32 { + self.off + } +} + impl fmt::Display for PtrAddInstruction { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "PtrAdd {}, {}", self.ptr.get(), self.off) + write!(f, "PtrAdd {}, {}", self.ptr(), self.offset()) } } @@ -662,6 +673,11 @@ mod tests { #[test] fn instr_size() { assert_eq!(mem::size_of::(), 7); + assert_eq!(mem::size_of::(), 4); + assert_eq!(mem::size_of::(), 6); + assert_eq!(mem::size_of::(), 6); + assert_eq!(mem::size_of::(), 6); + assert_eq!(mem::size_of::(), 6); assert!(mem::size_of::() <= mem::size_of::()); }