-
-
Notifications
You must be signed in to change notification settings - Fork 804
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat[venom]: add
extract_literals
pass (#4067)
extract `IRLiterals` which are instruction arguments; this reduces pressure on the stack scheduler because `_emit_input_operands` can cause stack storms when we hit `_stack_reorder`. by extracting them, we allow `DFTPass` to reorder literal emission in a more optimized way before even getting to `_emit_input_operands`
- Loading branch information
1 parent
7b0ee5f
commit bb9129a
Showing
2 changed files
with
39 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
from vyper.venom.analysis.dfg import DFGAnalysis | ||
from vyper.venom.analysis.liveness import LivenessAnalysis | ||
from vyper.venom.basicblock import IRInstruction, IRLiteral | ||
from vyper.venom.passes.base_pass import IRPass | ||
|
||
|
||
class ExtractLiteralsPass(IRPass): | ||
""" | ||
This pass extracts literals so that they can be reordered by the DFT pass | ||
""" | ||
|
||
def run_pass(self): | ||
for bb in self.function.get_basic_blocks(): | ||
self._process_bb(bb) | ||
|
||
self.analyses_cache.invalidate_analysis(DFGAnalysis) | ||
self.analyses_cache.invalidate_analysis(LivenessAnalysis) | ||
|
||
def _process_bb(self, bb): | ||
i = 0 | ||
while i < len(bb.instructions): | ||
inst = bb.instructions[i] | ||
if inst.opcode == "store": | ||
i += 1 | ||
continue | ||
|
||
for j, op in enumerate(inst.operands): | ||
# first operand to log is magic | ||
if inst.opcode == "log" and j == 0: | ||
continue | ||
|
||
if isinstance(op, IRLiteral): | ||
var = self.function.get_next_variable() | ||
to_insert = IRInstruction("store", [op], var) | ||
bb.insert_instruction(to_insert, index=i) | ||
inst.operands[j] = var | ||
i += 1 |