Skip to content

Commit

Permalink
Merge pull request rust-lang#140 from vext01/cast
Browse files Browse the repository at this point in the history
Serialise sign extend instructions.
  • Loading branch information
ltratt authored Apr 25, 2024
2 parents 8212ae1 + 100eaf8 commit d2eab13
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions llvm/lib/YkIR/YkIRWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ enum OpCode {
OpCodeInsertValue,
OpCodePtrAdd,
OpCodeBinOp,
OpCodeCast,
OpCodeUnimplemented = 255, // YKFIXME: Will eventually be deleted.
};

Expand All @@ -69,6 +70,10 @@ enum TypeKind {
TypeKindUnimplemented = 255, // YKFIXME: Will eventually be deleted.
};

enum CastKind {
CastKindSignExt = 0,
};

// A predicate used in a numeric comparison.
enum CmpPredicate {
PredEqual = 0,
Expand Down Expand Up @@ -603,6 +608,23 @@ class YkIRWriter {
InstIdx++;
}

void serialiseCastKind(enum CastKind Cast) { OutStreamer.emitInt8(Cast); }

/// Serialise a cast-like insruction.
void serialiseSExtInst(SExtInst *I, ValueLoweringMap &VLMap, unsigned BBIdx,
unsigned &InstIdx) {
// opcode:
serialiseOpcode(OpCodeCast);
// cast_kind:
serialiseCastKind(CastKindSignExt);
// val:
serialiseOperand(I, VLMap, I->getOperand(0));
// dest_type_idx:
OutStreamer.emitSizeT(typeIndex(I->getDestTy()));

VLMap[I] = {BBIdx, InstIdx};
InstIdx++;
}
void serialiseInst(Instruction *I, ValueLoweringMap &VLMap, unsigned BBIdx,
unsigned &InstIdx) {
// Macro to make the dispatch below easier to read/sort.
Expand All @@ -621,6 +643,7 @@ class YkIRWriter {
INST_SERIALISE(I, InsertValueInst, serialiseInsertValueInst);
INST_SERIALISE(I, LoadInst, serialiseLoadInst);
INST_SERIALISE(I, ReturnInst, serialiseReturnInst);
INST_SERIALISE(I, SExtInst, serialiseSExtInst);
INST_SERIALISE(I, StoreInst, serialiseStoreInst);

// INST_SERIALISE does an early return upon a match, so if we get here then
Expand Down

0 comments on commit d2eab13

Please sign in to comment.