Skip to content

Commit

Permalink
fix mattr handling
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilippvK committed Aug 23, 2024
1 parent 4dfafa4 commit 6034485
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 15 deletions.
4 changes: 2 additions & 2 deletions seal5/backends/llvmir/writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

from seal5.tools import cdsl2llvm
from seal5.model import Seal5InstrAttribute
from seal5.riscv_utils import build_mattr, get_riscv_defaults
from seal5.riscv_utils import build_riscv_mattr, get_riscv_defaults

logger = logging.getLogger("llvmir_behavior_writer")

Expand Down Expand Up @@ -130,7 +130,7 @@ def main():
arch_ = ext_settings.get_arch(name=set_name)
if arch is not None:
features.append(arch_)
mattr = build_mattr(features, xlen)
mattr = build_riscv_mattr(features, xlen)

install_dir = os.getenv("CDSL2LLVM_DIR", None)
assert install_dir is not None
Expand Down
4 changes: 2 additions & 2 deletions seal5/backends/patterngen/writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from seal5.tools import cdsl2llvm
from seal5.index import write_index_yaml, File, NamedPatch
from seal5.model import Seal5InstrAttribute
from seal5.riscv_utils import build_mattr, get_riscv_defaults
from seal5.riscv_utils import build_riscv_mattr, get_riscv_defaults

logger = logging.getLogger("patterngen_tablegen_writer")

Expand Down Expand Up @@ -122,7 +122,7 @@ def main():
if arch_ is not None:
features.append(arch_)

mattr = build_mattr(features, xlen)
mattr = build_riscv_mattr(features, xlen)

def process_instrunction(instr_def, set_name, set_dir, mattr, predicate, xlen):
includes_ = []
Expand Down
4 changes: 2 additions & 2 deletions seal5/pass_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from seal5.passes import Seal5Pass, PassType, PassScope, PassManager, PassResult
from seal5.types import PatchStage
from seal5.settings import Seal5Settings, PatchSettings
from seal5.riscv_utils import build_mattr, get_riscv_defaults
from seal5.riscv_utils import build_riscv_mattr, get_riscv_defaults

logger = get_logger()

Expand Down Expand Up @@ -1376,7 +1376,7 @@ def convert_llvmir_to_gmir(
features = [*default_features]
if arch_ is not None:
features.append(arch_)
mattr = build_mattr(default_features, xlen)
mattr = build_riscv_mattr(default_features, xlen)
if insn_names is None:
logger.warning("Skipping empty set %s", set_name)
continue
Expand Down
6 changes: 4 additions & 2 deletions seal5/riscv_utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from typing import Optional

from seal5.settings import RISCVSettings

def get_riscv_defaults(riscv_settings):

def get_riscv_defaults(riscv_settings: Optional[RISCVSettings] = None):
default_features = ["+m", "+fast-unaligned-access"]
default_xlen = None
if riscv_settings:
Expand All @@ -14,7 +16,7 @@ def get_riscv_defaults(riscv_settings):
return default_features, default_xlen


def build_mattr(features, xlen: Optional[int] = None):
def build_riscv_mattr(features, xlen: Optional[int] = None):
mattrs = []

def fix_prefix(x):
Expand Down
14 changes: 7 additions & 7 deletions seal5/tools/cdsl2llvm.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from seal5.settings import PatchSettings
from seal5.types import PatchStage
from seal5.index import File, Directory, NamedPatch, write_index_yaml
from seal5.riscv_utils import build_riscv_mattr, get_riscv_defaults
from seal5 import utils

logger = get_logger()
Expand Down Expand Up @@ -164,12 +165,12 @@ def run_pattern_gen(
pattern_gen_args.extend(["-p", preds_str])

if mattr is None:
attrs = ["+m", "+fast-unaligned-access"]
features, _ = get_riscv_defaults()
if ext:
ext_ = ext.lower()
ext_ = ext_.replace("std", "").replace("vendor", "").replace("ext", "")
attrs.append(f"+{ext_}")
mattr = ",".join(attrs)
features.append(f"+{ext_}")
mattr = build_riscv_mattr(features, xlen=xlen)

if mattr:
pattern_gen_args.extend(["--mattr2", mattr])
Expand Down Expand Up @@ -286,10 +287,9 @@ def convert_ll_to_gmir(
):
"""Convert LLVM-IR file to GMIR file."""
if mattr is None:
attrs = ["+m", "+fast-unaligned-access"]
if xlen == 64 and "+64bit" not in attrs:
attrs.append("+64bit")
mattr = ",".join(attrs)
input(">>>")
features, _ = get_riscv_defaults()
mattr = build_riscv_mattr(features, xlen=xlen)

assert xlen is not None, "Needs XLEN"

Expand Down

0 comments on commit 6034485

Please sign in to comment.