-
-
Notifications
You must be signed in to change notification settings - Fork 802
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This reverts commit a99ccf6.
- Loading branch information
Showing
2 changed files
with
48 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,46 @@ | ||
from vyper.venom.analysis.dfg import DFGAnalysis | ||
from vyper.venom.analysis.liveness import LivenessAnalysis | ||
from vyper.venom.basicblock import IRInstruction | ||
from vyper.venom.passes.base_pass import IRPass | ||
|
||
|
||
class StoreExpansionPass(IRPass): | ||
""" | ||
This pass expands variables to their uses though `store` instructions, | ||
reducing pressure on the stack scheduler | ||
""" | ||
|
||
def run_pass(self): | ||
dfg = self.analyses_cache.request_analysis(DFGAnalysis) | ||
|
||
for bb in self.function.get_basic_blocks(): | ||
for idx, inst in enumerate(bb.instructions): | ||
if inst.output is None: | ||
continue | ||
|
||
# print("ENTER", inst) | ||
self._process_inst(dfg, inst, idx) | ||
|
||
self.analyses_cache.invalidate_analysis(LivenessAnalysis) | ||
self.analyses_cache.invalidate_analysis(DFGAnalysis) | ||
|
||
def _process_inst(self, dfg, inst, idx): | ||
""" | ||
Process store instruction. If the variable is only used by a load instruction, | ||
forward the variable to the load instruction. | ||
""" | ||
var = inst.output | ||
uses = dfg.get_uses(var) | ||
|
||
insertion_idx = idx + 1 | ||
|
||
for use_inst in uses: | ||
if use_inst.parent != inst.parent: | ||
continue # improves codesize | ||
|
||
for i, operand in enumerate(use_inst.operands): | ||
if operand == var: | ||
new_var = self.function.get_next_variable() | ||
new_inst = IRInstruction("store", [var], new_var) | ||
inst.parent.insert_instruction(new_inst, insertion_idx) | ||
use_inst.operands[i] = new_var |