Skip to content

Commit ef1ca9f

Browse files
authored
Merge pull request rust-lang#165 from ptersilie/trunc
Lower TruncInst.
2 parents a90dbe0 + be6569c commit ef1ca9f

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

llvm/lib/YkIR/YkIRWriter.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ enum TypeKind {
7878
enum CastKind {
7979
CastKindSignExt = 0,
8080
CastKindZeroExt = 1,
81+
CastKindTrunc = 2,
8182
};
8283

8384
// A predicate used in a numeric comparison.
@@ -963,6 +964,36 @@ class YkIRWriter {
963964
InstIdx++;
964965
}
965966

967+
/// Serialise a trunc instruction.
968+
void serialiseTruncInst(TruncInst *I, FuncLowerCtxt &FLCtxt, unsigned BBIdx,
969+
unsigned &InstIdx) {
970+
// We don't support vectors.
971+
if (I->getOperand(0)->getType()->isVectorTy()) {
972+
serialiseUnimplementedInstruction(I, FLCtxt, BBIdx, InstIdx);
973+
return;
974+
}
975+
976+
DataLayout DL(&M);
977+
TypeSize SrcSize = DL.getTypeSizeInBits(I->getSrcTy());
978+
TypeSize DstSize = DL.getTypeSizeInBits(I->getDestTy());
979+
980+
// The bit size of the value must be larger than the bit size of the
981+
// destination type.
982+
assert(SrcSize > DstSize);
983+
984+
// opcode:
985+
serialiseOpcode(OpCodeCast);
986+
// cast_kind:
987+
serialiseCastKind(CastKindTrunc);
988+
// val:
989+
serialiseOperand(I, FLCtxt, I->getOperand(0));
990+
// dest_type_idx:
991+
OutStreamer.emitSizeT(typeIndex(I->getDestTy()));
992+
993+
FLCtxt.updateVLMap(I, InstIdx);
994+
InstIdx++;
995+
}
996+
966997
/// Serialise ptrtoint instruction.
967998
void serialisePtrToIntInst(PtrToIntInst *I, FuncLowerCtxt &FLCtxt,
968999
unsigned BBIdx, unsigned &InstIdx) {
@@ -1075,6 +1106,7 @@ class YkIRWriter {
10751106
INST_SERIALISE(I, ReturnInst, serialiseReturnInst);
10761107
INST_SERIALISE(I, ZExtInst, serialiseZExtInst);
10771108
INST_SERIALISE(I, SExtInst, serialiseSExtInst);
1109+
INST_SERIALISE(I, TruncInst, serialiseTruncInst);
10781110
INST_SERIALISE(I, StoreInst, serialiseStoreInst);
10791111
INST_SERIALISE(I, SwitchInst, serialiseSwitchInst);
10801112
INST_SERIALISE(I, PtrToIntInst, serialisePtrToIntInst);

0 commit comments

Comments
 (0)