[llvm] Refactoring llvm-ir2vec.cpp for better separation of concerns in the Tooling classes (PR #170078)

S. VenkataKeerthy via llvm-commits llvm-commits at lists.llvm.org
Sun Dec 7 22:11:02 PST 2025


================
@@ -282,45 +372,31 @@ class IR2VecTool {
 
   /// Generate embeddings for a single function
   void generateEmbeddings(const Function &F, raw_ostream &OS) const {
+    assert(Vocab && Vocab->isValid() && "Vocabulary not initialized");
     if (F.isDeclaration()) {
       OS << "Function " << F.getName() << " is a declaration, skipping.\n";
       return;
     }
 
-    // Create embedder for this function
-    assert(Vocab->isValid() && "Vocabulary is not valid");
-    auto Emb = Embedder::create(IR2VecEmbeddingKind, F, *Vocab);
-    if (!Emb) {
-      WithColor::error(errs(), ToolName)
-          << "Failed to create embedder for function " << F.getName() << "\n";
-      return;
-    }
-
     OS << "Function: " << F.getName() << "\n";
----------------
svkeerthy wrote:

Why not create `Emb` as we did earlier? Moving them to separate methods causes some duplication. 

https://github.com/llvm/llvm-project/pull/170078


More information about the llvm-commits mailing list