-
-
Notifications
You must be signed in to change notification settings - Fork 819
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
extract IRLiterals which are instruction arguments; this reduces pressure on the stack scheduler
- Loading branch information
1 parent
3371956
commit 6cf7b6b
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.utils import OrderedSet | ||
Check notice Code scanning / CodeQL Unused import Note
Import of 'OrderedSet' is not used.
|
||
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 |