Skip to content

Commit c47d7c9

Browse files
authored
Merge pull request rust-lang#158 from ptersilie/lower_ptrtoint
Lower PtrToInst instructions.
2 parents f2208d3 + 043e82b commit c47d7c9

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
@@ -954,6 +954,40 @@ class YkIRWriter {
954954
InstIdx++;
955955
}
956956

957+
/// Serialise ptrtoint instruction.
958+
void serialisePtrToIntInst(PtrToIntInst *I, FuncLowerCtxt &FLCtxt,
959+
unsigned BBIdx, unsigned &InstIdx) {
960+
if (I->getType()->isVectorTy()) {
961+
// Vector variants are currently not supported.
962+
serialiseUnimplementedInstruction(I, FLCtxt, BBIdx, InstIdx);
963+
return;
964+
}
965+
DataLayout DL(&M);
966+
TypeSize SrcSize = DL.getTypeSizeInBits(I->getSrcTy());
967+
TypeSize DstSize = DL.getTypeSizeInBits(I->getDestTy());
968+
969+
if (SrcSize <= DstSize) {
970+
// Zero extend
971+
// FIXME: We probably want to lower same-sized types to a bitcast, but
972+
// zeroextend will do for now.
973+
// opcode:
974+
serialiseOpcode(OpCodeCast);
975+
// cast_kind:
976+
serialiseCastKind(CastKindZeroExt);
977+
// val:
978+
serialiseOperand(I, FLCtxt, I->getPointerOperand());
979+
// dest_type_idx:
980+
OutStreamer.emitSizeT(typeIndex(I->getDestTy()));
981+
} else if (SrcSize > DstSize) {
982+
// Truncate
983+
serialiseUnimplementedInstruction(I, FLCtxt, BBIdx, InstIdx);
984+
return;
985+
}
986+
987+
FLCtxt.updateVLMap(I, InstIdx);
988+
InstIdx++;
989+
}
990+
957991
void serialiseSwitchInst(SwitchInst *I, FuncLowerCtxt &FLCtxt, unsigned BBIdx,
958992
unsigned &InstIdx) {
959993
// opcode:
@@ -1034,6 +1068,7 @@ class YkIRWriter {
10341068
INST_SERIALISE(I, SExtInst, serialiseSExtInst);
10351069
INST_SERIALISE(I, StoreInst, serialiseStoreInst);
10361070
INST_SERIALISE(I, SwitchInst, serialiseSwitchInst);
1071+
INST_SERIALISE(I, PtrToIntInst, serialisePtrToIntInst);
10371072

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

0 commit comments

Comments
 (0)