Skip to content

Commit 043e82b

Browse files
committed
Lower PtrToInst instructions.
1 parent c645c79 commit 043e82b

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

llvm/lib/YkIR/YkIRWriter.cpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -889,6 +889,40 @@ class YkIRWriter {
889889
InstIdx++;
890890
}
891891

892+
/// Serialise ptrtoint instruction.
893+
void serialisePtrToIntInst(PtrToIntInst *I, FuncLowerCtxt &FLCtxt,
894+
unsigned BBIdx, unsigned &InstIdx) {
895+
if (I->getType()->isVectorTy()) {
896+
// Vector variants are currently not supported.
897+
serialiseUnimplementedInstruction(I, FLCtxt, BBIdx, InstIdx);
898+
return;
899+
}
900+
DataLayout DL(&M);
901+
TypeSize SrcSize = DL.getTypeSizeInBits(I->getSrcTy());
902+
TypeSize DstSize = DL.getTypeSizeInBits(I->getDestTy());
903+
904+
if (SrcSize <= DstSize) {
905+
// Zero extend
906+
// FIXME: We probably want to lower same-sized types to a bitcast, but
907+
// zeroextend will do for now.
908+
// opcode:
909+
serialiseOpcode(OpCodeCast);
910+
// cast_kind:
911+
serialiseCastKind(CastKindZeroExt);
912+
// val:
913+
serialiseOperand(I, FLCtxt, I->getPointerOperand());
914+
// dest_type_idx:
915+
OutStreamer.emitSizeT(typeIndex(I->getDestTy()));
916+
} else if (SrcSize > DstSize) {
917+
// Truncate
918+
serialiseUnimplementedInstruction(I, FLCtxt, BBIdx, InstIdx);
919+
return;
920+
}
921+
922+
FLCtxt.updateVLMap(I, InstIdx);
923+
InstIdx++;
924+
}
925+
892926
void serialiseSwitchInst(SwitchInst *I, FuncLowerCtxt &FLCtxt, unsigned BBIdx,
893927
unsigned &InstIdx) {
894928
// opcode:
@@ -959,6 +993,7 @@ class YkIRWriter {
959993
INST_SERIALISE(I, SExtInst, serialiseSExtInst);
960994
INST_SERIALISE(I, StoreInst, serialiseStoreInst);
961995
INST_SERIALISE(I, SwitchInst, serialiseSwitchInst);
996+
INST_SERIALISE(I, PtrToIntInst, serialisePtrToIntInst);
962997

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

0 commit comments

Comments
 (0)