[llvm] [llvm-ir2vec] adding function-embedding map API to ir2vec python bindings (PR #177166)

Nishant Sachdeva via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 3 23:32:47 PST 2026


================
@@ -62,6 +69,27 @@ class PyIR2VecTool {
                                 .c_str());
     }
   }
+
+  nb::dict getFuncEmbMap() {
+    auto ToolFuncEmbMap = Tool->getFunctionEmbeddingsMap(OutputEmbeddingMode);
+    nb::dict NBFuncEmbMap;
+
+    for (const auto &[FuncPtr, FuncEmb] : ToolFuncEmbMap) {
+      std::string FuncName = FuncPtr->getName().str();
+      auto Data = FuncEmb.getData();
+      size_t Shape[1] = {Data.size()};
+      double *DataPtr = new double[Data.size()];
----------------
nishant-sachdeva wrote:

Technically, no. However, the capsule declaration does expect us to pass destructors etc.
We can also use a shared_ptr here too. Just that we have to pass a destructor anyway. 

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


More information about the llvm-commits mailing list