Skip to content

Commit 2353088

Browse files
authored
[IR2Vec] Adding tests to check multiple invocations of getFunctionVector() and getInstVecMap() return same results (#162365)
Tests for #162165. Missed it earlier.
1 parent fee4c16 commit 2353088

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

llvm/unittests/Analysis/IR2VecTest.cpp

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,60 @@ TEST_F(IR2VecTestFixture, GetFunctionVector_FlowAware) {
430430
EXPECT_TRUE(FuncVec.approximatelyEquals(Embedding(2, 58.1)));
431431
}
432432

433+
TEST_F(IR2VecTestFixture, MultipleComputeEmbeddingsConsistency_Symbolic) {
434+
auto Emb = Embedder::create(IR2VecKind::Symbolic, *F, *V);
435+
ASSERT_TRUE(static_cast<bool>(Emb));
436+
437+
// Get initial function vector
438+
const auto &FuncVec1 = Emb->getFunctionVector();
439+
440+
// Compute embeddings again by calling getFunctionVector multiple times
441+
const auto &FuncVec2 = Emb->getFunctionVector();
442+
const auto &FuncVec3 = Emb->getFunctionVector();
443+
444+
// All function vectors should be identical
445+
EXPECT_TRUE(FuncVec1.approximatelyEquals(FuncVec2));
446+
EXPECT_TRUE(FuncVec1.approximatelyEquals(FuncVec3));
447+
EXPECT_TRUE(FuncVec2.approximatelyEquals(FuncVec3));
448+
449+
// Also check that instruction vectors remain consistent
450+
const auto &InstMap1 = Emb->getInstVecMap();
451+
const auto &InstMap2 = Emb->getInstVecMap();
452+
453+
EXPECT_EQ(InstMap1.size(), InstMap2.size());
454+
for (const auto &[Inst, Vec1] : InstMap1) {
455+
ASSERT_TRUE(InstMap2.count(Inst));
456+
EXPECT_TRUE(Vec1.approximatelyEquals(InstMap2.at(Inst)));
457+
}
458+
}
459+
460+
TEST_F(IR2VecTestFixture, MultipleComputeEmbeddingsConsistency_FlowAware) {
461+
auto Emb = Embedder::create(IR2VecKind::FlowAware, *F, *V);
462+
ASSERT_TRUE(static_cast<bool>(Emb));
463+
464+
// Get initial function vector
465+
const auto &FuncVec1 = Emb->getFunctionVector();
466+
467+
// Compute embeddings again by calling getFunctionVector multiple times
468+
const auto &FuncVec2 = Emb->getFunctionVector();
469+
const auto &FuncVec3 = Emb->getFunctionVector();
470+
471+
// All function vectors should be identical
472+
EXPECT_TRUE(FuncVec1.approximatelyEquals(FuncVec2));
473+
EXPECT_TRUE(FuncVec1.approximatelyEquals(FuncVec3));
474+
EXPECT_TRUE(FuncVec2.approximatelyEquals(FuncVec3));
475+
476+
// Also check that instruction vectors remain consistent
477+
const auto &InstMap1 = Emb->getInstVecMap();
478+
const auto &InstMap2 = Emb->getInstVecMap();
479+
480+
EXPECT_EQ(InstMap1.size(), InstMap2.size());
481+
for (const auto &[Inst, Vec1] : InstMap1) {
482+
ASSERT_TRUE(InstMap2.count(Inst));
483+
EXPECT_TRUE(Vec1.approximatelyEquals(InstMap2.at(Inst)));
484+
}
485+
}
486+
433487
static constexpr unsigned MaxOpcodes = Vocabulary::MaxOpcodes;
434488
[[maybe_unused]]
435489
static constexpr unsigned MaxTypeIDs = Vocabulary::MaxTypeIDs;

0 commit comments

Comments
 (0)