-
-
Notifications
You must be signed in to change notification settings - Fork 812
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat[venom]: propagate
dload
instruction to venom (#4410)
this commit propagates `dload` instructions to venom from the frontend. this improves our ability to merge `dload/mstore` instructions. then, after the LowerDload pass, we have stripped both `dload` and `dloadbytes` instructions from venom.
- Loading branch information
1 parent
eee31e7
commit 724559a
Showing
8 changed files
with
73 additions
and
36 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
from vyper.utils import MemoryPositions | ||
from vyper.venom.analysis import DFGAnalysis, LivenessAnalysis | ||
from vyper.venom.basicblock import IRBasicBlock, IRInstruction, IRLabel, IRLiteral | ||
from vyper.venom.passes.base_pass import IRPass | ||
|
||
|
||
class LowerDloadPass(IRPass): | ||
""" | ||
Lower dload and dloadbytes instructions | ||
""" | ||
|
||
def run_pass(self): | ||
for bb in self.function.get_basic_blocks(): | ||
self._handle_bb(bb) | ||
self.analyses_cache.invalidate_analysis(LivenessAnalysis) | ||
self.analyses_cache.invalidate_analysis(DFGAnalysis) | ||
|
||
def _handle_bb(self, bb: IRBasicBlock): | ||
fn = bb.parent | ||
for idx, inst in enumerate(bb.instructions): | ||
if inst.opcode == "dload": | ||
(ptr,) = inst.operands | ||
var = fn.get_next_variable() | ||
bb.insert_instruction( | ||
IRInstruction("add", [ptr, IRLabel("code_end")], output=var), index=idx | ||
) | ||
idx += 1 | ||
dst = IRLiteral(MemoryPositions.FREE_VAR_SPACE) | ||
bb.insert_instruction( | ||
IRInstruction("codecopy", [IRLiteral(32), var, dst]), index=idx | ||
) | ||
|
||
inst.opcode = "mload" | ||
inst.operands = [dst] | ||
elif inst.opcode == "dloadbytes": | ||
_, src, _ = inst.operands | ||
code_ptr = fn.get_next_variable() | ||
bb.insert_instruction( | ||
IRInstruction("add", [src, IRLabel("code_end")], output=code_ptr), index=idx | ||
) | ||
inst.opcode = "codecopy" | ||
inst.operands[1] = code_ptr |
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