Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions seal5/backends/llvmir/writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ def main():

assert out_path.is_dir(), "Expecting output directory when using --splitted"
for set_name, set_def in model_obj.sets.items():
if len(set_def.instructions) == 0:
continue
xlen = set_def.xlen
metrics["n_sets"] += 1
ext_settings = set_def.settings
Expand Down
2 changes: 2 additions & 0 deletions seal5/backends/patterngen/writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ def main():

assert out_path.is_dir(), "Expecting output directory when using --splitted"
for set_name, set_def in model_obj.sets.items():
if len(set_def.instructions) == 0:
continue
xlen = set_def.xlen
artifacts[set_name] = []
metrics["n_sets"] += 1
Expand Down
4 changes: 3 additions & 1 deletion seal5/backends/report/properties/writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ def main():
# print("model", model)
for set_name, set_def in model_obj.sets.items():
# print("set_name", set_name)
if len(set_def.instructions) == 0:
continue
xlen = set_def.xlen
model = top_level.stem

Expand Down Expand Up @@ -104,7 +106,7 @@ def detect_opcode(instr_def): # TODO: move to transform and store as attr
# "48bit2": 0b10111,
"BRANCH": 0b11000,
"JALR": 0b11001,
# "reserved": 0b11010,
"reserved": 0b11010,
"JAL": 0b11011,
"SYSTEM": 0b11100,
"OP-P": 0b11101,
Expand Down
2 changes: 2 additions & 0 deletions seal5/backends/report/status/writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ def get_status(filtered_metrics, instr_name, invert: bool = False):
model_obj = load_model(top_level, compat=args.compat)

for set_name, set_def in model_obj.sets.items():
if len(set_def.instructions) == 0:
continue
xlen = set_def.xlen
model = top_level.stem
filtered_metrics = process_metrics(settings, model=model)
Expand Down
2 changes: 2 additions & 0 deletions seal5/backends/report/test_results/writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,8 @@ def filter_tests_by_set(tests, set_def, settings, model_name):
model_obj = load_model(top_level, compat=args.compat)

for set_name, set_def in model_obj.sets.items():
if len(set_def.instructions) == 0:
continue
xlen = set_def.xlen
model_name = top_level.stem

Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
def Feature${predicate} : RISCVExperimentalExtension<"${arch}", ${major}, ${minor}, "'${feature}' (${description})">;
def Feature${predicate} : RISCVExperimentalExtension<"${arch}", ${major}, ${minor}, "'${feature}' (${description})", ${implies}>;
def Has${predicate} : Predicate<"Subtarget->has${predicate}()">, AssemblerPredicate<(any_of Feature${predicate}), "'${feature}' (${description})">;
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
def Feature${predicate} : RISCVExtension<"${arch}", ${major}, ${minor}, "'${feature}' (${description})">;
def Feature${predicate} : RISCVExtension<"${arch}", ${major}, ${minor}, "'${feature}' (${description})", ${implies}>;
def Has${predicate} : Predicate<"Subtarget->has${predicate}()">, AssemblerPredicate<(any_of Feature${predicate}), "'${feature}' (${description})">;
26 changes: 20 additions & 6 deletions seal5/backends/riscv_features/writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@
logger = logging.getLogger("riscv_features")


def gen_riscv_features_str(name: str, ext_settings: ExtensionsSettings, llvm_settings: LLVMSettings):
def gen_riscv_features_str(name: str, ext_settings: ExtensionsSettings, llvm_settings: LLVMSettings, all_sets):
"""Generate features string for LLVM patch."""
requires = ext_settings.requires
# requires = ext_settings.requires
implies = ext_settings.requires
feature = ext_settings.get_feature(name=name)
arch_ = ext_settings.get_arch(name=name)
description = ext_settings.get_description(name=name)
Expand All @@ -37,8 +38,15 @@
experimental = ext_settings.experimental
vendor = ext_settings.vendor

if requires:
raise NotImplementedError
implied_features = set()
if implies:
for implied in implies:
assert implied in all_sets
implied_set_def = all_sets[implied]
implied_ext_settings = implied_set_def.settings
implied_feature = implied_ext_settings.get_feature(name=implied)
# implied_features.add(f"Feature{implied_feature}")
implied_features.add(f"FeatureExt{implied_feature}") # TODO: check missing Ext?

legacy = True
slim = False
Expand Down Expand Up @@ -70,7 +78,13 @@
assert feature.lower() == arch_, "LLVM 20 requires matching arch and feature names"
assert predicate == (f"Vendor{feature}" if vendor else f"StdExt{feature}")
content_text = content_template.render(
predicate=predicate, feature=feature, arch=arch_, description=description, major=major, minor=minor
predicate=predicate,
feature=feature,
arch=arch_,
description=description,
major=major,
minor=minor,
implies="[" + ", ".join(implied_features) + "]",
)
return content_text + "\n"

Expand Down Expand Up @@ -130,7 +144,7 @@
continue
metrics["n_success"] += 1
metrics["success_sets"].append(set_name)
content += gen_riscv_features_str(set_name, ext_settings, llvm_settings)
content += gen_riscv_features_str(set_name, ext_settings, llvm_settings, model["sets"])

Check failure on line 147 in seal5/backends/riscv_features/writer.py

View workflow job for this annotation

GitHub Actions / Flake8

seal5/backends/riscv_features/writer.py#L147

Undefined name 'model' (F821)
content = content.rstrip()
if len(content) > 0:
with open(out_path, "w", encoding="utf-8") as f:
Expand Down
2 changes: 2 additions & 0 deletions seal5/backends/riscv_instr_info/writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,8 @@ def main():
content = ""
# errs = []
for set_name, set_def in model_obj.sets.items():
if len(set_def.instructions) == 0:
continue
metrics["n_sets"] += 1
set_name_lower = set_name.lower()
artifacts[set_name] = []
Expand Down
22 changes: 15 additions & 7 deletions seal5/backends/yaml/writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,23 @@ def main():
data = {"extensions": {}}
for set_name, set_def in model_obj.sets.items():
# print("set", set_def)
is_group_set = False
if len(set_def.instructions) == 0:
assert len(set_def.extension) > 0
is_group_set = True
set_data = {"instructions": []}
riscv_data = {}
riscv_data["xlen"] = set_def.xlen
set_data["riscv"] = riscv_data
llvm_imm_types = set()
for instr in set_def.instructions.values():
set_data["instructions"].append(instr.name)
llvm_imm_types.update(instr.llvm_imm_types)
set_data["required_imm_types"] = list(llvm_imm_types)
if is_group_set:
# set_data["implies"] = set_def.extension
set_data["requires"] = set_def.extension
else:
riscv_data["xlen"] = set_def.xlen
set_data["riscv"] = riscv_data
llvm_imm_types = set()
for instr in set_def.instructions.values():
set_data["instructions"].append(instr.name)
llvm_imm_types.update(instr.llvm_imm_types)
set_data["required_imm_types"] = list(llvm_imm_types)
data["extensions"][set_name] = set_data
data = {"models": {model_name: data}}
with open(out_path, "w", encoding="utf-8") as f:
Expand Down
4 changes: 3 additions & 1 deletion seal5/frontends/coredsl2_seal5/architecture_model_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def visitInstruction_set(self, ctx: CoreDSL2Parser.Instruction_setContext):
raise M2ValueError("unexpected item encountered")

# instantiate M2-ISA-R object
i = arch.InstructionSet(name, extension, constants, memories, functions, instructions)
i = arch.InstructionSet(name, extension, constants, memories, functions, instructions, {})

if name in self._instruction_sets:
raise M2DuplicateError(f'instruction set "{name}" already defined')
Expand Down Expand Up @@ -184,6 +184,8 @@ def visitInstruction(self, ctx: CoreDSL2Parser.InstructionContext):
assembly = ctx.assembly.text.replace('"', "") if ctx.assembly is not None else None
mnemonic = ctx.mnemonic.text.replace('"', "") if ctx.mnemonic is not None else None

# TODO: add parsing of operands
# i = arch.Instruction(ctx.name.text, attributes, {}, encoding, mnemonic, assembly, ctx.behavior, None)
i = arch.Instruction(ctx.name.text, attributes, encoding, mnemonic, assembly, ctx.behavior, None)
self._instr_classes.add(i.size)

Expand Down
7 changes: 6 additions & 1 deletion seal5/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,14 @@ def __init__(
memories: "dict[str, Memory]",
functions: "dict[str, Function]",
instructions: "dict[tuple[int, int], Instruction]",
unencoded_instructions: "dict[str, Instruction]",
intrinsics: "dict[str, Seal5Intrinsic]",
constraints: "dict[str, Seal5Constraint]",
aliases: "dict[str, Seal5Alias]",
registers: "dict[str, Seal5Register]",
register_groups: "dict[str, Seal5RegisterGroup]",
):
super().__init__(name, extension, constants, memories, functions, instructions)
super().__init__(name, extension, constants, memories, functions, instructions, unencoded_instructions)

self.intrinsics = intrinsics
self.constraints = constraints
Expand Down Expand Up @@ -312,6 +313,10 @@ def __init__(
operands: "dict[str, Seal5Operand]",
):
del operands # TODO: use
function_info = None
# TODO: use user-defined operands
# operands_ = {} # TODO
# super().__init__(name, attributes, operands_, encoding, mnemonic, assembly, operation, function_info)
super().__init__(name, attributes, encoding, mnemonic, assembly, operation, function_info)
self.constraints = constraints
self.operands = {}
Expand Down
2 changes: 2 additions & 0 deletions seal5/pass_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -1612,6 +1612,8 @@ def convert_llvmir_to_gmir(
if insn_names is None:
logger.warning("Skipping empty set %s", set_name)
continue
if len(insn_names) == 0 and len(ext_settings.requires) > 0:
continue
assert len(insn_names) > 0, f"No instructions found in set: {set_name}"
# TODO: populate model in yaml backend!
for insn_name in insn_names:
Expand Down
38 changes: 0 additions & 38 deletions seal5/resources/patches/llvm/insert_markers_llvm18.patch
Original file line number Diff line number Diff line change
@@ -1,41 +1,3 @@
diff --git a/clang/include/clang/Basic/BuiltinsRISCV.def b/clang/include/clang/Basic/BuiltinsRISCV.def
--- a/clang/include/clang/Basic/BuiltinsRISCV.def
+++ b/clang/include/clang/Basic/BuiltinsRISCV.def
@@ -89,5 +89,8 @@ TARGET_BUILTIN(__builtin_riscv_sm3p1, "UiUi", "nc", "zksh")
TARGET_BUILTIN(__builtin_riscv_ntl_load, "v.", "t", "zihintntl")
TARGET_BUILTIN(__builtin_riscv_ntl_store, "v.", "t", "zihintntl")

+// BuiltinsRISCV.def - builtins_riscv - INSERTION_START
+// BuiltinsRISCV.def - builtins_riscv - INSERTION_END
+
#undef BUILTIN
#undef TARGET_BUILTIN
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -21243,6 +21243,9 @@ Value *CodeGenFunction::EmitRISCVBuiltinExpr(unsigned BuiltinID,
ID = Intrinsic::riscv_sha256sum1;
break;

+// CGBuiltin.cpp - cg_builtin - INSERTION_START
+// CGBuiltin.cpp - cg_builtin - INSERTION_END
+
// Zksed
case RISCV::BI__builtin_riscv_sm4ks:
ID = Intrinsic::riscv_sm4ks;
diff --git a/llvm/include/llvm/IR/IntrinsicsRISCV.td b/llvm/include/llvm/IR/IntrinsicsRISCV.td
--- a/llvm/include/llvm/IR/IntrinsicsRISCV.td
+++ b/llvm/include/llvm/IR/IntrinsicsRISCV.td
@@ -1882,6 +1882,9 @@ let TargetPrefix = "riscv" in {
// Zvksh
def int_riscv_vsm3c : RISCVBinaryAAXUnMaskedZvk<IsVI=1>;
def int_riscv_vsm3me : RISCVBinaryAAXUnMasked;
+
+// IntrinsicsRISCV.td - intrinsics_riscv - INSERTION_START
+// IntrinsicsRISCV.td - intrinsics_riscv - INSERTION_END
} // TargetPrefix = "riscv"

// Vendor extensions
diff --git a/llvm/include/llvm/InitializePasses.h b/llvm/include/llvm/InitializePasses.h
--- a/llvm/include/llvm/InitializePasses.h
+++ b/llvm/include/llvm/InitializePasses.h
Expand Down
Loading