Skip to content

Commit 9cb7ad9

Browse files
authored
Merge pull request rust-lang#137 from vext01/more-flexible-lowering
Make serialising Yk IR instructions more flexible.
2 parents 502f743 + 95e95f2 commit 9cb7ad9

File tree

1 file changed

+11
-20
lines changed

1 file changed

+11
-20
lines changed

llvm/lib/YkIR/YkIRWriter.cpp

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -642,7 +642,6 @@ class YkIRWriter {
642642

643643
void serialiseBlock(BasicBlock &BB, ValueLoweringMap &VLMap,
644644
unsigned &BBIdx) {
645-
// Keep the instruction skipping logic in one place.
646645
auto ShouldSkipInstr = [](Instruction *I) {
647646
// Skip non-semantic instrucitons for now.
648647
//
@@ -662,25 +661,15 @@ class YkIRWriter {
662661
return false;
663662
};
664663

665-
// Count instructions.
666-
//
667-
// FIXME: I don't like this much:
668-
//
669-
// - Assumes one LLVM instruction becomes exactly one Yk IR instruction.
670-
// - Requires a second loop to count ahead of time.
664+
// num_instrs:
671665
//
672-
// Can we emit the instrucitons into a temp buffer and keep a running count
673-
// of how many instructions we generated instead?
674-
size_t NumInstrs = 0;
675-
for (Instruction &I : BB) {
676-
if (ShouldSkipInstr(&I)) {
677-
continue;
678-
}
679-
NumInstrs++;
680-
}
666+
// We don't know how many instructions there will be in advance, so what we
667+
// do is emit a placeholder field (in the form of a symbol value) which is
668+
// patched up (assigned) later.
669+
MCContext &MCtxt = OutStreamer.getContext();
670+
MCSymbol *NumInstrsSym = MCtxt.createTempSymbol();
671+
OutStreamer.emitSymbolValue(NumInstrsSym, sizeof(size_t));
681672

682-
// num_instrs:
683-
OutStreamer.emitSizeT(NumInstrs);
684673
// instrs:
685674
unsigned InstIdx = 0;
686675
for (Instruction &I : BB) {
@@ -690,8 +679,10 @@ class YkIRWriter {
690679
serialiseInst(&I, VLMap, BBIdx, InstIdx);
691680
}
692681

693-
// Check we emitted the number of instructions that we promised.
694-
assert(InstIdx == NumInstrs);
682+
// Now that we have finished serialising instructions, we know how many
683+
// there are and we can patch up the "number of instructions" field.
684+
OutStreamer.emitAssignment(NumInstrsSym,
685+
MCConstantExpr::create(InstIdx, MCtxt));
695686

696687
BBIdx++;
697688
}

0 commit comments

Comments
 (0)