Skip to content

Commit 990a874

Browse files
authored
Store block params separately (#35)
Don't put them in the instruction stream. Instead put them in `Block::params`.
1 parent 5ec3fa2 commit 990a874

File tree

1 file changed

+30
-41
lines changed

1 file changed

+30
-41
lines changed

zjit/src/hir.rs

Lines changed: 30 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -356,8 +356,12 @@ impl Function {
356356
// Add an instruction to an SSA block
357357
fn push_insn(&mut self, block: BlockId, insn: Insn) -> InsnId {
358358
let id = InsnId(self.insns.len());
359+
if let Insn::Param { .. } = &insn {
360+
self.blocks[block.0].params.push(id);
361+
} else {
362+
self.blocks[block.0].insns.push(id);
363+
}
359364
self.insns.push(insn);
360-
self.blocks[block.0].insns.push(id);
361365
id
362366
}
363367

@@ -413,7 +417,15 @@ impl<'a> std::fmt::Display for FunctionPrinter<'a> {
413417
let fun = &self.fun;
414418
for (block_id, block) in fun.blocks.iter().enumerate() {
415419
let block_id = BlockId(block_id);
416-
writeln!(f, "{block_id}:")?;
420+
write!(f, "{block_id}(")?;
421+
if !block.params.is_empty() {
422+
let mut sep = "";
423+
for param in &block.params {
424+
write!(f, "{sep}{param}")?;
425+
sep = ", ";
426+
}
427+
}
428+
writeln!(f, "):")?;
417429
for insn_id in &block.insns {
418430
if !self.display_snapshot && matches!(fun.insns[insn_id.0], Insn::Snapshot {..}) {
419431
continue;
@@ -1083,7 +1095,7 @@ mod tests {
10831095
let iseq = compile_to_iseq(program);
10841096
let function = iseq_to_hir(iseq).unwrap();
10851097
assert_function_hir(function, "
1086-
bb0:
1098+
bb0():
10871099
v1 = Const Value(123)
10881100
v3 = Return v1
10891101
");
@@ -1097,7 +1109,7 @@ mod tests {
10971109
let iseq = compile_to_iseq(program);
10981110
let function = iseq_to_hir(iseq).unwrap();
10991111
assert_function_hir(function, "
1100-
bb0:
1112+
bb0():
11011113
v1 = Const Value(1)
11021114
v3 = Const Value(2)
11031115
v5 = Send v1, :+, v3
@@ -1113,7 +1125,7 @@ mod tests {
11131125
let iseq = compile_to_iseq(program);
11141126
let function = iseq_to_hir(iseq).unwrap();
11151127
assert_function_hir(function, "
1116-
bb0:
1128+
bb0():
11171129
v0 = Const Value(nil)
11181130
v2 = Const Value(1)
11191131
v6 = Return v2
@@ -1128,15 +1140,14 @@ mod tests {
11281140
let iseq = compile_to_iseq(program);
11291141
let function = iseq_to_hir(iseq).unwrap();
11301142
assert_function_hir(function, "
1131-
bb0:
1143+
bb0():
11321144
v0 = Const Value(nil)
11331145
v2 = Const Value(true)
11341146
v6 = Test v2
11351147
v7 = IfFalse v6, bb1(v2)
11361148
v9 = Const Value(3)
11371149
v11 = Return v9
1138-
bb1:
1139-
v12 = Param 0
1150+
bb1(v12):
11401151
v14 = Const Value(4)
11411152
v16 = Return v14
11421153
");
@@ -1151,9 +1162,7 @@ mod tests {
11511162
test(1, 2); test(1, 2)
11521163
");
11531164
assert_method_hir("test", "
1154-
bb0:
1155-
v0 = Param 0
1156-
v1 = Param 1
1165+
bb0(v0, v1):
11571166
v5 = PatchPoint BOPRedefined(INTEGER_REDEFINED_OP_FLAG, BOP_PLUS)
11581167
v6 = GuardType v0, Fixnum
11591168
v7 = GuardType v1, Fixnum
@@ -1171,9 +1180,7 @@ mod tests {
11711180
test(1, 2); test(1, 2)
11721181
");
11731182
assert_method_hir("test", "
1174-
bb0:
1175-
v0 = Param 0
1176-
v1 = Param 1
1183+
bb0(v0, v1):
11771184
v5 = PatchPoint BOPRedefined(INTEGER_REDEFINED_OP_FLAG, BOP_MINUS)
11781185
v6 = GuardType v0, Fixnum
11791186
v7 = GuardType v1, Fixnum
@@ -1191,9 +1198,7 @@ mod tests {
11911198
test(1, 2); test(1, 2)
11921199
");
11931200
assert_method_hir("test", "
1194-
bb0:
1195-
v0 = Param 0
1196-
v1 = Param 1
1201+
bb0(v0, v1):
11971202
v5 = PatchPoint BOPRedefined(INTEGER_REDEFINED_OP_FLAG, BOP_MULT)
11981203
v6 = GuardType v0, Fixnum
11991204
v7 = GuardType v1, Fixnum
@@ -1211,9 +1216,7 @@ mod tests {
12111216
test(1, 2); test(1, 2)
12121217
");
12131218
assert_method_hir("test", "
1214-
bb0:
1215-
v0 = Param 0
1216-
v1 = Param 1
1219+
bb0(v0, v1):
12171220
v5 = PatchPoint BOPRedefined(INTEGER_REDEFINED_OP_FLAG, BOP_DIV)
12181221
v6 = GuardType v0, Fixnum
12191222
v7 = GuardType v1, Fixnum
@@ -1231,9 +1234,7 @@ mod tests {
12311234
test(1, 2); test(1, 2)
12321235
");
12331236
assert_method_hir("test", "
1234-
bb0:
1235-
v0 = Param 0
1236-
v1 = Param 1
1237+
bb0(v0, v1):
12371238
v5 = PatchPoint BOPRedefined(INTEGER_REDEFINED_OP_FLAG, BOP_MOD)
12381239
v6 = GuardType v0, Fixnum
12391240
v7 = GuardType v1, Fixnum
@@ -1251,9 +1252,7 @@ mod tests {
12511252
test(1, 2); test(1, 2)
12521253
");
12531254
assert_method_hir("test", "
1254-
bb0:
1255-
v0 = Param 0
1256-
v1 = Param 1
1255+
bb0(v0, v1):
12571256
v5 = PatchPoint BOPRedefined(INTEGER_REDEFINED_OP_FLAG, BOP_EQ)
12581257
v6 = GuardType v0, Fixnum
12591258
v7 = GuardType v1, Fixnum
@@ -1271,9 +1270,7 @@ mod tests {
12711270
test(1, 2); test(1, 2)
12721271
");
12731272
assert_method_hir("test", "
1274-
bb0:
1275-
v0 = Param 0
1276-
v1 = Param 1
1273+
bb0(v0, v1):
12771274
v5 = PatchPoint BOPRedefined(INTEGER_REDEFINED_OP_FLAG, BOP_NEQ)
12781275
v6 = GuardType v0, Fixnum
12791276
v7 = GuardType v1, Fixnum
@@ -1291,9 +1288,7 @@ mod tests {
12911288
test(1, 2); test(1, 2)
12921289
");
12931290
assert_method_hir("test", "
1294-
bb0:
1295-
v0 = Param 0
1296-
v1 = Param 1
1291+
bb0(v0, v1):
12971292
v5 = PatchPoint BOPRedefined(INTEGER_REDEFINED_OP_FLAG, BOP_LT)
12981293
v6 = GuardType v0, Fixnum
12991294
v7 = GuardType v1, Fixnum
@@ -1311,9 +1306,7 @@ mod tests {
13111306
test(1, 2); test(1, 2)
13121307
");
13131308
assert_method_hir("test", "
1314-
bb0:
1315-
v0 = Param 0
1316-
v1 = Param 1
1309+
bb0(v0, v1):
13171310
v5 = PatchPoint BOPRedefined(INTEGER_REDEFINED_OP_FLAG, BOP_LE)
13181311
v6 = GuardType v0, Fixnum
13191312
v7 = GuardType v1, Fixnum
@@ -1331,9 +1324,7 @@ mod tests {
13311324
test(1, 2); test(1, 2)
13321325
");
13331326
assert_method_hir("test", "
1334-
bb0:
1335-
v0 = Param 0
1336-
v1 = Param 1
1327+
bb0(v0, v1):
13371328
v5 = PatchPoint BOPRedefined(INTEGER_REDEFINED_OP_FLAG, BOP_GT)
13381329
v6 = GuardType v0, Fixnum
13391330
v7 = GuardType v1, Fixnum
@@ -1351,9 +1342,7 @@ mod tests {
13511342
test(1, 2); test(1, 2)
13521343
");
13531344
assert_method_hir("test", "
1354-
bb0:
1355-
v0 = Param 0
1356-
v1 = Param 1
1345+
bb0(v0, v1):
13571346
v5 = PatchPoint BOPRedefined(INTEGER_REDEFINED_OP_FLAG, BOP_GE)
13581347
v6 = GuardType v0, Fixnum
13591348
v7 = GuardType v1, Fixnum

0 commit comments

Comments
 (0)