@@ -619,13 +619,46 @@ class YkIRWriter {
619
619
620
620
void serialiseBlock (BasicBlock &BB, ValueLoweringMap &VLMap,
621
621
unsigned &BBIdx) {
622
+ // Keep the instruction skipping logic in one place.
623
+ auto ShouldSkipInstr = [](Instruction *I) {
624
+ // Skip non-semantic instrucitons for now.
625
+ //
626
+ // We may come back to them later if we need better debugging
627
+ // facilities, but for now they just clutter up our AOT module.
628
+ return I->isDebugOrPseudoInst ();
629
+ };
630
+
631
+ // Count instructions.
632
+ //
633
+ // FIXME: I don't like this much:
634
+ //
635
+ // - Assumes one LLVM instruction becomes exactly one Yk IR instruction.
636
+ // - Requires a second loop to count ahead of time.
637
+ //
638
+ // Can we emit the instrucitons into a temp buffer and keep a running count
639
+ // of how many instructions we generated instead?
640
+ size_t NumInstrs = 0 ;
641
+ for (Instruction &I : BB) {
642
+ if (ShouldSkipInstr (&I)) {
643
+ continue ;
644
+ }
645
+ NumInstrs++;
646
+ }
647
+
622
648
// num_instrs:
623
- OutStreamer.emitSizeT (BB. size () );
649
+ OutStreamer.emitSizeT (NumInstrs );
624
650
// instrs:
625
651
unsigned InstIdx = 0 ;
626
652
for (Instruction &I : BB) {
653
+ if (ShouldSkipInstr (&I)) {
654
+ continue ;
655
+ }
627
656
serialiseInst (&I, VLMap, BBIdx, InstIdx);
628
657
}
658
+
659
+ // Check we emitted the number of instructions that we promised.
660
+ assert (InstIdx == NumInstrs);
661
+
629
662
BBIdx++;
630
663
}
631
664
0 commit comments