[llvm] [IR2Vec] Restructuring Vocabulary (PR #145119)
Mircea Trofin via llvm-commits
llvm-commits at lists.llvm.org
Tue Jul 1 12:18:14 PDT 2025
================
@@ -202,56 +263,40 @@ class Embedder {
/// representations obtained from the Vocabulary.
class LLVM_ABI SymbolicEmbedder : public Embedder {
private:
- /// Utility function to compute the embedding for a given type.
- Embedding getTypeEmbedding(const Type *Ty) const;
-
- /// Utility function to compute the embedding for a given operand.
- Embedding getOperandEmbedding(const Value *Op) const;
-
void computeEmbeddings() const override;
void computeEmbeddings(const BasicBlock &BB) const override;
public:
- SymbolicEmbedder(const Function &F, const Vocab &Vocabulary)
- : Embedder(F, Vocabulary) {
+ SymbolicEmbedder(const Function &F, const Vocabulary &Vocab)
+ : Embedder(F, Vocab) {
FuncVector = Embedding(Dimension, 0);
}
};
} // namespace ir2vec
-/// Class for storing the result of the IR2VecVocabAnalysis.
-class IR2VecVocabResult {
- ir2vec::Vocab Vocabulary;
- bool Valid = false;
-
-public:
- IR2VecVocabResult() = default;
- LLVM_ABI IR2VecVocabResult(ir2vec::Vocab &&Vocabulary);
-
- bool isValid() const { return Valid; }
- LLVM_ABI const ir2vec::Vocab &getVocabulary() const;
- LLVM_ABI unsigned getDimension() const;
- LLVM_ABI bool invalidate(Module &M, const PreservedAnalyses &PA,
- ModuleAnalysisManager::Invalidator &Inv) const;
-};
-
/// This analysis provides the vocabulary for IR2Vec. The vocabulary provides a
/// mapping between an entity of the IR (like opcode, type, argument, etc.) and
/// its corresponding embedding.
class IR2VecVocabAnalysis : public AnalysisInfoMixin<IR2VecVocabAnalysis> {
- ir2vec::Vocab Vocabulary;
+ using VocabVector = std::vector<ir2vec::Embedding>;
+ using VocabMap = std::map<std::string, ir2vec::Embedding>;
+ VocabMap OpcVocab, TypeVocab, ArgVocab;
+ VocabVector Vocab;
+
+ unsigned Dim = 0;
----------------
mtrofin wrote:
needed? isn't it a property of `Vocab`?
https://github.com/llvm/llvm-project/pull/145119
More information about the llvm-commits
mailing list