[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
Mon Dec 1 22:35:12 PST 2025


================
@@ -182,32 +206,14 @@ class IR2VecTool {
     return Vocab->isValid();
   }
 
-  /// Generate triplets for the module
-  /// Output format: MAX_RELATION=N header followed by relationships
-  void generateTriplets(raw_ostream &OS) const {
-    unsigned MaxRelation = NextRelation; // Track maximum relation ID
-    std::string Relationships;
-    raw_string_ostream RelOS(Relationships);
+  TripletResult getTriplets(const Function &F) const {
+    TripletResult Result;
+    Result.MaxRelation = 0;
 
-    for (const Function &F : M) {
-      unsigned FuncMaxRelation = generateTriplets(F, RelOS);
-      MaxRelation = std::max(MaxRelation, FuncMaxRelation);
-    }
-
-    RelOS.flush();
-
-    // Write metadata header followed by relationships
-    OS << "MAX_RELATION=" << MaxRelation << '\n';
-    OS << Relationships;
-  }
-
-  /// Generate triplets for a single function
-  /// Returns the maximum relation ID used in this function
-  unsigned generateTriplets(const Function &F, raw_ostream &OS) const {
     if (F.isDeclaration())
----------------
svkeerthy wrote:

Can still be an early return. This can be moved earlier.

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


More information about the llvm-commits mailing list