Unverified Commit 3f8e6b59 authored by Lei Wang's avatar Lei Wang Committed by GitHub
Browse files

[Builder] Enhance variable name binding and scope management (#1378)

- Improved handling of TVM Var/Buffer names to prevent out-of-scope errors when reusing Python names across different for-frames.
- Added assertions to ensure variables are defined within the correct control flow frame, enhancing error checking and code reliability.
parent 0921328d
...@@ -409,7 +409,14 @@ class Builder(BaseBuilder): ...@@ -409,7 +409,14 @@ class Builder(BaseBuilder):
if isinstance(value, tir.IntImm) and value.dtype == 'int32': if isinstance(value, tir.IntImm) and value.dtype == 'int32':
return value.value return value.value
if isinstance(value, (Var, Buffer)): if isinstance(value, (Var, Buffer)):
# Bind TVM Var/Buffer names and also record scope so reusing the same
# Python name (e.g., loop vars like `i`) across different for-frames
# works without triggering out-of-scope errors.
IRBuilder.name(name, value) IRBuilder.name(name, value)
if name != '_':
frame = self.find_frame_idx(TIR_VAR_SCOPE_FRAME)
assert frame is not None, f"Variable `{name}` is not defined inside any control flow."
self.name_inside_frame[name] = self.frames[frame]
return value return value
# 3. Bind immutable tilelang objects # 3. Bind immutable tilelang objects
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment