@@ -45,6 +45,7 @@ enum OpCode {
4545 ICmp,
4646 BinaryOperator,
4747 Ret,
48+ InsertValue,
4849 UnimplementedInstruction = 255 , // YKFIXME: Will eventually be deleted.
4950};
5051
@@ -63,6 +64,7 @@ enum TypeKind {
6364 Integer,
6465 Ptr,
6566 FunctionTy,
67+ Struct,
6668 UnimplementedType = 255 , // YKFIXME: Will eventually be deleted.
6769};
6870
@@ -350,6 +352,7 @@ class YkIRWriter {
350352 GENERIC_INST_SERIALISE (I, ICmpInst, ICmp)
351353 GENERIC_INST_SERIALISE (I, llvm::BinaryOperator, BinaryOperator)
352354 GENERIC_INST_SERIALISE (I, ReturnInst, Ret)
355+ GENERIC_INST_SERIALISE (I, llvm::InsertValueInst, InsertValue)
353356
354357 CUSTOM_INST_SERIALISE (I, AllocaInst, serialiseAllocaInst)
355358 CUSTOM_INST_SERIALISE (I, CallInst, serialiseCallInst)
@@ -365,6 +368,8 @@ class YkIRWriter {
365368 void serialiseUnimplementedInstruction (Instruction *I,
366369 ValueLoweringMap &VLMap,
367370 unsigned BBIdx, unsigned &InstIdx) {
371+ // type_index:
372+ OutStreamer.emitSizeT (typeIndex (I->getType ()));
368373 // opcode:
369374 serialiseOpcode (UnimplementedInstruction);
370375 // num_operands:
@@ -424,6 +429,23 @@ class YkIRWriter {
424429 OutStreamer.emitInt8 (Ty->isVarArg ());
425430 }
426431
432+ void serialiseStructType (StructType *STy) {
433+ OutStreamer.emitInt8 (TypeKind::Struct);
434+ unsigned NumFields = STy->getNumElements ();
435+ DataLayout DL (&M);
436+ const StructLayout *SL = DL.getStructLayout (STy);
437+ // num_fields:
438+ OutStreamer.emitSizeT (NumFields);
439+ // field_tys:
440+ for (unsigned I = 0 ; I < NumFields; I++) {
441+ OutStreamer.emitSizeT (typeIndex (STy->getElementType (I)));
442+ }
443+ // field_bit_offs:
444+ for (unsigned I = 0 ; I < NumFields; I++) {
445+ OutStreamer.emitSizeT (SL->getElementOffsetInBits (I));
446+ }
447+ }
448+
427449 void serialiseType (llvm::Type *Ty) {
428450 if (Ty->isVoidTy ()) {
429451 OutStreamer.emitInt8 (TypeKind::Void);
@@ -434,6 +456,8 @@ class YkIRWriter {
434456 OutStreamer.emitInt32 (ITy->getBitWidth ());
435457 } else if (FunctionType *FTy = dyn_cast<FunctionType>(Ty)) {
436458 serialiseFunctionType (FTy);
459+ } else if (StructType *STy = dyn_cast<StructType>(Ty)) {
460+ serialiseStructType (STy);
437461 } else {
438462 OutStreamer.emitInt8 (TypeKind::UnimplementedType);
439463 serialiseString (toString (Ty));
0 commit comments