-
-
Notifications
You must be signed in to change notification settings - Fork 813
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix[venom]: fix duplicate allocas (#4321)
this commit fixes a bug in the ir_node_to_venom translator. previously, `ir_node_to_venom` tried to detect unique allocas based on heuristics. this commit removes the heuristics and fixes the issue in the frontend by passing through a unique ID for each variable in the metadata. this ID is also passed into the `alloca` and `palloca` instructions to aid with debugging. note that this results in improved code, presumably due to more allocas being able to be reified. this commit makes a minor change to the `sqrt()`, builtin, which is to use `z_var.as_ir_node()` instead of `z_var.pos`, since `.as_ir_node()` correctly tags with the alloca metadata. to be maximally conservative, we could branch, only using `z_var.as_ir_node()` if we are using the venom pipeline, but the change should be correct for the legacy pipeline as well anyways. --------- Co-authored-by: Harry Kalogirou <[email protected]>
- Loading branch information
1 parent
f249c93
commit cda634d
Showing
9 changed files
with
89 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
from vyper.venom.passes.base_pass import IRPass | ||
|
||
|
||
class FloatAllocas(IRPass): | ||
""" | ||
This pass moves allocas to the entry basic block of a function | ||
We could probably move them to the immediate dominator of the basic | ||
block defining the alloca instead of the entry (which dominates all | ||
basic blocks), but this is done for expedience. | ||
Without this step, sccp fails, possibly because dominators are not | ||
guaranteed to be traversed first. | ||
""" | ||
|
||
def run_pass(self): | ||
entry_bb = self.function.entry | ||
assert entry_bb.is_terminated | ||
tmp = entry_bb.instructions.pop() | ||
|
||
for bb in self.function.get_basic_blocks(): | ||
if bb is entry_bb: | ||
continue | ||
|
||
# Extract alloca instructions | ||
non_alloca_instructions = [] | ||
for inst in bb.instructions: | ||
if inst.opcode in ("alloca", "palloca"): | ||
# note: order of allocas impacts bytecode. | ||
# TODO: investigate. | ||
entry_bb.insert_instruction(inst) | ||
else: | ||
non_alloca_instructions.append(inst) | ||
|
||
# Replace original instructions with filtered list | ||
bb.instructions = non_alloca_instructions | ||
|
||
entry_bb.instructions.append(tmp) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters