@@ -78,6 +78,7 @@ enum TypeKind {
78
78
enum CastKind {
79
79
CastKindSignExt = 0 ,
80
80
CastKindZeroExt = 1 ,
81
+ CastKindTrunc = 2 ,
81
82
};
82
83
83
84
// A predicate used in a numeric comparison.
@@ -963,6 +964,36 @@ class YkIRWriter {
963
964
InstIdx++;
964
965
}
965
966
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
+
966
997
// / Serialise ptrtoint instruction.
967
998
void serialisePtrToIntInst (PtrToIntInst *I, FuncLowerCtxt &FLCtxt,
968
999
unsigned BBIdx, unsigned &InstIdx) {
@@ -1075,6 +1106,7 @@ class YkIRWriter {
1075
1106
INST_SERIALISE (I, ReturnInst, serialiseReturnInst);
1076
1107
INST_SERIALISE (I, ZExtInst, serialiseZExtInst);
1077
1108
INST_SERIALISE (I, SExtInst, serialiseSExtInst);
1109
+ INST_SERIALISE (I, TruncInst, serialiseTruncInst);
1078
1110
INST_SERIALISE (I, StoreInst, serialiseStoreInst);
1079
1111
INST_SERIALISE (I, SwitchInst, serialiseSwitchInst);
1080
1112
INST_SERIALISE (I, PtrToIntInst, serialisePtrToIntInst);
0 commit comments