Flags into operand class

This commit is contained in:
stefandesouza
2024-02-24 12:11:52 +01:00
parent c2bd484170
commit fa95293cb0
3 changed files with 61 additions and 40 deletions

16
osaca/parser/flag.py Normal file
View File

@@ -0,0 +1,16 @@
#!/usr/bin/env python3
from osaca.parser.operand import Operand
class FlagOperand(Operand):
def __init__(self, name=None, source=False, destination=False):
super().__init__(name, source, destination)
def __str__(self):
return (
f"Flag(name={self._name}, source={self._source}, relocation={self._destination})"
)
def __repr__(self):
return self.__str__()

View File

@@ -12,13 +12,14 @@ from pathlib import Path
import ruamel.yaml import ruamel.yaml
from osaca import __version__, utils from osaca import __version__, utils
from osaca.parser import ParserX86ATT from osaca.parser import ParserX86ATT
from osaca.parser.instruction_form import instructionForm from osaca.parser.instruction_form import InstructionForm
from osaca.parser.operand import Operand from osaca.parser.operand import Operand
from osaca.parser.memory import MemoryOperand from osaca.parser.memory import MemoryOperand
from osaca.parser.register import RegisterOperand from osaca.parser.register import RegisterOperand
from osaca.parser.immediate import ImmediateOperand from osaca.parser.immediate import ImmediateOperand
from osaca.parser.identifier import IdentifierOperand from osaca.parser.identifier import IdentifierOperand
from osaca.parser.condition import ConditionOperand from osaca.parser.condition import ConditionOperand
from osaca.parser.flag import FlagOperand
class MachineModel(object): class MachineModel(object):
@@ -71,8 +72,8 @@ class MachineModel(object):
if self._path in MachineModel._runtime_cache and not lazy: if self._path in MachineModel._runtime_cache and not lazy:
self._data = MachineModel._runtime_cache[self._path] self._data = MachineModel._runtime_cache[self._path]
# check if file is cached # check if file is cached
cached = self._get_cached(self._path) if not lazy else False # cached = self._get_cached(self._path) if not lazy else False
if cached: if False:
self._data = cached self._data = cached
else: else:
yaml = self._create_yaml_object() yaml = self._create_yaml_object()
@@ -119,8 +120,8 @@ class MachineModel(object):
iform["hidden_operands"] = new_operands iform["hidden_operands"] = new_operands
# Change dict iform style to class style # Change dict iform style to class style
new_iform = instructionForm( new_iform = InstructionForm(
instruction_id=iform["name"].upper() if "name" in iform else None, mnemonic=iform["name"].upper() if "name" in iform else None,
operands_id=iform["operands"] if "operands" in iform else [], operands_id=iform["operands"] if "operands" in iform else [],
hidden_operands=iform["hidden_operands"] hidden_operands=iform["hidden_operands"]
if "hidden_operands" in iform if "hidden_operands" in iform
@@ -134,7 +135,7 @@ class MachineModel(object):
uops=iform["uops"] if "uops" in iform else None, uops=iform["uops"] if "uops" in iform else None,
port_pressure=iform["port_pressure"] if "port_pressure" in iform else None, port_pressure=iform["port_pressure"] if "port_pressure" in iform else None,
operation=iform["operation"] if "operation" in iform else None, operation=iform["operation"] if "operation" in iform else None,
breaks_dep=iform["breaks_dependency_on_equal_operands"] breaks_dependency_on_equal_operands=iform["breaks_dependency_on_equal_operands"]
if "breaks_dependency_on_equal_operands" in iform if "breaks_dependency_on_equal_operands" in iform
else False, else False,
semantic_operands=iform["semantic_operands"] semantic_operands=iform["semantic_operands"]
@@ -158,10 +159,10 @@ class MachineModel(object):
for m in self._data["load_throughput"]: for m in self._data["load_throughput"]:
new_throughputs.append( new_throughputs.append(
MemoryOperand( MemoryOperand(
base_id=m["base"], base=m["base"],
offset_ID=m["offset"], offset=m["offset"],
scale_id=m["scale"], scale=m["scale"],
index_id=m["index"], index=m["index"],
port_pressure=m["port_pressure"], port_pressure=m["port_pressure"],
dst=m["dst"] if "dst" in m else None, dst=m["dst"] if "dst" in m else None,
) )
@@ -173,10 +174,10 @@ class MachineModel(object):
for m in self._data["store_throughput"]: for m in self._data["store_throughput"]:
new_throughputs.append( new_throughputs.append(
MemoryOperand( MemoryOperand(
base_id=m["base"], base=m["base"],
offset_ID=m["offset"], offset=m["offset"],
scale_id=m["scale"], scale=m["scale"],
index_id=m["index"], index=m["index"],
port_pressure=m["port_pressure"], port_pressure=m["port_pressure"],
) )
) )
@@ -188,7 +189,7 @@ class MachineModel(object):
new_operands.append( new_operands.append(
RegisterOperand( RegisterOperand(
name=o["name"] if "name" in o else None, name=o["name"] if "name" in o else None,
prefix_id=o["prefix"] if "prefix" in o else None, prefix=o["prefix"] if "prefix" in o else None,
shape=o["shape"] if "shape" in o else None, shape=o["shape"] if "shape" in o else None,
mask=o["mask"] if "mask" in o else False, mask=o["mask"] if "mask" in o else False,
pre_indexed=o["pre_indexed"] if "pre_indexed" in o else False, pre_indexed=o["pre_indexed"] if "pre_indexed" in o else False,
@@ -203,14 +204,14 @@ class MachineModel(object):
if isinstance(o["index"], dict): if isinstance(o["index"], dict):
o["index"] = RegisterOperand( o["index"] = RegisterOperand(
name=o["index"]["name"], name=o["index"]["name"],
prefix_id=o["index"]["prefix"] if "prefix" in o["index"] else None, prefix=o["index"]["prefix"] if "prefix" in o["index"] else None,
) )
new_operands.append( new_operands.append(
MemoryOperand( MemoryOperand(
base_id=o["base"], base=o["base"],
offset_ID=o["offset"], offset=o["offset"],
index_id=o["index"], index=o["index"],
scale_id=o["scale"], scale=o["scale"],
source=o["source"] if "source" in o else False, source=o["source"] if "source" in o else False,
destination=o["destination"] if "destination" in o else False, destination=o["destination"] if "destination" in o else False,
pre_indexed=o["pre_indexed"] if "pre_indexed" in o else False, pre_indexed=o["pre_indexed"] if "pre_indexed" in o else False,
@@ -241,6 +242,14 @@ class MachineModel(object):
destination=o["destination"] if "destination" in o else False, destination=o["destination"] if "destination" in o else False,
) )
) )
elif o["class"] == "flag":
new_operands.append(
FlagOperand(
name=o["name"],
source=o["source"] if "source" in o else False,
destination=o["destination"] if "destination" in o else False,
)
)
else: else:
new_operands.append(o) new_operands.append(o)
@@ -310,7 +319,7 @@ class MachineModel(object):
# If it already exists. Overwrite information. # If it already exists. Overwrite information.
instr_data = self.get_instruction(instruction, operands) instr_data = self.get_instruction(instruction, operands)
if instr_data is None: if instr_data is None:
instr_data = instructionForm() instr_data = InstructionForm()
self._data["instruction_forms"].append(instr_data) self._data["instruction_forms"].append(instr_data)
self._data["instruction_forms_dict"][instruction].append(instr_data) self._data["instruction_forms_dict"][instruction].append(instr_data)
@@ -491,7 +500,7 @@ class MachineModel(object):
) )
yaml.dump({"load_throughput": formatted_load_throughput}, stream) yaml.dump({"load_throughput": formatted_load_throughput}, stream)
yaml.dump({"instruction_forms": formatted_instruction_forms}, stream) yaml.dump({"instruction_forms": formatted_instruction_forms }, stream)
""" """
if isinstance(stream, StringIO): if isinstance(stream, StringIO):
return stream.getvalue() return stream.getvalue()
@@ -612,15 +621,15 @@ class MachineModel(object):
if operand == "i": if operand == "i":
return ImmediateOperand(type_id="int") return ImmediateOperand(type_id="int")
elif operand in "wxbhsdq": elif operand in "wxbhsdq":
return RegisterOperand(prefix_id=operand) return RegisterOperand(prefix=operand)
elif operand.startswith("v"): elif operand.startswith("v"):
return RegisterOperand(prefix_id="v", shape=operand[1:2]) return RegisterOperand(prefix="v", shape=operand[1:2])
elif operand.startswith("m"): elif operand.startswith("m"):
return MemoryOperand( return MemoryOperand(
base_id="x" if "b" in operand else None, base="x" if "b" in operand else None,
offset_ID="imd" if "o" in operand else None, offset="imd" if "o" in operand else None,
index_id="gpr" if "i" in operand else None, index="gpr" if "i" in operand else None,
scale_id=8 if "s" in operand else 1, scale=8 if "s" in operand else 1,
pre_indexed=True if "r" in operand else False, pre_indexed=True if "r" in operand else False,
post_indexed=True if "p" in operand else False, post_indexed=True if "p" in operand else False,
) )
@@ -637,10 +646,10 @@ class MachineModel(object):
return ImmediateOperand(type_id="int") return ImmediateOperand(type_id="int")
elif operand.startswith("m"): elif operand.startswith("m"):
return MemoryOperand( return MemoryOperand(
base_id="gpr" if "b" in operand else None, base="gpr" if "b" in operand else None,
offset_ID="imd" if "o" in operand else None, offset="imd" if "o" in operand else None,
index_id="gpr" if "i" in operand else None, index="gpr" if "i" in operand else None,
scale_id=8 if "s" in operand else 1, scale=8 if "s" in operand else 1,
) )
else: else:
raise ValueError("Parameter {} is not a valid operand code".format(operand)) raise ValueError("Parameter {} is not a valid operand code".format(operand))

View File

@@ -13,6 +13,7 @@ from osaca.parser.memory import MemoryOperand
from osaca.parser.register import RegisterOperand from osaca.parser.register import RegisterOperand
from osaca.parser.immediate import ImmediateOperand from osaca.parser.immediate import ImmediateOperand
from osaca.parser.operand import Operand from osaca.parser.operand import Operand
from osaca.parser.flag import FlagOperand
class KernelDG(nx.DiGraph): class KernelDG(nx.DiGraph):
@@ -300,8 +301,7 @@ class KernelDG(nx.DiGraph):
if self.is_written(dst, instr_form): if self.is_written(dst, instr_form):
break break
if ( if (
not isinstance(dst, Operand) isinstance(dst, FlagOperand)
and ("flag" in dst or dst["class"] == "flag" if "class" in dst else False)
and flag_dependencies and flag_dependencies
): ):
# read of flag # read of flag
@@ -381,9 +381,7 @@ class KernelDG(nx.DiGraph):
): ):
if isinstance(src, RegisterOperand): if isinstance(src, RegisterOperand):
is_read = self.parser.is_reg_dependend_of(register, src) or is_read is_read = self.parser.is_reg_dependend_of(register, src) or is_read
if not isinstance(src, Operand) and ( if isinstance(src, FlagOperand):
"flag" in src or src["class"] == "flag" if "class" in src else False
):
is_read = self.parser.is_flag_dependend_of(register, src) or is_read is_read = self.parser.is_flag_dependend_of(register, src) or is_read
if isinstance(src, MemoryOperand): if isinstance(src, MemoryOperand):
if src.base is not None: if src.base is not None:
@@ -486,9 +484,7 @@ class KernelDG(nx.DiGraph):
): ):
if isinstance(dst, RegisterOperand): if isinstance(dst, RegisterOperand):
is_written = self.parser.is_reg_dependend_of(register, dst) or is_written is_written = self.parser.is_reg_dependend_of(register, dst) or is_written
if not isinstance(dst, Operand) and ( if isinstance(dst, FlagOperand):
"flag" in dst or dst["class"] == "flag" if "class" in dst else False
):
is_written = self.parser.is_flag_dependend_of(register, dst) or is_written is_written = self.parser.is_flag_dependend_of(register, dst) or is_written
if isinstance(dst, MemoryOperand): if isinstance(dst, MemoryOperand):
if dst.pre_indexed or dst.post_indexed: if dst.pre_indexed or dst.post_indexed: