Skip to content

Commit

Permalink
Fix the metadata deduplication
Browse files Browse the repository at this point in the history
The llvmlite debug metadata cache does not work as expected due to
the encoding value using address of DIToken instance and serves as
part of the key.

Solution is to extract the string value from the encoding object.

Since the DIToken class is designed to be a wrapper of enumeration
value, e.g. the DW_* enumerations, that should appear bare in the
emitted metadata, in this change, stringify DIToken is made to fix
the problem.

This solved llvmlite issue #1164
  • Loading branch information
jiel-nv committed Mar 3, 2025
1 parent 39bfde4 commit a85c314
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
9 changes: 9 additions & 0 deletions llvmlite/ir/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,15 @@ def _fix_di_operands(self, operands):
fixed_ops.append((name, op))
return fixed_ops

def str_ditok_operands(self, operands):
str_ops = []
for name, op in operands:
if name == 'encoding' and isinstance(op, values.DIToken):
# use string value instead of address of object
op = op.value
str_ops.append((name, op))
return str_ops

def add_metadata(self, operands):
"""
Add an unnamed metadata to the module with the given *operands*
Expand Down
7 changes: 0 additions & 7 deletions llvmlite/ir/values.py
Original file line number Diff line number Diff line change
Expand Up @@ -705,13 +705,6 @@ class DIToken:
Use this to wrap known constants, e.g. the DW_* enumerations.
"""
_instance = None

def __new__(cls, value):
if not cls._instance or cls._instance.value != value:
cls._instance = super().__new__(cls)
cls._instance.value = value
return cls._instance

def __init__(self, value):
self.value = value
Expand Down

0 comments on commit a85c314

Please sign in to comment.