@@ -47,24 +47,7 @@ enum OpCode {
4747 Ret,
4848 InsertValue,
4949 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,
6851 UnimplementedInstruction = 255 , // YKFIXME: Will eventually be deleted.
6952};
7053
@@ -103,6 +86,28 @@ enum CmpPredicate {
10386 PredSignedLessEqual,
10487};
10588
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+
106111template <class T > string toString (T *X) {
107112 string S;
108113 raw_string_ostream SS (S);
@@ -314,71 +319,81 @@ class YkIRWriter {
314319 void serialiseBinaryOperation (llvm::BinaryOperator *I,
315320 ValueLoweringMap &VLMap, unsigned BBIdx,
316321 unsigned &InstIdx) {
322+ assert (I->getNumOperands () == 2 );
323+
324+ // type index:
317325 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+
323337 VLMap[I] = {BBIdx, InstIdx};
324338 InstIdx++;
325339 }
326340
327- void serialiseBinOpcode (Instruction::BinaryOps BO) {
341+ // Serialise a binary operator.
342+ void serialiseBinOperator (Instruction::BinaryOps BO) {
328343 switch (BO) {
329344 case Instruction::BinaryOps::Add:
330- OutStreamer.emitInt8 (OpCode::Add );
345+ OutStreamer.emitInt8 (BinOp::BinOpAdd );
331346 break ;
332347 case Instruction::BinaryOps::Sub:
333- OutStreamer.emitInt8 (OpCode::Sub );
348+ OutStreamer.emitInt8 (BinOp::BinOpSub );
334349 break ;
335350 case Instruction::BinaryOps::Mul:
336- OutStreamer.emitInt8 (OpCode::Mul );
351+ OutStreamer.emitInt8 (BinOp::BinOpMul );
337352 break ;
338353 case Instruction::BinaryOps::Or:
339- OutStreamer.emitInt8 (OpCode::Or );
354+ OutStreamer.emitInt8 (BinOp::BinOpOr );
340355 break ;
341356 case Instruction::BinaryOps::And:
342- OutStreamer.emitInt8 (OpCode::And );
357+ OutStreamer.emitInt8 (BinOp::BinOpAnd );
343358 break ;
344359 case Instruction::BinaryOps::Xor:
345- OutStreamer.emitInt8 (OpCode::Xor );
360+ OutStreamer.emitInt8 (BinOp::BinOpXor );
346361 break ;
347362 case Instruction::BinaryOps::Shl:
348- OutStreamer.emitInt8 (OpCode::Shl );
363+ OutStreamer.emitInt8 (BinOp::BinOpShl );
349364 break ;
350365 case Instruction::BinaryOps::AShr:
351- OutStreamer.emitInt8 (OpCode::AShr );
366+ OutStreamer.emitInt8 (BinOp::BinOpAShr );
352367 break ;
353368 case Instruction::BinaryOps::FAdd:
354- OutStreamer.emitInt8 (OpCode::FAdd );
369+ OutStreamer.emitInt8 (BinOp::BinOpFAdd );
355370 break ;
356371 case Instruction::BinaryOps::FDiv:
357- OutStreamer.emitInt8 (OpCode::FDiv );
372+ OutStreamer.emitInt8 (BinOp::BinOpFDiv );
358373 break ;
359374 case Instruction::BinaryOps::FMul:
360- OutStreamer.emitInt8 (OpCode::FMul );
375+ OutStreamer.emitInt8 (BinOp::BinOpFMul );
361376 break ;
362377 case Instruction::BinaryOps::FRem:
363- OutStreamer.emitInt8 (OpCode::FRem );
378+ OutStreamer.emitInt8 (BinOp::BinOpFRem );
364379 break ;
365380 case Instruction::BinaryOps::FSub:
366- OutStreamer.emitInt8 (OpCode::FSub );
381+ OutStreamer.emitInt8 (BinOp::BinOpFSub );
367382 break ;
368383 case Instruction::BinaryOps::LShr:
369- OutStreamer.emitInt8 (OpCode::LShr );
384+ OutStreamer.emitInt8 (BinOp::BinOpLShr );
370385 break ;
371386 case Instruction::BinaryOps::SDiv:
372- OutStreamer.emitInt8 (OpCode::SDiv );
387+ OutStreamer.emitInt8 (BinOp::BinOpSDiv );
373388 break ;
374389 case Instruction::BinaryOps::SRem:
375- OutStreamer.emitInt8 (OpCode::SRem );
390+ OutStreamer.emitInt8 (BinOp::BinOpSRem );
376391 break ;
377392 case Instruction::BinaryOps::UDiv:
378- OutStreamer.emitInt8 (OpCode::UDiv );
393+ OutStreamer.emitInt8 (BinOp::BinOpUDiv );
379394 break ;
380395 case Instruction::BinaryOps::URem:
381- OutStreamer.emitInt8 (OpCode::URem );
396+ OutStreamer.emitInt8 (BinOp::BinOpURem );
382397 break ;
383398 case Instruction::BinaryOps::BinaryOpsEnd:
384399 break ;
0 commit comments