[llvm] [llvm-ir2vec] Breaking up llvm-ir2vec lib implementation to clean up MIR deps from ir2vec python bindings (PR #194414)

Nishant Sachdeva via llvm-commits llvm-commits at lists.llvm.org
Fri May 8 02:36:05 PDT 2026


https://github.com/nishant-sachdeva updated https://github.com/llvm/llvm-project/pull/194414

>From 2465351de876ccff65f37f83beee0f8a384eab9a Mon Sep 17 00:00:00 2001
From: nishant_sachdeva <nishant.sachdeva at research.iiit.ac.in>
Date: Mon, 27 Apr 2026 22:24:00 +0530
Subject: [PATCH] Breaking up llvm-ir2vec lib implementation to clean up MIR
 deps from ir2vec python bindings

---
 .../tools/llvm-ir2vec/Bindings/CMakeLists.txt |   2 +-
 llvm/tools/llvm-ir2vec/Bindings/PyIR2Vec.cpp  |   2 +-
 llvm/tools/llvm-ir2vec/CMakeLists.txt         |  26 +-
 llvm/tools/llvm-ir2vec/lib/CMakeLists.txt     |  21 +-
 llvm/tools/llvm-ir2vec/lib/Common.h           |  54 ++++
 .../lib/{Utils.cpp => IRUtils.cpp}            | 236 +-----------------
 llvm/tools/llvm-ir2vec/lib/IRUtils.h          | 119 +++++++++
 llvm/tools/llvm-ir2vec/lib/MIRUtils.cpp       | 236 ++++++++++++++++++
 llvm/tools/llvm-ir2vec/lib/MIRUtils.h         | 108 ++++++++
 llvm/tools/llvm-ir2vec/lib/Utils.h            | 232 -----------------
 llvm/tools/llvm-ir2vec/llvm-ir2vec.cpp        |   3 +-
 11 files changed, 555 insertions(+), 484 deletions(-)
 create mode 100644 llvm/tools/llvm-ir2vec/lib/Common.h
 rename llvm/tools/llvm-ir2vec/lib/{Utils.cpp => IRUtils.cpp} (53%)
 create mode 100644 llvm/tools/llvm-ir2vec/lib/IRUtils.h
 create mode 100644 llvm/tools/llvm-ir2vec/lib/MIRUtils.cpp
 create mode 100644 llvm/tools/llvm-ir2vec/lib/MIRUtils.h
 delete mode 100644 llvm/tools/llvm-ir2vec/lib/Utils.h

diff --git a/llvm/tools/llvm-ir2vec/Bindings/CMakeLists.txt b/llvm/tools/llvm-ir2vec/Bindings/CMakeLists.txt
index 582dfb3058385..d39a6d5654de0 100644
--- a/llvm/tools/llvm-ir2vec/Bindings/CMakeLists.txt
+++ b/llvm/tools/llvm-ir2vec/Bindings/CMakeLists.txt
@@ -37,7 +37,7 @@ nanobind_add_module(ir2vec MODULE PyIR2Vec.cpp)
 # (see mlir/cmake/modules/AddMLIRPython.cmake).
 target_compile_options(ir2vec PRIVATE -fexceptions -frtti)
 
-target_link_libraries(ir2vec PRIVATE LLVMEmbUtils)
+target_link_libraries(ir2vec PRIVATE LLVMIREmbUtils)
 target_include_directories(ir2vec PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/..)
 
 message(STATUS "Python bindings for llvm-ir2vec will be built with nanobind")
diff --git a/llvm/tools/llvm-ir2vec/Bindings/PyIR2Vec.cpp b/llvm/tools/llvm-ir2vec/Bindings/PyIR2Vec.cpp
index fa61c478e5c6d..28f84683d6b58 100644
--- a/llvm/tools/llvm-ir2vec/Bindings/PyIR2Vec.cpp
+++ b/llvm/tools/llvm-ir2vec/Bindings/PyIR2Vec.cpp
@@ -6,7 +6,7 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "lib/Utils.h"
+#include "lib/IRUtils.h"
 #include "llvm/IR/LLVMContext.h"
 #include "llvm/IR/Module.h"
 #include "llvm/IRReader/IRReader.h"
diff --git a/llvm/tools/llvm-ir2vec/CMakeLists.txt b/llvm/tools/llvm-ir2vec/CMakeLists.txt
index 694dc77e274b7..edd581915be7e 100644
--- a/llvm/tools/llvm-ir2vec/CMakeLists.txt
+++ b/llvm/tools/llvm-ir2vec/CMakeLists.txt
@@ -1,39 +1,35 @@
 set(LLVM_LINK_COMPONENTS
-  # Core LLVM components for IR processing
-  Analysis
-  Core
+  # IR reading (used by llvm-ir2vec.cpp directly)
   IRReader
-  Support
-  
+
   # Machine IR components (for -mode=mir)
-  CodeGen           
   MIRParser
   MC
-  Target
-  
+
   # Target initialization (required for MIR parsing)
   AllTargetsAsmParsers
   AllTargetsCodeGens
   AllTargetsDescs
   AllTargetsInfos
   TargetParser
-  )
+)
 
-# Add the lib subdirectory
+# Build the utility libraries first
 add_subdirectory(lib)
 
 # Main executable
 add_llvm_tool(llvm-ir2vec
   llvm-ir2vec.cpp
-  
+
   DEPENDS
   intrinsics_gen
 )
 
-target_link_libraries(llvm-ir2vec PRIVATE LLVMEmbUtils)
+# Link both libraries: IR tool for IR mode, MIR tool for MIR mode
+target_link_libraries(llvm-ir2vec PRIVATE LLVMIREmbUtils LLVMMIREmbUtils)
 
-option(LLVM_IR2VEC_ENABLE_PYTHON_BINDINGS 
-  "Build Python bindings for llvm-ir2vec" 
+option(LLVM_IR2VEC_ENABLE_PYTHON_BINDINGS
+  "Build Python bindings for llvm-ir2vec"
   OFF)
 
 set(LLVM_IR2VEC_TEST_PYTHON_BINDINGS False CACHE INTERNAL "")
@@ -41,4 +37,4 @@ set(LLVM_IR2VEC_TEST_PYTHON_BINDINGS False CACHE INTERNAL "")
 if(LLVM_IR2VEC_ENABLE_PYTHON_BINDINGS)
   add_subdirectory(Bindings)
   set(LLVM_IR2VEC_TEST_PYTHON_BINDINGS True CACHE INTERNAL "" FORCE)
-endif()
+endif()
\ No newline at end of file
diff --git a/llvm/tools/llvm-ir2vec/lib/CMakeLists.txt b/llvm/tools/llvm-ir2vec/lib/CMakeLists.txt
index e27ace1da54d4..9e86612699c31 100644
--- a/llvm/tools/llvm-ir2vec/lib/CMakeLists.txt
+++ b/llvm/tools/llvm-ir2vec/lib/CMakeLists.txt
@@ -1,6 +1,7 @@
-add_llvm_library(LLVMEmbUtils STATIC
-  Utils.cpp
+add_llvm_library(LLVMIREmbUtils STATIC
+  IRUtils.cpp
 
+  PARTIAL_SOURCES_INTENDED
   BUILDTREE_ONLY
 
   DEPENDS
@@ -8,8 +9,20 @@ add_llvm_library(LLVMEmbUtils STATIC
 
   LINK_COMPONENTS
   Analysis
-  CodeGen
   Core
   Support
-  Target
 )
+
+add_llvm_library(LLVMMIREmbUtils STATIC
+  MIRUtils.cpp
+
+  PARTIAL_SOURCES_INTENDED
+  BUILDTREE_ONLY
+
+  DEPENDS
+  intrinsics_gen
+
+  LINK_COMPONENTS
+  CodeGen
+  Target
+)
\ No newline at end of file
diff --git a/llvm/tools/llvm-ir2vec/lib/Common.h b/llvm/tools/llvm-ir2vec/lib/Common.h
new file mode 100644
index 0000000000000..4344a9d652b67
--- /dev/null
+++ b/llvm/tools/llvm-ir2vec/lib/Common.h
@@ -0,0 +1,54 @@
+//===- Common.h - Shared types for IR2Vec/MIR2Vec tools -----------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// This file contains shared types and constants used by both the IR2Vec
+/// and MIR2Vec tool implementations. It has no dependency on either the
+/// LLVM IR or Machine IR APIs, making it safe to include from either side.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_TOOLS_LLVM_IR2VEC_UTILS_COMMON_H
+#define LLVM_TOOLS_LLVM_IR2VEC_UTILS_COMMON_H
+
+#include <string>
+#include <vector>
+
+namespace llvm {
+
+/// Tool name for error reporting
+static const char *ToolName = "llvm-ir2vec";
+
+/// Specifies the granularity at which embeddings are generated.
+enum EmbeddingLevel {
+  InstructionLevel, // Generate instruction-level embeddings
+  BasicBlockLevel,  // Generate basic block-level embeddings
+  FunctionLevel     // Generate function-level embeddings
+};
+
+/// Represents a single knowledge graph triplet (Head, Relation, Tail)
+/// where indices reference entities in an EntityList
+struct Triplet {
+  unsigned Head = 0;     ///< Index of the head entity in the entity list
+  unsigned Tail = 0;     ///< Index of the tail entity in the entity list
+  unsigned Relation = 0; ///< Relation type (see RelationType enum)
+};
+
+/// Result structure containing all generated triplets and metadata
+struct TripletResult {
+  unsigned MaxRelation =
+      0; ///< Highest relation index used (for ArgRelation + N)
+  std::vector<Triplet> Triplets; ///< Collection of all generated triplets
+};
+
+/// Entity mappings: [entity_name]
+using EntityList = std::vector<std::string>;
+
+} // namespace llvm
+
+#endif // LLVM_TOOLS_LLVM_IR2VEC_UTILS_COMMON_H
\ No newline at end of file
diff --git a/llvm/tools/llvm-ir2vec/lib/Utils.cpp b/llvm/tools/llvm-ir2vec/lib/IRUtils.cpp
similarity index 53%
rename from llvm/tools/llvm-ir2vec/lib/Utils.cpp
rename to llvm/tools/llvm-ir2vec/lib/IRUtils.cpp
index d37fd5e24de8e..b8801c40487f9 100644
--- a/llvm/tools/llvm-ir2vec/lib/Utils.cpp
+++ b/llvm/tools/llvm-ir2vec/lib/IRUtils.cpp
@@ -1,4 +1,4 @@
-//===- Utils.cpp - IR2Vec/MIR2Vec Embedding Generation Tool -----------===//
+//===- IRUtils.cpp - IR2Vec Embedding Generation ----------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -7,13 +7,12 @@
 //===----------------------------------------------------------------------===//
 ///
 /// \file
-/// This file implements the IR2VecTool and MIR2VecTool classes for
-/// IR2Vec/MIR2Vec embedding generation.
+/// This file implements the IR2VecTool class for IR2Vec embedding generation
+/// from LLVM IR. It has no dependency on Machine IR.
 ///
 //===----------------------------------------------------------------------===//
 
-#include "Utils.h"
-#include "llvm/ADT/ArrayRef.h"
+#include "IRUtils.h"
 #include "llvm/Analysis/IR2Vec.h"
 #include "llvm/IR/BasicBlock.h"
 #include "llvm/IR/Function.h"
@@ -27,20 +26,12 @@
 #include "llvm/Support/Debug.h"
 #include "llvm/Support/Errc.h"
 #include "llvm/Support/Error.h"
+#include "llvm/Support/WithColor.h"
 #include "llvm/Support/raw_ostream.h"
 
-#include "llvm/CodeGen/MIR2Vec.h"
-#include "llvm/CodeGen/MIRParser/MIRParser.h"
-#include "llvm/CodeGen/MachineFunction.h"
-#include "llvm/CodeGen/MachineModuleInfo.h"
-#include "llvm/CodeGen/TargetInstrInfo.h"
-#include "llvm/CodeGen/TargetRegisterInfo.h"
-#include "llvm/Target/TargetMachine.h"
-
 #define DEBUG_TYPE "ir2vec"
 
 namespace llvm {
-
 namespace ir2vec {
 
 Expected<std::shared_ptr<Vocabulary>> loadVocabulary(StringRef VocabPath) {
@@ -256,7 +247,6 @@ void IR2VecTool::writeEmbeddingsToStream(const Function &F, raw_ostream &OS,
 
   OS << "Function: " << F.getName() << "\n";
 
-  // Generate embeddings based on the specified level
   switch (Level) {
   case FunctionLevel:
     Emb->getFunctionVector().print(OS);
@@ -277,218 +267,4 @@ void IR2VecTool::writeEmbeddingsToStream(const Function &F, raw_ostream &OS,
 }
 
 } // namespace ir2vec
-
-namespace mir2vec {
-
-bool MIR2VecTool::initializeVocabulary(const Module &M) {
-  MIR2VecVocabProvider Provider(MMI);
-  auto VocabOrErr = Provider.getVocabulary(M);
-  if (!VocabOrErr) {
-    WithColor::error(errs(), ToolName)
-        << "Failed to load MIR2Vec vocabulary - "
-        << toString(VocabOrErr.takeError()) << "\n";
-    return false;
-  }
-  Vocab = std::make_unique<MIRVocabulary>(std::move(*VocabOrErr));
-  return true;
-}
-
-bool MIR2VecTool::initializeVocabularyForLayout(const Module &M) {
-  for (const Function &F : M.getFunctionDefs()) {
-    MachineFunction *MF = MMI.getMachineFunction(F);
-    if (!MF)
-      continue;
-
-    const TargetInstrInfo &TII = *MF->getSubtarget().getInstrInfo();
-    const TargetRegisterInfo &TRI = *MF->getSubtarget().getRegisterInfo();
-    const MachineRegisterInfo &MRI = MF->getRegInfo();
-
-    auto VocabOrErr = MIRVocabulary::createDummyVocabForTest(TII, TRI, MRI, 1);
-    if (!VocabOrErr) {
-      WithColor::error(errs(), ToolName)
-          << "Failed to create dummy vocabulary - "
-          << toString(VocabOrErr.takeError()) << "\n";
-      return false;
-    }
-    Vocab = std::make_unique<MIRVocabulary>(std::move(*VocabOrErr));
-    return true;
-  }
-
-  WithColor::error(errs(), ToolName)
-      << "No machine functions found to initialize vocabulary\n";
-  return false;
-}
-
-TripletResult MIR2VecTool::generateTriplets(const MachineFunction &MF) const {
-  TripletResult Result;
-  Result.MaxRelation = MIRNextRelation;
-
-  if (!Vocab) {
-    WithColor::error(errs(), ToolName)
-        << "MIR Vocabulary must be initialized for triplet generation.\n";
-    return Result;
-  }
-
-  unsigned PrevOpcode = 0;
-  bool HasPrevOpcode = false;
-  for (const MachineBasicBlock &MBB : MF) {
-    for (const MachineInstr &MI : MBB) {
-      // Skip debug instructions
-      if (MI.isDebugInstr())
-        continue;
-
-      // Get opcode entity ID
-      unsigned OpcodeID = Vocab->getEntityIDForOpcode(MI.getOpcode());
-
-      // Add "Next" relationship with previous instruction
-      if (HasPrevOpcode) {
-        Result.Triplets.push_back({PrevOpcode, OpcodeID, MIRNextRelation});
-        LLVM_DEBUG(dbgs() << Vocab->getStringKey(PrevOpcode) << '\t'
-                          << Vocab->getStringKey(OpcodeID) << '\t' << "Next\n");
-      }
-
-      // Add "Arg" relationships for operands
-      unsigned ArgIndex = 0;
-      for (const MachineOperand &MO : MI.operands()) {
-        auto OperandID = Vocab->getEntityIDForMachineOperand(MO);
-        unsigned RelationID = MIRArgRelation + ArgIndex;
-        Result.Triplets.push_back({OpcodeID, OperandID, RelationID});
-        LLVM_DEBUG({
-          std::string OperandStr = Vocab->getStringKey(OperandID);
-          dbgs() << Vocab->getStringKey(OpcodeID) << '\t' << OperandStr << '\t'
-                 << "Arg" << ArgIndex << '\n';
-        });
-
-        ++ArgIndex;
-      }
-
-      // Update MaxRelation if there were operands
-      if (ArgIndex > 0)
-        Result.MaxRelation =
-            std::max(Result.MaxRelation, MIRArgRelation + ArgIndex - 1);
-
-      PrevOpcode = OpcodeID;
-      HasPrevOpcode = true;
-    }
-  }
-
-  return Result;
-}
-
-TripletResult MIR2VecTool::generateTriplets(const Module &M) const {
-  TripletResult Result;
-  Result.MaxRelation = MIRNextRelation;
-
-  for (const Function &F : M.getFunctionDefs()) {
-    MachineFunction *MF = MMI.getMachineFunction(F);
-    if (!MF) {
-      WithColor::warning(errs(), ToolName)
-          << "No MachineFunction for " << F.getName() << "\n";
-      continue;
-    }
-
-    TripletResult FuncResult = generateTriplets(*MF);
-    Result.MaxRelation = std::max(Result.MaxRelation, FuncResult.MaxRelation);
-    Result.Triplets.insert(Result.Triplets.end(), FuncResult.Triplets.begin(),
-                           FuncResult.Triplets.end());
-  }
-
-  return Result;
-}
-
-void MIR2VecTool::writeTripletsToStream(const Module &M,
-                                        raw_ostream &OS) const {
-  auto Result = generateTriplets(M);
-  OS << "MAX_RELATION=" << Result.MaxRelation << '\n';
-  for (const auto &T : Result.Triplets)
-    OS << T.Head << '\t' << T.Tail << '\t' << T.Relation << '\n';
-}
-
-EntityList MIR2VecTool::collectEntityMappings() const {
-  if (!Vocab) {
-    WithColor::error(errs(), ToolName)
-        << "Vocabulary must be initialized for entity mappings.\n";
-    return {};
-  }
-
-  const unsigned EntityCount = Vocab->getCanonicalSize();
-  EntityList Result;
-  for (unsigned EntityID = 0; EntityID < EntityCount; ++EntityID)
-    Result.push_back(Vocab->getStringKey(EntityID));
-
-  return Result;
-}
-
-void MIR2VecTool::writeEntitiesToStream(raw_ostream &OS) const {
-  auto Entities = collectEntityMappings();
-  if (Entities.empty())
-    return;
-
-  OS << Entities.size() << "\n";
-  for (unsigned EntityID = 0; EntityID < Entities.size(); ++EntityID)
-    OS << Entities[EntityID] << '\t' << EntityID << '\n';
-}
-
-void MIR2VecTool::writeEmbeddingsToStream(const Module &M, raw_ostream &OS,
-                                          EmbeddingLevel Level) const {
-  if (!Vocab) {
-    WithColor::error(errs(), ToolName) << "Vocabulary not initialized.\n";
-    return;
-  }
-
-  for (const Function &F : M.getFunctionDefs()) {
-    MachineFunction *MF = MMI.getMachineFunction(F);
-    if (!MF) {
-      WithColor::warning(errs(), ToolName)
-          << "No MachineFunction for " << F.getName() << "\n";
-      continue;
-    }
-
-    writeEmbeddingsToStream(*MF, OS, Level);
-  }
-}
-
-void MIR2VecTool::writeEmbeddingsToStream(MachineFunction &MF, raw_ostream &OS,
-                                          EmbeddingLevel Level) const {
-  if (!Vocab) {
-    WithColor::error(errs(), ToolName) << "Vocabulary not initialized.\n";
-    return;
-  }
-
-  auto Emb = MIREmbedder::create(MIR2VecKind::Symbolic, MF, *Vocab);
-  if (!Emb) {
-    WithColor::error(errs(), ToolName)
-        << "Failed to create embedder for " << MF.getName() << "\n";
-    return;
-  }
-
-  OS << "MIR2Vec embeddings for machine function " << MF.getName() << ":\n";
-
-  // Generate embeddings based on the specified level
-  switch (Level) {
-  case FunctionLevel:
-    OS << "Function vector: ";
-    Emb->getMFunctionVector().print(OS);
-    break;
-  case BasicBlockLevel:
-    OS << "Basic block vectors:\n";
-    for (const MachineBasicBlock &MBB : MF) {
-      OS << "MBB " << MBB.getName() << ": ";
-      Emb->getMBBVector(MBB).print(OS);
-    }
-    break;
-  case InstructionLevel:
-    OS << "Instruction vectors:\n";
-    for (const MachineBasicBlock &MBB : MF) {
-      for (const MachineInstr &MI : MBB) {
-        OS << MI << " -> ";
-        Emb->getMInstVector(MI).print(OS);
-      }
-    }
-    break;
-  }
-}
-
-} // namespace mir2vec
-
-} // namespace llvm
+} // namespace llvm
\ No newline at end of file
diff --git a/llvm/tools/llvm-ir2vec/lib/IRUtils.h b/llvm/tools/llvm-ir2vec/lib/IRUtils.h
new file mode 100644
index 0000000000000..9fb6800da77a4
--- /dev/null
+++ b/llvm/tools/llvm-ir2vec/lib/IRUtils.h
@@ -0,0 +1,119 @@
+//===- IRUtils.h - IR2Vec Tool Class ------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// This file contains the IR2VecTool class definition for generating
+/// embeddings and triplets from LLVM IR. It has no dependency on Machine IR.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_TOOLS_LLVM_IR2VEC_UTILS_IRUTILS_H
+#define LLVM_TOOLS_LLVM_IR2VEC_UTILS_IRUTILS_H
+
+#include "Common.h"
+#include "llvm/ADT/DenseMap.h"
+#include "llvm/Analysis/IR2Vec.h"
+#include "llvm/IR/Function.h"
+#include "llvm/IR/Module.h"
+#include "llvm/IR/PassInstrumentation.h"
+#include "llvm/IR/PassManager.h"
+#include "llvm/Support/Error.h"
+#include "llvm/Support/raw_ostream.h"
+#include <memory>
+
+#define DEBUG_TYPE "ir2vec"
+
+namespace llvm {
+
+/// Per-function embedding map: Function* -> Embedding
+using FuncEmbMap = DenseMap<const Function *, ir2vec::Embedding>;
+
+namespace ir2vec {
+
+/// Relation types for IR triplet generation
+enum RelationType {
+  TypeRelation = 0, ///< Instruction to type relationship
+  NextRelation = 1, ///< Sequential instruction relationship
+  ArgRelation = 2   ///< Instruction to operand relationship (ArgRelation + N)
+};
+
+/// Load an IR2Vec vocabulary from a JSON file on disk.
+Expected<std::shared_ptr<Vocabulary>> loadVocabulary(StringRef VocabPath);
+
+/// Helper class for collecting IR triplets and generating embeddings
+class IR2VecTool {
+private:
+  Module &M;
+  ModuleAnalysisManager MAM;
+
+  /// \note The API around vocab object is not thread-safe.
+  /// Specifically, calling setVocabulary() on an instance while
+  /// another thread reading the Vocab object with the same instance
+  /// can cause a data race on this internal shared_ptr<Vocabulary> member.
+  std::shared_ptr<Vocabulary> Vocab;
+
+public:
+  explicit IR2VecTool(Module &M) : M(M) {}
+
+  /// Creates the embedding object for downstream embedding streaming
+  Expected<std::unique_ptr<Embedder>>
+  createIR2VecEmbedder(const Function &F, IR2VecKind Kind) const;
+
+  /// Sets the vocabulary for this tool instance.
+  /// This allows sharing the same vocabulary instance across multiple
+  /// IR2VecTool instances, which is useful for generating embeddings for
+  /// multiple functions without needing to reload the vocabulary each time.
+  Error setVocabulary(std::shared_ptr<Vocabulary> V);
+
+  /// Generate triplets for a single function
+  /// Returns a TripletResult with:
+  ///   - Triplets: vector of all (subject, object, relation) tuples
+  ///   - MaxRelation: highest Arg relation ID used, or NextRelation if none
+  TripletResult generateTriplets(const Function &F) const;
+
+  /// Get triplets for the entire module
+  TripletResult generateTriplets() const;
+
+  /// Collect triplets for the module and dump output to stream
+  /// Output format: MAX_RELATION=N header followed by relationships
+  void writeTripletsToStream(raw_ostream &OS) const;
+
+  /// Generate entity mappings for the entire vocabulary
+  /// Returns EntityList containing all entity strings
+  static EntityList collectEntityMappings();
+
+  /// Dump entity ID to string mappings
+  static void writeEntitiesToStream(raw_ostream &OS);
+
+  /// Get embedding for a single function
+  Expected<Embedding> getFunctionEmbedding(const Function &F,
+                                           IR2VecKind Kind) const;
+
+  /// Get embeddings for all functions in the module
+  Expected<FuncEmbMap> getFunctionEmbeddingsMap(IR2VecKind Kind) const;
+
+  /// Get embeddings for all basic blocks in a function
+  Expected<BBEmbeddingsMap> getBBEmbeddingsMap(const Function &F,
+                                               IR2VecKind Kind) const;
+
+  /// Get embeddings for all instructions in a function
+  Expected<InstEmbeddingsMap> getInstEmbeddingsMap(const Function &F,
+                                                   IR2VecKind Kind) const;
+
+  /// Generate embeddings for the entire module
+  void writeEmbeddingsToStream(raw_ostream &OS, EmbeddingLevel Level) const;
+
+  /// Generate embeddings for a single function
+  void writeEmbeddingsToStream(const Function &F, raw_ostream &OS,
+                               EmbeddingLevel Level) const;
+};
+
+} // namespace ir2vec
+} // namespace llvm
+
+#endif // LLVM_TOOLS_LLVM_IR2VEC_UTILS_IRUTILS_H
\ No newline at end of file
diff --git a/llvm/tools/llvm-ir2vec/lib/MIRUtils.cpp b/llvm/tools/llvm-ir2vec/lib/MIRUtils.cpp
new file mode 100644
index 0000000000000..5b9ae71b62db1
--- /dev/null
+++ b/llvm/tools/llvm-ir2vec/lib/MIRUtils.cpp
@@ -0,0 +1,236 @@
+//===- MIRUtils.cpp - MIR2Vec Embedding Generation --------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// This file implements the MIR2VecTool class for MIR2Vec embedding generation
+/// from LLVM Machine IR. It has no dependency on the IR2Vec embedding API.
+///
+//===----------------------------------------------------------------------===//
+
+#include "MIRUtils.h"
+#include "llvm/CodeGen/MIR2Vec.h"
+#include "llvm/CodeGen/MIRParser/MIRParser.h"
+#include "llvm/CodeGen/MachineFunction.h"
+#include "llvm/CodeGen/MachineModuleInfo.h"
+#include "llvm/CodeGen/TargetInstrInfo.h"
+#include "llvm/CodeGen/TargetRegisterInfo.h"
+#include "llvm/Support/Debug.h"
+#include "llvm/Support/WithColor.h"
+#include "llvm/Support/raw_ostream.h"
+#include "llvm/Target/TargetMachine.h"
+
+#define DEBUG_TYPE "ir2vec"
+
+namespace llvm {
+namespace mir2vec {
+
+bool MIR2VecTool::initializeVocabulary(const Module &M) {
+  MIR2VecVocabProvider Provider(MMI);
+  auto VocabOrErr = Provider.getVocabulary(M);
+  if (!VocabOrErr) {
+    WithColor::error(errs(), ToolName)
+        << "Failed to load MIR2Vec vocabulary - "
+        << toString(VocabOrErr.takeError()) << "\n";
+    return false;
+  }
+  Vocab = std::make_unique<MIRVocabulary>(std::move(*VocabOrErr));
+  return true;
+}
+
+bool MIR2VecTool::initializeVocabularyForLayout(const Module &M) {
+  for (const Function &F : M.getFunctionDefs()) {
+    MachineFunction *MF = MMI.getMachineFunction(F);
+    if (!MF)
+      continue;
+
+    const TargetInstrInfo &TII = *MF->getSubtarget().getInstrInfo();
+    const TargetRegisterInfo &TRI = *MF->getSubtarget().getRegisterInfo();
+    const MachineRegisterInfo &MRI = MF->getRegInfo();
+
+    auto VocabOrErr = MIRVocabulary::createDummyVocabForTest(TII, TRI, MRI, 1);
+    if (!VocabOrErr) {
+      WithColor::error(errs(), ToolName)
+          << "Failed to create dummy vocabulary - "
+          << toString(VocabOrErr.takeError()) << "\n";
+      return false;
+    }
+    Vocab = std::make_unique<MIRVocabulary>(std::move(*VocabOrErr));
+    return true;
+  }
+
+  WithColor::error(errs(), ToolName)
+      << "No machine functions found to initialize vocabulary\n";
+  return false;
+}
+
+TripletResult MIR2VecTool::generateTriplets(const MachineFunction &MF) const {
+  TripletResult Result;
+  Result.MaxRelation = MIRNextRelation;
+
+  if (!Vocab) {
+    WithColor::error(errs(), ToolName)
+        << "MIR Vocabulary must be initialized for triplet generation.\n";
+    return Result;
+  }
+
+  unsigned PrevOpcode = 0;
+  bool HasPrevOpcode = false;
+  for (const MachineBasicBlock &MBB : MF) {
+    for (const MachineInstr &MI : MBB) {
+      if (MI.isDebugInstr())
+        continue;
+
+      unsigned OpcodeID = Vocab->getEntityIDForOpcode(MI.getOpcode());
+
+      if (HasPrevOpcode) {
+        Result.Triplets.push_back({PrevOpcode, OpcodeID, MIRNextRelation});
+        LLVM_DEBUG(dbgs() << Vocab->getStringKey(PrevOpcode) << '\t'
+                          << Vocab->getStringKey(OpcodeID) << '\t' << "Next\n");
+      }
+
+      unsigned ArgIndex = 0;
+      for (const MachineOperand &MO : MI.operands()) {
+        auto OperandID = Vocab->getEntityIDForMachineOperand(MO);
+        unsigned RelationID = MIRArgRelation + ArgIndex;
+        Result.Triplets.push_back({OpcodeID, OperandID, RelationID});
+        LLVM_DEBUG({
+          std::string OperandStr = Vocab->getStringKey(OperandID);
+          dbgs() << Vocab->getStringKey(OpcodeID) << '\t' << OperandStr << '\t'
+                 << "Arg" << ArgIndex << '\n';
+        });
+
+        ++ArgIndex;
+      }
+
+      if (ArgIndex > 0)
+        Result.MaxRelation =
+            std::max(Result.MaxRelation, MIRArgRelation + ArgIndex - 1);
+
+      PrevOpcode = OpcodeID;
+      HasPrevOpcode = true;
+    }
+  }
+
+  return Result;
+}
+
+TripletResult MIR2VecTool::generateTriplets(const Module &M) const {
+  TripletResult Result;
+  Result.MaxRelation = MIRNextRelation;
+
+  for (const Function &F : M.getFunctionDefs()) {
+    MachineFunction *MF = MMI.getMachineFunction(F);
+    if (!MF) {
+      WithColor::warning(errs(), ToolName)
+          << "No MachineFunction for " << F.getName() << "\n";
+      continue;
+    }
+
+    TripletResult FuncResult = generateTriplets(*MF);
+    Result.MaxRelation = std::max(Result.MaxRelation, FuncResult.MaxRelation);
+    Result.Triplets.insert(Result.Triplets.end(), FuncResult.Triplets.begin(),
+                           FuncResult.Triplets.end());
+  }
+
+  return Result;
+}
+
+void MIR2VecTool::writeTripletsToStream(const Module &M,
+                                        raw_ostream &OS) const {
+  auto Result = generateTriplets(M);
+  OS << "MAX_RELATION=" << Result.MaxRelation << '\n';
+  for (const auto &T : Result.Triplets)
+    OS << T.Head << '\t' << T.Tail << '\t' << T.Relation << '\n';
+}
+
+EntityList MIR2VecTool::collectEntityMappings() const {
+  if (!Vocab) {
+    WithColor::error(errs(), ToolName)
+        << "Vocabulary must be initialized for entity mappings.\n";
+    return {};
+  }
+
+  const unsigned EntityCount = Vocab->getCanonicalSize();
+  EntityList Result;
+  for (unsigned EntityID = 0; EntityID < EntityCount; ++EntityID)
+    Result.push_back(Vocab->getStringKey(EntityID));
+
+  return Result;
+}
+
+void MIR2VecTool::writeEntitiesToStream(raw_ostream &OS) const {
+  auto Entities = collectEntityMappings();
+  if (Entities.empty())
+    return;
+
+  OS << Entities.size() << "\n";
+  for (unsigned EntityID = 0; EntityID < Entities.size(); ++EntityID)
+    OS << Entities[EntityID] << '\t' << EntityID << '\n';
+}
+
+void MIR2VecTool::writeEmbeddingsToStream(const Module &M, raw_ostream &OS,
+                                          EmbeddingLevel Level) const {
+  if (!Vocab) {
+    WithColor::error(errs(), ToolName) << "Vocabulary not initialized.\n";
+    return;
+  }
+
+  for (const Function &F : M.getFunctionDefs()) {
+    MachineFunction *MF = MMI.getMachineFunction(F);
+    if (!MF) {
+      WithColor::warning(errs(), ToolName)
+          << "No MachineFunction for " << F.getName() << "\n";
+      continue;
+    }
+
+    writeEmbeddingsToStream(*MF, OS, Level);
+  }
+}
+
+void MIR2VecTool::writeEmbeddingsToStream(MachineFunction &MF, raw_ostream &OS,
+                                          EmbeddingLevel Level) const {
+  if (!Vocab) {
+    WithColor::error(errs(), ToolName) << "Vocabulary not initialized.\n";
+    return;
+  }
+
+  auto Emb = MIREmbedder::create(MIR2VecKind::Symbolic, MF, *Vocab);
+  if (!Emb) {
+    WithColor::error(errs(), ToolName)
+        << "Failed to create embedder for " << MF.getName() << "\n";
+    return;
+  }
+
+  OS << "MIR2Vec embeddings for machine function " << MF.getName() << ":\n";
+
+  switch (Level) {
+  case FunctionLevel:
+    OS << "Function vector: ";
+    Emb->getMFunctionVector().print(OS);
+    break;
+  case BasicBlockLevel:
+    OS << "Basic block vectors:\n";
+    for (const MachineBasicBlock &MBB : MF) {
+      OS << "MBB " << MBB.getName() << ": ";
+      Emb->getMBBVector(MBB).print(OS);
+    }
+    break;
+  case InstructionLevel:
+    OS << "Instruction vectors:\n";
+    for (const MachineBasicBlock &MBB : MF) {
+      for (const MachineInstr &MI : MBB) {
+        OS << MI << " -> ";
+        Emb->getMInstVector(MI).print(OS);
+      }
+    }
+    break;
+  }
+}
+
+} // namespace mir2vec
+} // namespace llvm
\ No newline at end of file
diff --git a/llvm/tools/llvm-ir2vec/lib/MIRUtils.h b/llvm/tools/llvm-ir2vec/lib/MIRUtils.h
new file mode 100644
index 0000000000000..5cb491c5b815c
--- /dev/null
+++ b/llvm/tools/llvm-ir2vec/lib/MIRUtils.h
@@ -0,0 +1,108 @@
+//===- MIRUtils.h - MIR2Vec Tool Class ----------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// This file contains the MIR2VecTool class definition for generating
+/// embeddings and triplets from LLVM Machine IR. It has no dependency on
+/// the LLVM IR embedding API (IR2VecTool).
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_TOOLS_LLVM_IR2VEC_UTILS_MIRUTILS_H
+#define LLVM_TOOLS_LLVM_IR2VEC_UTILS_MIRUTILS_H
+
+#include "Common.h"
+#include "llvm/CodeGen/MIR2Vec.h"
+#include "llvm/CodeGen/MIRParser/MIRParser.h"
+#include "llvm/CodeGen/MachineFunction.h"
+#include "llvm/CodeGen/MachineModuleInfo.h"
+#include "llvm/CodeGen/TargetInstrInfo.h"
+#include "llvm/CodeGen/TargetRegisterInfo.h"
+#include "llvm/IR/LLVMContext.h"
+#include "llvm/IR/Module.h"
+#include "llvm/Support/Error.h"
+#include "llvm/Support/raw_ostream.h"
+#include "llvm/Target/TargetMachine.h"
+#include <memory>
+
+namespace llvm {
+
+namespace mir2vec {
+
+/// Relation types for MIR2Vec triplet generation
+enum MIRRelationType {
+  MIRNextRelation = 0, ///< Sequential instruction relationship
+  MIRArgRelation = 1 ///< Instruction to operand relationship (ArgRelation + N)
+};
+
+/// Helper class for MIR2Vec embedding generation
+class MIR2VecTool {
+private:
+  MachineModuleInfo &MMI;
+  std::unique_ptr<MIRVocabulary> Vocab;
+
+public:
+  explicit MIR2VecTool(MachineModuleInfo &MMI) : MMI(MMI) {}
+
+  /// Initialize MIR2Vec vocabulary from file (for embeddings generation)
+  bool initializeVocabulary(const Module &M);
+
+  /// Initialize vocabulary with layout information only.
+  /// This creates a minimal vocabulary with correct layout but no actual
+  /// embeddings. Sufficient for generating training data and entity mappings.
+  ///
+  /// Note: Requires target-specific information from the first machine function
+  /// to determine the vocabulary layout (number of opcodes, register classes).
+  ///
+  /// FIXME: Use --target option to get target info directly, avoiding the need
+  /// to parse machine functions for pre-training operations.
+  bool initializeVocabularyForLayout(const Module &M);
+
+  /// Get triplets for a single machine function
+  /// Returns TripletResult containing MaxRelation and vector of Triplets
+  TripletResult generateTriplets(const MachineFunction &MF) const;
+
+  /// Get triplets for the entire module
+  /// Returns TripletResult containing aggregated MaxRelation and all Triplets
+  TripletResult generateTriplets(const Module &M) const;
+
+  /// Collect triplets for the module and write to output stream
+  /// Output format: MAX_RELATION=N header followed by relationships
+  void writeTripletsToStream(const Module &M, raw_ostream &OS) const;
+
+  /// Generate entity mappings for the entire vocabulary
+  EntityList collectEntityMappings() const;
+
+  /// Generate entity mappings and write to output stream
+  void writeEntitiesToStream(raw_ostream &OS) const;
+
+  /// Generate embeddings for all machine functions in the module
+  void writeEmbeddingsToStream(const Module &M, raw_ostream &OS,
+                               EmbeddingLevel Level) const;
+
+  /// Generate embeddings for a specific machine function
+  void writeEmbeddingsToStream(MachineFunction &MF, raw_ostream &OS,
+                               EmbeddingLevel Level) const;
+
+  /// Get the MIR vocabulary instance
+  const MIRVocabulary *getVocabulary() const { return Vocab.get(); }
+};
+
+/// Helper structure to hold MIR context.
+/// CRITICAL: Member declaration order matters for correct destruction.
+struct MIRContext {
+  LLVMContext Context; // Must be first: other members hold references into it
+  std::unique_ptr<Module> M;
+  std::unique_ptr<MachineModuleInfo> MMI;
+  std::unique_ptr<TargetMachine> TM;
+};
+
+} // namespace mir2vec
+} // namespace llvm
+
+#endif // LLVM_TOOLS_LLVM_IR2VEC_UTILS_MIRUTILS_H
\ No newline at end of file
diff --git a/llvm/tools/llvm-ir2vec/lib/Utils.h b/llvm/tools/llvm-ir2vec/lib/Utils.h
deleted file mode 100644
index 9856ae6f9c168..0000000000000
--- a/llvm/tools/llvm-ir2vec/lib/Utils.h
+++ /dev/null
@@ -1,232 +0,0 @@
-//===- Utils.h - IR2Vec/MIR2Vec Tool Classes ----------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-///
-/// \file
-/// This file contains the IR2VecTool and MIR2VecTool class definitions for
-/// the llvm-ir2vec embedding generation tool.
-///
-//===----------------------------------------------------------------------===//
-
-#ifndef LLVM_TOOLS_LLVM_IR2VEC_UTILS_UTILS_H
-#define LLVM_TOOLS_LLVM_IR2VEC_UTILS_UTILS_H
-
-#include "llvm/ADT/ArrayRef.h"
-#include "llvm/ADT/DenseMap.h"
-#include "llvm/Analysis/IR2Vec.h"
-#include "llvm/CodeGen/MIR2Vec.h"
-#include "llvm/CodeGen/MIRParser/MIRParser.h"
-#include "llvm/CodeGen/MachineFunction.h"
-#include "llvm/CodeGen/MachineModuleInfo.h"
-#include "llvm/CodeGen/TargetInstrInfo.h"
-#include "llvm/CodeGen/TargetRegisterInfo.h"
-#include "llvm/IR/BasicBlock.h"
-#include "llvm/IR/Function.h"
-#include "llvm/IR/InstIterator.h"
-#include "llvm/IR/Instructions.h"
-#include "llvm/IR/LLVMContext.h"
-#include "llvm/IR/Module.h"
-#include "llvm/IR/PassInstrumentation.h"
-#include "llvm/IR/PassManager.h"
-#include "llvm/IR/Type.h"
-#include "llvm/Support/Debug.h"
-#include "llvm/Support/Error.h"
-#include "llvm/Support/WithColor.h"
-#include "llvm/Support/raw_ostream.h"
-#include "llvm/Target/TargetMachine.h"
-#include <memory>
-#include <string>
-#include <vector>
-
-#define DEBUG_TYPE "ir2vec"
-
-namespace llvm {
-
-/// Tool name for error reporting
-static const char *ToolName = "llvm-ir2vec";
-
-/// Specifies the granularity at which embeddings are generated.
-enum EmbeddingLevel {
-  InstructionLevel, // Generate instruction-level embeddings
-  BasicBlockLevel,  // Generate basic block-level embeddings
-  FunctionLevel     // Generate function-level embeddings
-};
-
-/// Represents a single knowledge graph triplet (Head, Relation, Tail)
-/// where indices reference entities in an EntityList
-struct Triplet {
-  unsigned Head = 0;     ///< Index of the head entity in the entity list
-  unsigned Tail = 0;     ///< Index of the tail entity in the entity list
-  unsigned Relation = 0; ///< Relation type (see RelationType enum)
-};
-
-/// Result structure containing all generated triplets and metadata
-struct TripletResult {
-  unsigned MaxRelation =
-      0; ///< Highest relation index used (for ArgRelation + N)
-  std::vector<Triplet> Triplets; ///< Collection of all generated triplets
-};
-
-/// Entity mappings: [entity_name]
-using EntityList = std::vector<std::string>;
-using FuncEmbMap = DenseMap<const Function *, ir2vec::Embedding>;
-
-namespace ir2vec {
-
-/// Relation types for triplet generation
-enum RelationType {
-  TypeRelation = 0, ///< Instruction to type relationship
-  NextRelation = 1, ///< Sequential instruction relationship
-  ArgRelation = 2   ///< Instruction to operand relationship (ArgRelation + N)
-};
-
-/// Load an IR2Vec vocabulary from a JSON file on disk.
-Expected<std::shared_ptr<Vocabulary>> loadVocabulary(StringRef VocabPath);
-
-/// Helper class for collecting IR triplets and generating embeddings
-class IR2VecTool {
-private:
-  Module &M;
-  ModuleAnalysisManager MAM;
-
-  /// \note The API around vocab object is not thread-safe.
-  /// Specifically, calling setVocabulary() on an instance while
-  /// another thread reading the Vocab object with the same instance
-  /// can cause a data race on this internal shared_ptr<Vocabulary> member.
-  std::shared_ptr<Vocabulary> Vocab;
-
-public:
-  explicit IR2VecTool(Module &M) : M(M) {}
-
-  /// Creates the embedding object for downstream embedding streaming
-  Expected<std::unique_ptr<Embedder>>
-  createIR2VecEmbedder(const Function &F, IR2VecKind Kind) const;
-
-  /// Sets the vocabulary for this tool instance.
-  /// This allows sharing the same vocabulary instance across multiple
-  /// IR2VecTool instances, which is useful for generating embeddings for
-  /// multiple functions without needing to reload the vocabulary each time.
-  Error setVocabulary(std::shared_ptr<Vocabulary> V);
-
-  /// Generate triplets for a single function
-  /// Returns a TripletResult with:
-  ///   - Triplets: vector of all (subject, object, relation) tuples
-  ///   - MaxRelation: highest Arg relation ID used, or NextRelation if none
-  TripletResult generateTriplets(const Function &F) const;
-
-  /// Get triplets for the entire module
-  TripletResult generateTriplets() const;
-
-  /// Collect triplets for the module and dump output to stream
-  /// Output format: MAX_RELATION=N header followed by relationships
-  void writeTripletsToStream(raw_ostream &OS) const;
-
-  /// Generate entity mappings for the entire vocabulary
-  /// Returns EntityList containing all entity strings
-  static EntityList collectEntityMappings();
-
-  /// Dump entity ID to string mappings
-  static void writeEntitiesToStream(raw_ostream &OS);
-
-  // Get embedding for a single function
-  Expected<Embedding> getFunctionEmbedding(const Function &F,
-                                           IR2VecKind Kind) const;
-
-  /// Get embeddings for all functions in the module
-  Expected<FuncEmbMap> getFunctionEmbeddingsMap(IR2VecKind Kind) const;
-
-  /// Get embeddings for all basic blocks in a function
-  Expected<BBEmbeddingsMap> getBBEmbeddingsMap(const Function &F,
-                                               IR2VecKind Kind) const;
-  /// Get embeddings for all instructions in a function
-  Expected<InstEmbeddingsMap> getInstEmbeddingsMap(const Function &F,
-                                                   IR2VecKind Kind) const;
-
-  /// Generate embeddings for the entire module
-  void writeEmbeddingsToStream(raw_ostream &OS, EmbeddingLevel Level) const;
-
-  /// Generate embeddings for a single function
-  void writeEmbeddingsToStream(const Function &F, raw_ostream &OS,
-                               EmbeddingLevel Level) const;
-};
-
-} // namespace ir2vec
-
-namespace mir2vec {
-
-/// Relation types for MIR2Vec triplet generation
-enum MIRRelationType {
-  MIRNextRelation = 0, ///< Sequential instruction relationship
-  MIRArgRelation = 1 ///< Instruction to operand relationship (ArgRelation + N)
-};
-
-/// Helper class for MIR2Vec embedding generation
-class MIR2VecTool {
-private:
-  MachineModuleInfo &MMI;
-  std::unique_ptr<MIRVocabulary> Vocab;
-
-public:
-  explicit MIR2VecTool(MachineModuleInfo &MMI) : MMI(MMI) {}
-
-  /// Initialize MIR2Vec vocabulary from file (for embeddings generation)
-  bool initializeVocabulary(const Module &M);
-
-  /// Initialize vocabulary with layout information only.
-  /// This creates a minimal vocabulary with correct layout but no actual
-  /// embeddings. Sufficient for generating training data and entity mappings.
-  ///
-  /// Note: Requires target-specific information from the first machine function
-  /// to determine the vocabulary layout (number of opcodes, register classes).
-  ///
-  /// FIXME: Use --target option to get target info directly, avoiding the need
-  /// to parse machine functions for pre-training operations.
-  bool initializeVocabularyForLayout(const Module &M);
-
-  /// Get triplets for a single machine function
-  /// Returns TripletResult containing MaxRelation and vector of Triplets
-  TripletResult generateTriplets(const MachineFunction &MF) const;
-
-  /// Get triplets for the entire module
-  /// Returns TripletResult containing aggregated MaxRelation and all Triplets
-  TripletResult generateTriplets(const Module &M) const;
-
-  /// Collect triplets for the module and write to output stream
-  /// Output format: MAX_RELATION=N header followed by relationships
-  void writeTripletsToStream(const Module &M, raw_ostream &OS) const;
-
-  /// Generate entity mappings for the entire vocabulary
-  EntityList collectEntityMappings() const;
-
-  /// Generate entity mappings and write to output stream
-  void writeEntitiesToStream(raw_ostream &OS) const;
-
-  /// Generate embeddings for all machine functions in the module
-  void writeEmbeddingsToStream(const Module &M, raw_ostream &OS,
-                               EmbeddingLevel Level) const;
-
-  /// Generate embeddings for a specific machine function
-  void writeEmbeddingsToStream(MachineFunction &MF, raw_ostream &OS,
-                               EmbeddingLevel Level) const;
-
-  /// Get the MIR vocabulary instance
-  const MIRVocabulary *getVocabulary() const { return Vocab.get(); }
-};
-
-/// Helper structure to hold MIR context
-struct MIRContext {
-  LLVMContext Context; // CRITICAL: Must be first for proper destruction order
-  std::unique_ptr<Module> M;
-  std::unique_ptr<MachineModuleInfo> MMI;
-  std::unique_ptr<TargetMachine> TM;
-};
-
-} // namespace mir2vec
-
-} // namespace llvm
-
-#endif // LLVM_TOOLS_LLVM_IR2VEC_UTILS_UTILS_H
diff --git a/llvm/tools/llvm-ir2vec/llvm-ir2vec.cpp b/llvm/tools/llvm-ir2vec/llvm-ir2vec.cpp
index 372f1d06b6b6e..8c45fad0681a2 100644
--- a/llvm/tools/llvm-ir2vec/llvm-ir2vec.cpp
+++ b/llvm/tools/llvm-ir2vec/llvm-ir2vec.cpp
@@ -54,7 +54,8 @@
 ///
 //===----------------------------------------------------------------------===//
 
-#include "lib/Utils.h"
+#include "lib/IRUtils.h"
+#include "lib/MIRUtils.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/Analysis/IR2Vec.h"
 #include "llvm/CodeGen/CommandFlags.h"



More information about the llvm-commits mailing list