@@ -36,36 +36,36 @@ const uint32_t Magic = 0xedd5f00d;
3636const uint32_t Version = 0 ;
3737
3838enum OpCode {
39- Nop = 0 ,
40- Load ,
41- Store ,
42- Alloca ,
43- Call ,
44- Br ,
45- CondBr ,
46- ICmp ,
47- Ret ,
48- InsertValue ,
49- PtrAdd ,
50- BinOp ,
51- UnimplementedInstruction = 255 , // YKFIXME: Will eventually be deleted.
39+ OpCodeNop = 0 ,
40+ OpCodeLoad ,
41+ OpCodeStore ,
42+ OpCodeAlloca ,
43+ OpCodeCall ,
44+ OpCodeBr ,
45+ OpCodeCondBr ,
46+ OpCodeICmp ,
47+ OpCodeRet ,
48+ OpCodeInsertValue ,
49+ OpCodePtrAdd ,
50+ OpCodeBinOp ,
51+ OpCodeUnimplemented = 255 , // YKFIXME: Will eventually be deleted.
5252};
5353
5454enum OperandKind {
55- Constant = 0 ,
56- LocalVariable ,
57- Global ,
58- Function ,
59- Arg ,
55+ OperandKindConstant = 0 ,
56+ OperandKindLocal ,
57+ OperandKindGlobal ,
58+ OperandKindFunction ,
59+ OperandKindArg ,
6060};
6161
6262enum TypeKind {
63- Void = 0 ,
64- Integer ,
65- Ptr ,
66- FunctionTy ,
67- Struct ,
68- UnimplementedType = 255 , // YKFIXME: Will eventually be deleted.
63+ TypeKindVoid = 0 ,
64+ TypeKindInteger ,
65+ TypeKindPtr ,
66+ TypeKindFunction ,
67+ TypeKindStruct ,
68+ TypeKindUnimplemented = 255 , // YKFIXME: Will eventually be deleted.
6969};
7070
7171// A predicate used in a numeric comparison.
@@ -190,8 +190,8 @@ class YkIRWriter {
190190
191191 // Return the index of the LLVM constant `C`, inserting a new entry if
192192 // necessary.
193- size_t constantIndex (class Constant *C) {
194- vector<class Constant *>::iterator Found =
193+ size_t constantIndex (Constant *C) {
194+ vector<Constant *>::iterator Found =
195195 std::find (Constants.begin (), Constants.end (), C);
196196 if (Found != Constants.end ()) {
197197 return std::distance (Constants.begin (), Found);
@@ -203,8 +203,8 @@ class YkIRWriter {
203203
204204 // Return the index of the LLVM global `G`, inserting a new entry if
205205 // necessary.
206- size_t globalIndex (class GlobalVariable *G) {
207- vector<class GlobalVariable *>::iterator Found =
206+ size_t globalIndex (GlobalVariable *G) {
207+ vector<GlobalVariable *>::iterator Found =
208208 std::find (Globals.begin (), Globals.end (), G);
209209 if (Found != Globals.end ()) {
210210 return std::distance (Globals.begin (), Found);
@@ -227,21 +227,23 @@ class YkIRWriter {
227227 }
228228
229229 void serialiseOpcode (OpCode Code) { OutStreamer.emitInt8 (Code); }
230+ void serialiseOperandKind (OperandKind Kind) { OutStreamer.emitInt8 (Kind); }
231+ void serialiseTypeKind (TypeKind Kind) { OutStreamer.emitInt8 (Kind); }
230232
231233 void serialiseConstantOperand (Instruction *Parent, llvm::Constant *C) {
232- OutStreamer. emitInt8 (OperandKind::Constant );
234+ serialiseOperandKind (OperandKindConstant );
233235 OutStreamer.emitSizeT (constantIndex (C));
234236 }
235237
236238 void serialiseLocalVariableOperand (Instruction *I, ValueLoweringMap &VLMap) {
237239 auto [BBIdx, InstIdx] = VLMap.at (I);
238- OutStreamer. emitInt8 (OperandKind::LocalVariable );
240+ serialiseOperandKind (OperandKindLocal );
239241 OutStreamer.emitSizeT (BBIdx);
240242 OutStreamer.emitSizeT (InstIdx);
241243 }
242244
243245 void serialiseFunctionOperand (llvm::Function *F) {
244- OutStreamer. emitInt8 (OperandKind::Function );
246+ serialiseOperandKind (OperandKindFunction );
245247 OutStreamer.emitSizeT (functionIndex (F));
246248 }
247249
@@ -254,15 +256,15 @@ class YkIRWriter {
254256 // This assumes that the argument indices match in both IRs.
255257
256258 // opcode:
257- OutStreamer. emitInt8 (OperandKind::Arg );
259+ serialiseOperandKind (OperandKindArg );
258260 // parent function index:
259261 OutStreamer.emitSizeT (getIndex (&M, A->getParent ()));
260262 // arg index
261263 OutStreamer.emitSizeT (A->getArgNo ());
262264 }
263265
264266 void serialiseGlobalOperand (GlobalVariable *G) {
265- OutStreamer. emitInt8 (OperandKind::Global );
267+ serialiseOperandKind (OperandKindGlobal );
266268 OutStreamer.emitSizeT (globalIndex (G));
267269 }
268270
@@ -290,7 +292,7 @@ class YkIRWriter {
290292 assert (I->getNumOperands () == 2 );
291293
292294 // opcode:
293- OutStreamer. emitInt8 (OpCode::BinOp );
295+ serialiseOpcode (OpCodeBinOp );
294296 // left-hand side:
295297 serialiseOperand (I, VLMap, I->getOperand (0 ));
296298 // binary operator:
@@ -370,7 +372,7 @@ class YkIRWriter {
370372 void serialiseAllocaInst (AllocaInst *I, ValueLoweringMap &VLMap,
371373 unsigned BBIdx, unsigned &InstIdx) {
372374 // opcode:
373- serialiseOpcode (OpCode::Alloca );
375+ serialiseOpcode (OpCodeAlloca );
374376
375377 // type to be allocated:
376378 OutStreamer.emitSizeT (typeIndex (I->getAllocatedType ()));
@@ -418,7 +420,7 @@ class YkIRWriter {
418420 assert (I->getCalledFunction ());
419421
420422 // opcode:
421- serialiseOpcode (OpCode::Call );
423+ serialiseOpcode (OpCodeCall );
422424 // callee:
423425 OutStreamer.emitSizeT (functionIndex (I->getCalledFunction ()));
424426 // num_args:
@@ -445,10 +447,10 @@ class YkIRWriter {
445447 // traces will guide us.
446448 //
447449 // opcode:
448- serialiseOpcode (OpCode::Br );
450+ serialiseOpcode (OpCodeBr );
449451 } else {
450452 // opcode:
451- serialiseOpcode (OpCode::CondBr );
453+ serialiseOpcode (OpCodeCondBr );
452454 // We DO need operands for conditional branches, so that we can build
453455 // guards.
454456 //
@@ -465,7 +467,7 @@ class YkIRWriter {
465467 void serialiseLoadInst (LoadInst *I, ValueLoweringMap &VLMap, unsigned BBIdx,
466468 unsigned &InstIdx) {
467469 // opcode:
468- serialiseOpcode (OpCode::Load );
470+ serialiseOpcode (OpCodeLoad );
469471 // ptr:
470472 serialiseOperand (I, VLMap, I->getPointerOperand ());
471473 // type_idx:
@@ -478,7 +480,7 @@ class YkIRWriter {
478480 void serialiseStoreInst (StoreInst *I, ValueLoweringMap &VLMap, unsigned BBIdx,
479481 unsigned &InstIdx) {
480482 // opcode:
481- serialiseOpcode (OpCode::Store );
483+ serialiseOpcode (OpCodeStore );
482484 // value:
483485 serialiseOperand (I, VLMap, I->getValueOperand ());
484486 // ptr:
@@ -497,7 +499,7 @@ class YkIRWriter {
497499 assert (Res);
498500
499501 // opcode:
500- serialiseOpcode (OpCode::PtrAdd );
502+ serialiseOpcode (OpCodePtrAdd );
501503 // type_idx:
502504 OutStreamer.emitSizeT (typeIndex (I->getType ()));
503505 // pointer:
@@ -552,7 +554,7 @@ class YkIRWriter {
552554 void serialiseICmpInst (ICmpInst *I, ValueLoweringMap &VLMap, unsigned BBIdx,
553555 unsigned &InstIdx) {
554556 // opcode:
555- serialiseOpcode (OpCode::ICmp );
557+ serialiseOpcode (OpCodeICmp );
556558 // type_idx:
557559 OutStreamer.emitSizeT (typeIndex (I->getType ()));
558560 // lhs:
@@ -569,7 +571,7 @@ class YkIRWriter {
569571 void serialiseReturnInst (ReturnInst *I, ValueLoweringMap &VLMap,
570572 unsigned BBIdx, unsigned &InstIdx) {
571573 // opcode:
572- serialiseOpcode (OpCode::Ret );
574+ serialiseOpcode (OpCodeRet );
573575
574576 Value *RV = I->getReturnValue ();
575577 if (RV == nullptr ) {
@@ -588,7 +590,7 @@ class YkIRWriter {
588590 void serialiseInsertValueInst (InsertValueInst *I, ValueLoweringMap &VLMap,
589591 unsigned BBIdx, unsigned &InstIdx) {
590592 // opcode:
591- serialiseOpcode (OpCode::InsertValue );
593+ serialiseOpcode (OpCodeInsertValue );
592594 // agg:
593595 serialiseOperand (I, VLMap, I->getAggregateOperand ());
594596 // elem:
@@ -626,7 +628,7 @@ class YkIRWriter {
626628 ValueLoweringMap &VLMap,
627629 unsigned BBIdx, unsigned &InstIdx) {
628630 // opcode:
629- serialiseOpcode (UnimplementedInstruction );
631+ serialiseOpcode (OpCodeUnimplemented );
630632 // stringified problem instruction
631633 serialiseString (toString (I));
632634
@@ -713,7 +715,7 @@ class YkIRWriter {
713715 }
714716
715717 void serialiseFunctionType (FunctionType *Ty) {
716- OutStreamer. emitInt8 (TypeKind::FunctionTy );
718+ serialiseTypeKind (TypeKindFunction );
717719 // num_args:
718720 OutStreamer.emitSizeT (Ty->getNumParams ());
719721 // arg_tys:
@@ -727,7 +729,7 @@ class YkIRWriter {
727729 }
728730
729731 void serialiseStructType (StructType *STy) {
730- OutStreamer. emitInt8 (TypeKind::Struct );
732+ serialiseTypeKind (TypeKindStruct );
731733 unsigned NumFields = STy->getNumElements ();
732734 DataLayout DL (&M);
733735 const StructLayout *SL = DL.getStructLayout (STy);
@@ -745,20 +747,20 @@ class YkIRWriter {
745747
746748 void serialiseType (llvm::Type *Ty) {
747749 if (Ty->isVoidTy ()) {
748- OutStreamer. emitInt8 (TypeKind::Void );
750+ serialiseTypeKind (TypeKindVoid );
749751 } else if (PointerType *PT = dyn_cast<PointerType>(Ty)) {
750752 // FIXME: The Yk runtime assumes all pointers are void-ptr-sized.
751753 assert (DL.getPointerSize (PT->getAddressSpace ()) == sizeof (void *));
752- OutStreamer. emitInt8 (TypeKind::Ptr );
754+ serialiseTypeKind (TypeKindPtr );
753755 } else if (IntegerType *ITy = dyn_cast<IntegerType>(Ty)) {
754- OutStreamer. emitInt8 (TypeKind::Integer );
756+ serialiseTypeKind (TypeKindInteger );
755757 OutStreamer.emitInt32 (ITy->getBitWidth ());
756758 } else if (FunctionType *FTy = dyn_cast<FunctionType>(Ty)) {
757759 serialiseFunctionType (FTy);
758760 } else if (StructType *STy = dyn_cast<StructType>(Ty)) {
759761 serialiseStructType (STy);
760762 } else {
761- OutStreamer. emitInt8 (TypeKind::UnimplementedType );
763+ serialiseTypeKind (TypeKindUnimplemented );
762764 serialiseString (toString (Ty));
763765 }
764766 }
@@ -772,23 +774,23 @@ class YkIRWriter {
772774 }
773775 }
774776
775- void serialiseUnimplementedConstant (class Constant *C) {
777+ void serialiseUnimplementedConstant (Constant *C) {
776778 // type_index:
777779 OutStreamer.emitSizeT (typeIndex (C->getType ()));
778780 // num_bytes:
779781 // Just report zero for now.
780782 OutStreamer.emitSizeT (0 );
781783 }
782784
783- void serialiseConstant (class Constant *C) {
785+ void serialiseConstant (Constant *C) {
784786 if (ConstantInt *CI = dyn_cast<ConstantInt>(C)) {
785787 serialiseConstantInt (CI);
786788 } else {
787789 serialiseUnimplementedConstant (C);
788790 }
789791 }
790792
791- void serialiseGlobal (class GlobalVariable *G) {
793+ void serialiseGlobal (GlobalVariable *G) {
792794 OutStreamer.emitInt8 (G->isThreadLocal ());
793795 serialiseString (G->getName ());
794796 }
@@ -820,14 +822,14 @@ class YkIRWriter {
820822 // num_constants:
821823 OutStreamer.emitSizeT (Constants.size ());
822824 // constants:
823- for (class Constant *&C : Constants) {
825+ for (Constant *&C : Constants) {
824826 serialiseConstant (C);
825827 }
826828
827829 // num_globals:
828830 OutStreamer.emitSizeT (Globals.size ());
829831 // globals:
830- for (class GlobalVariable *&G : Globals) {
832+ for (GlobalVariable *&G : Globals) {
831833 serialiseGlobal (G);
832834 }
833835
0 commit comments