Skip to content

Commit

Permalink
Serialise switch instructions.
Browse files Browse the repository at this point in the history
  • Loading branch information
vext01 committed Apr 29, 2024
1 parent 94fbc4b commit a789859
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions llvm/lib/YkIR/YkIRWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ enum OpCode {
OpCodeBinOp,
OpCodeCast,
OpCodeDeoptSafepoint,
OpCodeSwitch,
OpCodeUnimplemented = 255, // YKFIXME: Will eventually be deleted.
};

Expand Down Expand Up @@ -653,6 +654,32 @@ class YkIRWriter {
VLMap[I] = {BBIdx, InstIdx};
InstIdx++;
}

void serialiseSwitchInst(SwitchInst *I, ValueLoweringMap &VLMap,
unsigned BBIdx, unsigned &InstIdx) {
// opcode:
serialiseOpcode(OpCodeSwitch);
// test_val:
serialiseOperand(I, VLMap, I->getCondition());
// default_dest:
serialiseBlockLabel(I->getDefaultDest());
// num_cases:
assert(I->getNumCases() == std::distance(I->case_begin(), I->case_end()));
OutStreamer.emitSizeT(I->getNumCases());
// case_values:
for (auto &Case : I->cases()) {
// We can't handle case values larger than uint64_t for now.
assert(Case.getCaseValue()->getBitWidth() <= 64);
OutStreamer.emitInt64(Case.getCaseValue()->getZExtValue());
}
// case_dests:
for (auto &Case : I->cases()) {
serialiseBlockLabel(Case.getCaseSuccessor());
}

InstIdx++;
}

void serialiseInst(Instruction *I, ValueLoweringMap &VLMap, unsigned BBIdx,
unsigned &InstIdx) {
// Macro to make the dispatch below easier to read/sort.
Expand All @@ -673,6 +700,7 @@ class YkIRWriter {
INST_SERIALISE(I, ReturnInst, serialiseReturnInst);
INST_SERIALISE(I, SExtInst, serialiseSExtInst);
INST_SERIALISE(I, StoreInst, serialiseStoreInst);
INST_SERIALISE(I, SwitchInst, serialiseSwitchInst);

// INST_SERIALISE does an early return upon a match, so if we get here then
// the instruction wasn't handled.
Expand Down

0 comments on commit a789859

Please sign in to comment.