Skip to content

Commit

Permalink
Fix tests and make ptradd instruction packed.
Browse files Browse the repository at this point in the history
  • Loading branch information
ptersilie committed Feb 13, 2024
1 parent e9f4c62 commit 73566fe
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
1 change: 1 addition & 0 deletions tests/ir_lowering/empty.ll
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
; # IR format version: 0
; # Num funcs: 1
; # Num consts: 0
; # Num globals: 0
; # Num types: 2
;
; func main() {
Expand Down
14 changes: 13 additions & 1 deletion ykrt/src/compile/jitc_yk/aot_ir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -1177,6 +1178,16 @@ mod tests {
// bytes:
data.write_u32::<NativeEndian>(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);
Expand Down Expand Up @@ -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 {
Expand All @@ -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
Expand Down
18 changes: 17 additions & 1 deletion ykrt/src/compile/jitc_yk/jit_ir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -507,16 +507,27 @@ 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,
/// The offset.
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())
}
}

Expand Down Expand Up @@ -662,6 +673,11 @@ mod tests {
#[test]
fn instr_size() {
assert_eq!(mem::size_of::<CallInstruction>(), 7);
assert_eq!(mem::size_of::<StoreInstruction>(), 4);
assert_eq!(mem::size_of::<LoadInstruction>(), 6);
assert_eq!(mem::size_of::<LoadGlobalInstruction>(), 6);
assert_eq!(mem::size_of::<StoreGlobalInstruction>(), 6);
assert_eq!(mem::size_of::<PtrAddInstruction>(), 6);
assert!(mem::size_of::<Instruction>() <= mem::size_of::<u64>());
}

Expand Down

0 comments on commit 73566fe

Please sign in to comment.