@@ -55,13 +55,15 @@ enum OperandKind {
55
55
Type,
56
56
Function,
57
57
Block,
58
+ Arg,
58
59
UnimplementedOperand = 255 ,
59
60
};
60
61
61
62
enum TypeKind {
62
63
Void = 0 ,
63
64
Integer,
64
65
Ptr ,
66
+ FunctionTy,
65
67
UnimplementedType = 255 , // YKFIXME: Will eventually be deleted.
66
68
};
67
69
@@ -133,8 +135,17 @@ class YkIRWriter {
133
135
if (Found != Types.end ()) {
134
136
return std::distance (Types.begin (), Found);
135
137
}
138
+
139
+ // Not found. Assign it a type index.
136
140
size_t Idx = Types.size ();
137
141
Types.push_back (Ty);
142
+
143
+ // If the newly-registered type is an aggregate type that contains other
144
+ // types, then assign them type indices now too.
145
+ for (llvm::Type *STy : Ty->subtypes ()) {
146
+ typeIndex (STy);
147
+ }
148
+
138
149
return Idx;
139
150
}
140
151
@@ -206,12 +217,20 @@ class YkIRWriter {
206
217
serialiseString (toString (V));
207
218
}
208
219
220
+ void serialiseArgOperand (ValueLoweringMap &VLMap, Argument *A) {
221
+ // This assumes that the argument indices match in both IRs.
222
+ OutStreamer.emitInt8 (OperandKind::Arg);
223
+ OutStreamer.emitSizeT (A->getArgNo ());
224
+ }
225
+
209
226
void serialiseOperand (Instruction *Parent, ValueLoweringMap &VLMap,
210
227
Value *V) {
211
228
if (llvm::Function *F = dyn_cast<llvm::Function>(V)) {
212
229
serialiseFunctionOperand (F);
213
230
} else if (llvm::Constant *C = dyn_cast<llvm::Constant>(V)) {
214
231
serialiseConstantOperand (Parent, C);
232
+ } else if (llvm::Argument *A = dyn_cast<llvm::Argument>(V)) {
233
+ serialiseArgOperand (VLMap, A);
215
234
} else if (Instruction *I = dyn_cast<Instruction>(V)) {
216
235
// If an instruction defines the operand, it's a local variable.
217
236
serialiseLocalVariableOperand (I, VLMap);
@@ -372,9 +391,17 @@ class YkIRWriter {
372
391
BBIdx++;
373
392
}
374
393
394
+ void serialiseArg (Argument *A) {
395
+ // type_index:
396
+ OutStreamer.emitSizeT (typeIndex (A->getType ()));
397
+ }
398
+
375
399
void serialiseFunc (llvm::Function &F) {
376
400
// name:
377
401
serialiseString (F.getName ());
402
+ // type_idx:
403
+ OutStreamer.emitSizeT (typeIndex (F.getFunctionType ()));
404
+ F.getType ()->dump ();
378
405
// num_blocks:
379
406
OutStreamer.emitSizeT (F.size ());
380
407
// blocks:
@@ -385,6 +412,20 @@ class YkIRWriter {
385
412
}
386
413
}
387
414
415
+ void serialiseFunctionType (FunctionType *Ty) {
416
+ OutStreamer.emitInt8 (TypeKind::FunctionTy);
417
+ // num_args:
418
+ OutStreamer.emitSizeT (Ty->getNumParams ());
419
+ // arg_tys:
420
+ for (llvm::Type *SubTy : Ty->params ()) {
421
+ OutStreamer.emitSizeT (typeIndex (SubTy));
422
+ }
423
+ // ret_ty:
424
+ OutStreamer.emitSizeT (typeIndex (Ty->getReturnType ()));
425
+ // is_vararg:
426
+ OutStreamer.emitInt8 (Ty->isVarArg ());
427
+ }
428
+
388
429
void serialiseType (llvm::Type *Ty) {
389
430
if (Ty->isVoidTy ()) {
390
431
OutStreamer.emitInt8 (TypeKind::Void);
@@ -393,6 +434,8 @@ class YkIRWriter {
393
434
} else if (IntegerType *ITy = dyn_cast<IntegerType>(Ty)) {
394
435
OutStreamer.emitInt8 (TypeKind::Integer);
395
436
OutStreamer.emitInt32 (ITy->getBitWidth ());
437
+ } else if (FunctionType *FTy = dyn_cast<FunctionType>(Ty)) {
438
+ serialiseFunctionType (FTy);
396
439
} else {
397
440
OutStreamer.emitInt8 (TypeKind::UnimplementedType);
398
441
serialiseString (toString (Ty));
0 commit comments