Skip to content

Commit 21ed80c

Browse files
authored
Merge pull request rust-lang#124 from vext01/misc
Tweak successor lowering / filter out debug instructions from AOT IR.
2 parents 0ec612c + 3d6427a commit 21ed80c

File tree

1 file changed

+38
-4
lines changed

1 file changed

+38
-4
lines changed

llvm/lib/YkIR/YkIRWriter.cpp

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -459,16 +459,17 @@ class YkIRWriter {
459459
//
460460
// Note that in LLVM IR, the operands are ordered (despite the order they
461461
// appear in the language reference): cond, if-false, if-true. We
462-
// re-order those during lowering to avoid confusion.
462+
// use `getSuccessor()`, so as to re-order those during lowering to avoid
463+
// confusion.
463464
//
464465
// num_operands:
465466
OutStreamer.emitInt32(3);
466467
// OPERAND 0: condition.
467468
serialiseOperand(I, VLMap, I->getOperand(0));
468469
// OPERAND 1: block to go to if true.
469-
serialiseOperand(I, VLMap, I->getOperand(2));
470+
serialiseOperand(I, VLMap, I->getSuccessor(0));
470471
// OPERAND 2: block to go to if false.
471-
serialiseOperand(I, VLMap, I->getOperand(1));
472+
serialiseOperand(I, VLMap, I->getSuccessor(1));
472473
}
473474
InstIdx++;
474475
}
@@ -618,13 +619,46 @@ class YkIRWriter {
618619

619620
void serialiseBlock(BasicBlock &BB, ValueLoweringMap &VLMap,
620621
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+
621648
// num_instrs:
622-
OutStreamer.emitSizeT(BB.size());
649+
OutStreamer.emitSizeT(NumInstrs);
623650
// instrs:
624651
unsigned InstIdx = 0;
625652
for (Instruction &I : BB) {
653+
if (ShouldSkipInstr(&I)) {
654+
continue;
655+
}
626656
serialiseInst(&I, VLMap, BBIdx, InstIdx);
627657
}
658+
659+
// Check we emitted the number of instructions that we promised.
660+
assert(InstIdx == NumInstrs);
661+
628662
BBIdx++;
629663
}
630664

0 commit comments

Comments
 (0)