From 768d39907f17aa2780053906496fd3de021aadf8 Mon Sep 17 00:00:00 2001 From: Mircea Trofin Date: Fri, 5 Sep 2025 15:50:13 +0000 Subject: [PATCH 1/2] [nfc][ir2vec] Remove `Valid` field It is tied to the vocab having had been set. Checking that vector's `emtpy` is sufficient. Less state to track (for a maintainer) --- llvm/include/llvm/Analysis/IR2Vec.h | 13 ++++++------- llvm/lib/Analysis/IR2Vec.cpp | 9 +-------- 2 files changed, 7 insertions(+), 15 deletions(-) diff --git a/llvm/include/llvm/Analysis/IR2Vec.h b/llvm/include/llvm/Analysis/IR2Vec.h index b7b881999241e..82e2f396388e8 100644 --- a/llvm/include/llvm/Analysis/IR2Vec.h +++ b/llvm/include/llvm/Analysis/IR2Vec.h @@ -164,7 +164,6 @@ class Vocabulary { friend class llvm::IR2VecVocabAnalysis; using VocabVector = std::vector; VocabVector Vocab; - bool Valid = false; public: // Slot layout: @@ -210,9 +209,9 @@ class Vocabulary { static_cast(OperandKind::MaxOperandKind); Vocabulary() = default; - LLVM_ABI Vocabulary(VocabVector &&Vocab); + LLVM_ABI Vocabulary(VocabVector &&Vocab) : Vocab(std::move(Vocab)) {} - LLVM_ABI bool isValid() const; + LLVM_ABI bool isValid() const { return !Vocab.empty(); }; LLVM_ABI unsigned getDimension() const; /// Total number of entries (opcodes + canonicalized types + operand kinds) static constexpr size_t getCanonicalSize() { return NumCanonicalEntries; } @@ -243,22 +242,22 @@ class Vocabulary { /// Const Iterator type aliases using const_iterator = VocabVector::const_iterator; const_iterator begin() const { - assert(Valid && "IR2Vec Vocabulary is invalid"); + assert(isValid() && "IR2Vec Vocabulary is invalid"); return Vocab.begin(); } const_iterator cbegin() const { - assert(Valid && "IR2Vec Vocabulary is invalid"); + assert(isValid() && "IR2Vec Vocabulary is invalid"); return Vocab.cbegin(); } const_iterator end() const { - assert(Valid && "IR2Vec Vocabulary is invalid"); + assert(isValid() && "IR2Vec Vocabulary is invalid"); return Vocab.end(); } const_iterator cend() const { - assert(Valid && "IR2Vec Vocabulary is invalid"); + assert(isValid() && "IR2Vec Vocabulary is invalid"); return Vocab.cend(); } diff --git a/llvm/lib/Analysis/IR2Vec.cpp b/llvm/lib/Analysis/IR2Vec.cpp index 98849fd922843..99afc0601d523 100644 --- a/llvm/lib/Analysis/IR2Vec.cpp +++ b/llvm/lib/Analysis/IR2Vec.cpp @@ -260,15 +260,8 @@ void FlowAwareEmbedder::computeEmbeddings(const BasicBlock &BB) const { // Vocabulary //===----------------------------------------------------------------------===// -Vocabulary::Vocabulary(VocabVector &&Vocab) - : Vocab(std::move(Vocab)), Valid(true) {} - -bool Vocabulary::isValid() const { - return Vocab.size() == NumCanonicalEntries && Valid; -} - unsigned Vocabulary::getDimension() const { - assert(Valid && "IR2Vec Vocabulary is invalid"); + assert(isValid() && "IR2Vec Vocabulary is invalid"); return Vocab[0].size(); } From 4f92e0827baffd0593086ff86df8169dba3ebe45 Mon Sep 17 00:00:00 2001 From: Mircea Trofin Date: Sat, 6 Sep 2025 00:19:17 +0000 Subject: [PATCH 2/2] fix isValid() --- llvm/include/llvm/Analysis/IR2Vec.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/llvm/include/llvm/Analysis/IR2Vec.h b/llvm/include/llvm/Analysis/IR2Vec.h index 82e2f396388e8..3671c1c71ac0b 100644 --- a/llvm/include/llvm/Analysis/IR2Vec.h +++ b/llvm/include/llvm/Analysis/IR2Vec.h @@ -211,7 +211,7 @@ class Vocabulary { Vocabulary() = default; LLVM_ABI Vocabulary(VocabVector &&Vocab) : Vocab(std::move(Vocab)) {} - LLVM_ABI bool isValid() const { return !Vocab.empty(); }; + LLVM_ABI bool isValid() const { return Vocab.size() == NumCanonicalEntries; }; LLVM_ABI unsigned getDimension() const; /// Total number of entries (opcodes + canonicalized types + operand kinds) static constexpr size_t getCanonicalSize() { return NumCanonicalEntries; }