@@ -47,24 +47,7 @@ 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
+ BinOp,
68
51
UnimplementedInstruction = 255 , // YKFIXME: Will eventually be deleted.
69
52
};
70
53
@@ -103,6 +86,28 @@ enum CmpPredicate {
103
86
PredSignedLessEqual,
104
87
};
105
88
89
+ // A binary operator.
90
+ enum BinOp {
91
+ BinOpAdd,
92
+ BinOpSub,
93
+ BinOpMul,
94
+ BinOpOr,
95
+ BinOpAnd,
96
+ BinOpXor,
97
+ BinOpShl,
98
+ BinOpAShr,
99
+ BinOpFAdd,
100
+ BinOpFDiv,
101
+ BinOpFMul,
102
+ BinOpFRem,
103
+ BinOpFSub,
104
+ BinOpLShr,
105
+ BinOpSDiv,
106
+ BinOpSRem,
107
+ BinOpUDiv,
108
+ BinOpURem,
109
+ };
110
+
106
111
template <class T > string toString (T *X) {
107
112
string S;
108
113
raw_string_ostream SS (S);
@@ -314,71 +319,81 @@ class YkIRWriter {
314
319
void serialiseBinaryOperation (llvm::BinaryOperator *I,
315
320
ValueLoweringMap &VLMap, unsigned BBIdx,
316
321
unsigned &InstIdx) {
322
+ assert (I->getNumOperands () == 2 );
323
+
324
+ // type index:
317
325
OutStreamer.emitSizeT (typeIndex (I->getType ()));
318
- serialiseBinOpcode (I->getOpcode ());
319
- OutStreamer.emitInt32 (I->getNumOperands ());
320
- for (Value *O : I->operands ()) {
321
- serialiseOperand (I, VLMap, O);
322
- }
326
+ // opcode:
327
+ OutStreamer.emitInt8 (OpCode::BinOp);
328
+ // num operands:
329
+ OutStreamer.emitInt32 (3 );
330
+ // left-hand side:
331
+ serialiseOperand (I, VLMap, I->getOperand (0 ));
332
+ // binary operator:
333
+ serialiseBinOperator (I->getOpcode ());
334
+ // right-hand side:
335
+ serialiseOperand (I, VLMap, I->getOperand (1 ));
336
+
323
337
VLMap[I] = {BBIdx, InstIdx};
324
338
InstIdx++;
325
339
}
326
340
327
- void serialiseBinOpcode (Instruction::BinaryOps BO) {
341
+ // Serialise a binary operator.
342
+ void serialiseBinOperator (Instruction::BinaryOps BO) {
328
343
switch (BO) {
329
344
case Instruction::BinaryOps::Add:
330
- OutStreamer.emitInt8 (OpCode::Add );
345
+ OutStreamer.emitInt8 (BinOp::BinOpAdd );
331
346
break ;
332
347
case Instruction::BinaryOps::Sub:
333
- OutStreamer.emitInt8 (OpCode::Sub );
348
+ OutStreamer.emitInt8 (BinOp::BinOpSub );
334
349
break ;
335
350
case Instruction::BinaryOps::Mul:
336
- OutStreamer.emitInt8 (OpCode::Mul );
351
+ OutStreamer.emitInt8 (BinOp::BinOpMul );
337
352
break ;
338
353
case Instruction::BinaryOps::Or:
339
- OutStreamer.emitInt8 (OpCode::Or );
354
+ OutStreamer.emitInt8 (BinOp::BinOpOr );
340
355
break ;
341
356
case Instruction::BinaryOps::And:
342
- OutStreamer.emitInt8 (OpCode::And );
357
+ OutStreamer.emitInt8 (BinOp::BinOpAnd );
343
358
break ;
344
359
case Instruction::BinaryOps::Xor:
345
- OutStreamer.emitInt8 (OpCode::Xor );
360
+ OutStreamer.emitInt8 (BinOp::BinOpXor );
346
361
break ;
347
362
case Instruction::BinaryOps::Shl:
348
- OutStreamer.emitInt8 (OpCode::Shl );
363
+ OutStreamer.emitInt8 (BinOp::BinOpShl );
349
364
break ;
350
365
case Instruction::BinaryOps::AShr:
351
- OutStreamer.emitInt8 (OpCode::AShr );
366
+ OutStreamer.emitInt8 (BinOp::BinOpAShr );
352
367
break ;
353
368
case Instruction::BinaryOps::FAdd:
354
- OutStreamer.emitInt8 (OpCode::FAdd );
369
+ OutStreamer.emitInt8 (BinOp::BinOpFAdd );
355
370
break ;
356
371
case Instruction::BinaryOps::FDiv:
357
- OutStreamer.emitInt8 (OpCode::FDiv );
372
+ OutStreamer.emitInt8 (BinOp::BinOpFDiv );
358
373
break ;
359
374
case Instruction::BinaryOps::FMul:
360
- OutStreamer.emitInt8 (OpCode::FMul );
375
+ OutStreamer.emitInt8 (BinOp::BinOpFMul );
361
376
break ;
362
377
case Instruction::BinaryOps::FRem:
363
- OutStreamer.emitInt8 (OpCode::FRem );
378
+ OutStreamer.emitInt8 (BinOp::BinOpFRem );
364
379
break ;
365
380
case Instruction::BinaryOps::FSub:
366
- OutStreamer.emitInt8 (OpCode::FSub );
381
+ OutStreamer.emitInt8 (BinOp::BinOpFSub );
367
382
break ;
368
383
case Instruction::BinaryOps::LShr:
369
- OutStreamer.emitInt8 (OpCode::LShr );
384
+ OutStreamer.emitInt8 (BinOp::BinOpLShr );
370
385
break ;
371
386
case Instruction::BinaryOps::SDiv:
372
- OutStreamer.emitInt8 (OpCode::SDiv );
387
+ OutStreamer.emitInt8 (BinOp::BinOpSDiv );
373
388
break ;
374
389
case Instruction::BinaryOps::SRem:
375
- OutStreamer.emitInt8 (OpCode::SRem );
390
+ OutStreamer.emitInt8 (BinOp::BinOpSRem );
376
391
break ;
377
392
case Instruction::BinaryOps::UDiv:
378
- OutStreamer.emitInt8 (OpCode::UDiv );
393
+ OutStreamer.emitInt8 (BinOp::BinOpUDiv );
379
394
break ;
380
395
case Instruction::BinaryOps::URem:
381
- OutStreamer.emitInt8 (OpCode::URem );
396
+ OutStreamer.emitInt8 (BinOp::BinOpURem );
382
397
break ;
383
398
case Instruction::BinaryOps::BinaryOpsEnd:
384
399
break ;
0 commit comments