[llvm] Refactoring llvm-ir2vec.cpp for better separation of concerns in the Tooling classes (PR #170078)
Mircea Trofin via llvm-commits
llvm-commits at lists.llvm.org
Fri Dec 12 10:45:11 PST 2025
================
@@ -249,23 +254,57 @@ class IR2VecTool {
++ArgIndex;
}
// Only update MaxRelation if there were operands
- if (ArgIndex > 0) {
+ if (ArgIndex > 0)
MaxRelation = std::max(MaxRelation, ArgRelation + ArgIndex - 1);
- }
PrevOpcode = Opcode;
HasPrevOpcode = true;
}
}
- return MaxRelation;
+ Result.MaxRelation = MaxRelation;
+ return Result;
}
- /// Dump entity ID to string mappings
- static void generateEntityMappings(raw_ostream &OS) {
+ /// Get triplets for the entire module
+ TripletResult generateTriplets() const {
+ TripletResult Result;
+ Result.MaxRelation = NextRelation;
+
+ for (const Function &F : M.getFunctionDefs()) {
+ TripletResult FuncResult = generateTriplets(F);
+ Result.MaxRelation = std::max(Result.MaxRelation, FuncResult.MaxRelation);
+ Result.Triplets.insert(Result.Triplets.end(), FuncResult.Triplets.begin(),
+ FuncResult.Triplets.end());
+ }
+
+ return Result;
+ }
+
+ /// Collect triplets for the module and dump output to stream
+ /// Output format: MAX_RELATION=N header followed by relationships
+ void generateTriplets(raw_ostream &OS) const {
----------------
mtrofin wrote:
nit: dumpTriplets? (something more IO-ish). or "outputTriplets"
https://github.com/llvm/llvm-project/pull/170078
More information about the llvm-commits
mailing list