-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[nfc][ir2vec] Remove Valid
field
#157132
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[nfc][ir2vec] Remove Valid
field
#157132
Conversation
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/pr-subscribers-llvm-analysis Author: Mircea Trofin (mtrofin) ChangesIt is tied to the vocab having had been set. Checking that vector's Full diff: https://github.com/llvm/llvm-project/pull/157132.diff 2 Files Affected:
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<ir2vec::Embedding>;
VocabVector Vocab;
- bool Valid = false;
public:
// Slot layout:
@@ -210,9 +209,9 @@ class Vocabulary {
static_cast<unsigned>(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();
}
|
@llvm/pr-subscribers-mlgo Author: Mircea Trofin (mtrofin) ChangesIt is tied to the vocab having had been set. Checking that vector's Full diff: https://github.com/llvm/llvm-project/pull/157132.diff 2 Files Affected:
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<ir2vec::Embedding>;
VocabVector Vocab;
- bool Valid = false;
public:
// Slot layout:
@@ -210,9 +209,9 @@ class Vocabulary {
static_cast<unsigned>(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();
}
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, makes sense. Thanks!
Merge activity
|
It is tied to the vocab having had been set. Checking that vector's
emtpy
is sufficient. Less state to track (for a maintainer)