[llvm] [llvm-ir2vec] Added Enum for ir2vec embedding mode (PR #190466)
via llvm-commits
llvm-commits at lists.llvm.org
Sat Apr 4 08:38:36 PDT 2026
github-actions[bot] wrote:
<!--LLVM CODE FORMAT COMMENT: {darker}-->
:warning: Python code formatter, darker found issues in your code. :warning:
<details>
<summary>
You can test this locally with the following command:
</summary>
``````````bash
darker --check --diff -r origin/main...HEAD llvm/test/tools/llvm-ir2vec/bindings/ir2vec-getBBEmbMap.py llvm/test/tools/llvm-ir2vec/bindings/ir2vec-getFuncEmb.py llvm/test/tools/llvm-ir2vec/bindings/ir2vec-getFuncEmbMap.py llvm/test/tools/llvm-ir2vec/bindings/ir2vec-getFuncNames.py llvm/test/tools/llvm-ir2vec/bindings/ir2vec-getInstEmbMap.py llvm/test/tools/llvm-ir2vec/bindings/ir2vec-initEmbedding.py
``````````
:warning:
The reproduction instructions above might return results for more than one PR
in a stack if you are using a stacked PR workflow. You can limit the results by
changing `origin/main` to the base branch/commit you want to compare against.
:warning:
</details>
<details>
<summary>
View the diff from darker here.
</summary>
``````````diff
--- ir2vec-getBBEmbMap.py 2026-04-04 15:31:49.000000 +0000
+++ ir2vec-getBBEmbMap.py 2026-04-04 15:38:07.696033 +0000
@@ -4,11 +4,13 @@
import ir2vec
ll_file = sys.argv[1]
vocab_path = sys.argv[2]
-tool = ir2vec.initEmbedding(filename=ll_file, mode=ir2vec.IR2VecKind.Symbolic, vocabPath=vocab_path)
+tool = ir2vec.initEmbedding(
+ filename=ll_file, mode=ir2vec.IR2VecKind.Symbolic, vocabPath=vocab_path
+)
# Success case
bb_map = tool.getBBEmbMap("conditional")
for bb in sorted(bb_map.keys()):
print(f"BB: {bb}, EMB: {bb_map[bb].tolist()}")
--- ir2vec-getFuncEmb.py 2026-04-04 15:31:49.000000 +0000
+++ ir2vec-getFuncEmb.py 2026-04-04 15:38:07.709073 +0000
@@ -4,11 +4,13 @@
import ir2vec
ll_file = sys.argv[1]
vocab_path = sys.argv[2]
-tool = ir2vec.initEmbedding(filename=ll_file, mode=ir2vec.IR2VecKind.Symbolic, vocabPath=vocab_path)
+tool = ir2vec.initEmbedding(
+ filename=ll_file, mode=ir2vec.IR2VecKind.Symbolic, vocabPath=vocab_path
+)
# Success case
emb = tool.getFuncEmb("add")
print(f"SUCCESS: {emb.tolist()}")
# CHECK: SUCCESS: [38.0, 40.0, 42.0]
--- ir2vec-getFuncEmbMap.py 2026-04-04 15:31:49.000000 +0000
+++ ir2vec-getFuncEmbMap.py 2026-04-04 15:38:07.720533 +0000
@@ -4,11 +4,13 @@
import ir2vec
ll_file = sys.argv[1]
vocab_path = sys.argv[2]
-tool = ir2vec.initEmbedding(filename=ll_file, mode=ir2vec.IR2VecKind.Symbolic, vocabPath=vocab_path)
+tool = ir2vec.initEmbedding(
+ filename=ll_file, mode=ir2vec.IR2VecKind.Symbolic, vocabPath=vocab_path
+)
# Success case
emb_map = tool.getFuncEmbMap()
for name in sorted(emb_map.keys()):
print(f"FUNC: {name}, EMB: {emb_map[name].tolist()}")
--- ir2vec-getFuncNames.py 2026-04-04 15:31:49.000000 +0000
+++ ir2vec-getFuncNames.py 2026-04-04 15:38:07.731630 +0000
@@ -4,11 +4,13 @@
import ir2vec
ll_file = sys.argv[1]
vocab_path = sys.argv[2]
-tool = ir2vec.initEmbedding(filename=ll_file, mode=ir2vec.IR2VecKind.Symbolic, vocabPath=vocab_path)
+tool = ir2vec.initEmbedding(
+ filename=ll_file, mode=ir2vec.IR2VecKind.Symbolic, vocabPath=vocab_path
+)
# Success case
func_names = tool.getFuncNames()
for name in sorted(func_names):
print(f"FUNC: {name}")
--- ir2vec-getInstEmbMap.py 2026-04-04 15:31:49.000000 +0000
+++ ir2vec-getInstEmbMap.py 2026-04-04 15:38:07.744140 +0000
@@ -4,11 +4,13 @@
import ir2vec
ll_file = sys.argv[1]
vocab_path = sys.argv[2]
-tool = ir2vec.initEmbedding(filename=ll_file, mode=ir2vec.IR2VecKind.Symbolic, vocabPath=vocab_path)
+tool = ir2vec.initEmbedding(
+ filename=ll_file, mode=ir2vec.IR2VecKind.Symbolic, vocabPath=vocab_path
+)
# Success case
inst_map = tool.getInstEmbMap("add")
for inst in sorted(inst_map.keys()):
print(f"INST: {inst}")
--- ir2vec-initEmbedding.py 2026-04-04 15:31:49.000000 +0000
+++ ir2vec-initEmbedding.py 2026-04-04 15:38:07.767041 +0000
@@ -5,11 +5,13 @@
ll_file = sys.argv[1]
vocab_path = sys.argv[2]
# Success case
-tool = ir2vec.initEmbedding(filename=ll_file, mode=ir2vec.IR2VecKind.Symbolic, vocabPath=vocab_path)
+tool = ir2vec.initEmbedding(
+ filename=ll_file, mode=ir2vec.IR2VecKind.Symbolic, vocabPath=vocab_path
+)
print(f"SUCCESS: {type(tool).__name__}")
# CHECK: SUCCESS: IR2VecTool
# Error: Invalid mode
try:
@@ -18,32 +20,40 @@
print("ERROR: Invalid mode")
# CHECK: ERROR: Invalid mode
# Error: Empty vocab path
try:
- ir2vec.initEmbedding(filename=ll_file, mode=ir2vec.IR2VecKind.Symbolic, vocabPath="")
+ ir2vec.initEmbedding(
+ filename=ll_file, mode=ir2vec.IR2VecKind.Symbolic, vocabPath=""
+ )
except ValueError:
print("ERROR: Empty vocab path")
# CHECK: ERROR: Empty vocab path
# Error: Invalid file
try:
- ir2vec.initEmbedding(filename="/bad.ll", mode=ir2vec.IR2VecKind.Symbolic, vocabPath=vocab_path)
+ ir2vec.initEmbedding(
+ filename="/bad.ll", mode=ir2vec.IR2VecKind.Symbolic, vocabPath=vocab_path
+ )
except ValueError:
print("ERROR: Invalid file")
# CHECK: ERROR: Invalid file
# Error: Empty filename
try:
- ir2vec.initEmbedding(filename="", mode=ir2vec.IR2VecKind.Symbolic, vocabPath=vocab_path)
+ ir2vec.initEmbedding(
+ filename="", mode=ir2vec.IR2VecKind.Symbolic, vocabPath=vocab_path
+ )
except ValueError:
print("ERROR: Empty filename")
# CHECK: ERROR: Empty filename
# Error: Invalid vocab file
try:
- ir2vec.initEmbedding(filename=ll_file, mode=ir2vec.IR2VecKind.Symbolic, vocabPath="/bad.json")
+ ir2vec.initEmbedding(
+ filename=ll_file, mode=ir2vec.IR2VecKind.Symbolic, vocabPath="/bad.json"
+ )
except ValueError:
print("ERROR: Invalid vocab")
# CHECK: ERROR: Invalid vocab
# Error: Malformed JSON vocab
@@ -52,11 +62,13 @@
with tempfile.NamedTemporaryFile(mode="w", suffix=".json", delete=False) as f:
f.write("{ this is not valid json }")
bad_vocab = f.name
try:
- ir2vec.initEmbedding(filename=ll_file, mode=ir2vec.IR2VecKind.Symbolic, vocabPath=bad_vocab)
+ ir2vec.initEmbedding(
+ filename=ll_file, mode=ir2vec.IR2VecKind.Symbolic, vocabPath=bad_vocab
+ )
except ValueError:
print("ERROR: Invalid vocab file")
finally:
os.unlink(bad_vocab)
# CHECK: ERROR: Invalid vocab file
``````````
</details>
https://github.com/llvm/llvm-project/pull/190466
More information about the llvm-commits
mailing list