@@ -47,6 +47,24 @@ enum OpCode {
47
47
Ret,
48
48
InsertValue,
49
49
PtrAdd,
50
+ Add,
51
+ Sub,
52
+ Mul,
53
+ Or,
54
+ And,
55
+ Xor,
56
+ Shl,
57
+ AShr,
58
+ FAdd,
59
+ FDiv,
60
+ FMul,
61
+ FRem,
62
+ FSub,
63
+ LShr,
64
+ SDiv,
65
+ SRem,
66
+ UDiv,
67
+ URem,
50
68
UnimplementedInstruction = 255 , // YKFIXME: Will eventually be deleted.
51
69
};
52
70
@@ -278,6 +296,80 @@ class YkIRWriter {
278
296
InstIdx++;
279
297
}
280
298
299
+ void serialiseBinaryOperation (llvm::BinaryOperator *I,
300
+ ValueLoweringMap &VLMap, unsigned BBIdx,
301
+ unsigned &InstIdx) {
302
+ OutStreamer.emitSizeT (typeIndex (I->getType ()));
303
+ serialiseBinOpcode (I->getOpcode ());
304
+ OutStreamer.emitInt32 (I->getNumOperands ());
305
+ for (Value *O : I->operands ()) {
306
+ serialiseOperand (I, VLMap, O);
307
+ }
308
+ VLMap[I] = {BBIdx, InstIdx};
309
+ InstIdx++;
310
+ }
311
+
312
+ void serialiseBinOpcode (Instruction::BinaryOps BO) {
313
+ switch (BO) {
314
+ case Instruction::BinaryOps::Add:
315
+ OutStreamer.emitInt8 (OpCode::Add);
316
+ break ;
317
+ case Instruction::BinaryOps::Sub:
318
+ OutStreamer.emitInt8 (OpCode::Sub);
319
+ break ;
320
+ case Instruction::BinaryOps::Mul:
321
+ OutStreamer.emitInt8 (OpCode::Mul);
322
+ break ;
323
+ case Instruction::BinaryOps::Or:
324
+ OutStreamer.emitInt8 (OpCode::Or);
325
+ break ;
326
+ case Instruction::BinaryOps::And:
327
+ OutStreamer.emitInt8 (OpCode::And);
328
+ break ;
329
+ case Instruction::BinaryOps::Xor:
330
+ OutStreamer.emitInt8 (OpCode::Xor);
331
+ break ;
332
+ case Instruction::BinaryOps::Shl:
333
+ OutStreamer.emitInt8 (OpCode::Shl);
334
+ break ;
335
+ case Instruction::BinaryOps::AShr:
336
+ OutStreamer.emitInt8 (OpCode::AShr);
337
+ break ;
338
+ case Instruction::BinaryOps::FAdd:
339
+ OutStreamer.emitInt8 (OpCode::FAdd);
340
+ break ;
341
+ case Instruction::BinaryOps::FDiv:
342
+ OutStreamer.emitInt8 (OpCode::FDiv);
343
+ break ;
344
+ case Instruction::BinaryOps::FMul:
345
+ OutStreamer.emitInt8 (OpCode::FMul);
346
+ break ;
347
+ case Instruction::BinaryOps::FRem:
348
+ OutStreamer.emitInt8 (OpCode::FRem);
349
+ break ;
350
+ case Instruction::BinaryOps::FSub:
351
+ OutStreamer.emitInt8 (OpCode::FSub);
352
+ break ;
353
+ case Instruction::BinaryOps::LShr:
354
+ OutStreamer.emitInt8 (OpCode::LShr);
355
+ break ;
356
+ case Instruction::BinaryOps::SDiv:
357
+ OutStreamer.emitInt8 (OpCode::SDiv);
358
+ break ;
359
+ case Instruction::BinaryOps::SRem:
360
+ OutStreamer.emitInt8 (OpCode::SRem);
361
+ break ;
362
+ case Instruction::BinaryOps::UDiv:
363
+ OutStreamer.emitInt8 (OpCode::UDiv);
364
+ break ;
365
+ case Instruction::BinaryOps::URem:
366
+ OutStreamer.emitInt8 (OpCode::URem);
367
+ break ;
368
+ case Instruction::BinaryOps::BinaryOpsEnd:
369
+ break ;
370
+ }
371
+ }
372
+
281
373
void serialiseAllocaInst (AllocaInst *I, ValueLoweringMap &VLMap,
282
374
unsigned BBIdx, unsigned &InstIdx) {
283
375
// type_index:
@@ -393,7 +485,6 @@ class YkIRWriter {
393
485
GENERIC_INST_SERIALISE (I, LoadInst, Load)
394
486
GENERIC_INST_SERIALISE (I, StoreInst, Store)
395
487
GENERIC_INST_SERIALISE (I, ICmpInst, ICmp)
396
- GENERIC_INST_SERIALISE (I, llvm::BinaryOperator, BinaryOperator)
397
488
GENERIC_INST_SERIALISE (I, ReturnInst, Ret)
398
489
GENERIC_INST_SERIALISE (I, llvm::InsertValueInst, InsertValue)
399
490
GENERIC_INST_SERIALISE (I, StoreInst, Store)
@@ -402,6 +493,7 @@ class YkIRWriter {
402
493
CUSTOM_INST_SERIALISE (I, CallInst, serialiseCallInst)
403
494
CUSTOM_INST_SERIALISE (I, BranchInst, serialiseBranchInst)
404
495
CUSTOM_INST_SERIALISE (I, GetElementPtrInst, serialiseGetElementPtr)
496
+ CUSTOM_INST_SERIALISE (I, llvm::BinaryOperator, serialiseBinaryOperation)
405
497
406
498
// GENERIC_INST_SERIALISE and CUSTOM_INST_SERIALISE do an early return upon
407
499
// a match, so if we get here then the instruction wasn't handled.
0 commit comments