[llvm] [IR2VecTest] Avoid magic constants (PR #150878)
Alexander Richardson via llvm-commits
llvm-commits at lists.llvm.org
Sun Jul 27 22:16:20 PDT 2025
https://github.com/arichardson created https://github.com/llvm/llvm-project/pull/150878
Instead make the members of Vocabulary public. This was causing test
failures with https://github.com/llvm/llvm-project/pull/139357.
>From dc0e7a6f083147ee688891f263340db73bcb8a20 Mon Sep 17 00:00:00 2001
From: Alex Richardson <alexrichardson at google.com>
Date: Sun, 27 Jul 2025 22:15:52 -0700
Subject: [PATCH] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20initia?=
=?UTF-8?q?l=20version?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Created using spr 1.3.6-beta.1
---
llvm/include/llvm/Analysis/IR2Vec.h | 2 +-
llvm/unittests/Analysis/IR2VecTest.cpp | 6 +++---
2 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/llvm/include/llvm/Analysis/IR2Vec.h b/llvm/include/llvm/Analysis/IR2Vec.h
index d87457cac7642..498c19be6a75e 100644
--- a/llvm/include/llvm/Analysis/IR2Vec.h
+++ b/llvm/include/llvm/Analysis/IR2Vec.h
@@ -153,6 +153,7 @@ class Vocabulary {
static_cast<unsigned>(OperandKind::MaxOperandKind),
"OperandKindNames array size must match MaxOperandKind");
+public:
/// Vocabulary layout constants
#define LAST_OTHER_INST(NUM) static constexpr unsigned MaxOpcodes = NUM;
#include "llvm/IR/Instruction.def"
@@ -162,7 +163,6 @@ class Vocabulary {
static constexpr unsigned MaxOperandKinds =
static_cast<unsigned>(OperandKind::MaxOperandKind);
-public:
Vocabulary() = default;
Vocabulary(VocabVector &&Vocab);
diff --git a/llvm/unittests/Analysis/IR2VecTest.cpp b/llvm/unittests/Analysis/IR2VecTest.cpp
index 7c9a5464bfe1d..e288585033c53 100644
--- a/llvm/unittests/Analysis/IR2VecTest.cpp
+++ b/llvm/unittests/Analysis/IR2VecTest.cpp
@@ -364,9 +364,9 @@ TEST_F(IR2VecTestFixture, GetFunctionVector) {
EXPECT_TRUE(FuncVec.approximatelyEquals(Embedding(2, 44.4)));
}
-static constexpr unsigned MaxOpcodes = 67;
-static constexpr unsigned MaxTypeIDs = 21;
-static constexpr unsigned MaxOperands = 4;
+static constexpr unsigned MaxOpcodes = Vocabulary::MaxOpcodes;
+static constexpr unsigned MaxTypeIDs = Vocabulary::MaxTypeIDs;
+static constexpr unsigned MaxOperands = Vocabulary::MaxOperandKinds;
TEST(IR2VecVocabularyTest, DummyVocabTest) {
for (unsigned Dim = 1; Dim <= 10; ++Dim) {
More information about the llvm-commits
mailing list