@@ -396,6 +396,69 @@ TEST(IR2VecVocabularyTest, DummyVocabTest) {
396
396
}
397
397
}
398
398
399
+ TEST (IR2VecVocabularyTest, NumericIDMap) {
400
+ // Test getNumericID for opcodes
401
+ EXPECT_EQ (Vocabulary::getNumericID (1u ), 0u );
402
+ EXPECT_EQ (Vocabulary::getNumericID (13u ), 12u );
403
+ EXPECT_EQ (Vocabulary::getNumericID (MaxOpcodes), MaxOpcodes - 1 );
404
+
405
+ // Test getNumericID for Type IDs
406
+ EXPECT_EQ (Vocabulary::getNumericID (Type::VoidTyID),
407
+ MaxOpcodes + static_cast <unsigned >(Type::VoidTyID));
408
+ EXPECT_EQ (Vocabulary::getNumericID (Type::HalfTyID),
409
+ MaxOpcodes + static_cast <unsigned >(Type::HalfTyID));
410
+ EXPECT_EQ (Vocabulary::getNumericID (Type::FloatTyID),
411
+ MaxOpcodes + static_cast <unsigned >(Type::FloatTyID));
412
+ EXPECT_EQ (Vocabulary::getNumericID (Type::IntegerTyID),
413
+ MaxOpcodes + static_cast <unsigned >(Type::IntegerTyID));
414
+ EXPECT_EQ (Vocabulary::getNumericID (Type::PointerTyID),
415
+ MaxOpcodes + static_cast <unsigned >(Type::PointerTyID));
416
+
417
+ // Test getNumericID for Value operands
418
+ LLVMContext Ctx;
419
+ Module M (" TestM" , Ctx);
420
+ FunctionType *FTy =
421
+ FunctionType::get (Type::getVoidTy (Ctx), {Type::getInt32Ty (Ctx)}, false );
422
+ Function *F = Function::Create (FTy, Function::ExternalLinkage, " testFunc" , M);
423
+
424
+ // Test Function operand
425
+ EXPECT_EQ (Vocabulary::getNumericID (F),
426
+ MaxOpcodes + MaxTypeIDs + 0u ); // Function = 0
427
+
428
+ // Test Constant operand
429
+ Constant *C = ConstantInt::get (Type::getInt32Ty (Ctx), 42 );
430
+ EXPECT_EQ (Vocabulary::getNumericID (C),
431
+ MaxOpcodes + MaxTypeIDs + 2u ); // Constant = 2
432
+
433
+ // Test Pointer operand
434
+ BasicBlock *BB = BasicBlock::Create (Ctx, " entry" , F);
435
+ AllocaInst *PtrVal = new AllocaInst (Type::getInt32Ty (Ctx), 0 , " ptr" , BB);
436
+ EXPECT_EQ (Vocabulary::getNumericID (PtrVal),
437
+ MaxOpcodes + MaxTypeIDs + 1u ); // Pointer = 1
438
+
439
+ // Test Variable operand (function argument)
440
+ Argument *Arg = F->getArg (0 );
441
+ EXPECT_EQ (Vocabulary::getNumericID (Arg),
442
+ MaxOpcodes + MaxTypeIDs + 3u ); // Variable = 3
443
+ }
444
+
445
+ #if GTEST_HAS_DEATH_TEST
446
+ #ifndef NDEBUG
447
+ TEST (IR2VecVocabularyTest, NumericIDMapInvalidInputs) {
448
+ // Test invalid opcode IDs
449
+ EXPECT_DEATH (Vocabulary::getNumericID (0u ), " Invalid opcode" );
450
+ EXPECT_DEATH (Vocabulary::getNumericID (MaxOpcodes + 1 ), " Invalid opcode" );
451
+
452
+ // Test invalid type IDs
453
+ EXPECT_DEATH (Vocabulary::getNumericID (static_cast <Type::TypeID>(MaxTypeIDs)),
454
+ " Invalid type ID" );
455
+ EXPECT_DEATH (
456
+ Vocabulary::getNumericID (static_cast <Type::TypeID>(MaxTypeIDs + 10 )),
457
+ " Invalid type ID" );
458
+ }
459
+ #endif // NDEBUG
460
+ #endif // GTEST_HAS_DEATH_TEST
461
+
399
462
TEST (IR2VecVocabularyTest, StringKeyGeneration) {
400
463
EXPECT_EQ (Vocabulary::getStringKey (0 ), " Ret" );
401
464
EXPECT_EQ (Vocabulary::getStringKey (12 ), " Add" );
0 commit comments