[llvm] [llvm-ir2vec] Adding getFuncNames API to ir2vec python bindings (PR #180473)
Nishant Sachdeva via llvm-commits
llvm-commits at lists.llvm.org
Thu Mar 5 09:50:36 PST 2026
https://github.com/nishant-sachdeva updated https://github.com/llvm/llvm-project/pull/180473
>From 8790834286fabc1a17b4a013172f2eb66a1aef5a Mon Sep 17 00:00:00 2001
From: nishant-sachdeva <nishant.sachdeva at research.iiit.ac.in>
Date: Mon, 9 Feb 2026 12:27:13 +0530
Subject: [PATCH] Adding getFuncNames API to ir2vec python bindings
---
.../tools/llvm-ir2vec/bindings/ir2vec-bindings.py | 10 ++++++++++
llvm/tools/llvm-ir2vec/Bindings/PyIR2Vec.cpp | 11 +++++++++++
2 files changed, 21 insertions(+)
diff --git a/llvm/test/tools/llvm-ir2vec/bindings/ir2vec-bindings.py b/llvm/test/tools/llvm-ir2vec/bindings/ir2vec-bindings.py
index bb29d33dc8ca6..c9c241ccf90c0 100644
--- a/llvm/test/tools/llvm-ir2vec/bindings/ir2vec-bindings.py
+++ b/llvm/test/tools/llvm-ir2vec/bindings/ir2vec-bindings.py
@@ -12,6 +12,12 @@
print("SUCCESS: Tool initialized")
print(f"Tool type: {type(tool).__name__}")
+ # Test getFuncNames
+ print("\n=== Function Names ===")
+ func_names = tool.getFuncNames()
+ for func_name in sorted(func_names):
+ print(f"Function: {func_name}")
+
# Test getFuncEmbMap
print("\n=== Function Embeddings ===")
func_emb_map = tool.getFuncEmbMap()
@@ -57,6 +63,10 @@
# CHECK: SUCCESS: Tool initialized
# CHECK: Tool type: IR2VecTool
+# CHECK: === Function Names ===
+# CHECK: Function: add
+# CHECK: Function: conditional
+# CHECK: Function: multiply
# CHECK: === Function Embeddings ===
# CHECK: Function: add
# CHECK-NEXT: Embedding: [38.0, 40.0, 42.0]
diff --git a/llvm/tools/llvm-ir2vec/Bindings/PyIR2Vec.cpp b/llvm/tools/llvm-ir2vec/Bindings/PyIR2Vec.cpp
index e4ddaf9c14e5a..df372aedb9b63 100644
--- a/llvm/tools/llvm-ir2vec/Bindings/PyIR2Vec.cpp
+++ b/llvm/tools/llvm-ir2vec/Bindings/PyIR2Vec.cpp
@@ -70,6 +70,14 @@ class PyIR2VecTool {
}
}
+ nb::list getFuncNames() {
+ nb::list NbFuncNames;
+ for (const Function &F : M->getFunctionDefs()) {
+ NbFuncNames.append(nb::str(F.getName().str().c_str()));
+ }
+ return NbFuncNames;
+ }
+
nb::dict getFuncEmbMap() {
auto ToolFuncEmbMap = Tool->getFunctionEmbeddingsMap(OutputEmbeddingMode);
@@ -196,6 +204,9 @@ NB_MODULE(ir2vec, m) {
.def(nb::init<const std::string &, const std::string &,
const std::string &>(),
nb::arg("filename"), nb::arg("mode"), nb::arg("vocabPath"))
+ .def("getFuncNames", &PyIR2VecTool::getFuncNames,
+ "Get list of all defined functions in the module\n"
+ "Returns: list[str] - Function names")
.def("getFuncEmbMap", &PyIR2VecTool::getFuncEmbMap,
"Generate function-level embeddings for all functions\n"
"Returns: dict[str, ndarray[float64]] - "
More information about the llvm-commits
mailing list