[llvm] [llvm-ir2vec] Adding initEmbedding API to ir2vec python bindings (PR #177092)

Nishant Sachdeva via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 29 23:04:11 PST 2026


================
@@ -6,8 +6,80 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include "lib/Utils.h"
+#include "llvm/IR/LLVMContext.h"
+#include "llvm/IR/Module.h"
+#include "llvm/IRReader/IRReader.h"
+#include "llvm/Support/SourceMgr.h"
+
 #include <nanobind/nanobind.h>
+#include <nanobind/stl/string.h>
+#include <nanobind/stl/unique_ptr.h>
+
+#include <fstream>
+#include <memory>
+#include <string>
 
 namespace nb = nanobind;
+using namespace llvm;
+using namespace llvm::ir2vec;
+
+namespace {
+
+std::unique_ptr<Module> getLLVMIR(const std::string &Filename,
+                                  LLVMContext &Context) {
+  SMDiagnostic Err;
+  auto M = parseIRFile(Filename, Err, Context);
+  if (!M)
+    throw nb::value_error(("Failed to parse IR file '" + Filename +
----------------
nishant-sachdeva wrote:

Per `mlir/cmake/modules/AddMLIRPython.cmake :: L871-891`, we have 

```
################################################################################
# Build python extension
################################################################################
.......
.......
.......
  # The extension itself must be compiled with RTTI and exceptions enabled.
  # Also, some warning classes triggered by nanobind are disabled.
  set(eh_rtti_enable)
  if (MSVC)
    set(eh_rtti_enable /EHsc /GR)
  elseif(LLVM_COMPILER_IS_GCC_COMPATIBLE OR CLANG_CL)
    set(eh_rtti_enable -frtti -fexceptions)
  endif ()
```

Here, we can see that the python bindings are compiled with `eh_rtti_enable -frtti -fexceptions` flags 

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


More information about the llvm-commits mailing list