aboutsummaryrefslogtreecommitdiff
path: root/llvm/unittests/Analysis
diff options
context:
space:
mode:
authorS. VenkataKeerthy <31350914+svkeerthy@users.noreply.github.com>2025-06-30 18:24:08 -0700
committerGitHub <noreply@github.com>2025-06-30 18:24:08 -0700
commit9438048816892229445b4db352fceb487a83e7f2 (patch)
tree2df4134352b6fd910a68ba5f83b1849283b8aca8 /llvm/unittests/Analysis
parent24c4bba076b5cd453d53e58aa9ca41b1a78526d8 (diff)
downloadllvm-9438048816892229445b4db352fceb487a83e7f2.zip
llvm-9438048816892229445b4db352fceb487a83e7f2.tar.gz
llvm-9438048816892229445b4db352fceb487a83e7f2.tar.bz2
[IR2Vec] Simplifying creation of Embedder (#143999)
This change simplifies the API by removing the error handling complexity. - Changed `Embedder::create()` to return `std::unique_ptr<Embedder>` directly instead of `Expected<std::unique_ptr<Embedder>>` - Updated documentation and tests to reflect the new API - Added death test for invalid IR2Vec kind in debug mode - In release mode, simply returns nullptr for invalid kinds instead of creating an error (Tracking issue - #141817)
Diffstat (limited to 'llvm/unittests/Analysis')
-rw-r--r--llvm/unittests/Analysis/FunctionPropertiesAnalysisTest.cpp7
-rw-r--r--llvm/unittests/Analysis/IR2VecTest.cpp44
2 files changed, 20 insertions, 31 deletions
diff --git a/llvm/unittests/Analysis/FunctionPropertiesAnalysisTest.cpp b/llvm/unittests/Analysis/FunctionPropertiesAnalysisTest.cpp
index e50486bc..ca4f5d0 100644
--- a/llvm/unittests/Analysis/FunctionPropertiesAnalysisTest.cpp
+++ b/llvm/unittests/Analysis/FunctionPropertiesAnalysisTest.cpp
@@ -127,10 +127,9 @@ protected:
}
std::unique_ptr<ir2vec::Embedder> createEmbedder(const Function &F) {
- auto EmbResult =
- ir2vec::Embedder::create(IR2VecKind::Symbolic, F, Vocabulary);
- EXPECT_TRUE(static_cast<bool>(EmbResult));
- return std::move(*EmbResult);
+ auto Emb = ir2vec::Embedder::create(IR2VecKind::Symbolic, F, Vocabulary);
+ EXPECT_TRUE(static_cast<bool>(Emb));
+ return std::move(Emb);
}
};
diff --git a/llvm/unittests/Analysis/IR2VecTest.cpp b/llvm/unittests/Analysis/IR2VecTest.cpp
index c3ed6e9..05af55b 100644
--- a/llvm/unittests/Analysis/IR2VecTest.cpp
+++ b/llvm/unittests/Analysis/IR2VecTest.cpp
@@ -216,10 +216,7 @@ TEST(IR2VecTest, CreateSymbolicEmbedder) {
FunctionType *FTy = FunctionType::get(Type::getVoidTy(Ctx), false);
Function *F = Function::Create(FTy, Function::ExternalLinkage, "f", M);
- auto Result = Embedder::create(IR2VecKind::Symbolic, *F, V);
- EXPECT_TRUE(static_cast<bool>(Result));
-
- auto *Emb = Result->get();
+ auto Emb = Embedder::create(IR2VecKind::Symbolic, *F, V);
EXPECT_NE(Emb, nullptr);
}
@@ -231,15 +228,16 @@ TEST(IR2VecTest, CreateInvalidMode) {
FunctionType *FTy = FunctionType::get(Type::getVoidTy(Ctx), false);
Function *F = Function::Create(FTy, Function::ExternalLinkage, "f", M);
- // static_cast an invalid int to IR2VecKind
+// static_cast an invalid int to IR2VecKind
+#ifndef NDEBUG
+#if GTEST_HAS_DEATH_TEST
+ EXPECT_DEATH(Embedder::create(static_cast<IR2VecKind>(-1), *F, V),
+ "Unknown IR2Vec kind");
+#endif // GTEST_HAS_DEATH_TEST
+#else
auto Result = Embedder::create(static_cast<IR2VecKind>(-1), *F, V);
EXPECT_FALSE(static_cast<bool>(Result));
-
- std::string ErrMsg;
- llvm::handleAllErrors(
- Result.takeError(),
- [&](const llvm::ErrorInfoBase &EIB) { ErrMsg = EIB.message(); });
- EXPECT_NE(ErrMsg.find("Unknown IR2VecKind"), std::string::npos);
+#endif // NDEBUG
}
TEST(IR2VecTest, LookupVocab) {
@@ -298,10 +296,6 @@ protected:
Instruction *AddInst = nullptr;
Instruction *RetInst = nullptr;
- float OriginalOpcWeight = ::OpcWeight;
- float OriginalTypeWeight = ::TypeWeight;
- float OriginalArgWeight = ::ArgWeight;
-
void SetUp() override {
V = {{"add", {1.0, 2.0}},
{"integerTy", {0.25, 0.25}},
@@ -325,9 +319,8 @@ protected:
};
TEST_F(IR2VecTestFixture, GetInstVecMap) {
- auto Result = Embedder::create(IR2VecKind::Symbolic, *F, V);
- ASSERT_TRUE(static_cast<bool>(Result));
- auto Emb = std::move(*Result);
+ auto Emb = Embedder::create(IR2VecKind::Symbolic, *F, V);
+ ASSERT_TRUE(static_cast<bool>(Emb));
const auto &InstMap = Emb->getInstVecMap();
@@ -348,9 +341,8 @@ TEST_F(IR2VecTestFixture, GetInstVecMap) {
}
TEST_F(IR2VecTestFixture, GetBBVecMap) {
- auto Result = Embedder::create(IR2VecKind::Symbolic, *F, V);
- ASSERT_TRUE(static_cast<bool>(Result));
- auto Emb = std::move(*Result);
+ auto Emb = Embedder::create(IR2VecKind::Symbolic, *F, V);
+ ASSERT_TRUE(static_cast<bool>(Emb));
const auto &BBMap = Emb->getBBVecMap();
@@ -365,9 +357,8 @@ TEST_F(IR2VecTestFixture, GetBBVecMap) {
}
TEST_F(IR2VecTestFixture, GetBBVector) {
- auto Result = Embedder::create(IR2VecKind::Symbolic, *F, V);
- ASSERT_TRUE(static_cast<bool>(Result));
- auto Emb = std::move(*Result);
+ auto Emb = Embedder::create(IR2VecKind::Symbolic, *F, V);
+ ASSERT_TRUE(static_cast<bool>(Emb));
const auto &BBVec = Emb->getBBVector(*BB);
@@ -377,9 +368,8 @@ TEST_F(IR2VecTestFixture, GetBBVector) {
}
TEST_F(IR2VecTestFixture, GetFunctionVector) {
- auto Result = Embedder::create(IR2VecKind::Symbolic, *F, V);
- ASSERT_TRUE(static_cast<bool>(Result));
- auto Emb = std::move(*Result);
+ auto Emb = Embedder::create(IR2VecKind::Symbolic, *F, V);
+ ASSERT_TRUE(static_cast<bool>(Emb));
const auto &FuncVec = Emb->getFunctionVector();