optimizer fixed 👍
This commit is contained in:
@@ -21,7 +21,7 @@ class Optimizer:
|
||||
self.rules: list[PeepholeRule] = []
|
||||
|
||||
def match_instruction(self, pattern: Instruction, instr: Instruction, bindings: Dict[str, str]) -> bool:
|
||||
#print(pattern.opcode == instr.opcode, instr.opcode, instr.operands, pattern.opcode)
|
||||
print(pattern.opcode == instr.opcode, instr.opcode, instr.operands, pattern.opcode)
|
||||
if pattern.opcode != instr.opcode:
|
||||
return False
|
||||
if len(pattern.operands) != len(instr.operands):
|
||||
@@ -37,6 +37,7 @@ class Optimizer:
|
||||
else:
|
||||
if p_op != i_op:
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
def match_window(self, patterns: List[Instruction], window: List[Instruction]) -> Union[Dict[str, str], None]:
|
||||
@@ -88,6 +89,7 @@ class Optimizer:
|
||||
matched = True
|
||||
break
|
||||
if not matched:
|
||||
print('next')
|
||||
i += 1
|
||||
|
||||
self.lines = [f"{line.opcode} {', '.join(line.operands)}\n" for line in self.lines]
|
||||
|
@@ -124,13 +124,13 @@ class X86_64Optimizer(Optimizer):
|
||||
|
||||
PeepholeRule(
|
||||
match=[
|
||||
Instruction("mov", ["a", "b"]),
|
||||
Instruction("mov", ["c", "d"]),
|
||||
Instruction("cmp", ["a", "d"])
|
||||
Instruction("mov", ["rax", "y"]),
|
||||
Instruction("mov", ["rbx", "x"]),
|
||||
Instruction("cmp", ["rax", "rbx"])
|
||||
],
|
||||
replace=[
|
||||
Instruction("mov", ["c", "d"]),
|
||||
Instruction("cmp", ["b", "c"])
|
||||
Instruction("mov", ["rax", "y"]),
|
||||
Instruction("cmp", ["rax", "x"])
|
||||
]
|
||||
)
|
||||
]
|
Reference in New Issue
Block a user